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

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_unittest.cc

Issue 2106663004: arc: Initial implemetation of Chrome sync for Arc packages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wrap bridge state related method in unit_tests. Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 305 }
306 306
307 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { 307 void RemovePackage(const arc::mojom::ArcPackageInfo& package) {
308 arc_test_.RemovePackage(package); 308 arc_test_.RemovePackage(package);
309 } 309 }
310 310
311 AppListControllerDelegate* controller() { return controller_.get(); } 311 AppListControllerDelegate* controller() { return controller_.get(); }
312 312
313 Profile* profile() { return profile_.get(); } 313 Profile* profile() { return profile_.get(); }
314 314
315 ArcAppTest* arc_test() {
316 return &arc_test_;
317 }
318
315 const std::vector<arc::mojom::AppInfo>& fake_apps() const { 319 const std::vector<arc::mojom::AppInfo>& fake_apps() const {
316 return arc_test_.fake_apps(); 320 return arc_test_.fake_apps();
317 } 321 }
318 322
319 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const { 323 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const {
320 return arc_test_.fake_packages(); 324 return arc_test_.fake_packages();
321 } 325 }
322 326
323 const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const { 327 const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const {
324 return arc_test_.fake_shortcuts(); 328 return arc_test_.fake_shortcuts();
325 } 329 }
326 330
327 arc::FakeArcBridgeService* bridge_service() {
328 return arc_test_.bridge_service();
329 }
330
331 arc::FakeAppInstance* app_instance() { 331 arc::FakeAppInstance* app_instance() {
332 return arc_test_.app_instance(); 332 return arc_test_.app_instance();
333 } 333 }
334 334
335 private: 335 private:
336 ArcAppTest arc_test_; 336 ArcAppTest arc_test_;
337 std::unique_ptr<app_list::AppListModel> model_; 337 std::unique_ptr<app_list::AppListModel> model_;
338 std::unique_ptr<test::TestAppListControllerDelegate> controller_; 338 std::unique_ptr<test::TestAppListControllerDelegate> controller_;
339 std::unique_ptr<ArcAppModelBuilder> builder_; 339 std::unique_ptr<ArcAppModelBuilder> builder_;
340 340
341 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); 341 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest);
342 }; 342 };
343 343
344 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { 344 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) {
345 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); 345 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>());
346 bridge_service()->SetReady(); 346 arc_test()->SetBridgeServiceReady();
347 app_instance()->SendRefreshPackageList(fake_packages()); 347 app_instance()->SendRefreshPackageList(fake_packages());
348 ValidateHavePackages(fake_packages()); 348 ValidateHavePackages(fake_packages());
349 349
350 arc::mojom::ArcPackageInfo package; 350 arc::mojom::ArcPackageInfo package;
351 package.package_name = kTestPackageName; 351 package.package_name = kTestPackageName;
352 package.package_version = 2; 352 package.package_version = 2;
353 package.last_backup_android_id = 2; 353 package.last_backup_android_id = 2;
354 package.last_backup_time = 2; 354 package.last_backup_time = 2;
355 package.sync = true; 355 package.sync = true;
356 356
357 RemovePackage(package); 357 RemovePackage(package);
358 app_instance()->SendPackageUninstalled(package.package_name); 358 app_instance()->SendPackageUninstalled(package.package_name);
359 ValidateHavePackages(fake_packages()); 359 ValidateHavePackages(fake_packages());
360 360
361 AddPackage(package); 361 AddPackage(package);
362 app_instance()->SendPackageAdded(package); 362 app_instance()->SendPackageAdded(package);
363 ValidateHavePackages(fake_packages()); 363 ValidateHavePackages(fake_packages());
364 } 364 }
365 365
366 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { 366 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) {
367 // There should already have been one call, when the interface was 367 // There should already have been one call, when the interface was
368 // registered. 368 // registered.
369 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); 369 EXPECT_EQ(1, app_instance()->refresh_app_list_count());
370 bridge_service()->SetReady(); 370 arc_test()->SetBridgeServiceReady();
371 app_instance()->RefreshAppList(); 371 app_instance()->RefreshAppList();
372 EXPECT_EQ(2, app_instance()->refresh_app_list_count()); 372 EXPECT_EQ(2, app_instance()->refresh_app_list_count());
373 } 373 }
374 374
375 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { 375 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) {
376 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 376 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
377 bridge_service()->SetReady(); 377 arc_test()->SetBridgeServiceReady();
378 app_instance()->RefreshAppList(); 378 app_instance()->RefreshAppList();
379 app_instance()->SendRefreshAppList(fake_apps()); 379 app_instance()->SendRefreshAppList(fake_apps());
380 ValidateHaveApps(fake_apps()); 380 ValidateHaveApps(fake_apps());
381 } 381 }
382 382
383 TEST_F(ArcAppModelBuilderTest, InstallShortcut) { 383 TEST_F(ArcAppModelBuilderTest, InstallShortcut) {
384 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 384 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
385 bridge_service()->SetReady(); 385 arc_test()->SetBridgeServiceReady();
386 386
387 app_instance()->SendInstallShortcuts(fake_shortcuts()); 387 app_instance()->SendInstallShortcuts(fake_shortcuts());
388 ValidateHaveShortcuts(fake_shortcuts()); 388 ValidateHaveShortcuts(fake_shortcuts());
389 } 389 }
390 390
391 TEST_F(ArcAppModelBuilderTest, RefreshAllPreservesShortcut) { 391 TEST_F(ArcAppModelBuilderTest, RefreshAllPreservesShortcut) {
392 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 392 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
393 bridge_service()->SetReady(); 393 arc_test()->SetBridgeServiceReady();
394 app_instance()->RefreshAppList(); 394 app_instance()->RefreshAppList();
395 app_instance()->SendRefreshAppList(fake_apps()); 395 app_instance()->SendRefreshAppList(fake_apps());
396 ValidateHaveApps(fake_apps()); 396 ValidateHaveApps(fake_apps());
397 397
398 app_instance()->SendInstallShortcuts(fake_shortcuts()); 398 app_instance()->SendInstallShortcuts(fake_shortcuts());
399 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); 399 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts());
400 400
401 app_instance()->RefreshAppList(); 401 app_instance()->RefreshAppList();
402 app_instance()->SendRefreshAppList(fake_apps()); 402 app_instance()->SendRefreshAppList(fake_apps());
403 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); 403 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts());
404 } 404 }
405 405
406 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { 406 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) {
407 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 407 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
408 bridge_service()->SetReady(); 408 arc_test()->SetBridgeServiceReady();
409 app_instance()->RefreshAppList(); 409 app_instance()->RefreshAppList();
410 // Send info about all fake apps except last. 410 // Send info about all fake apps except last.
411 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), 411 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(),
412 fake_apps().end() - 1); 412 fake_apps().end() - 1);
413 app_instance()->SendRefreshAppList(apps1); 413 app_instance()->SendRefreshAppList(apps1);
414 // At this point all apps (except last) should exist and be ready. 414 // At this point all apps (except last) should exist and be ready.
415 ValidateHaveApps(apps1); 415 ValidateHaveApps(apps1);
416 ValidateAppReadyState(apps1, true); 416 ValidateAppReadyState(apps1, true);
417 417
418 // Send info about all fake apps except first. 418 // Send info about all fake apps except first.
(...skipping 14 matching lines...) Expand all
433 std::vector<arc::mojom::AppInfo> no_apps; 433 std::vector<arc::mojom::AppInfo> no_apps;
434 app_instance()->SendRefreshAppList(no_apps); 434 app_instance()->SendRefreshAppList(no_apps);
435 // At this point no app should exist. 435 // At this point no app should exist.
436 ValidateHaveApps(no_apps); 436 ValidateHaveApps(no_apps);
437 } 437 }
438 438
439 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveApps) { 439 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveApps) {
440 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 440 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
441 ASSERT_NE(nullptr, prefs); 441 ASSERT_NE(nullptr, prefs);
442 442
443 bridge_service()->SetReady(); 443 arc_test()->SetBridgeServiceReady();
444 app_instance()->RefreshAppList(); 444 app_instance()->RefreshAppList();
445 EXPECT_EQ(0u, GetArcItemCount()); 445 EXPECT_EQ(0u, GetArcItemCount());
446 EXPECT_EQ(0u, prefs->GetAppIds().size()); 446 EXPECT_EQ(0u, prefs->GetAppIds().size());
447 447
448 app_instance()->SendRefreshAppList(fake_apps()); 448 app_instance()->SendRefreshAppList(fake_apps());
449 std::vector<std::string> ids = prefs->GetAppIds(); 449 std::vector<std::string> ids = prefs->GetAppIds();
450 EXPECT_EQ(fake_apps().size(), ids.size()); 450 EXPECT_EQ(fake_apps().size(), ids.size());
451 ValidateAppReadyState(fake_apps(), true); 451 ValidateAppReadyState(fake_apps(), true);
452 452
453 // Stopping service does not delete items. It makes them non-ready. 453 // Stopping service does not delete items. It makes them non-ready.
454 bridge_service()->SetStopped(); 454 arc_test()->SetBridgeServiceStopped();
455 // Ids should be the same. 455 // Ids should be the same.
456 EXPECT_EQ(ids, prefs->GetAppIds()); 456 EXPECT_EQ(ids, prefs->GetAppIds());
457 ValidateAppReadyState(fake_apps(), false); 457 ValidateAppReadyState(fake_apps(), false);
458 458
459 // Setting service ready does not change anything because RefreshAppList is 459 // Setting service ready does not change anything because RefreshAppList is
460 // not called. 460 // not called.
461 bridge_service()->SetReady(); 461 arc_test()->SetBridgeServiceReady();
462 // Ids should be the same. 462 // Ids should be the same.
463 EXPECT_EQ(ids, prefs->GetAppIds()); 463 EXPECT_EQ(ids, prefs->GetAppIds());
464 ValidateAppReadyState(fake_apps(), false); 464 ValidateAppReadyState(fake_apps(), false);
465 465
466 // Refreshing app list makes apps available. 466 // Refreshing app list makes apps available.
467 app_instance()->SendRefreshAppList(fake_apps()); 467 app_instance()->SendRefreshAppList(fake_apps());
468 EXPECT_EQ(ids, prefs->GetAppIds()); 468 EXPECT_EQ(ids, prefs->GetAppIds());
469 ValidateAppReadyState(fake_apps(), true); 469 ValidateAppReadyState(fake_apps(), true);
470 } 470 }
471 471
472 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveShortcuts) { 472 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveShortcuts) {
473 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 473 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
474 ASSERT_NE(nullptr, prefs); 474 ASSERT_NE(nullptr, prefs);
475 475
476 bridge_service()->SetReady(); 476 arc_test()->SetBridgeServiceReady();
477 app_instance()->RefreshAppList(); 477 app_instance()->RefreshAppList();
478 EXPECT_EQ(0u, GetArcItemCount()); 478 EXPECT_EQ(0u, GetArcItemCount());
479 EXPECT_EQ(0u, prefs->GetAppIds().size()); 479 EXPECT_EQ(0u, prefs->GetAppIds().size());
480 480
481 app_instance()->SendInstallShortcuts(fake_shortcuts()); 481 app_instance()->SendInstallShortcuts(fake_shortcuts());
482 std::vector<std::string> ids = prefs->GetAppIds(); 482 std::vector<std::string> ids = prefs->GetAppIds();
483 EXPECT_EQ(fake_shortcuts().size(), ids.size()); 483 EXPECT_EQ(fake_shortcuts().size(), ids.size());
484 ValidateShortcutReadyState(fake_shortcuts(), true); 484 ValidateShortcutReadyState(fake_shortcuts(), true);
485 485
486 // Stopping service does not delete items. It makes them non-ready. 486 // Stopping service does not delete items. It makes them non-ready.
487 bridge_service()->SetStopped(); 487 arc_test()->SetBridgeServiceStopped();
488 // Ids should be the same. 488 // Ids should be the same.
489 EXPECT_EQ(ids, prefs->GetAppIds()); 489 EXPECT_EQ(ids, prefs->GetAppIds());
490 ValidateShortcutReadyState(fake_shortcuts(), false); 490 ValidateShortcutReadyState(fake_shortcuts(), false);
491 491
492 // Setting service ready does not change anything because RefreshAppList is 492 // Setting service ready does not change anything because RefreshAppList is
493 // not called. 493 // not called.
494 bridge_service()->SetReady(); 494 arc_test()->SetBridgeServiceReady();
495 // Ids should be the same. 495 // Ids should be the same.
496 EXPECT_EQ(ids, prefs->GetAppIds()); 496 EXPECT_EQ(ids, prefs->GetAppIds());
497 ValidateShortcutReadyState(fake_shortcuts(), false); 497 ValidateShortcutReadyState(fake_shortcuts(), false);
498 498
499 // Refreshing app list makes apps available. 499 // Refreshing app list makes apps available.
500 app_instance()->RefreshAppList(); 500 app_instance()->RefreshAppList();
501 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>()); 501 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>());
502 EXPECT_EQ(ids, prefs->GetAppIds()); 502 EXPECT_EQ(ids, prefs->GetAppIds());
503 ValidateShortcutReadyState(fake_shortcuts(), true); 503 ValidateShortcutReadyState(fake_shortcuts(), true);
504 } 504 }
505 505
506 TEST_F(ArcAppModelBuilderTest, RestartPreserveApps) { 506 TEST_F(ArcAppModelBuilderTest, RestartPreserveApps) {
507 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 507 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
508 ASSERT_NE(nullptr, prefs); 508 ASSERT_NE(nullptr, prefs);
509 509
510 // Start from scratch and fill with apps. 510 // Start from scratch and fill with apps.
511 bridge_service()->SetReady(); 511 arc_test()->SetBridgeServiceReady();
512 app_instance()->SendRefreshAppList(fake_apps()); 512 app_instance()->SendRefreshAppList(fake_apps());
513 std::vector<std::string> ids = prefs->GetAppIds(); 513 std::vector<std::string> ids = prefs->GetAppIds();
514 EXPECT_EQ(fake_apps().size(), ids.size()); 514 EXPECT_EQ(fake_apps().size(), ids.size());
515 ValidateAppReadyState(fake_apps(), true); 515 ValidateAppReadyState(fake_apps(), true);
516 516
517 // This recreates model and ARC apps will be read from prefs. 517 // This recreates model and ARC apps will be read from prefs.
518 bridge_service()->SetStopped(); 518 arc_test()->SetBridgeServiceStopped();
519 CreateBuilder(); 519 CreateBuilder();
520 ValidateAppReadyState(fake_apps(), false); 520 ValidateAppReadyState(fake_apps(), false);
521 } 521 }
522 522
523 TEST_F(ArcAppModelBuilderTest, RestartPreserveShortcuts) { 523 TEST_F(ArcAppModelBuilderTest, RestartPreserveShortcuts) {
524 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 524 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
525 ASSERT_NE(nullptr, prefs); 525 ASSERT_NE(nullptr, prefs);
526 526
527 // Start from scratch and install shortcuts. 527 // Start from scratch and install shortcuts.
528 bridge_service()->SetReady(); 528 arc_test()->SetBridgeServiceReady();
529 app_instance()->SendInstallShortcuts(fake_shortcuts()); 529 app_instance()->SendInstallShortcuts(fake_shortcuts());
530 std::vector<std::string> ids = prefs->GetAppIds(); 530 std::vector<std::string> ids = prefs->GetAppIds();
531 EXPECT_EQ(fake_apps().size(), ids.size()); 531 EXPECT_EQ(fake_apps().size(), ids.size());
532 ValidateShortcutReadyState(fake_shortcuts(), true); 532 ValidateShortcutReadyState(fake_shortcuts(), true);
533 533
534 // This recreates model and ARC apps and shortcuts will be read from prefs. 534 // This recreates model and ARC apps and shortcuts will be read from prefs.
535 bridge_service()->SetStopped(); 535 arc_test()->SetBridgeServiceStopped();
536 CreateBuilder(); 536 CreateBuilder();
537 ValidateShortcutReadyState(fake_shortcuts(), false); 537 ValidateShortcutReadyState(fake_shortcuts(), false);
538 } 538 }
539 539
540 TEST_F(ArcAppModelBuilderTest, LaunchApps) { 540 TEST_F(ArcAppModelBuilderTest, LaunchApps) {
541 // Disable attempts to dismiss app launcher view. 541 // Disable attempts to dismiss app launcher view.
542 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); 542 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller());
543 543
544 bridge_service()->SetReady(); 544 arc_test()->SetBridgeServiceReady();
545 app_instance()->RefreshAppList(); 545 app_instance()->RefreshAppList();
546 app_instance()->SendRefreshAppList(fake_apps()); 546 app_instance()->SendRefreshAppList(fake_apps());
547 547
548 // Simulate item activate. 548 // Simulate item activate.
549 const arc::mojom::AppInfo& app_first = fake_apps()[0]; 549 const arc::mojom::AppInfo& app_first = fake_apps()[0];
550 const arc::mojom::AppInfo& app_last = fake_apps()[0]; 550 const arc::mojom::AppInfo& app_last = fake_apps()[0];
551 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 551 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
552 ArcAppItem* item_last = FindArcItem(ArcAppTest::GetAppId(app_last)); 552 ArcAppItem* item_last = FindArcItem(ArcAppTest::GetAppId(app_last));
553 ASSERT_NE(nullptr, item_first); 553 ASSERT_NE(nullptr, item_first);
554 ASSERT_NE(nullptr, item_last); 554 ASSERT_NE(nullptr, item_last);
555 item_first->Activate(0); 555 item_first->Activate(0);
556 item_last->Activate(0); 556 item_last->Activate(0);
557 item_first->Activate(0); 557 item_first->Activate(0);
558 558
559 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = 559 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests =
560 app_instance()->launch_requests(); 560 app_instance()->launch_requests();
561 ASSERT_EQ(3u, launch_requests.size()); 561 ASSERT_EQ(3u, launch_requests.size());
562 EXPECT_TRUE(launch_requests[0]->IsForApp(app_first)); 562 EXPECT_TRUE(launch_requests[0]->IsForApp(app_first));
563 EXPECT_TRUE(launch_requests[1]->IsForApp(app_last)); 563 EXPECT_TRUE(launch_requests[1]->IsForApp(app_last));
564 EXPECT_TRUE(launch_requests[2]->IsForApp(app_first)); 564 EXPECT_TRUE(launch_requests[2]->IsForApp(app_first));
565 565
566 // Test an attempt to launch of a not-ready app. 566 // Test an attempt to launch of a not-ready app.
567 bridge_service()->SetStopped(); 567 arc_test()->SetBridgeServiceStopped();
568 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 568 item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
569 ASSERT_NE(nullptr, item_first); 569 ASSERT_NE(nullptr, item_first);
570 size_t launch_request_count_before = app_instance()->launch_requests().size(); 570 size_t launch_request_count_before = app_instance()->launch_requests().size();
571 item_first->Activate(0); 571 item_first->Activate(0);
572 // Number of launch requests must not change. 572 // Number of launch requests must not change.
573 EXPECT_EQ(launch_request_count_before, 573 EXPECT_EQ(launch_request_count_before,
574 app_instance()->launch_requests().size()); 574 app_instance()->launch_requests().size());
575 } 575 }
576 576
577 TEST_F(ArcAppModelBuilderTest, LaunchShortcuts) { 577 TEST_F(ArcAppModelBuilderTest, LaunchShortcuts) {
578 // Disable attempts to dismiss app launcher view. 578 // Disable attempts to dismiss app launcher view.
579 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); 579 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller());
580 580
581 bridge_service()->SetReady(); 581 arc_test()->SetBridgeServiceReady();
582 app_instance()->RefreshAppList(); 582 app_instance()->RefreshAppList();
583 app_instance()->SendInstallShortcuts(fake_shortcuts()); 583 app_instance()->SendInstallShortcuts(fake_shortcuts());
584 584
585 // Simulate item activate. 585 // Simulate item activate.
586 const arc::mojom::ShortcutInfo& app_first = fake_shortcuts()[0]; 586 const arc::mojom::ShortcutInfo& app_first = fake_shortcuts()[0];
587 const arc::mojom::ShortcutInfo& app_last = fake_shortcuts()[0]; 587 const arc::mojom::ShortcutInfo& app_last = fake_shortcuts()[0];
588 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 588 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
589 ArcAppItem* item_last = FindArcItem(ArcAppTest::GetAppId(app_last)); 589 ArcAppItem* item_last = FindArcItem(ArcAppTest::GetAppId(app_last));
590 ASSERT_NE(nullptr, item_first); 590 ASSERT_NE(nullptr, item_first);
591 ASSERT_NE(nullptr, item_last); 591 ASSERT_NE(nullptr, item_last);
592 item_first->Activate(0); 592 item_first->Activate(0);
593 item_last->Activate(0); 593 item_last->Activate(0);
594 item_first->Activate(0); 594 item_first->Activate(0);
595 595
596 const ScopedVector<mojo::String>& launch_intents = 596 const ScopedVector<mojo::String>& launch_intents =
597 app_instance()->launch_intents(); 597 app_instance()->launch_intents();
598 ASSERT_EQ(3u, launch_intents.size()); 598 ASSERT_EQ(3u, launch_intents.size());
599 EXPECT_EQ(app_first.intent_uri, *launch_intents[0]); 599 EXPECT_EQ(app_first.intent_uri, *launch_intents[0]);
600 EXPECT_EQ(app_last.intent_uri, *launch_intents[1]); 600 EXPECT_EQ(app_last.intent_uri, *launch_intents[1]);
601 EXPECT_EQ(app_first.intent_uri, *launch_intents[2]); 601 EXPECT_EQ(app_first.intent_uri, *launch_intents[2]);
602 602
603 // Test an attempt to launch of a not-ready shortcut. 603 // Test an attempt to launch of a not-ready shortcut.
604 bridge_service()->SetStopped(); 604 arc_test()->SetBridgeServiceStopped();
605 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 605 item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
606 ASSERT_NE(nullptr, item_first); 606 ASSERT_NE(nullptr, item_first);
607 size_t launch_request_count_before = app_instance()->launch_intents().size(); 607 size_t launch_request_count_before = app_instance()->launch_intents().size();
608 item_first->Activate(0); 608 item_first->Activate(0);
609 // Number of launch requests must not change. 609 // Number of launch requests must not change.
610 EXPECT_EQ(launch_request_count_before, 610 EXPECT_EQ(launch_request_count_before,
611 app_instance()->launch_intents().size()); 611 app_instance()->launch_intents().size());
612 } 612 }
613 613
614 TEST_F(ArcAppModelBuilderTest, RequestIcons) { 614 TEST_F(ArcAppModelBuilderTest, RequestIcons) {
615 // Make sure we are on UI thread. 615 // Make sure we are on UI thread.
616 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 616 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
617 617
618 bridge_service()->SetReady(); 618 arc_test()->SetBridgeServiceReady();
619 app_instance()->RefreshAppList(); 619 app_instance()->RefreshAppList();
620 app_instance()->SendRefreshAppList(fake_apps()); 620 app_instance()->SendRefreshAppList(fake_apps());
621 621
622 // Validate that no icon exists at the beginning and request icon for 622 // Validate that no icon exists at the beginning and request icon for
623 // each supported scale factor. This will start asynchronous loading. 623 // each supported scale factor. This will start asynchronous loading.
624 uint32_t expected_mask = 0; 624 uint32_t expected_mask = 0;
625 const std::vector<ui::ScaleFactor>& scale_factors = 625 const std::vector<ui::ScaleFactor>& scale_factors =
626 ui::GetSupportedScaleFactors(); 626 ui::GetSupportedScaleFactors();
627 for (auto& scale_factor : scale_factors) { 627 for (auto& scale_factor : scale_factors) {
628 expected_mask |= 1 << scale_factor; 628 expected_mask |= 1 << scale_factor;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 const std::string id = ArcAppTest::GetAppId(app); 663 const std::string id = ArcAppTest::GetAppId(app);
664 ASSERT_NE(app_masks.find(id), app_masks.end()); 664 ASSERT_NE(app_masks.find(id), app_masks.end());
665 EXPECT_EQ(app_masks[id], expected_mask); 665 EXPECT_EQ(app_masks[id], expected_mask);
666 } 666 }
667 } 667 }
668 668
669 TEST_F(ArcAppModelBuilderTest, RequestShortcutIcons) { 669 TEST_F(ArcAppModelBuilderTest, RequestShortcutIcons) {
670 // Make sure we are on UI thread. 670 // Make sure we are on UI thread.
671 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 671 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
672 672
673 bridge_service()->SetReady(); 673 arc_test()->SetBridgeServiceReady();
674 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0]; 674 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0];
675 app_instance()->SendInstallShortcut(shortcut); 675 app_instance()->SendInstallShortcut(shortcut);
676 676
677 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 677 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
678 ASSERT_NE(nullptr, prefs); 678 ASSERT_NE(nullptr, prefs);
679 679
680 // Validate that no icon exists at the beginning and request icon for 680 // Validate that no icon exists at the beginning and request icon for
681 // each supported scale factor. This will start asynchronous loading. 681 // each supported scale factor. This will start asynchronous loading.
682 uint32_t expected_mask = 0; 682 uint32_t expected_mask = 0;
683 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(shortcut)); 683 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(shortcut));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 const base::FilePath icon_path = 720 const base::FilePath icon_path =
721 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor); 721 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor);
722 EXPECT_TRUE(base::PathExists(icon_path)); 722 EXPECT_TRUE(base::PathExists(icon_path));
723 } 723 }
724 } 724 }
725 725
726 TEST_F(ArcAppModelBuilderTest, InstallIcon) { 726 TEST_F(ArcAppModelBuilderTest, InstallIcon) {
727 // Make sure we are on UI thread. 727 // Make sure we are on UI thread.
728 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 728 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
729 729
730 bridge_service()->SetReady(); 730 arc_test()->SetBridgeServiceReady();
731 app_instance()->RefreshAppList(); 731 app_instance()->RefreshAppList();
732 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 732 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
733 fake_apps().begin(), fake_apps().begin() + 1)); 733 fake_apps().begin(), fake_apps().begin() + 1));
734 const arc::mojom::AppInfo& app = fake_apps()[0]; 734 const arc::mojom::AppInfo& app = fake_apps()[0];
735 735
736 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 736 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
737 ASSERT_NE(nullptr, prefs); 737 ASSERT_NE(nullptr, prefs);
738 738
739 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; 739 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0];
740 const float scale = ui::GetScaleForScaleFactor(scale_factor); 740 const float scale = ui::GetScaleForScaleFactor(scale_factor);
(...skipping 19 matching lines...) Expand all
760 std::string icon_data; 760 std::string icon_data;
761 // Read the file from disk and compare with reference data. 761 // Read the file from disk and compare with reference data.
762 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data)); 762 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data));
763 ASSERT_EQ(icon_data, png_data); 763 ASSERT_EQ(icon_data, png_data);
764 } 764 }
765 765
766 TEST_F(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) { 766 TEST_F(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) {
767 // Make sure we are on UI thread. 767 // Make sure we are on UI thread.
768 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 768 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
769 769
770 bridge_service()->SetReady(); 770 arc_test()->SetBridgeServiceReady();
771 app_instance()->RefreshAppList(); 771 app_instance()->RefreshAppList();
772 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 772 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
773 fake_apps().begin(), fake_apps().begin() + 1)); 773 fake_apps().begin(), fake_apps().begin() + 1));
774 const arc::mojom::AppInfo& app = fake_apps()[0]; 774 const arc::mojom::AppInfo& app = fake_apps()[0];
775 775
776 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 776 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
777 ASSERT_NE(nullptr, prefs); 777 ASSERT_NE(nullptr, prefs);
778 778
779 const std::string app_id = ArcAppTest::GetAppId(app); 779 const std::string app_id = ArcAppTest::GetAppId(app);
780 const base::FilePath app_path = prefs->GetAppPath(app_id); 780 const base::FilePath app_path = prefs->GetAppPath(app_id);
(...skipping 22 matching lines...) Expand all
803 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 803 content::BrowserThread::GetBlockingPool()->FlushForTesting();
804 base::RunLoop().RunUntilIdle(); 804 base::RunLoop().RunUntilIdle();
805 } while (base::PathExists(app_path)); 805 } while (base::PathExists(app_path));
806 EXPECT_FALSE(base::PathExists(app_path)); 806 EXPECT_FALSE(base::PathExists(app_path));
807 } 807 }
808 808
809 TEST_F(ArcAppModelBuilderTest, LastLaunchTime) { 809 TEST_F(ArcAppModelBuilderTest, LastLaunchTime) {
810 // Make sure we are on UI thread. 810 // Make sure we are on UI thread.
811 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 811 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
812 812
813 bridge_service()->SetReady(); 813 arc_test()->SetBridgeServiceReady();
814 app_instance()->RefreshAppList(); 814 app_instance()->RefreshAppList();
815 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 815 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
816 fake_apps().begin(), fake_apps().begin() + 2)); 816 fake_apps().begin(), fake_apps().begin() + 2));
817 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 817 const arc::mojom::AppInfo& app1 = fake_apps()[0];
818 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 818 const arc::mojom::AppInfo& app2 = fake_apps()[1];
819 const std::string id1 = ArcAppTest::GetAppId(app1); 819 const std::string id1 = ArcAppTest::GetAppId(app1);
820 const std::string id2 = ArcAppTest::GetAppId(app2); 820 const std::string id2 = ArcAppTest::GetAppId(app2);
821 821
822 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 822 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
823 ASSERT_NE(nullptr, prefs); 823 ASSERT_NE(nullptr, prefs);
(...skipping 27 matching lines...) Expand all
851 } 851 }
852 852
853 // TODO(crbug.com/628425) -- reenable once this test is less flaky. 853 // TODO(crbug.com/628425) -- reenable once this test is less flaky.
854 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { 854 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) {
855 const arc::mojom::AppInfo& app = fake_apps()[0]; 855 const arc::mojom::AppInfo& app = fake_apps()[0];
856 const std::string app_id = ArcAppTest::GetAppId(app); 856 const std::string app_id = ArcAppTest::GetAppId(app);
857 857
858 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 858 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
859 ASSERT_NE(nullptr, prefs); 859 ASSERT_NE(nullptr, prefs);
860 860
861 bridge_service()->SetReady(); 861 arc_test()->SetBridgeServiceReady();
862 app_instance()->RefreshAppList(); 862 app_instance()->RefreshAppList();
863 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 863 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
864 fake_apps().begin(), fake_apps().begin() + 1)); 864 fake_apps().begin(), fake_apps().begin() + 1));
865 865
866 FakeAppIconLoaderDelegate delegate; 866 FakeAppIconLoaderDelegate delegate;
867 ArcAppIconLoader icon_loader(profile(), 867 ArcAppIconLoader icon_loader(profile(),
868 app_list::kListIconSize, 868 app_list::kListIconSize,
869 &delegate); 869 &delegate);
870 EXPECT_EQ(0UL, delegate.update_image_cnt()); 870 EXPECT_EQ(0UL, delegate.update_image_cnt());
871 icon_loader.FetchImage(app_id); 871 icon_loader.FetchImage(app_id);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 905 const arc::mojom::AppInfo& app2 = fake_apps()[1];
906 const arc::mojom::AppInfo& app3 = fake_apps()[2]; 906 const arc::mojom::AppInfo& app3 = fake_apps()[2];
907 const std::string id1 = ArcAppTest::GetAppId(app1); 907 const std::string id1 = ArcAppTest::GetAppId(app1);
908 const std::string id2 = ArcAppTest::GetAppId(app2); 908 const std::string id2 = ArcAppTest::GetAppId(app2);
909 const std::string id3 = ArcAppTest::GetAppId(app3); 909 const std::string id3 = ArcAppTest::GetAppId(app3);
910 910
911 ArcAppLauncher launcher1(profile(), id1, true); 911 ArcAppLauncher launcher1(profile(), id1, true);
912 EXPECT_FALSE(launcher1.app_launched()); 912 EXPECT_FALSE(launcher1.app_launched());
913 EXPECT_TRUE(prefs->HasObserver(&launcher1)); 913 EXPECT_TRUE(prefs->HasObserver(&launcher1));
914 914
915 bridge_service()->SetReady(); 915 arc_test()->SetBridgeServiceReady();
916 916
917 ArcAppLauncher launcher3(profile(), id3, true); 917 ArcAppLauncher launcher3(profile(), id3, true);
918 EXPECT_FALSE(launcher1.app_launched()); 918 EXPECT_FALSE(launcher1.app_launched());
919 EXPECT_TRUE(prefs->HasObserver(&launcher1)); 919 EXPECT_TRUE(prefs->HasObserver(&launcher1));
920 EXPECT_FALSE(launcher3.app_launched()); 920 EXPECT_FALSE(launcher3.app_launched());
921 EXPECT_TRUE(prefs->HasObserver(&launcher3)); 921 EXPECT_TRUE(prefs->HasObserver(&launcher3));
922 922
923 EXPECT_EQ(0u, app_instance()->launch_requests().size()); 923 EXPECT_EQ(0u, app_instance()->launch_requests().size());
924 924
925 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin(), 925 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin(),
926 fake_apps().begin() + 2); 926 fake_apps().begin() + 2);
927 app_instance()->SendRefreshAppList(apps); 927 app_instance()->SendRefreshAppList(apps);
928 928
929 EXPECT_TRUE(launcher1.app_launched()); 929 EXPECT_TRUE(launcher1.app_launched());
930 ASSERT_EQ(1u, app_instance()->launch_requests().size()); 930 ASSERT_EQ(1u, app_instance()->launch_requests().size());
931 EXPECT_TRUE(app_instance()->launch_requests()[0]->IsForApp(app1)); 931 EXPECT_TRUE(app_instance()->launch_requests()[0]->IsForApp(app1));
932 EXPECT_FALSE(launcher3.app_launched()); 932 EXPECT_FALSE(launcher3.app_launched());
933 EXPECT_FALSE(prefs->HasObserver(&launcher1)); 933 EXPECT_FALSE(prefs->HasObserver(&launcher1));
934 EXPECT_TRUE(prefs->HasObserver(&launcher3)); 934 EXPECT_TRUE(prefs->HasObserver(&launcher3));
935 935
936 ArcAppLauncher launcher2(profile(), id2, true); 936 ArcAppLauncher launcher2(profile(), id2, true);
937 EXPECT_TRUE(launcher2.app_launched()); 937 EXPECT_TRUE(launcher2.app_launched());
938 EXPECT_FALSE(prefs->HasObserver(&launcher2)); 938 EXPECT_FALSE(prefs->HasObserver(&launcher2));
939 ASSERT_EQ(2u, app_instance()->launch_requests().size()); 939 ASSERT_EQ(2u, app_instance()->launch_requests().size());
940 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); 940 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2));
941 } 941 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698