1 /* 2 * Copyright (C) 2021 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.managedprovisioning; 18 19 import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; 20 21 import static com.google.common.truth.Truth.assertThat; 22 23 import static org.robolectric.Shadows.shadowOf; 24 25 import android.app.Activity; 26 27 import org.junit.Ignore; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 import org.robolectric.Robolectric; 31 import org.robolectric.RobolectricTestRunner; 32 import org.robolectric.shadows.ShadowWindow; 33 34 @RunWith(RobolectricTestRunner.class) 35 public final class ManagedProvisioningApplicationTest { 36 private final ManagedProvisioningApplication mApplication = 37 new ManagedProvisioningApplication(); 38 39 @Ignore("b/218480743") 40 @Test markKeepScreenOn_works()41 public void markKeepScreenOn_works() { 42 Activity activity = createActivity(); 43 ShadowWindow shadowWindow = shadowOf(activity.getWindow()); 44 mApplication.markKeepScreenOn(); 45 46 mApplication.maybeKeepScreenOn(activity); 47 48 assertThat(shadowWindow.getFlag(FLAG_KEEP_SCREEN_ON)).isTrue(); 49 } 50 51 @Ignore("b/218480743") 52 @Test markKeepScreenOn_screenNotMarkedOn_flagNotSet()53 public void markKeepScreenOn_screenNotMarkedOn_flagNotSet() { 54 Activity activity = createActivity(); 55 ShadowWindow shadowWindow = shadowOf(activity.getWindow()); 56 57 mApplication.maybeKeepScreenOn(activity); 58 59 assertThat(shadowWindow.getFlag(FLAG_KEEP_SCREEN_ON)).isFalse(); 60 } 61 createActivity()62 private Activity createActivity() { 63 return Robolectric.buildActivity(Activity.class) 64 .create() 65 .start() 66 .resume() 67 .visible() 68 .get(); 69 } 70 } 71