AmbientModeTest.java revision b31c3281d870e9abb673db239234d580dcc4feff
1/* 2 * Copyright (C) 2017 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 17package androidx.wear.ambient; 18 19import static org.junit.Assert.assertFalse; 20import static org.junit.Assert.assertTrue; 21 22import android.support.test.filters.MediumTest; 23import android.support.test.rule.ActivityTestRule; 24import android.support.test.runner.AndroidJUnit4; 25import androidx.wear.widget.util.WakeLockRule; 26 27import com.google.android.wearable.compat.WearableActivityController; 28 29import org.junit.Rule; 30import org.junit.Test; 31import org.junit.runner.RunWith; 32 33@MediumTest 34@RunWith(AndroidJUnit4.class) 35public class AmbientModeTest { 36 @Rule 37 public final WakeLockRule mWakeLock = new WakeLockRule(); 38 39 @Rule 40 public final ActivityTestRule<AmbientModeTestActivity> mActivityRule = new ActivityTestRule<>( 41 AmbientModeTestActivity.class); 42 43 @Test 44 public void testEnterAmbientCallback() throws Throwable { 45 AmbientModeTestActivity activity = mActivityRule.getActivity(); 46 47 WearableActivityController.getLastInstance().enterAmbient(); 48 assertTrue(activity.mEnterAmbientCalled); 49 assertFalse(activity.mUpdateAmbientCalled); 50 assertFalse(activity.mExitAmbientCalled); 51 } 52 53 @Test 54 public void testUpdateAmbientCallback() throws Throwable { 55 AmbientModeTestActivity activity = mActivityRule.getActivity(); 56 57 WearableActivityController.getLastInstance().updateAmbient(); 58 assertFalse(activity.mEnterAmbientCalled); 59 assertTrue(activity.mUpdateAmbientCalled); 60 assertFalse(activity.mExitAmbientCalled); 61 } 62 63 @Test 64 public void testExitAmbientCallback() throws Throwable { 65 AmbientModeTestActivity activity = mActivityRule.getActivity(); 66 67 WearableActivityController.getLastInstance().exitAmbient(); 68 assertFalse(activity.mEnterAmbientCalled); 69 assertFalse(activity.mUpdateAmbientCalled); 70 assertTrue(activity.mExitAmbientCalled); 71 } 72 73 @Test 74 public void testIsAmbientEnabled() { 75 assertTrue(WearableActivityController.getLastInstance().isAmbientEnabled()); 76 } 77 78 @Test 79 public void testCallsControllerIsAmbient() { 80 AmbientModeTestActivity activity = mActivityRule.getActivity(); 81 82 WearableActivityController.getLastInstance().setAmbient(true); 83 assertTrue(activity.getAmbientController().isAmbient()); 84 85 WearableActivityController.getLastInstance().setAmbient(false); 86 assertFalse(activity.getAmbientController().isAmbient()); 87 } 88} 89