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

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

Issue 2791463002: mash: Remove ShelfDelegate; move functions to ShelfModel. (Closed)
Patch Set: Sync and rebase; cleanup. Created 3 years, 8 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/public/cpp/shelf_item_delegate.h" 5 #include "ash/public/cpp/shelf_item_delegate.h"
6 #include "ash/shelf/shelf_delegate.h"
7 #include "ash/shelf/shelf_model.h" 6 #include "ash/shelf/shelf_model.h"
8 #include "ash/shell.h" 7 #include "ash/shell.h"
9 #include "ash/wm/window_util.h" 8 #include "ash/wm/window_util.h"
10 #include "base/macros.h" 9 #include "base/macros.h"
11 #include "base/run_loop.h" 10 #include "base/run_loop.h"
12 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" 13 #include "chrome/browser/chromeos/arc/arc_auth_notification.h"
15 #include "chrome/browser/chromeos/arc/arc_service_launcher.h" 14 #include "chrome/browser/chromeos/arc/arc_service_launcher.h"
16 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 15 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 apps.push_back(std::move(app)); 100 apps.push_back(std::move(app));
102 } 101 }
103 102
104 return apps; 103 return apps;
105 } 104 }
106 105
107 ChromeLauncherController* chrome_controller() { 106 ChromeLauncherController* chrome_controller() {
108 return ChromeLauncherController::instance(); 107 return ChromeLauncherController::instance();
109 } 108 }
110 109
111 ash::ShelfDelegate* shelf_delegate() {
112 return ash::Shell::Get()->shelf_delegate();
113 }
114
115 class AppAnimatedWaiter { 110 class AppAnimatedWaiter {
116 public: 111 public:
117 explicit AppAnimatedWaiter(const std::string& app_id) : app_id_(app_id) {} 112 explicit AppAnimatedWaiter(const std::string& app_id) : app_id_(app_id) {}
118 113
119 void Wait() { 114 void Wait() {
120 const base::TimeDelta threshold = 115 const base::TimeDelta threshold =
121 base::TimeDelta::FromMilliseconds(kAppAnimatedThresholdMs); 116 base::TimeDelta::FromMilliseconds(kAppAnimatedThresholdMs);
122 ArcAppDeferredLauncherController* controller = 117 ArcAppDeferredLauncherController* controller =
123 chrome_controller()->GetArcDeferredLauncher(); 118 chrome_controller()->GetArcDeferredLauncher();
124 while (controller->GetActiveTime(app_id_) < threshold) { 119 while (controller->GetActiveTime(app_id_) < threshold) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (arc_session_manager()->profile() != profile()) 246 if (arc_session_manager()->profile() != profile())
252 arc::ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile()); 247 arc::ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile());
253 app_instance_observer()->OnInstanceReady(); 248 app_instance_observer()->OnInstanceReady();
254 } 249 }
255 250
256 void StopInstance() { 251 void StopInstance() {
257 arc_session_manager()->Shutdown(); 252 arc_session_manager()->Shutdown();
258 app_instance_observer()->OnInstanceClosed(); 253 app_instance_observer()->OnInstanceClosed();
259 } 254 }
260 255
261 ash::ShelfItemDelegate* GetAppItemController(const std::string& id) { 256 ash::ShelfItemDelegate* GetShelfItemDelegate(const std::string& id) {
262 const ash::ShelfID shelf_id = shelf_delegate()->GetShelfIDForAppID(id); 257 ash::ShelfModel* model = ash::Shell::Get()->shelf_model();
263 return ash::Shell::Get()->shelf_model()->GetShelfItemDelegate(shelf_id); 258 return model->GetShelfItemDelegate(model->GetShelfIDForAppID(id));
264 } 259 }
265 260
266 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); } 261 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); }
267 262
268 // Returns as AppHost interface in order to access to private implementation 263 // Returns as AppHost interface in order to access to private implementation
269 // of the interface. 264 // of the interface.
270 arc::mojom::AppHost* app_host() { return app_prefs(); } 265 arc::mojom::AppHost* app_host() { return app_prefs(); }
271 266
272 // Returns as AppInstance observer interface in order to access to private 267 // Returns as AppInstance observer interface in order to access to private
273 // implementation of the interface. 268 // implementation of the interface.
(...skipping 27 matching lines...) Expand all
301 }; 296 };
302 297
303 // This tests simulates normal workflow for starting ARC app in deferred mode. 298 // This tests simulates normal workflow for starting ARC app in deferred mode.
304 IN_PROC_BROWSER_TEST_P(ArcAppDeferredLauncherBrowserTest, StartAppDeferred) { 299 IN_PROC_BROWSER_TEST_P(ArcAppDeferredLauncherBrowserTest, StartAppDeferred) {
305 // Install app to remember existing apps. 300 // Install app to remember existing apps.
306 StartInstance(); 301 StartInstance();
307 InstallTestApps(kTestAppPackage, false); 302 InstallTestApps(kTestAppPackage, false);
308 SendPackageAdded(kTestAppPackage, false); 303 SendPackageAdded(kTestAppPackage, false);
309 304
310 const std::string app_id = GetTestApp1Id(kTestAppPackage); 305 const std::string app_id = GetTestApp1Id(kTestAppPackage);
306 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model();
311 if (is_pinned()) { 307 if (is_pinned()) {
312 shelf_delegate()->PinAppWithID(app_id); 308 shelf_model->PinAppWithID(app_id);
313 const ash::ShelfID shelf_id = shelf_delegate()->GetShelfIDForAppID(app_id); 309 const ash::ShelfID shelf_id = shelf_model->GetShelfIDForAppID(app_id);
314 EXPECT_TRUE(shelf_id); 310 EXPECT_TRUE(shelf_id);
315 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id); 311 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id);
316 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); 312 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title);
317 } else { 313 } else {
318 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 314 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id));
319 } 315 }
320 316
321 StopInstance(); 317 StopInstance();
322 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = 318 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
323 app_prefs()->GetApp(app_id); 319 app_prefs()->GetApp(app_id);
324 EXPECT_FALSE(app_info); 320 EXPECT_FALSE(app_info);
325 321
326 // Restart instance. App should be taken from prefs but its state is non-ready 322 // Restart instance. App should be taken from prefs but its state is non-ready
327 // currently. 323 // currently.
328 StartInstance(); 324 StartInstance();
329 app_info = app_prefs()->GetApp(app_id); 325 app_info = app_prefs()->GetApp(app_id);
330 ASSERT_TRUE(app_info); 326 ASSERT_TRUE(app_info);
331 EXPECT_FALSE(app_info->ready); 327 EXPECT_FALSE(app_info->ready);
332 if (is_pinned()) 328 if (is_pinned())
333 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 329 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id));
334 else 330 else
335 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 331 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id));
336 332
337 // Launching non-ready ARC app creates item on shelf and spinning animation. 333 // Launching non-ready ARC app creates item on shelf and spinning animation.
338 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON); 334 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON);
339 const ash::ShelfID shelf_id = shelf_delegate()->GetShelfIDForAppID(app_id); 335 const ash::ShelfID shelf_id = shelf_model->GetShelfIDForAppID(app_id);
340 EXPECT_TRUE(shelf_id); 336 EXPECT_TRUE(shelf_id);
341 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id); 337 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id);
342 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); 338 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title);
343 AppAnimatedWaiter(app_id).Wait(); 339 AppAnimatedWaiter(app_id).Wait();
344 340
345 switch (test_action()) { 341 switch (test_action()) {
346 case TEST_ACTION_START: 342 case TEST_ACTION_START:
347 // Now simulates that ARC is started and app list is refreshed. This 343 // Now simulates that ARC is started and app list is refreshed. This
348 // should stop animation and delete icon from the shelf. 344 // should stop animation and delete icon from the shelf.
349 InstallTestApps(kTestAppPackage, false); 345 InstallTestApps(kTestAppPackage, false);
350 SendPackageAdded(kTestAppPackage, false); 346 SendPackageAdded(kTestAppPackage, false);
351 EXPECT_TRUE(chrome_controller() 347 EXPECT_TRUE(chrome_controller()
352 ->GetArcDeferredLauncher() 348 ->GetArcDeferredLauncher()
353 ->GetActiveTime(app_id) 349 ->GetActiveTime(app_id)
354 .is_zero()); 350 .is_zero());
355 if (is_pinned()) 351 if (is_pinned())
356 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 352 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id));
357 else 353 else
358 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 354 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id));
359 break; 355 break;
360 case TEST_ACTION_EXIT: 356 case TEST_ACTION_EXIT:
361 // Just exist Chrome. 357 // Just exist Chrome.
362 break; 358 break;
363 case TEST_ACTION_CLOSE: 359 case TEST_ACTION_CLOSE:
364 // Close item during animation. 360 // Close item during animation.
365 { 361 {
366 ash::ShelfItemDelegate* controller = GetAppItemController(app_id); 362 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(app_id);
367 ASSERT_TRUE(controller); 363 ASSERT_TRUE(delegate);
368 controller->Close(); 364 delegate->Close();
369 EXPECT_TRUE(chrome_controller() 365 EXPECT_TRUE(chrome_controller()
370 ->GetArcDeferredLauncher() 366 ->GetArcDeferredLauncher()
371 ->GetActiveTime(app_id) 367 ->GetActiveTime(app_id)
372 .is_zero()); 368 .is_zero());
373 if (is_pinned()) 369 if (is_pinned())
374 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id)); 370 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id));
375 else 371 else
376 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id)); 372 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id));
377 } 373 }
378 break; 374 break;
379 } 375 }
380 } 376 }
381 377
382 INSTANTIATE_TEST_CASE_P(ArcAppDeferredLauncherBrowserTestInstance, 378 INSTANTIATE_TEST_CASE_P(ArcAppDeferredLauncherBrowserTestInstance,
383 ArcAppDeferredLauncherBrowserTest, 379 ArcAppDeferredLauncherBrowserTest,
384 ::testing::ValuesIn(build_test_parameter)); 380 ::testing::ValuesIn(build_test_parameter));
385 381
386 // This tests validates pin state on package update and remove. 382 // This tests validates pin state on package update and remove.
387 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) { 383 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) {
388 StartInstance(); 384 StartInstance();
389 385
390 // Make use app list sync service is started. Normally it is started when 386 // Make use app list sync service is started. Normally it is started when
391 // sycing is initialized. 387 // sycing is initialized.
392 app_list::AppListSyncableServiceFactory::GetForProfile(profile())->GetModel(); 388 app_list::AppListSyncableServiceFactory::GetForProfile(profile())->GetModel();
393 389
394 InstallTestApps(kTestAppPackage, true); 390 InstallTestApps(kTestAppPackage, true);
395 SendPackageAdded(kTestAppPackage, false); 391 SendPackageAdded(kTestAppPackage, false);
396 392
397 const std::string app_id1 = GetTestApp1Id(kTestAppPackage); 393 const std::string app_id1 = GetTestApp1Id(kTestAppPackage);
398 const std::string app_id2 = GetTestApp2Id(kTestAppPackage); 394 const std::string app_id2 = GetTestApp2Id(kTestAppPackage);
399 shelf_delegate()->PinAppWithID(app_id1); 395 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model();
400 shelf_delegate()->PinAppWithID(app_id2); 396 shelf_model->PinAppWithID(app_id1);
397 shelf_model->PinAppWithID(app_id2);
401 const ash::ShelfID shelf_id1_before = 398 const ash::ShelfID shelf_id1_before =
402 shelf_delegate()->GetShelfIDForAppID(app_id1); 399 shelf_model->GetShelfIDForAppID(app_id1);
403 EXPECT_TRUE(shelf_id1_before); 400 EXPECT_TRUE(shelf_id1_before);
404 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id2)); 401 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id2));
405 402
406 // Package contains only one app. App list is not shown for updated package. 403 // Package contains only one app. App list is not shown for updated package.
407 SendPackageUpdated(kTestAppPackage, false); 404 SendPackageUpdated(kTestAppPackage, false);
408 // Second pin should gone. 405 // Second pin should gone.
409 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1)); 406 EXPECT_EQ(shelf_id1_before, shelf_model->GetShelfIDForAppID(app_id1));
410 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); 407 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id2));
411 408
412 // Package contains two apps. App list is not shown for updated package. 409 // Package contains two apps. App list is not shown for updated package.
413 SendPackageUpdated(kTestAppPackage, true); 410 SendPackageUpdated(kTestAppPackage, true);
414 // Second pin should not appear. 411 // Second pin should not appear.
415 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1)); 412 EXPECT_EQ(shelf_id1_before, shelf_model->GetShelfIDForAppID(app_id1));
416 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); 413 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id2));
417 414
418 // Package removed. 415 // Package removed.
419 SendPackageRemoved(kTestAppPackage); 416 SendPackageRemoved(kTestAppPackage);
420 // No pin is expected. 417 // No pin is expected.
421 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id1)); 418 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id1));
422 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); 419 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id2));
423 } 420 }
424 421
425 // This test validates that app list is shown on new package and not shown 422 // This test validates that app list is shown on new package and not shown
426 // on package update. 423 // on package update.
427 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, AppListShown) { 424 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, AppListShown) {
428 StartInstance(); 425 StartInstance();
429 AppListService* app_list_service = AppListService::Get(); 426 AppListService* app_list_service = AppListService::Get();
430 ASSERT_TRUE(app_list_service); 427 ASSERT_TRUE(app_list_service);
431 428
432 EXPECT_FALSE(app_list_service->IsAppListVisible()); 429 EXPECT_FALSE(app_list_service->IsAppListVisible());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 arc::ArcAppShelfId(kTestShelfGroup, app_id).ToString(); 497 arc::ArcAppShelfId(kTestShelfGroup, app_id).ToString();
501 const std::string shelf_id2 = 498 const std::string shelf_id2 =
502 arc::ArcAppShelfId(kTestShelfGroup2, app_id).ToString(); 499 arc::ArcAppShelfId(kTestShelfGroup2, app_id).ToString();
503 const std::string shelf_id3 = 500 const std::string shelf_id3 =
504 arc::ArcAppShelfId(kTestShelfGroup3, app_id).ToString(); 501 arc::ArcAppShelfId(kTestShelfGroup3, app_id).ToString();
505 502
506 // 1 task for group 1 503 // 1 task for group 1
507 app_host()->OnTaskCreated(1, info->package_name, info->activity, info->name, 504 app_host()->OnTaskCreated(1, info->package_name, info->activity, info->name,
508 CreateIntentUriWithShelfGroup(kTestShelfGroup)); 505 CreateIntentUriWithShelfGroup(kTestShelfGroup));
509 506
510 ash::ShelfItemDelegate* controller1 = GetAppItemController(shelf_id1); 507 ash::ShelfItemDelegate* delegate1 = GetShelfItemDelegate(shelf_id1);
511 ASSERT_TRUE(controller1); 508 ASSERT_TRUE(delegate1);
512 509
513 // 2 tasks for group 2 510 // 2 tasks for group 2
514 app_host()->OnTaskCreated(2, info->package_name, info->activity, info->name, 511 app_host()->OnTaskCreated(2, info->package_name, info->activity, info->name,
515 CreateIntentUriWithShelfGroup(kTestShelfGroup2)); 512 CreateIntentUriWithShelfGroup(kTestShelfGroup2));
516 513
517 ash::ShelfItemDelegate* controller2 = GetAppItemController(shelf_id2); 514 ash::ShelfItemDelegate* delegate2 = GetShelfItemDelegate(shelf_id2);
518 ASSERT_TRUE(controller2); 515 ASSERT_TRUE(delegate2);
519 ASSERT_NE(controller1, controller2); 516 ASSERT_NE(delegate1, delegate2);
520 517
521 app_host()->OnTaskCreated(3, info->package_name, info->activity, info->name, 518 app_host()->OnTaskCreated(3, info->package_name, info->activity, info->name,
522 CreateIntentUriWithShelfGroup(kTestShelfGroup2)); 519 CreateIntentUriWithShelfGroup(kTestShelfGroup2));
523 520
524 ASSERT_EQ(controller2, GetAppItemController(shelf_id2)); 521 ASSERT_EQ(delegate2, GetShelfItemDelegate(shelf_id2));
525 522
526 // 2 tasks for group 3 which does not have shortcut. 523 // 2 tasks for group 3 which does not have shortcut.
527 app_host()->OnTaskCreated(4, info->package_name, info->activity, info->name, 524 app_host()->OnTaskCreated(4, info->package_name, info->activity, info->name,
528 CreateIntentUriWithShelfGroup(kTestShelfGroup3)); 525 CreateIntentUriWithShelfGroup(kTestShelfGroup3));
529 526
530 ash::ShelfItemDelegate* controller3 = GetAppItemController(shelf_id3); 527 ash::ShelfItemDelegate* delegate3 = GetShelfItemDelegate(shelf_id3);
531 ASSERT_TRUE(controller3); 528 ASSERT_TRUE(delegate3);
532 ASSERT_NE(controller1, controller3); 529 ASSERT_NE(delegate1, delegate3);
533 ASSERT_NE(controller2, controller3); 530 ASSERT_NE(delegate2, delegate3);
534 531
535 app_host()->OnTaskCreated(5, info->package_name, info->activity, info->name, 532 app_host()->OnTaskCreated(5, info->package_name, info->activity, info->name,
536 CreateIntentUriWithShelfGroup(kTestShelfGroup3)); 533 CreateIntentUriWithShelfGroup(kTestShelfGroup3));
537 534
538 ASSERT_EQ(controller3, GetAppItemController(shelf_id3)); 535 ASSERT_EQ(delegate3, GetShelfItemDelegate(shelf_id3));
539 536
540 // Destroy task #0, this kills shelf group 1 537 // Destroy task #0, this kills shelf group 1
541 app_host()->OnTaskDestroyed(1); 538 app_host()->OnTaskDestroyed(1);
542 EXPECT_FALSE(GetAppItemController(shelf_id1)); 539 EXPECT_FALSE(GetShelfItemDelegate(shelf_id1));
543 540
544 // Destroy task #1, shelf group 2 is still alive 541 // Destroy task #1, shelf group 2 is still alive
545 app_host()->OnTaskDestroyed(2); 542 app_host()->OnTaskDestroyed(2);
546 EXPECT_EQ(controller2, GetAppItemController(shelf_id2)); 543 EXPECT_EQ(delegate2, GetShelfItemDelegate(shelf_id2));
547 // Destroy task #2, this kills shelf group 2 544 // Destroy task #2, this kills shelf group 2
548 app_host()->OnTaskDestroyed(3); 545 app_host()->OnTaskDestroyed(3);
549 EXPECT_FALSE(GetAppItemController(shelf_id2)); 546 EXPECT_FALSE(GetShelfItemDelegate(shelf_id2));
550 547
551 // Disable ARC, this removes app and as result kills shelf group 3. 548 // Disable ARC, this removes app and as result kills shelf group 3.
552 arc::SetArcPlayStoreEnabledForProfile(profile(), false); 549 arc::SetArcPlayStoreEnabledForProfile(profile(), false);
553 EXPECT_FALSE(GetAppItemController(shelf_id3)); 550 EXPECT_FALSE(GetShelfItemDelegate(shelf_id3));
554 } 551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698