Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/ui/ash/launcher/arc_app_launcher_browsertest.cc

Issue 2228663003: arc: Add package app list updated event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase2 Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_unittest.cc ('k') | components/arc/common/app.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/shelf/shelf_delegate.h" 5 #include "ash/common/shelf/shelf_delegate.h"
6 #include "ash/common/wm_shell.h" 6 #include "ash/common/wm_shell.h"
7 #include "ash/shelf/shelf_util.h" 7 #include "ash/shelf/shelf_util.h"
8 #include "ash/wm/window_util.h" 8 #include "ash/wm/window_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 23 matching lines...) Expand all
34 const arc::mojom::ArcPackageInfo& package_info) { 34 const arc::mojom::ArcPackageInfo& package_info) {
35 return package_info.Clone(); 35 return package_info.Clone();
36 } 36 }
37 }; 37 };
38 38
39 } // namespace mojo 39 } // namespace mojo
40 40
41 namespace { 41 namespace {
42 42
43 const char kTestAppName[] = "Test Arc App"; 43 const char kTestAppName[] = "Test Arc App";
44 const char kTestAppName2[] = "Test Arc App 2";
44 const char kTestAppPackage[] = "test.arc.app.package"; 45 const char kTestAppPackage[] = "test.arc.app.package";
45 const char kTestAppActivity[] = "test.arc.app.package.activity"; 46 const char kTestAppActivity[] = "test.arc.app.package.activity";
47 const char kTestAppActivity2[] = "test.arc.app.package.activity2";
46 constexpr int kAppAnimatedThresholdMs = 100; 48 constexpr int kAppAnimatedThresholdMs = 100;
47 49
48 std::string GetTestAppId() { 50 std::string GetTestApp1Id() {
49 return ArcAppListPrefs::GetAppId(kTestAppPackage, kTestAppActivity); 51 return ArcAppListPrefs::GetAppId(kTestAppPackage, kTestAppActivity);
50 } 52 }
51 53
54 std::string GetTestApp2Id() {
55 return ArcAppListPrefs::GetAppId(kTestAppPackage, kTestAppActivity2);
56 }
57
58 mojo::Array<arc::mojom::AppInfoPtr> GetTestAppsList(bool multi_app) {
59 std::vector<arc::mojom::AppInfo> apps;
60
61 arc::mojom::AppInfo app;
62 app.name = kTestAppName;
63 app.package_name = kTestAppPackage;
64 app.activity = kTestAppActivity;
65 app.sticky = false;
66 apps.push_back(app);
67
68 if (multi_app) {
69 app.name = kTestAppName2;
70 app.package_name = kTestAppPackage;
71 app.activity = kTestAppActivity2;
72 app.sticky = false;
73 apps.push_back(app);
74 }
75
76 return mojo::Array<arc::mojom::AppInfoPtr>::From(apps);
77 }
78
52 ChromeLauncherController* chrome_controller() { 79 ChromeLauncherController* chrome_controller() {
53 return ChromeLauncherController::instance(); 80 return ChromeLauncherController::instance();
54 } 81 }
55 82
56 ash::ShelfDelegate* shelf_delegate() { 83 ash::ShelfDelegate* shelf_delegate() {
57 return ash::WmShell::Get()->shelf_delegate(); 84 return ash::WmShell::Get()->shelf_delegate();
58 } 85 }
59 86
60 class AppAnimatedWaiter { 87 class AppAnimatedWaiter {
61 public: 88 public:
(...skipping 24 matching lines...) Expand all
86 113
87 TestParameter build_test_parameter[] = { 114 TestParameter build_test_parameter[] = {
88 TestParameter(TEST_ACTION_START, false), 115 TestParameter(TEST_ACTION_START, false),
89 TestParameter(TEST_ACTION_EXIT, false), 116 TestParameter(TEST_ACTION_EXIT, false),
90 TestParameter(TEST_ACTION_CLOSE, false), 117 TestParameter(TEST_ACTION_CLOSE, false),
91 TestParameter(TEST_ACTION_START, true), 118 TestParameter(TEST_ACTION_START, true),
92 }; 119 };
93 120
94 } // namespace 121 } // namespace
95 122
96 class ArcAppLauncherBrowserTest 123 class ArcAppLauncherBrowserTest : public ExtensionBrowserTest {
97 : public ExtensionBrowserTest,
98 public testing::WithParamInterface<TestParameter> {
99 public: 124 public:
100 ArcAppLauncherBrowserTest() {} 125 ArcAppLauncherBrowserTest() {}
101 ~ArcAppLauncherBrowserTest() override {} 126 ~ArcAppLauncherBrowserTest() override {}
102 127
103 protected: 128 protected:
104 // content::BrowserTestBase: 129 // content::BrowserTestBase:
105 void SetUpCommandLine(base::CommandLine* command_line) override { 130 void SetUpCommandLine(base::CommandLine* command_line) override {
106 ExtensionBrowserTest::SetUpCommandLine(command_line); 131 ExtensionBrowserTest::SetUpCommandLine(command_line);
107 command_line->AppendSwitch(chromeos::switches::kEnableArc); 132 command_line->AppendSwitch(chromeos::switches::kEnableArc);
108 } 133 }
109 134
110 void SetUpInProcessBrowserTestFixture() override { 135 void SetUpInProcessBrowserTestFixture() override {
111 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); 136 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
112 arc::ArcAuthService::DisableUIForTesting(); 137 arc::ArcAuthService::DisableUIForTesting();
113 } 138 }
114 139
115 void SetUpOnMainThread() override { arc::ArcAuthService::Get()->EnableArc(); } 140 void SetUpOnMainThread() override { arc::ArcAuthService::Get()->EnableArc(); }
116 141
117 void InstallTestApp() { 142 void InstallTestApps(bool multi_app) {
118 std::vector<arc::mojom::AppInfo> apps; 143 app_host()->OnAppListRefreshed(GetTestAppsList(multi_app));
119
120 arc::mojom::AppInfo app;
121 app.name = kTestAppName;
122 app.package_name = kTestAppPackage;
123 app.activity = kTestAppActivity;
124 app.sticky = false;
125 apps.push_back(app);
126
127 app_host()->OnAppListRefreshed(
128 mojo::Array<arc::mojom::AppInfoPtr>::From(apps));
129 144
130 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = 145 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
131 app_prefs()->GetApp(GetTestAppId()); 146 app_prefs()->GetApp(GetTestApp1Id());
132 ASSERT_TRUE(app_info); 147 ASSERT_TRUE(app_info);
133 EXPECT_TRUE(app_info->ready); 148 EXPECT_TRUE(app_info->ready);
149 if (multi_app) {
150 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info2 =
151 app_prefs()->GetApp(GetTestApp2Id());
152 ASSERT_TRUE(app_info2);
153 EXPECT_TRUE(app_info2->ready);
154 }
155
156 arc::mojom::ArcPackageInfo package_info;
157 package_info.package_name = kTestAppPackage;
158 package_info.package_version = 1;
159 package_info.last_backup_android_id = 1;
160 package_info.last_backup_time = 1;
161 package_info.sync = false;
162 app_host()->OnPackageAdded(arc::mojom::ArcPackageInfo::From(package_info));
163
134 base::RunLoop().RunUntilIdle(); 164 base::RunLoop().RunUntilIdle();
135 } 165 }
136 166
167 void SendPackageUpdated(bool multi_app) {
168 app_host()->OnPackageAppListRefreshed(kTestAppPackage,
169 GetTestAppsList(multi_app));
170 }
171
172 void SendPackageRemoved() { app_host()->OnPackageRemoved(kTestAppPackage); }
173
137 void StartInstance() { 174 void StartInstance() {
138 auth_service()->OnPrimaryUserProfilePrepared(profile()); 175 auth_service()->OnPrimaryUserProfilePrepared(profile());
139 app_instance_observer()->OnInstanceReady(); 176 app_instance_observer()->OnInstanceReady();
140 } 177 }
141 178
142 void StopInstance() { 179 void StopInstance() {
143 auth_service()->Shutdown(); 180 auth_service()->Shutdown();
144 app_instance_observer()->OnInstanceClosed(); 181 app_instance_observer()->OnInstanceClosed();
145 } 182 }
146 183
147 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); } 184 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); }
148 185
149 // Returns as AppHost interface in order to access to private implementation 186 // Returns as AppHost interface in order to access to private implementation
150 // of the interface. 187 // of the interface.
151 arc::mojom::AppHost* app_host() { return app_prefs(); } 188 arc::mojom::AppHost* app_host() { return app_prefs(); }
152 189
153 // Returns as AppInstance observer interface in order to access to private 190 // Returns as AppInstance observer interface in order to access to private
154 // implementation of the interface. 191 // implementation of the interface.
155 arc::InstanceHolder<arc::mojom::AppInstance>::Observer* 192 arc::InstanceHolder<arc::mojom::AppInstance>::Observer*
156 app_instance_observer() { 193 app_instance_observer() {
157 return app_prefs(); 194 return app_prefs();
158 } 195 }
159 196
160 arc::ArcAuthService* auth_service() { return arc::ArcAuthService::Get(); } 197 arc::ArcAuthService* auth_service() { return arc::ArcAuthService::Get(); }
161 198
199 private:
200 DISALLOW_COPY_AND_ASSIGN(ArcAppLauncherBrowserTest);
201 };
202
203 class ArcAppDeferredLauncherBrowserTest
204 : public ArcAppLauncherBrowserTest,
205 public testing::WithParamInterface<TestParameter> {
206 public:
207 ArcAppDeferredLauncherBrowserTest() {}
208 ~ArcAppDeferredLauncherBrowserTest() override {}
209
210 protected:
162 bool is_pinned() const { return std::tr1::get<1>(GetParam()); } 211 bool is_pinned() const { return std::tr1::get<1>(GetParam()); }
163 212
164 TestAction test_action() const { return std::tr1::get<0>(GetParam()); } 213 TestAction test_action() const { return std::tr1::get<0>(GetParam()); }
165 214
166 private: 215 private:
167 DISALLOW_COPY_AND_ASSIGN(ArcAppLauncherBrowserTest); 216 DISALLOW_COPY_AND_ASSIGN(ArcAppDeferredLauncherBrowserTest);
168 }; 217 };
169 218
170 // This tests simulates normal workflow for starting Arc app in deferred mode. 219 // This tests simulates normal workflow for starting Arc app in deferred mode.
171 IN_PROC_BROWSER_TEST_P(ArcAppLauncherBrowserTest, StartAppDeferred) { 220 IN_PROC_BROWSER_TEST_P(ArcAppDeferredLauncherBrowserTest, StartAppDeferred) {
172 // Install app to remember existing apps. 221 // Install app to remember existing apps.
173 InstallTestApp(); 222 InstallTestApps(false);
174 223
175 const std::string app_id = GetTestAppId(); 224 const std::string app_id = GetTestApp1Id();
176 if (is_pinned()) { 225 if (is_pinned()) {
177 shelf_delegate()->PinAppWithID(app_id); 226 shelf_delegate()->PinAppWithID(app_id);
178 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 227 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id));
179 } else { 228 } else {
180 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 229 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id));
181 } 230 }
182 231
183 StopInstance(); 232 StopInstance();
184 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = 233 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
185 app_prefs()->GetApp(app_id); 234 app_prefs()->GetApp(app_id);
(...skipping 12 matching lines...) Expand all
198 247
199 // Launching non-ready Arc app creates item on shelf and spinning animation. 248 // Launching non-ready Arc app creates item on shelf and spinning animation.
200 arc::LaunchApp(profile(), app_id); 249 arc::LaunchApp(profile(), app_id);
201 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 250 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id));
202 AppAnimatedWaiter(app_id).Wait(); 251 AppAnimatedWaiter(app_id).Wait();
203 252
204 switch (test_action()) { 253 switch (test_action()) {
205 case TEST_ACTION_START: 254 case TEST_ACTION_START:
206 // Now simulates that Arc is started and app list is refreshed. This 255 // Now simulates that Arc is started and app list is refreshed. This
207 // should stop animation and delete icon from the shelf. 256 // should stop animation and delete icon from the shelf.
208 InstallTestApp(); 257 InstallTestApps(false);
209 EXPECT_TRUE(chrome_controller() 258 EXPECT_TRUE(chrome_controller()
210 ->GetArcDeferredLauncher() 259 ->GetArcDeferredLauncher()
211 ->GetActiveTime(app_id) 260 ->GetActiveTime(app_id)
212 .is_zero()); 261 .is_zero());
213 if (is_pinned()) 262 if (is_pinned())
214 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 263 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id));
215 else 264 else
216 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 265 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id));
217 break; 266 break;
218 case TEST_ACTION_EXIT: 267 case TEST_ACTION_EXIT:
(...skipping 13 matching lines...) Expand all
232 .is_zero()); 281 .is_zero());
233 if (is_pinned()) 282 if (is_pinned())
234 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 283 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id));
235 else 284 else
236 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 285 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id));
237 } 286 }
238 break; 287 break;
239 } 288 }
240 } 289 }
241 290
242 INSTANTIATE_TEST_CASE_P(ArcAppLauncherBrowserTestInstance, 291 INSTANTIATE_TEST_CASE_P(ArcAppDeferredLauncherBrowserTestInstance,
243 ArcAppLauncherBrowserTest, 292 ArcAppDeferredLauncherBrowserTest,
244 ::testing::ValuesIn(build_test_parameter)); 293 ::testing::ValuesIn(build_test_parameter));
294
295 // This tests validates pin state on package update and remove.
296 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) {
297 InstallTestApps(true);
298
299 const std::string app_id1 = GetTestApp1Id();
300 const std::string app_id2 = GetTestApp2Id();
301 shelf_delegate()->PinAppWithID(app_id1);
302 shelf_delegate()->PinAppWithID(app_id2);
303 const ash::ShelfID shelf_id1_before =
304 shelf_delegate()->GetShelfIDForAppID(app_id1);
305 EXPECT_TRUE(shelf_id1_before);
306 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id2));
307
308 // Package contains only one app.
309 SendPackageUpdated(false);
310 // Second pin should gone.
311 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1));
312 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
313
314 // Package contains two apps.
315 SendPackageUpdated(true);
316 // Second pin should not appear.
317 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1));
318 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
319
320 // Package removed.
321 SendPackageRemoved();
322 // No pin is expected.
323 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id1));
324 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
325 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_unittest.cc ('k') | components/arc/common/app.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698