• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23 
24 import android.app.Instrumentation;
25 import android.server.wm.TestJournalProvider.TestJournalContainer;
26 import android.server.wm.backlegacyapp.Components;
27 import android.view.KeyEvent;
28 
29 import androidx.test.platform.app.InstrumentationRegistry;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 
34 /**
35  * Integration test for back navigation legacy mode
36  */
37 public class BackNavigationLegacyTest extends ActivityManagerTestBase {
38     private Instrumentation mInstrumentation;
39 
40     @Before
setup()41     public void setup() {
42         mInstrumentation = InstrumentationRegistry.getInstrumentation();
43 
44     }
45 
46     @Test
receiveOnBackPressed()47     public void receiveOnBackPressed() {
48         TestJournalContainer.start();
49         launchActivity(BACK_LEGACY);
50         mWmState.assertActivityDisplayed(BACK_LEGACY);
51         waitAndAssertActivityState(BACK_LEGACY, STATE_RESUMED, "Activity should be resumed");
52         mInstrumentation.waitForIdleSync();
53         mInstrumentation.getUiAutomation().syncInputTransactions();
54         TouchHelper.injectKey(KeyEvent.KEYCODE_BACK, false /* longpress */, true /* sync */);
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