1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.design.widget; 18 19import static android.support.design.testutils.AppBarLayoutMatchers.isCollapsed; 20import static android.support.design.testutils.SwipeUtils.swipeUp; 21import static android.support.design.testutils.TestUtilsMatchers.hasZ; 22import static android.support.test.espresso.Espresso.onView; 23import static android.support.test.espresso.assertion.ViewAssertions.matches; 24import static android.support.test.espresso.matcher.ViewMatchers.withId; 25 26import android.support.design.test.R; 27import android.support.design.testutils.ActivityUtils; 28import android.support.test.filters.LargeTest; 29 30import org.junit.Before; 31import org.junit.Test; 32 33@LargeTest 34public class AppBarWithCollapsingToolbarStateRestoreTest 35 extends BaseInstrumentationTestCase<AppBarLayoutCollapsePinTestActivity> { 36 37 private AppBarLayoutCollapsePinTestActivity mActivity; 38 39 public AppBarWithCollapsingToolbarStateRestoreTest() { 40 super(AppBarLayoutCollapsePinTestActivity.class); 41 } 42 43 @Before 44 public void setup() { 45 mActivity = mActivityTestRule.getActivity(); 46 } 47 48 @Test 49 public void testRecreateAndRestore() throws Throwable { 50 final AppBarLayout appBar = (AppBarLayout) mActivity.findViewById(R.id.app_bar); 51 52 // Swipe up and collapse the AppBarLayout 53 onView(withId(R.id.coordinator_layout)) 54 .perform(swipeUp( 55 appBar.getLeft() + (appBar.getWidth() / 2), 56 appBar.getBottom() + 20, 57 appBar.getHeight())); 58 onView(withId(R.id.app_bar)) 59 .check(matches(hasZ())) 60 .check(matches(isCollapsed())); 61 62 mActivity = ActivityUtils.recreateActivity(mActivityTestRule, mActivity); 63 ActivityUtils.waitForExecution(mActivityTestRule); 64 65 // And check that the app bar still is restored correctly 66 onView(withId(R.id.app_bar)) 67 .check(matches(hasZ())) 68 .check(matches(isCollapsed())); 69 } 70} 71