blob: 15ed77ec694080ca4f1dc75812aede12841fc703 [file] [log] [blame]
Adam Lesinski7f3f4992016-03-30 10:32:15 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package android.app.activity;
17
18import android.app.UiAutomation;
19import android.content.res.Configuration;
20import android.support.test.InstrumentationRegistry;
21import android.support.test.filters.SmallTest;
22import android.support.test.runner.AndroidJUnit4;
23import android.test.ActivityInstrumentationTestCase2;
24
25import org.junit.After;
26import org.junit.Before;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29
30@SmallTest
31@RunWith(AndroidJUnit4.class)
32public class ApplyOverrideConfigurationTest extends
33 ActivityInstrumentationTestCase2<ApplyOverrideConfigurationActivity> {
34
35 public static final int OVERRIDE_WIDTH = 9999;
36
37 public ApplyOverrideConfigurationTest() {
38 super(ApplyOverrideConfigurationActivity.class);
39 }
40
41 @Before
42 @Override
43 public void setUp() throws Exception {
44 super.setUp();
45 injectInstrumentation(InstrumentationRegistry.getInstrumentation());
46 getInstrumentation().getUiAutomation().setRotation(UiAutomation.ROTATION_FREEZE_0);
47 }
48
49 @Test
50 public void testConfigurationIsOverriden() throws Exception {
51 Configuration config = getActivity().getResources().getConfiguration();
52 assertEquals(OVERRIDE_WIDTH, config.smallestScreenWidthDp);
53
54 getInstrumentation().getUiAutomation().setRotation(UiAutomation.ROTATION_FREEZE_90);
55
56 config = getActivity().getResources().getConfiguration();
57 assertEquals(OVERRIDE_WIDTH, config.smallestScreenWidthDp);
58 }
59
60 @After
61 @Override
62 public void tearDown() throws Exception {
63 getInstrumentation().getUiAutomation().setRotation(UiAutomation.ROTATION_UNFREEZE);
64 super.tearDown();
65 }
66}