• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 package com.android.launcher3.ui;
17 
18 import android.support.test.filters.LargeTest;
19 import android.support.test.runner.AndroidJUnit4;
20 import android.support.test.uiautomator.UiObject2;
21 import android.support.test.uiautomator.Until;
22 
23 import com.android.launcher3.R;
24 import com.android.launcher3.util.Condition;
25 import com.android.launcher3.util.Wait;
26 import com.android.launcher3.util.rule.LauncherActivityRule;
27 import com.android.launcher3.util.rule.ShellCommandRule;
28 
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 
35 import static org.junit.Assert.assertTrue;
36 
37 @LargeTest
38 @RunWith(AndroidJUnit4.class)
39 public class WorkTabTest extends AbstractLauncherUiTest {
40     @Rule
41     public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
42     @Rule
43     public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher();
44 
45     private int mProfileUserId;
46 
47     @Before
createWorkProfile()48     public void createWorkProfile() throws Exception {
49         String output =
50                 mDevice.executeShellCommand(
51                         "pm create-user --profileOf 0 --managed TestProfile");
52         assertTrue("Failed to create work profile", output.startsWith("Success"));
53 
54         String[] tokens = output.split("\\s+");
55         mProfileUserId = Integer.parseInt(tokens[tokens.length - 1]);
56 
57         mDevice.executeShellCommand("am start-user " + mProfileUserId);
58     }
59 
60     @After
removeWorkProfile()61     public void removeWorkProfile() throws Exception {
62         mDevice.executeShellCommand("pm remove-user " + mProfileUserId);
63     }
64 
65     @Test
workTabExists()66     public void workTabExists() {
67         mActivityMonitor.startLauncher();
68 
69         // Open all apps and wait for load complete
70         final UiObject2 appsContainer = openAllApps();
71         assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));
72 
73         assertTrue("Personal tab is missing",
74                 mDevice.wait(Until.hasObject(getSelectorForId(R.id.tab_personal)),
75                         LARGE_UI_TIMEOUT));
76         assertTrue("Work tab is missing",
77                 mDevice.wait(Until.hasObject(getSelectorForId(R.id.tab_work)), LARGE_UI_TIMEOUT));
78     }
79 }