Adam Lesinski | 7f3f499 | 2016-03-30 10:32:15 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package android.app.activity; |
| 17 | |
| 18 | import android.app.UiAutomation; |
| 19 | import android.content.res.Configuration; |
| 20 | import android.support.test.InstrumentationRegistry; |
| 21 | import android.support.test.filters.SmallTest; |
| 22 | import android.support.test.runner.AndroidJUnit4; |
| 23 | import android.test.ActivityInstrumentationTestCase2; |
| 24 | |
| 25 | import org.junit.After; |
| 26 | import org.junit.Before; |
| 27 | import org.junit.Test; |
| 28 | import org.junit.runner.RunWith; |
| 29 | |
| 30 | @SmallTest |
| 31 | @RunWith(AndroidJUnit4.class) |
| 32 | public 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 | } |