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