Home | History | Annotate | Download | only in policy
      1 /*
      2  * Copyright (C) 2018 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.internal.policy;
     18 
     19 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
     20 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
     21 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
     22 
     23 import static org.hamcrest.Matchers.is;
     24 import static org.junit.Assert.assertThat;
     25 
     26 import android.content.Context;
     27 import android.platform.test.annotations.Presubmit;
     28 import android.support.test.InstrumentationRegistry;
     29 import android.support.test.filters.SmallTest;
     30 import android.support.test.runner.AndroidJUnit4;
     31 import android.view.ActionMode;
     32 import android.view.ContextThemeWrapper;
     33 
     34 import com.android.frameworks.coretests.R;
     35 
     36 import org.junit.Before;
     37 import org.junit.Test;
     38 import org.junit.runner.RunWith;
     39 
     40 /**
     41  * Tests {@link PhoneWindow}'s {@link ActionMode} related methods.
     42  */
     43 @SmallTest
     44 @Presubmit
     45 @RunWith(AndroidJUnit4.class)
     46 public final class PhoneWindowTest {
     47 
     48     private PhoneWindow mPhoneWindow;
     49     private Context mContext;
     50 
     51     @Before
     52     public void setUp() throws Exception {
     53         mContext = InstrumentationRegistry.getContext();
     54     }
     55 
     56     @Test
     57     public void layoutInDisplayCutoutMode_unset() throws Exception {
     58         createPhoneWindowWithTheme(R.style.LayoutInDisplayCutoutModeUnset);
     59         installDecor();
     60 
     61         assertThat(mPhoneWindow.getAttributes().layoutInDisplayCutoutMode,
     62                 is(LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT));
     63     }
     64 
     65     @Test
     66     public void layoutInDisplayCutoutMode_default() throws Exception {
     67         createPhoneWindowWithTheme(R.style.LayoutInDisplayCutoutModeDefault);
     68         installDecor();
     69 
     70         assertThat(mPhoneWindow.getAttributes().layoutInDisplayCutoutMode,
     71                 is(LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT));
     72     }
     73 
     74     @Test
     75     public void layoutInDisplayCutoutMode_shortEdges() throws Exception {
     76         createPhoneWindowWithTheme(R.style.LayoutInDisplayCutoutModeShortEdges);
     77         installDecor();
     78 
     79         assertThat(mPhoneWindow.getAttributes().layoutInDisplayCutoutMode,
     80                 is(LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES));
     81     }
     82 
     83     @Test
     84     public void layoutInDisplayCutoutMode_never() throws Exception {
     85         createPhoneWindowWithTheme(R.style.LayoutInDisplayCutoutModeNever);
     86         installDecor();
     87 
     88         assertThat(mPhoneWindow.getAttributes().layoutInDisplayCutoutMode,
     89                 is(LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER));
     90     }
     91 
     92     private void createPhoneWindowWithTheme(int theme) {
     93         mPhoneWindow = new PhoneWindow(new ContextThemeWrapper(mContext, theme));
     94     }
     95 
     96     private void installDecor() {
     97         mPhoneWindow.getDecorView();
     98     }
     99 }