1 /* 2 * Copyright 2013 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 * Copyright (C) 2013 The Android Open Source Project 18 * 19 * Licensed under the Apache License, Version 2.0 (the "License"); 20 * you may not use this file except in compliance with the License. 21 * You may obtain a copy of the License at 22 * 23 * http://www.apache.org/licenses/LICENSE-2.0 24 * 25 * Unless required by applicable law or agreed to in writing, software 26 * distributed under the License is distributed on an "AS IS" BASIS, 27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 * See the License for the specific language governing permissions and 29 * limitations under the License. 30 */ 31 package com.example.android.advancedimmersivemode.tests; 32 33 import com.example.android.advancedimmersivemode.*; 34 35 import android.test.ActivityInstrumentationTestCase2; 36 import android.test.UiThreadTest; 37 38 /** 39 * Tests for AdvancedImmersiveMode sample. 40 */ 41 public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> { 42 43 private MainActivity mTestActivity; 44 private AdvancedImmersiveModeFragment mTestFragment; 45 46 public SampleTests() { 47 super(MainActivity.class); 48 } 49 50 @Override 51 protected void setUp() throws Exception { 52 super.setUp(); 53 54 mTestActivity = getActivity(); 55 mTestFragment = (AdvancedImmersiveModeFragment) 56 mTestActivity.getSupportFragmentManager().getFragments().get(1); 57 } 58 59 /** 60 * Test if the test fixture has been set up correctly. 61 */ 62 public void testPreconditions() { 63 assertNotNull("mTestActivity is null", mTestActivity); 64 assertNotNull("mTestFragment is null", mTestFragment); 65 } 66 67 68 /** 69 * Verify that the UI flags actually changed when the toggle method is called. 70 */ 71 @UiThreadTest 72 public void testFlagsChanged() { 73 int uiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility(); 74 mTestFragment.mImmersiveModeCheckBox.setChecked(true); 75 mTestFragment.mHideNavCheckbox.setChecked(true); 76 mTestFragment.mHideStatusBarCheckBox.setChecked(true); 77 mTestFragment.toggleUiFlags(); 78 int newUiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility(); 79 assertTrue("UI Flags didn't toggle.", uiFlags != newUiFlags); 80 } 81 }