Home | History | Annotate | Download | only in wm
      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 
     17 package com.android.server.wm;
     18 
     19 import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
     20 import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE;
     21 import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
     22 import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
     23 import static org.junit.Assert.assertEquals;
     24 
     25 import android.content.Context;
     26 import android.platform.test.annotations.Presubmit;
     27 import android.support.test.InstrumentationRegistry;
     28 import android.support.test.filters.SmallTest;
     29 import android.support.test.runner.AndroidJUnit4;
     30 
     31 import org.junit.Before;
     32 import org.junit.Rule;
     33 import org.junit.Test;
     34 import org.junit.runner.RunWith;
     35 
     36 /**
     37  * Test class for {@link AppTransition}.
     38  *
     39  * atest AppTransitionTests
     40  */
     41 @SmallTest
     42 @Presubmit
     43 @RunWith(AndroidJUnit4.class)
     44 public class AppTransitionTests {
     45 
     46     @Rule
     47     public final WindowManagerServiceRule mRule = new WindowManagerServiceRule();
     48     private WindowManagerService mWm;
     49 
     50     @Before
     51     public void setUp() throws Exception {
     52         final Context context = InstrumentationRegistry.getTargetContext();
     53         mWm = mRule.getWindowManagerService();
     54     }
     55 
     56     @Test
     57     public void testKeyguardOverride() throws Exception {
     58         mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */);
     59         mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */);
     60         assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mWm.mAppTransition.getAppTransition());
     61     }
     62 
     63     @Test
     64     public void testKeyguardKeep() throws Exception {
     65         mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */);
     66         mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */);
     67         assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mWm.mAppTransition.getAppTransition());
     68     }
     69 
     70     @Test
     71     public void testForceOverride() throws Exception {
     72         mWm.prepareAppTransition(TRANSIT_KEYGUARD_UNOCCLUDE, false /* alwaysKeepCurrent */);
     73         mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */,
     74                 0 /* flags */, true /* forceOverride */);
     75         assertEquals(TRANSIT_ACTIVITY_OPEN, mWm.mAppTransition.getAppTransition());
     76     }
     77 
     78     @Test
     79     public void testCrashing() throws Exception {
     80         mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */);
     81         mWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */);
     82         assertEquals(TRANSIT_CRASHING_ACTIVITY_CLOSE, mWm.mAppTransition.getAppTransition());
     83     }
     84 
     85     @Test
     86     public void testKeepKeyguard_withCrashing() throws Exception {
     87         mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */);
     88         mWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */);
     89         assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mWm.mAppTransition.getAppTransition());
     90     }
     91 }
     92