• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 package com.android.settings.dashboard;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.app.Activity;
22 import android.app.Fragment;
23 import android.app.Instrumentation;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.pm.ActivityInfo;
27 import android.provider.Settings;
28 import android.support.test.InstrumentationRegistry;
29 import android.support.test.filters.SmallTest;
30 import android.support.test.runner.AndroidJUnit4;
31 import android.support.test.uiautomator.By;
32 import android.support.test.uiautomator.UiDevice;
33 import android.support.test.uiautomator.UiObject2;
34 import android.support.test.uiautomator.Until;
35 
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 
40 import java.util.List;
41 
42 @RunWith(AndroidJUnit4.class)
43 @SmallTest
44 public class DashboardSummaryInstrumentationTest {
45 
46     private static final long TIMEOUT = 2000l;
47 
48     private Context mContext;
49     private Instrumentation mInstrumentation;
50 
51     private UiDevice mDevice;
52 
53     @Before
setUp()54     public void setUp() {
55         mInstrumentation = InstrumentationRegistry.getInstrumentation();
56         mDevice = UiDevice.getInstance(mInstrumentation);
57         mContext = InstrumentationRegistry.getTargetContext();
58     }
59 
60     @Test
rotate_shouldSaveCategoriesChangedState()61     public void rotate_shouldSaveCategoriesChangedState() {
62         final Intent intent = new Intent(Settings.ACTION_SETTINGS)
63                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
64         final Activity activity = mInstrumentation.startActivitySync(intent);
65 
66         activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
67         activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
68 
69         final UiObject2 item = mDevice.wait(Until.findObject(By.res("android:id/title")
70                 .text("Network & internet")), TIMEOUT);
71         assertThat(item).isNotNull();
72 
73         final List<Fragment> fragments = activity.getFragmentManager().getFragments();
74         final DashboardSummary fragment = (DashboardSummary) fragments.get(0);
75 
76         assertThat(fragment.mIsOnCategoriesChangedCalled).isTrue();
77     }
78 
79 }
80