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

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

Issue 2150583002: Fix ArcAppModelBuilderTest (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Also fix other tests in the suite 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const gfx::ImageSkia& image() { return image_; } 59 const gfx::ImageSkia& image() { return image_; }
60 60
61 private: 61 private:
62 size_t update_image_cnt_ = 0; 62 size_t update_image_cnt_ = 0;
63 std::string app_id_; 63 std::string app_id_;
64 gfx::ImageSkia image_; 64 gfx::ImageSkia image_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(FakeAppIconLoaderDelegate); 66 DISALLOW_COPY_AND_ASSIGN(FakeAppIconLoaderDelegate);
67 }; 67 };
68 68
69 void WaitForIconReady(ArcAppListPrefs* prefs,
70 const std::string& app_id,
71 ui::ScaleFactor scale_factor) {
72 const base::FilePath icon_path = prefs->GetIconPath(app_id, scale_factor);
73 // Process pending tasks. This performs multiple thread hops, so we need
74 // to run it continuously until it is resolved.
75 do {
76 content::BrowserThread::GetBlockingPool()->FlushForTesting();
77 base::RunLoop().RunUntilIdle();
78 } while (!base::PathExists(icon_path));
79 }
80
69 } // namespace 81 } // namespace
70 82
71 class ArcAppModelBuilderTest : public AppListTestBase { 83 class ArcAppModelBuilderTest : public AppListTestBase {
72 public: 84 public:
73 ArcAppModelBuilderTest() {} 85 ArcAppModelBuilderTest() {}
74 ~ArcAppModelBuilderTest() override { 86 ~ArcAppModelBuilderTest() override {
75 // Release profile file in order to keep right sequence. 87 // Release profile file in order to keep right sequence.
76 profile_.reset(); 88 profile_.reset();
77 } 89 }
78 90
79 void SetUp() override { 91 void SetUp() override {
80 AppListTestBase::SetUp(); 92 AppListTestBase::SetUp();
81 arc_test_.SetUp(profile_.get()); 93 arc_test_.SetUp(profile_.get());
82 CreateBuilder(); 94 CreateBuilder();
95
96 // Validating decoded content does not fit well for unit tests.
97 ArcAppIcon::DisableSafeDecodingForTesting();
83 } 98 }
84 99
85 void TearDown() override { 100 void TearDown() override {
86 arc_test_.TearDown(); 101 arc_test_.TearDown();
87 ResetBuilder(); 102 ResetBuilder();
88 } 103 }
89 104
90 protected: 105 protected:
91 // Creates a new builder, destroying any existing one. 106 // Creates a new builder, destroying any existing one.
92 void CreateBuilder() { 107 void CreateBuilder() {
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 item_first->Activate(0); 555 item_first->Activate(0);
541 app_instance()->WaitForIncomingMethodCall(); 556 app_instance()->WaitForIncomingMethodCall();
542 item_last->Activate(0); 557 item_last->Activate(0);
543 app_instance()->WaitForIncomingMethodCall(); 558 app_instance()->WaitForIncomingMethodCall();
544 item_first->Activate(0); 559 item_first->Activate(0);
545 app_instance()->WaitForIncomingMethodCall(); 560 app_instance()->WaitForIncomingMethodCall();
546 561
547 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = 562 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests =
548 app_instance()->launch_requests(); 563 app_instance()->launch_requests();
549 ASSERT_EQ(3u, launch_requests.size()); 564 ASSERT_EQ(3u, launch_requests.size());
550 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first)); 565 EXPECT_TRUE(launch_requests[0]->IsForApp(app_first));
551 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last)); 566 EXPECT_TRUE(launch_requests[1]->IsForApp(app_last));
552 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first)); 567 EXPECT_TRUE(launch_requests[2]->IsForApp(app_first));
553 568
554 // Test an attempt to launch of a not-ready app. 569 // Test an attempt to launch of a not-ready app.
555 bridge_service()->SetStopped(); 570 bridge_service()->SetStopped();
556 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 571 item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
557 ASSERT_NE(nullptr, item_first); 572 ASSERT_NE(nullptr, item_first);
558 size_t launch_request_count_before = app_instance()->launch_requests().size(); 573 size_t launch_request_count_before = app_instance()->launch_requests().size();
559 item_first->Activate(0); 574 item_first->Activate(0);
560 // Number of launch requests must not change. 575 // Number of launch requests must not change.
561 EXPECT_EQ(launch_request_count_before, 576 EXPECT_EQ(launch_request_count_before,
562 app_instance()->launch_requests().size()); 577 app_instance()->launch_requests().size());
(...skipping 17 matching lines...) Expand all
580 item_first->Activate(0); 595 item_first->Activate(0);
581 app_instance()->WaitForIncomingMethodCall(); 596 app_instance()->WaitForIncomingMethodCall();
582 item_last->Activate(0); 597 item_last->Activate(0);
583 app_instance()->WaitForIncomingMethodCall(); 598 app_instance()->WaitForIncomingMethodCall();
584 item_first->Activate(0); 599 item_first->Activate(0);
585 app_instance()->WaitForIncomingMethodCall(); 600 app_instance()->WaitForIncomingMethodCall();
586 601
587 const ScopedVector<mojo::String>& launch_intents = 602 const ScopedVector<mojo::String>& launch_intents =
588 app_instance()->launch_intents(); 603 app_instance()->launch_intents();
589 ASSERT_EQ(3u, launch_intents.size()); 604 ASSERT_EQ(3u, launch_intents.size());
590 EXPECT_EQ(true, app_first.intent_uri == *launch_intents[0]); 605 EXPECT_EQ(app_first.intent_uri, *launch_intents[0]);
591 EXPECT_EQ(true, app_last.intent_uri == *launch_intents[1]); 606 EXPECT_EQ(app_last.intent_uri, *launch_intents[1]);
592 EXPECT_EQ(true, app_first.intent_uri == *launch_intents[2]); 607 EXPECT_EQ(app_first.intent_uri, *launch_intents[2]);
593 608
594 // Test an attempt to launch of a not-ready shortcut. 609 // Test an attempt to launch of a not-ready shortcut.
595 bridge_service()->SetStopped(); 610 bridge_service()->SetStopped();
596 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 611 item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
597 ASSERT_NE(nullptr, item_first); 612 ASSERT_NE(nullptr, item_first);
598 size_t launch_request_count_before = app_instance()->launch_intents().size(); 613 size_t launch_request_count_before = app_instance()->launch_intents().size();
599 item_first->Activate(0); 614 item_first->Activate(0);
600 // Number of launch requests must not change. 615 // Number of launch requests must not change.
601 EXPECT_EQ(launch_request_count_before, 616 EXPECT_EQ(launch_request_count_before,
602 app_instance()->launch_intents().size()); 617 app_instance()->launch_intents().size());
(...skipping 12 matching lines...) Expand all
615 uint32_t expected_mask = 0; 630 uint32_t expected_mask = 0;
616 const std::vector<ui::ScaleFactor>& scale_factors = 631 const std::vector<ui::ScaleFactor>& scale_factors =
617 ui::GetSupportedScaleFactors(); 632 ui::GetSupportedScaleFactors();
618 for (auto& scale_factor : scale_factors) { 633 for (auto& scale_factor : scale_factors) {
619 expected_mask |= 1 << scale_factor; 634 expected_mask |= 1 << scale_factor;
620 for (auto& app : fake_apps()) { 635 for (auto& app : fake_apps()) {
621 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(app)); 636 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(app));
622 ASSERT_NE(nullptr, app_item); 637 ASSERT_NE(nullptr, app_item);
623 const float scale = ui::GetScaleForScaleFactor(scale_factor); 638 const float scale = ui::GetScaleForScaleFactor(scale_factor);
624 app_item->icon().GetRepresentation(scale); 639 app_item->icon().GetRepresentation(scale);
640
641 // This does not result in an icon being loaded, so WaitForIconReady
642 // cannot be used.
643 content::BrowserThread::GetBlockingPool()->FlushForTesting();
644 base::RunLoop().RunUntilIdle();
625 } 645 }
626 } 646 }
627 647
628 // Process pending tasks.
629 content::BrowserThread::GetBlockingPool()->FlushForTesting();
630 base::RunLoop().RunUntilIdle();
631 // Normally just one call to RunUntilIdle() suffices to make sure 648 // Normally just one call to RunUntilIdle() suffices to make sure
632 // all RequestAppIcon() calls are delivered, but on slower machines 649 // all RequestAppIcon() calls are delivered, but on slower machines
633 // (especially when running under Valgrind), they might not get 650 // (especially when running under Valgrind), they might not get
634 // delivered on time. Wait for the remaining tasks individually. 651 // delivered on time. Wait for the remaining tasks individually.
635 const size_t expected_size = scale_factors.size() * fake_apps().size(); 652 const size_t expected_size = scale_factors.size() * fake_apps().size();
636 while (app_instance()->icon_requests().size() < expected_size) { 653 while (app_instance()->icon_requests().size() < expected_size) {
637 app_instance()->WaitForIncomingMethodCall(); 654 app_instance()->WaitForIncomingMethodCall();
638 } 655 }
639 656
640 // At this moment we should receive all requests for icon loading. 657 // At this moment we should receive all requests for icon loading.
(...skipping 14 matching lines...) Expand all
655 // Validate that we have a request for each icon for each supported scale 672 // Validate that we have a request for each icon for each supported scale
656 // factor. 673 // factor.
657 EXPECT_EQ(fake_apps().size(), app_masks.size()); 674 EXPECT_EQ(fake_apps().size(), app_masks.size());
658 for (auto& app : fake_apps()) { 675 for (auto& app : fake_apps()) {
659 const std::string id = ArcAppTest::GetAppId(app); 676 const std::string id = ArcAppTest::GetAppId(app);
660 ASSERT_NE(app_masks.find(id), app_masks.end()); 677 ASSERT_NE(app_masks.find(id), app_masks.end());
661 EXPECT_EQ(app_masks[id], expected_mask); 678 EXPECT_EQ(app_masks[id], expected_mask);
662 } 679 }
663 } 680 }
664 681
665 // TODO(crbug.com/624446) - reenable once this test is fixed 682 TEST_F(ArcAppModelBuilderTest, RequestShortcutIcons) {
666 TEST_F(ArcAppModelBuilderTest, DISABLED_RequestShortcutIcons) {
667 // Make sure we are on UI thread. 683 // Make sure we are on UI thread.
668 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 684 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
669 685
670 bridge_service()->SetReady(); 686 bridge_service()->SetReady();
671 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0]; 687 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0];
672 app_instance()->SendInstallShortcut(shortcut); 688 app_instance()->SendInstallShortcut(shortcut);
673 689
674 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 690 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
675 ASSERT_NE(nullptr, prefs); 691 ASSERT_NE(nullptr, prefs);
676 692
677 // Validate that no icon exists at the beginning and request icon for 693 // Validate that no icon exists at the beginning and request icon for
678 // each supported scale factor. This will start asynchronous loading. 694 // each supported scale factor. This will start asynchronous loading.
679 uint32_t expected_mask = 0; 695 uint32_t expected_mask = 0;
680 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(shortcut)); 696 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(shortcut));
681 ASSERT_NE(nullptr, app_item); 697 ASSERT_NE(nullptr, app_item);
682 const std::vector<ui::ScaleFactor>& scale_factors = 698 const std::vector<ui::ScaleFactor>& scale_factors =
683 ui::GetSupportedScaleFactors(); 699 ui::GetSupportedScaleFactors();
684 for (auto& scale_factor : scale_factors) { 700 for (auto& scale_factor : scale_factors) {
685 expected_mask |= 1 << scale_factor; 701 expected_mask |= 1 << scale_factor;
686 const float scale = ui::GetScaleForScaleFactor(scale_factor); 702 const float scale = ui::GetScaleForScaleFactor(scale_factor);
687 const base::FilePath icon_path = 703 const base::FilePath icon_path =
688 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor); 704 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor);
689 EXPECT_EQ(true, !base::PathExists(icon_path)); 705 EXPECT_FALSE(base::PathExists(icon_path));
690 706
691 app_item->icon().GetRepresentation(scale); 707 app_item->icon().GetRepresentation(scale);
708 WaitForIconReady(prefs, ArcAppTest::GetAppId(shortcut), scale_factor);
692 } 709 }
693 710
694 // Process pending tasks.
695 content::BrowserThread::GetBlockingPool()->FlushForTesting();
696 base::RunLoop().RunUntilIdle();
697
698 // At this moment we should receive all requests for icon loading. 711 // At this moment we should receive all requests for icon loading.
699 const size_t expected_size = scale_factors.size(); 712 const size_t expected_size = scale_factors.size();
700 const ScopedVector<arc::FakeAppInstance::ShortcutIconRequest>& icon_requests = 713 const ScopedVector<arc::FakeAppInstance::ShortcutIconRequest>& icon_requests =
701 app_instance()->shortcut_icon_requests(); 714 app_instance()->shortcut_icon_requests();
702 EXPECT_EQ(expected_size, icon_requests.size()); 715 EXPECT_EQ(expected_size, icon_requests.size());
703 uint32_t app_mask = 0; 716 uint32_t app_mask = 0;
704 for (size_t i = 0; i < icon_requests.size(); ++i) { 717 for (size_t i = 0; i < icon_requests.size(); ++i) {
705 const arc::FakeAppInstance::ShortcutIconRequest* icon_request = 718 const arc::FakeAppInstance::ShortcutIconRequest* icon_request =
706 icon_requests[i]; 719 icon_requests[i];
707 EXPECT_EQ(shortcut.icon_resource_id, icon_request->icon_resource_id()); 720 EXPECT_EQ(shortcut.icon_resource_id, icon_request->icon_resource_id());
708 721
709 // Make sure no double requests. 722 // Make sure no double requests.
710 EXPECT_NE(app_mask, app_mask | (1 << icon_request->scale_factor())); 723 EXPECT_NE(app_mask, app_mask | (1 << icon_request->scale_factor()));
711 app_mask |= (1 << icon_request->scale_factor()); 724 app_mask |= (1 << icon_request->scale_factor());
712 } 725 }
713 726
714 // Validate that we have a request for each icon for each supported scale 727 // Validate that we have a request for each icon for each supported scale
715 // factor. 728 // factor.
716 EXPECT_EQ(app_mask, expected_mask); 729 EXPECT_EQ(app_mask, expected_mask);
717 730
718 // Validate all icon files are installed. 731 // Validate all icon files are installed.
719 for (auto& scale_factor : scale_factors) { 732 for (auto& scale_factor : scale_factors) {
720 const base::FilePath icon_path = 733 const base::FilePath icon_path =
721 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor); 734 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor);
722 EXPECT_EQ(true, base::PathExists(icon_path)); 735 EXPECT_TRUE(base::PathExists(icon_path));
723 } 736 }
724 } 737 }
725 738
726 TEST_F(ArcAppModelBuilderTest, InstallIcon) { 739 TEST_F(ArcAppModelBuilderTest, InstallIcon) {
727 // Make sure we are on UI thread. 740 // Make sure we are on UI thread.
728 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 741 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
729 742
730 bridge_service()->SetReady(); 743 bridge_service()->SetReady();
731 app_instance()->RefreshAppList(); 744 app_instance()->RefreshAppList();
732 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 745 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
733 fake_apps().begin(), fake_apps().begin() + 1)); 746 fake_apps().begin(), fake_apps().begin() + 1));
734 const arc::mojom::AppInfo& app = fake_apps()[0]; 747 const arc::mojom::AppInfo& app = fake_apps()[0];
735 748
736 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 749 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
737 ASSERT_NE(nullptr, prefs); 750 ASSERT_NE(nullptr, prefs);
738 751
739 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; 752 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0];
740 const float scale = ui::GetScaleForScaleFactor(scale_factor); 753 const float scale = ui::GetScaleForScaleFactor(scale_factor);
741 const base::FilePath icon_path = prefs->GetIconPath(ArcAppTest::GetAppId(app), 754 const base::FilePath icon_path = prefs->GetIconPath(ArcAppTest::GetAppId(app),
742 scale_factor); 755 scale_factor);
743 EXPECT_EQ(true, !base::PathExists(icon_path)); 756 EXPECT_FALSE(base::PathExists(icon_path));
744 757
745 const ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(app)); 758 const ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(app));
746 EXPECT_NE(nullptr, app_item); 759 EXPECT_NE(nullptr, app_item);
747 // This initiates async loading. 760 // This initiates async loading.
748 app_item->icon().GetRepresentation(scale); 761 app_item->icon().GetRepresentation(scale);
749 762
750 // Process pending tasks.
751 content::BrowserThread::GetBlockingPool()->FlushForTesting();
752 base::RunLoop().RunUntilIdle();
753
754 // Validating decoded content does not fit well for unit tests.
755 ArcAppIcon::DisableSafeDecodingForTesting();
756
757 // Now send generated icon for the app. 763 // Now send generated icon for the app.
758 std::string png_data; 764 std::string png_data;
759 EXPECT_EQ(true, app_instance()->GenerateAndSendIcon( 765 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
760 app, static_cast<arc::mojom::ScaleFactor>(scale_factor), 766 app, static_cast<arc::mojom::ScaleFactor>(scale_factor), &png_data));
761 &png_data)); 767 WaitForIconReady(prefs, ArcAppTest::GetAppId(app), scale_factor);
762
763 // Process pending tasks.
764 content::BrowserThread::GetBlockingPool()->FlushForTesting();
765 base::RunLoop().RunUntilIdle();
766 768
767 // Validate that icons are installed, have right content and icon is 769 // Validate that icons are installed, have right content and icon is
768 // refreshed for ARC app item. 770 // refreshed for ARC app item.
769 EXPECT_EQ(true, base::PathExists(icon_path)); 771 EXPECT_TRUE(base::PathExists(icon_path));
770 772
771 std::string icon_data; 773 std::string icon_data;
772 // Read the file from disk and compare with reference data. 774 // Read the file from disk and compare with reference data.
773 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data)); 775 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data));
774 ASSERT_EQ(icon_data, png_data); 776 ASSERT_EQ(icon_data, png_data);
775 } 777 }
776 778
777 TEST_F(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) { 779 TEST_F(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) {
778 // Make sure we are on UI thread. 780 // Make sure we are on UI thread.
779 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 781 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
780 782
781 bridge_service()->SetReady(); 783 bridge_service()->SetReady();
782 app_instance()->RefreshAppList(); 784 app_instance()->RefreshAppList();
783 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 785 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
784 fake_apps().begin(), fake_apps().begin() + 1)); 786 fake_apps().begin(), fake_apps().begin() + 1));
785 const arc::mojom::AppInfo& app = fake_apps()[0]; 787 const arc::mojom::AppInfo& app = fake_apps()[0];
786 788
787 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 789 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
788 ASSERT_NE(nullptr, prefs); 790 ASSERT_NE(nullptr, prefs);
789 791
790 const std::string app_id = ArcAppTest::GetAppId(app); 792 const std::string app_id = ArcAppTest::GetAppId(app);
791 const base::FilePath app_path = prefs->GetAppPath(app_id); 793 const base::FilePath app_path = prefs->GetAppPath(app_id);
792 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; 794 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0];
793 795
794 // No app folder by default. 796 // No app folder by default.
795 EXPECT_EQ(true, !base::PathExists(app_path)); 797 base::RunLoop().RunUntilIdle();
798 EXPECT_FALSE(base::PathExists(app_path));
796 799
797 // Request icon, this will create app folder. 800 // Request icon, this will create app folder.
798 prefs->RequestIcon(app_id, scale_factor); 801 prefs->RequestIcon(app_id, scale_factor);
799 // Now send generated icon for the app. 802 // Now send generated icon for the app.
800 std::string png_data; 803 std::string png_data;
801 EXPECT_EQ(true, app_instance()->GenerateAndSendIcon( 804 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
802 app, static_cast<arc::mojom::ScaleFactor>(scale_factor), 805 app, static_cast<arc::mojom::ScaleFactor>(scale_factor), &png_data));
803 &png_data)); 806 WaitForIconReady(prefs, app_id, scale_factor);
804 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 807 EXPECT_TRUE(base::PathExists(app_path));
805 base::RunLoop().RunUntilIdle();
806 EXPECT_EQ(true, base::PathExists(app_path));
807 808
808 // Send empty app list. This will delete app and its folder. 809 // Send empty app list. This will delete app and its folder.
809 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>()); 810 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>());
810 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 811 // Process pending tasks. This performs multiple thread hops, so we need
811 base::RunLoop().RunUntilIdle(); 812 // to run it continuously until it is resolved.
812 EXPECT_EQ(true, !base::PathExists(app_path)); 813 do {
814 content::BrowserThread::GetBlockingPool()->FlushForTesting();
815 base::RunLoop().RunUntilIdle();
816 } while (base::PathExists(app_path));
xiyuan 2016/07/14 22:59:32 Could this be WaitForIconReady ?
Luis Héctor Chávez 2016/07/14 23:25:45 No, it needs the opposite condition. I'll add a co
817 EXPECT_FALSE(base::PathExists(app_path));
813 } 818 }
814 819
815 TEST_F(ArcAppModelBuilderTest, LastLaunchTime) { 820 TEST_F(ArcAppModelBuilderTest, LastLaunchTime) {
816 // Make sure we are on UI thread. 821 // Make sure we are on UI thread.
817 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 822 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
818 823
819 bridge_service()->SetReady(); 824 bridge_service()->SetReady();
820 app_instance()->RefreshAppList(); 825 app_instance()->RefreshAppList();
821 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 826 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
822 fake_apps().begin(), fake_apps().begin() + 2)); 827 fake_apps().begin(), fake_apps().begin() + 2));
(...skipping 26 matching lines...) Expand all
849 base::Time time_before = base::Time::Now(); 854 base::Time time_before = base::Time::Now();
850 arc::LaunchApp(profile(), id2); 855 arc::LaunchApp(profile(), id2);
851 base::Time time_after = base::Time::Now(); 856 base::Time time_after = base::Time::Now();
852 857
853 app_info = prefs->GetApp(id2); 858 app_info = prefs->GetApp(id2);
854 ASSERT_NE(nullptr, app_info.get()); 859 ASSERT_NE(nullptr, app_info.get());
855 ASSERT_LE(time_before, app_info->last_launch_time); 860 ASSERT_LE(time_before, app_info->last_launch_time);
856 ASSERT_GE(time_after, app_info->last_launch_time); 861 ASSERT_GE(time_after, app_info->last_launch_time);
857 } 862 }
858 863
859 TEST_F(ArcAppModelBuilderTest, IconLoader) { 864 TEST_F(ArcAppModelBuilderTest, IconLoader) {
Luis Héctor Chávez 2016/07/14 22:44:32 This test is unfortunately still flaky (5-10%) eve
xiyuan 2016/07/14 22:59:32 Yes, we should disable it until resolved so that s
860 // Validating decoded content does not fit well for unit tests.
861 ArcAppIcon::DisableSafeDecodingForTesting();
862
863 const arc::mojom::AppInfo& app = fake_apps()[0]; 865 const arc::mojom::AppInfo& app = fake_apps()[0];
864 const std::string app_id = ArcAppTest::GetAppId(app); 866 const std::string app_id = ArcAppTest::GetAppId(app);
865 867
868 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
869 ASSERT_NE(nullptr, prefs);
870
866 bridge_service()->SetReady(); 871 bridge_service()->SetReady();
867 app_instance()->RefreshAppList(); 872 app_instance()->RefreshAppList();
868 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 873 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
869 fake_apps().begin(), fake_apps().begin() + 1)); 874 fake_apps().begin(), fake_apps().begin() + 1));
870 875
871 FakeAppIconLoaderDelegate delegate; 876 FakeAppIconLoaderDelegate delegate;
872 ArcAppIconLoader icon_loader(profile(), 877 ArcAppIconLoader icon_loader(profile(),
873 app_list::kListIconSize, 878 app_list::kListIconSize,
874 &delegate); 879 &delegate);
875 EXPECT_EQ(0UL, delegate.update_image_cnt()); 880 EXPECT_EQ(0UL, delegate.update_image_cnt());
876 icon_loader.FetchImage(app_id); 881 icon_loader.FetchImage(app_id);
877 EXPECT_EQ(1UL, delegate.update_image_cnt()); 882 EXPECT_EQ(1UL, delegate.update_image_cnt());
878 EXPECT_EQ(app_id, delegate.app_id()); 883 EXPECT_EQ(app_id, delegate.app_id());
879 884
880 // Validate default image. 885 // Validate default image.
881 ValidateIcon(delegate.image()); 886 ValidateIcon(delegate.image());
882 887
883 const std::vector<ui::ScaleFactor>& scale_factors = 888 const std::vector<ui::ScaleFactor>& scale_factors =
884 ui::GetSupportedScaleFactors(); 889 ui::GetSupportedScaleFactors();
890 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(app));
xiyuan 2016/07/14 22:59:32 nit: Isn't ArcAppTest::GetAppId(app) here the |app
Luis Héctor Chávez 2016/07/14 23:25:45 Good catch, done.
885 for (auto& scale_factor : scale_factors) { 891 for (auto& scale_factor : scale_factors) {
886 std::string png_data; 892 std::string png_data;
887 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( 893 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
888 app, static_cast<arc::mojom::ScaleFactor>(scale_factor), &png_data)); 894 app, static_cast<arc::mojom::ScaleFactor>(scale_factor), &png_data));
895 const float scale = ui::GetScaleForScaleFactor(scale_factor);
896 // Force the icon to be loaded.
897 app_item->icon().GetRepresentation(scale);
898 WaitForIconReady(prefs, ArcAppTest::GetAppId(app), scale_factor);
xiyuan 2016/07/14 22:59:32 nit: ArcAppTest::GetAppId(app) -> app_id ?
Luis Héctor Chávez 2016/07/14 23:25:45 Done.
889 } 899 }
890 900
891 // Process pending tasks, this installs icons.
892 content::BrowserThread::GetBlockingPool()->FlushForTesting();
893 base::RunLoop().RunUntilIdle();
894
895 // Allow one more circle to read and decode installed icons.
896 content::BrowserThread::GetBlockingPool()->FlushForTesting();
897 base::RunLoop().RunUntilIdle();
898
899 // Validate loaded image. 901 // Validate loaded image.
900 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); 902 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt());
901 EXPECT_EQ(app_id, delegate.app_id()); 903 EXPECT_EQ(app_id, delegate.app_id());
902 ValidateIcon(delegate.image()); 904 ValidateIcon(delegate.image());
903 } 905 }
904 906
905 TEST_F(ArcAppModelBuilderTest, AppLauncher) { 907 TEST_F(ArcAppModelBuilderTest, AppLauncher) {
906 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); 908 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
907 ASSERT_NE(nullptr, prefs); 909 ASSERT_NE(nullptr, prefs);
908 910
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 EXPECT_FALSE(prefs->HasObserver(&launcher1)); 944 EXPECT_FALSE(prefs->HasObserver(&launcher1));
943 EXPECT_TRUE(prefs->HasObserver(&launcher3)); 945 EXPECT_TRUE(prefs->HasObserver(&launcher3));
944 946
945 ArcAppLauncher launcher2(profile(), id2, true); 947 ArcAppLauncher launcher2(profile(), id2, true);
946 EXPECT_TRUE(launcher2.app_launched()); 948 EXPECT_TRUE(launcher2.app_launched());
947 app_instance()->WaitForIncomingMethodCall(); 949 app_instance()->WaitForIncomingMethodCall();
948 EXPECT_FALSE(prefs->HasObserver(&launcher2)); 950 EXPECT_FALSE(prefs->HasObserver(&launcher2));
949 ASSERT_EQ(2u, app_instance()->launch_requests().size()); 951 ASSERT_EQ(2u, app_instance()->launch_requests().size());
950 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); 952 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2));
951 } 953 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698