Chromium Code Reviews| Index: chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
| diff --git a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
| index c72110be9266834b5876fdf0d31117ed3a98156a..55cb189dd5216145069c734a34b960357210a129 100644 |
| --- a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
| +++ b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
| @@ -21,6 +21,7 @@ |
| #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "components/arc/arc_bridge_service.h" |
| +#include "components/arc/test/fake_app_instance.h" |
| #include "components/arc/test/fake_arc_bridge_service.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -60,6 +61,14 @@ class ArcAppModelBuilderTest : public AppListTestBase { |
| } |
| bridge_service_.reset(new arc::FakeArcBridgeService()); |
| + app_instance_.reset( |
| + new arc::FakeAppInstance(ArcAppListPrefs::Get(profile_.get()))); |
| + arc::AppInstancePtr instance; |
| + app_instance_->Bind(mojo::GetProxy(&instance)); |
| + bridge_service_->OnAppInstanceReady(std::move(instance)); |
| + // Wait for Init() and then RefreshAppList(). |
| + app_instance_->WaitForIncomingMethodCall(); |
|
dcheng
2015/12/20 01:49:45
Too bad there isn't some sort of way to be more ex
xiyuan
2015/12/21 17:05:53
Yeah, this is confusing to read. Can we add someth
Luis Héctor Chávez
2015/12/21 17:24:21
Done.
|
| + app_instance_->WaitForIncomingMethodCall(); |
| // Check initial conditions. |
| EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); |
| @@ -189,13 +198,14 @@ class ArcAppModelBuilderTest : public AppListTestBase { |
| ASSERT_NE(nullptr, app_item); |
| EXPECT_NE(ready, app_item->ready()); |
| } |
| - |
| } |
| AppListControllerDelegate* controller() { return controller_.get(); } |
| arc::FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } |
| + arc::FakeAppInstance* app_instance() { return app_instance_.get(); } |
| + |
| const std::vector<arc::AppInfo>& fake_apps() const { return fake_apps_; } |
| private: |
| @@ -203,49 +213,55 @@ class ArcAppModelBuilderTest : public AppListTestBase { |
| scoped_ptr<test::TestAppListControllerDelegate> controller_; |
| scoped_ptr<ArcAppModelBuilder> builder_; |
| scoped_ptr<arc::FakeArcBridgeService> bridge_service_; |
| + scoped_ptr<arc::FakeAppInstance> app_instance_; |
| std::vector<arc::AppInfo> fake_apps_; |
| DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); |
| }; |
| TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { |
| - EXPECT_EQ(0, bridge_service()->refresh_app_list_count()); |
| + // There should already have been one call, when the interface was |
| + // registered. |
| + EXPECT_EQ(1, app_instance()->refresh_app_list_count()); |
| bridge_service()->SetReady(); |
| - EXPECT_EQ(1, bridge_service()->refresh_app_list_count()); |
| + app_instance()->RefreshAppList(); |
| + EXPECT_EQ(2, app_instance()->refresh_app_list_count()); |
| } |
| TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { |
| ValidateHaveApps(std::vector<arc::AppInfo>()); |
| bridge_service()->SetReady(); |
| - bridge_service()->SendRefreshAppList(fake_apps()); |
| + app_instance()->RefreshAppList(); |
| + app_instance()->SendRefreshAppList(fake_apps()); |
| ValidateHaveApps(fake_apps()); |
| } |
| TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { |
| ValidateHaveApps(std::vector<arc::AppInfo>()); |
| bridge_service()->SetReady(); |
| + app_instance()->RefreshAppList(); |
| // Send info about all fake apps except last. |
| std::vector<arc::AppInfo> apps1(fake_apps().begin(), fake_apps().end() - 1); |
| - bridge_service()->SendRefreshAppList(apps1); |
| + app_instance()->SendRefreshAppList(apps1); |
| // At this point all apps (except last) should exist and be ready. |
| ValidateHaveApps(apps1); |
| ValidateAppReadyState(apps1, true); |
| // Send info about all fake apps except first. |
| std::vector<arc::AppInfo> apps2(fake_apps().begin() + 1, fake_apps().end()); |
| - bridge_service()->SendRefreshAppList(apps2); |
| + app_instance()->SendRefreshAppList(apps2); |
| // At this point all apps should exist but first one should be non-ready. |
| ValidateHaveApps(fake_apps()); |
| ValidateAppReadyState(apps2, true); |
| // Send info about all fake apps. |
| - bridge_service()->SendRefreshAppList(fake_apps()); |
| + app_instance()->SendRefreshAppList(fake_apps()); |
| // At this point all apps should exist and be ready. |
| ValidateHaveApps(fake_apps()); |
| ValidateAppReadyState(fake_apps(), true); |
| // Send info no app available. |
| - bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>()); |
| + app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>()); |
| // At this point all apps should exist and be non-ready. |
| ValidateHaveApps(fake_apps()); |
| ValidateAppReadyState(fake_apps(), false); |
| @@ -256,10 +272,11 @@ TEST_F(ArcAppModelBuilderTest, StopServiceDisablesApps) { |
| ASSERT_NE(nullptr, prefs); |
| bridge_service()->SetReady(); |
| + app_instance()->RefreshAppList(); |
| EXPECT_EQ(static_cast<size_t>(0), GetArcItemCount()); |
| EXPECT_EQ(static_cast<size_t>(0), prefs->GetAppIds().size()); |
| - bridge_service()->SendRefreshAppList(fake_apps()); |
| + app_instance()->SendRefreshAppList(fake_apps()); |
| std::vector<std::string> ids = prefs->GetAppIds(); |
| EXPECT_EQ(fake_apps().size(), ids.size()); |
| ValidateAppReadyState(fake_apps(), true); |
| @@ -276,7 +293,8 @@ TEST_F(ArcAppModelBuilderTest, LaunchApps) { |
| ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); |
| bridge_service()->SetReady(); |
| - bridge_service()->SendRefreshAppList(fake_apps()); |
| + app_instance()->RefreshAppList(); |
| + app_instance()->SendRefreshAppList(fake_apps()); |
| // Simulate item activate. |
| const arc::AppInfo& app_first = fake_apps()[0]; |
| @@ -286,26 +304,28 @@ TEST_F(ArcAppModelBuilderTest, LaunchApps) { |
| ASSERT_NE(nullptr, item_first); |
| ASSERT_NE(nullptr, item_last); |
| item_first->Activate(0); |
| + app_instance()->WaitForIncomingMethodCall(); |
| item_last->Activate(0); |
| + app_instance()->WaitForIncomingMethodCall(); |
| item_first->Activate(0); |
| + app_instance()->WaitForIncomingMethodCall(); |
| - const ScopedVector<arc::FakeArcBridgeService::Request>& launch_requests = |
| - bridge_service()->launch_requests(); |
| - EXPECT_EQ(static_cast<size_t>(3), launch_requests.size()); |
| + const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = |
| + app_instance()->launch_requests(); |
| + ASSERT_EQ(static_cast<size_t>(3), launch_requests.size()); |
| EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first)); |
| EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last)); |
| EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first)); |
| // Test an attempt to launch of a not-ready app. |
| - bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>()); |
| + app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>()); |
| item_first = FindArcItem(GetAppId(app_first)); |
| ASSERT_NE(nullptr, item_first); |
| - size_t launch_request_count_before = |
| - bridge_service()->launch_requests().size(); |
| + size_t launch_request_count_before = app_instance()->launch_requests().size(); |
| item_first->Activate(0); |
| // Number of launch requests must not change. |
| EXPECT_EQ(launch_request_count_before, |
| - bridge_service()->launch_requests().size()); |
| + app_instance()->launch_requests().size()); |
| } |
| TEST_F(ArcAppModelBuilderTest, RequestIcons) { |
| @@ -314,7 +334,8 @@ TEST_F(ArcAppModelBuilderTest, RequestIcons) { |
| content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| bridge_service()->SetReady(); |
| - bridge_service()->SendRefreshAppList(fake_apps()); |
| + app_instance()->RefreshAppList(); |
| + app_instance()->SendRefreshAppList(fake_apps()); |
| // Validate that no icon exists at the beginning and request icon for |
| // each supported scale factor. This will start asynchronous loading. |
| @@ -334,15 +355,22 @@ TEST_F(ArcAppModelBuilderTest, RequestIcons) { |
| // Process pending tasks. |
| content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| base::RunLoop().RunUntilIdle(); |
| + // Normally just one call to RunUntilIdle() suffices to make sure |
| + // all RequestAppIcon() calls are delivered, but on slower machines |
| + // (especially when running under Valgrind), they might not get |
| + // delivered on time. Wait for the remaining tasks individually. |
| + const size_t expected_size = scale_factors.size() * fake_apps().size(); |
| + while (app_instance()->icon_requests().size() < expected_size) { |
| + app_instance()->WaitForIncomingMethodCall(); |
| + } |
| // At this moment we should receive all requests for icon loading. |
| - const ScopedVector<arc::FakeArcBridgeService::IconRequest>& icon_requests = |
| - bridge_service()->icon_requests(); |
| - EXPECT_EQ(scale_factors.size() * fake_apps().size(), icon_requests.size()); |
| + const ScopedVector<arc::FakeAppInstance::IconRequest>& icon_requests = |
| + app_instance()->icon_requests(); |
| + EXPECT_EQ(expected_size, icon_requests.size()); |
| std::map<std::string, uint32_t> app_masks; |
| for (size_t i = 0; i < icon_requests.size(); ++i) { |
| - const arc::FakeArcBridgeService::IconRequest* icon_request = |
| - icon_requests[i]; |
| + const arc::FakeAppInstance::IconRequest* icon_request = icon_requests[i]; |
| const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(), |
| icon_request->activity()); |
| // Make sure no double requests. |
| @@ -368,8 +396,9 @@ TEST_F(ArcAppModelBuilderTest, InstallIcon) { |
| bridge_service()->SetReady(); |
| - bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>( |
| - fake_apps().begin(), fake_apps().begin() + 1)); |
| + app_instance()->RefreshAppList(); |
| + app_instance()->SendRefreshAppList( |
| + std::vector<arc::AppInfo>(fake_apps().begin(), fake_apps().begin() + 1)); |
| const arc::AppInfo& app = fake_apps()[0]; |
| ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| @@ -395,10 +424,9 @@ TEST_F(ArcAppModelBuilderTest, InstallIcon) { |
| // Now send generated icon for the app. |
| std::string png_data; |
| - EXPECT_EQ(true, bridge_service()->GenerateAndSendIcon( |
| - app, |
| - static_cast<arc::ScaleFactor>(scale_factor), |
| - &png_data)); |
| + EXPECT_EQ(true, |
| + app_instance()->GenerateAndSendIcon( |
| + app, static_cast<arc::ScaleFactor>(scale_factor), &png_data)); |
| // Process pending tasks. |
| content::BrowserThread::GetBlockingPool()->FlushForTesting(); |