1 /* 2 * Copyright (C) 2022 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 package android.server.wm; 17 18 import static android.server.wm.WindowManagerState.STATE_RESUMED; 19 import static android.server.wm.backlegacyapp.Components.BACK_LEGACY; 20 import static android.view.Display.DEFAULT_DISPLAY; 21 22 import static org.junit.Assert.assertFalse; 23 import static org.junit.Assert.assertTrue; 24 25 import android.platform.test.annotations.Presubmit; 26 import android.server.wm.TestJournalProvider.TestJournalContainer; 27 import android.server.wm.backlegacyapp.Components; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 32 /** 33 * Integration test for back navigation legacy mode 34 * 35 * <p>Build/Install/Run: 36 * atest CtsWindowManagerDeviceTestCases:BackNavigationLegacyGestureTest 37 */ 38 @Presubmit 39 public class BackNavigationLegacyGestureTest extends ActivityManagerTestBase { 40 private static final int ACTIVITY_FOCUS_TIMEOUT_MS = 3000; 41 @Before setup()42 public void setup() throws Exception { 43 super.setUp(); 44 enableAndAssumeGestureNavigationMode(); 45 } 46 47 @Test receiveOnBackPressed()48 public void receiveOnBackPressed() { 49 TestJournalContainer.start(); 50 launchActivity(BACK_LEGACY); 51 mWmState.assertActivityDisplayed(BACK_LEGACY); 52 waitAndAssertActivityState(BACK_LEGACY, STATE_RESUMED, "Activity should be resumed"); 53 waitForActivityFocused(ACTIVITY_FOCUS_TIMEOUT_MS, BACK_LEGACY); 54 triggerBackEventByGesture(DEFAULT_DISPLAY); 55 waitForIdle(); 56 assertTrue("OnBackPressed should have been called", 57 TestJournalContainer.get(BACK_LEGACY).extras.getBoolean( 58 Components.KEY_ON_BACK_PRESSED_CALLED)); 59 assertFalse("OnBackInvoked should not have been called", 60 TestJournalContainer.get(BACK_LEGACY).extras.getBoolean( 61 Components.KEY_ON_BACK_INVOKED_CALLED)); 62 } 63 } 64