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

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: 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
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 kTestAppPackage[] = "test.arc.app.package"; 44 const char kTestAppName2[] = "Test Arc App 2";
45 // TODO(khmel): use '.' when it is safe in ArcAppListPrefs.
khmel 2016/08/09 15:31:28 Due buggy implementation of package support in arc
xiyuan 2016/08/09 16:51:14 Can we fix this? Losting data for dogfooder might
khmel 2016/08/09 17:46:39 Nice easy fix :). Thanks! Also fixed one more GetD
46 const char kTestAppPackage[] = "test_arc_app_package";
45 const char kTestAppActivity[] = "test.arc.app.package.activity"; 47 const char kTestAppActivity[] = "test.arc.app.package.activity";
48 const char kTestAppActivity2[] = "test.arc.app.package.activity2";
46 constexpr int kAppAnimatedThresholdMs = 100; 49 constexpr int kAppAnimatedThresholdMs = 100;
47 50
48 std::string GetTestAppId() { 51 std::string GetTestApp1Id() {
49 return ArcAppListPrefs::GetAppId(kTestAppPackage, kTestAppActivity); 52 return ArcAppListPrefs::GetAppId(kTestAppPackage, kTestAppActivity);
50 } 53 }
51 54
55 std::string GetTestApp2Id() {
56 return ArcAppListPrefs::GetAppId(kTestAppPackage, kTestAppActivity2);
57 }
58
59 mojo::Array<arc::mojom::AppInfoPtr> GetTestAppsList(bool multi_app) {
60 std::vector<arc::mojom::AppInfo> apps;
61
62 arc::mojom::AppInfo app;
63 app.name = kTestAppName;
64 app.package_name = kTestAppPackage;
65 app.activity = kTestAppActivity;
66 app.sticky = false;
67 apps.push_back(app);
68
69 if (multi_app) {
70 app.name = kTestAppName2;
71 app.package_name = kTestAppPackage;
72 app.activity = kTestAppActivity2;
73 app.sticky = false;
74 apps.push_back(app);
75 }
76
77 return mojo::Array<arc::mojom::AppInfoPtr>::From(apps);
78 }
79
52 ChromeLauncherController* chrome_controller() { 80 ChromeLauncherController* chrome_controller() {
53 return ChromeLauncherController::instance(); 81 return ChromeLauncherController::instance();
54 } 82 }
55 83
56 ash::ShelfDelegate* shelf_delegate() { 84 ash::ShelfDelegate* shelf_delegate() {
57 return ash::WmShell::Get()->shelf_delegate(); 85 return ash::WmShell::Get()->shelf_delegate();
58 } 86 }
59 87
60 class AppAnimatedWaiter { 88 class AppAnimatedWaiter {
61 public: 89 public:
(...skipping 24 matching lines...) Expand all
86 114
87 TestParameter build_test_parameter[] = { 115 TestParameter build_test_parameter[] = {
88 TestParameter(TEST_ACTION_START, false), 116 TestParameter(TEST_ACTION_START, false),
89 TestParameter(TEST_ACTION_EXIT, false), 117 TestParameter(TEST_ACTION_EXIT, false),
90 TestParameter(TEST_ACTION_CLOSE, false), 118 TestParameter(TEST_ACTION_CLOSE, false),
91 TestParameter(TEST_ACTION_START, true), 119 TestParameter(TEST_ACTION_START, true),
92 }; 120 };
93 121
94 } // namespace 122 } // namespace
95 123
96 class ArcAppLauncherBrowserTest 124 class ArcAppLauncherBrowserTest : public ExtensionBrowserTest {
97 : public ExtensionBrowserTest,
98 public testing::WithParamInterface<TestParameter> {
99 public: 125 public:
100 ArcAppLauncherBrowserTest() {} 126 ArcAppLauncherBrowserTest() {}
101 ~ArcAppLauncherBrowserTest() override {} 127 ~ArcAppLauncherBrowserTest() override {}
102 128
103 protected: 129 protected:
104 // content::BrowserTestBase: 130 // content::BrowserTestBase:
105 void SetUpCommandLine(base::CommandLine* command_line) override { 131 void SetUpCommandLine(base::CommandLine* command_line) override {
106 ExtensionBrowserTest::SetUpCommandLine(command_line); 132 ExtensionBrowserTest::SetUpCommandLine(command_line);
107 command_line->AppendSwitch(chromeos::switches::kEnableArc); 133 command_line->AppendSwitch(chromeos::switches::kEnableArc);
108 } 134 }
109 135
110 void SetUpInProcessBrowserTestFixture() override { 136 void SetUpInProcessBrowserTestFixture() override {
111 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); 137 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
112 arc::ArcAuthService::DisableUIForTesting(); 138 arc::ArcAuthService::DisableUIForTesting();
113 } 139 }
114 140
115 void SetUpOnMainThread() override { arc::ArcAuthService::Get()->EnableArc(); } 141 void SetUpOnMainThread() override { arc::ArcAuthService::Get()->EnableArc(); }
116 142
117 void InstallTestApp() { 143 void InstallTestApps(bool multi_app) {
118 std::vector<arc::mojom::AppInfo> apps; 144 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 145
130 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = 146 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
131 app_prefs()->GetApp(GetTestAppId()); 147 app_prefs()->GetApp(GetTestApp1Id());
132 ASSERT_TRUE(app_info); 148 ASSERT_TRUE(app_info);
133 EXPECT_TRUE(app_info->ready); 149 EXPECT_TRUE(app_info->ready);
150 if (multi_app) {
151 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info2 =
152 app_prefs()->GetApp(GetTestApp2Id());
153 ASSERT_TRUE(app_info2);
154 EXPECT_TRUE(app_info2->ready);
155 }
156
157 arc::mojom::ArcPackageInfo package_info;
158 package_info.package_name = kTestAppPackage;
159 package_info.package_version = 1;
160 package_info.last_backup_android_id = 1;
161 package_info.last_backup_time = 1;
162 package_info.sync = false;
163 app_host()->OnPackageAdded(arc::mojom::ArcPackageInfo::From(package_info));
164
134 base::RunLoop().RunUntilIdle(); 165 base::RunLoop().RunUntilIdle();
135 } 166 }
136 167
168 void SendPackageUpdated(bool multi_app) {
169 app_host()->OnPackageAppListRefreshed(kTestAppPackage,
170 GetTestAppsList(multi_app));
171 }
172
173 void SendPackageRemoved() { app_host()->OnPackageRemoved(kTestAppPackage); }
174
137 void StartInstance() { 175 void StartInstance() {
138 auth_service()->OnPrimaryUserProfilePrepared(profile()); 176 auth_service()->OnPrimaryUserProfilePrepared(profile());
139 app_instance_observer()->OnInstanceReady(); 177 app_instance_observer()->OnInstanceReady();
140 } 178 }
141 179
142 void StopInstance() { 180 void StopInstance() {
143 auth_service()->Shutdown(); 181 auth_service()->Shutdown();
144 app_instance_observer()->OnInstanceClosed(); 182 app_instance_observer()->OnInstanceClosed();
145 } 183 }
146 184
147 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); } 185 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); }
148 186
149 // Returns as AppHost interface in order to access to private implementation 187 // Returns as AppHost interface in order to access to private implementation
150 // of the interface. 188 // of the interface.
151 arc::mojom::AppHost* app_host() { return app_prefs(); } 189 arc::mojom::AppHost* app_host() { return app_prefs(); }
152 190
153 // Returns as AppInstance observer interface in order to access to private 191 // Returns as AppInstance observer interface in order to access to private
154 // implementation of the interface. 192 // implementation of the interface.
155 arc::InstanceHolder<arc::mojom::AppInstance>::Observer* 193 arc::InstanceHolder<arc::mojom::AppInstance>::Observer*
156 app_instance_observer() { 194 app_instance_observer() {
157 return app_prefs(); 195 return app_prefs();
158 } 196 }
159 197
160 arc::ArcAuthService* auth_service() { return arc::ArcAuthService::Get(); } 198 arc::ArcAuthService* auth_service() { return arc::ArcAuthService::Get(); }
161 199
200 private:
201 DISALLOW_COPY_AND_ASSIGN(ArcAppLauncherBrowserTest);
202 };
203
204 class ArcAppDeferredLauncherBrowserTest
205 : public ArcAppLauncherBrowserTest,
206 public testing::WithParamInterface<TestParameter> {
207 public:
208 ArcAppDeferredLauncherBrowserTest() {}
209 ~ArcAppDeferredLauncherBrowserTest() override {}
210
211 protected:
162 bool is_pinned() const { return std::tr1::get<1>(GetParam()); } 212 bool is_pinned() const { return std::tr1::get<1>(GetParam()); }
163 213
164 TestAction test_action() const { return std::tr1::get<0>(GetParam()); } 214 TestAction test_action() const { return std::tr1::get<0>(GetParam()); }
165 215
166 private: 216 private:
167 DISALLOW_COPY_AND_ASSIGN(ArcAppLauncherBrowserTest); 217 DISALLOW_COPY_AND_ASSIGN(ArcAppDeferredLauncherBrowserTest);
168 }; 218 };
169 219
170 // This tests simulates normal workflow for starting Arc app in deferred mode. 220 // This tests simulates normal workflow for starting Arc app in deferred mode.
171 IN_PROC_BROWSER_TEST_P(ArcAppLauncherBrowserTest, StartAppDeferred) { 221 IN_PROC_BROWSER_TEST_P(ArcAppDeferredLauncherBrowserTest, StartAppDeferred) {
172 // Install app to remember existing apps. 222 // Install app to remember existing apps.
173 InstallTestApp(); 223 InstallTestApps(false);
174 224
175 const std::string app_id = GetTestAppId(); 225 const std::string app_id = GetTestApp1Id();
176 if (is_pinned()) { 226 if (is_pinned()) {
177 shelf_delegate()->PinAppWithID(app_id); 227 shelf_delegate()->PinAppWithID(app_id);
178 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 228 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id));
179 } else { 229 } else {
180 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 230 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id));
181 } 231 }
182 232
183 StopInstance(); 233 StopInstance();
184 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = 234 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
185 app_prefs()->GetApp(app_id); 235 app_prefs()->GetApp(app_id);
(...skipping 12 matching lines...) Expand all
198 248
199 // Launching non-ready Arc app creates item on shelf and spinning animation. 249 // Launching non-ready Arc app creates item on shelf and spinning animation.
200 arc::LaunchApp(profile(), app_id); 250 arc::LaunchApp(profile(), app_id);
201 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 251 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id));
202 AppAnimatedWaiter(app_id).Wait(); 252 AppAnimatedWaiter(app_id).Wait();
203 253
204 switch (test_action()) { 254 switch (test_action()) {
205 case TEST_ACTION_START: 255 case TEST_ACTION_START:
206 // Now simulates that Arc is started and app list is refreshed. This 256 // Now simulates that Arc is started and app list is refreshed. This
207 // should stop animation and delete icon from the shelf. 257 // should stop animation and delete icon from the shelf.
208 InstallTestApp(); 258 InstallTestApps(false);
209 EXPECT_TRUE(chrome_controller() 259 EXPECT_TRUE(chrome_controller()
210 ->GetArcDeferredLauncher() 260 ->GetArcDeferredLauncher()
211 ->GetActiveTime(app_id) 261 ->GetActiveTime(app_id)
212 .is_zero()); 262 .is_zero());
213 if (is_pinned()) 263 if (is_pinned())
214 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 264 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id));
215 else 265 else
216 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 266 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id));
217 break; 267 break;
218 case TEST_ACTION_EXIT: 268 case TEST_ACTION_EXIT:
(...skipping 13 matching lines...) Expand all
232 .is_zero()); 282 .is_zero());
233 if (is_pinned()) 283 if (is_pinned())
234 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 284 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id));
235 else 285 else
236 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 286 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id));
237 } 287 }
238 break; 288 break;
239 } 289 }
240 } 290 }
241 291
242 INSTANTIATE_TEST_CASE_P(ArcAppLauncherBrowserTestInstance, 292 INSTANTIATE_TEST_CASE_P(ArcAppDeferredLauncherBrowserTestInstance,
243 ArcAppLauncherBrowserTest, 293 ArcAppDeferredLauncherBrowserTest,
244 ::testing::ValuesIn(build_test_parameter)); 294 ::testing::ValuesIn(build_test_parameter));
295
296 // This tests validates pin state on package update and remove.
297 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) {
298 InstallTestApps(true);
299
300 const std::string app_id1 = GetTestApp1Id();
301 const std::string app_id2 = GetTestApp2Id();
302 shelf_delegate()->PinAppWithID(app_id1);
303 shelf_delegate()->PinAppWithID(app_id2);
304 const ash::ShelfID shelf_id1_before =
305 shelf_delegate()->GetShelfIDForAppID(app_id1);
306 EXPECT_TRUE(shelf_id1_before);
307 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id2));
308
309 // Package contains only one app.
310 SendPackageUpdated(false);
311 // Second pin should gone.
312 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1));
313 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
314
315 // Package contains two apps.
316 SendPackageUpdated(true);
317 // Second pin should not appear.
318 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1));
319 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
320
321 // Package removed.
322 SendPackageRemoved();
323 // No pin is expected.
324 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id1));
325 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698