blob: 32be962a4a258fb0d070ddf6a75e988ef401eef8 [file] [log] [blame]
Kenny Guyda652442015-01-26 14:49:13 +00001/*
2 * Copyright (C) 2014 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
17package com.android.cts.devicepolicy;
18
19import com.android.ddmlib.Log.LogLevel;
20import com.android.tradefed.device.DeviceNotAvailableException;
21import com.android.tradefed.log.LogUtil.CLog;
22
23/**
24 * Set of tests for LauncherApps with managed profiles.
25 */
26public class LauncherAppsSingleUserTest extends BaseLauncherAppsTest {
27
28 private boolean mHasLauncherApps;
29
30 @Override
31 protected void setUp() throws Exception {
32 super.setUp();
33 mHasLauncherApps = getDevice().getApiLevel() >= 21;
34
35 if (mHasLauncherApps) {
36 installTestApps();
37 }
38 }
39
40 @Override
41 protected void tearDown() throws Exception {
42 if (mHasLauncherApps) {
43 uninstallTestApps();
44 }
45 super.tearDown();
46 }
47
48 public void testInstallAppMainUser() throws Exception {
49 if (!mHasLauncherApps) {
50 return;
51 }
52 installApp(SIMPLE_APP_APK);
53 try {
54 int serialNumber = getUserSerialNumber(0);
55 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
56 LAUNCHER_TESTS_CLASS, "testSimpleAppInstalledForUser",
57 0, "-e testUser " + serialNumber));
58 } finally {
59 getDevice().uninstallPackage(SIMPLE_APP_PKG);
60 }
61 }
62
63 public void testLauncherCallbackPackageAddedMainUser() throws Exception {
64 if (!mHasLauncherApps) {
65 return;
66 }
67 startCallbackService();
68 installApp(SIMPLE_APP_APK);
69 try {
70 int serialNumber = getUserSerialNumber(0);
71 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
72 LAUNCHER_TESTS_CLASS,
73 "testPackageAddedCallbackForUser",
74 0, "-e testUser " + serialNumber));
75 } finally {
76 getDevice().uninstallPackage(SIMPLE_APP_PKG);
77 }
78 }
79
80 public void testLauncherCallbackPackageRemovedMainUser() throws Exception {
81 if (!mHasLauncherApps) {
82 return;
83 }
84 installApp(SIMPLE_APP_APK);
85 try {
86 startCallbackService();
87 int serialNumber = getUserSerialNumber(0);
88 getDevice().uninstallPackage(SIMPLE_APP_PKG);
89 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
90 LAUNCHER_TESTS_CLASS,
91 "testPackageRemovedCallbackForUser",
92 0, "-e testUser " + serialNumber));
93 } finally {
94 getDevice().uninstallPackage(SIMPLE_APP_PKG);
95 }
96 }
97
98 public void testLauncherCallbackPackageChangedMainUser() throws Exception {
99 if (!mHasLauncherApps) {
100 return;
101 }
102 installApp(SIMPLE_APP_APK);
103 try {
104 startCallbackService();
105 int serialNumber = getUserSerialNumber(0);
106 installApp(SIMPLE_APP_APK);
107 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
108 LAUNCHER_TESTS_CLASS,
109 "testPackageChangedCallbackForUser",
110 0, "-e testUser " + serialNumber));
111 } finally {
112 getDevice().uninstallPackage(SIMPLE_APP_PKG);
113 }
114 }
115
116 public void testLauncherNonExportedAppFails() throws Exception {
117 if (!mHasLauncherApps) {
118 return;
119 }
120 installApp(SIMPLE_APP_APK);
121 try {
122 int serialNumber = getUserSerialNumber(0);
123 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
124 LAUNCHER_TESTS_CLASS, "testLaunchNonExportActivityFails",
125 0, "-e testUser " + serialNumber));
126 } finally {
127 getDevice().uninstallPackage(SIMPLE_APP_PKG);
128 }
129 }
130
131 public void testLaunchNonExportActivityFails() throws Exception {
132 if (!mHasLauncherApps) {
133 return;
134 }
135 installApp(SIMPLE_APP_APK);
136 try {
137 int serialNumber = getUserSerialNumber(0);
138 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
139 LAUNCHER_TESTS_CLASS, "testLaunchNonExportLauncherFails",
140 0, "-e testUser " + serialNumber));
141 } finally {
142 getDevice().uninstallPackage(SIMPLE_APP_PKG);
143 }
144 }
145
146 public void testLaunchMainActivity() throws Exception {
147 if (!mHasLauncherApps) {
148 return;
149 }
150 installApp(SIMPLE_APP_APK);
151 try {
152 int serialNumber = getUserSerialNumber(0);
153 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
154 LAUNCHER_TESTS_CLASS, "testLaunchMainActivity",
155 0, "-e testUser " + serialNumber));
156 } finally {
157 getDevice().uninstallPackage(SIMPLE_APP_PKG);
158 }
159 }
160}