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

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

Issue 1534413002: arc-bridge: Make ArcAppModelBuilderTest more reliable (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Even more stable runs Created 5 years 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
« no previous file with comments | « no previous file | components/arc/test/fake_app_instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 app.activity = buffer; 59 app.activity = buffer;
60 fake_apps_.push_back(app); 60 fake_apps_.push_back(app);
61 } 61 }
62 62
63 bridge_service_.reset(new arc::FakeArcBridgeService()); 63 bridge_service_.reset(new arc::FakeArcBridgeService());
64 app_instance_.reset( 64 app_instance_.reset(
65 new arc::FakeAppInstance(ArcAppListPrefs::Get(profile_.get()))); 65 new arc::FakeAppInstance(ArcAppListPrefs::Get(profile_.get())));
66 arc::AppInstancePtr instance; 66 arc::AppInstancePtr instance;
67 app_instance_->Bind(mojo::GetProxy(&instance)); 67 app_instance_->Bind(mojo::GetProxy(&instance));
68 bridge_service_->OnAppInstanceReady(std::move(instance)); 68 bridge_service_->OnAppInstanceReady(std::move(instance));
69 // Wait for Init() and then RefreshAppList().
70 app_instance_->WaitForIncomingMethodCall();
71 app_instance_->WaitForIncomingMethodCall();
69 72
70 // Check initial conditions. 73 // Check initial conditions.
71 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); 74 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get());
72 EXPECT_EQ(true, !arc::ArcBridgeService::Get()->available()); 75 EXPECT_EQ(true, !arc::ArcBridgeService::Get()->available());
73 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, 76 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED,
74 arc::ArcBridgeService::Get()->state()); 77 arc::ArcBridgeService::Get()->state());
75 78
76 CreateBuilder(); 79 CreateBuilder();
77 80
78 // At this point we should have ArcAppListPrefs as observer of service. 81 // At this point we should have ArcAppListPrefs as observer of service.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 scoped_ptr<test::TestAppListControllerDelegate> controller_; 213 scoped_ptr<test::TestAppListControllerDelegate> controller_;
211 scoped_ptr<ArcAppModelBuilder> builder_; 214 scoped_ptr<ArcAppModelBuilder> builder_;
212 scoped_ptr<arc::FakeArcBridgeService> bridge_service_; 215 scoped_ptr<arc::FakeArcBridgeService> bridge_service_;
213 scoped_ptr<arc::FakeAppInstance> app_instance_; 216 scoped_ptr<arc::FakeAppInstance> app_instance_;
214 std::vector<arc::AppInfo> fake_apps_; 217 std::vector<arc::AppInfo> fake_apps_;
215 218
216 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); 219 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest);
217 }; 220 };
218 221
219 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { 222 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) {
220 EXPECT_EQ(0, app_instance()->refresh_app_list_count()); 223 // There should already have been one call, when the interface was
224 // registered.
225 EXPECT_EQ(1, app_instance()->refresh_app_list_count());
221 bridge_service()->SetReady(); 226 bridge_service()->SetReady();
222 app_instance()->RefreshAppList(); 227 app_instance()->RefreshAppList();
223 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); 228 EXPECT_EQ(2, app_instance()->refresh_app_list_count());
224 } 229 }
225 230
226 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { 231 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) {
227 ValidateHaveApps(std::vector<arc::AppInfo>()); 232 ValidateHaveApps(std::vector<arc::AppInfo>());
228 bridge_service()->SetReady(); 233 bridge_service()->SetReady();
229 app_instance()->RefreshAppList(); 234 app_instance()->RefreshAppList();
230 app_instance()->SendRefreshAppList(fake_apps()); 235 app_instance()->SendRefreshAppList(fake_apps());
231 ValidateHaveApps(fake_apps()); 236 ValidateHaveApps(fake_apps());
232 } 237 }
233 238
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 app_instance()->SendRefreshAppList(fake_apps()); 297 app_instance()->SendRefreshAppList(fake_apps());
293 298
294 // Simulate item activate. 299 // Simulate item activate.
295 const arc::AppInfo& app_first = fake_apps()[0]; 300 const arc::AppInfo& app_first = fake_apps()[0];
296 const arc::AppInfo& app_last = fake_apps()[0]; 301 const arc::AppInfo& app_last = fake_apps()[0];
297 ArcAppItem* item_first = FindArcItem(GetAppId(app_first)); 302 ArcAppItem* item_first = FindArcItem(GetAppId(app_first));
298 ArcAppItem* item_last = FindArcItem(GetAppId(app_last)); 303 ArcAppItem* item_last = FindArcItem(GetAppId(app_last));
299 ASSERT_NE(nullptr, item_first); 304 ASSERT_NE(nullptr, item_first);
300 ASSERT_NE(nullptr, item_last); 305 ASSERT_NE(nullptr, item_last);
301 item_first->Activate(0); 306 item_first->Activate(0);
307 app_instance()->WaitForIncomingMethodCall();
302 item_last->Activate(0); 308 item_last->Activate(0);
309 app_instance()->WaitForIncomingMethodCall();
303 item_first->Activate(0); 310 item_first->Activate(0);
304 311 app_instance()->WaitForIncomingMethodCall();
305 // Process pending tasks.
306 base::RunLoop().RunUntilIdle();
307 312
308 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = 313 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests =
309 app_instance()->launch_requests(); 314 app_instance()->launch_requests();
310 ASSERT_EQ(static_cast<size_t>(3), launch_requests.size()); 315 ASSERT_EQ(static_cast<size_t>(3), launch_requests.size());
311 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first)); 316 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first));
312 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last)); 317 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last));
313 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first)); 318 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first));
314 319
315 // Test an attempt to launch of a not-ready app. 320 // Test an attempt to launch of a not-ready app.
316 app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>()); 321 app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>());
(...skipping 26 matching lines...) Expand all
343 ArcAppItem* app_item = FindArcItem(GetAppId(app)); 348 ArcAppItem* app_item = FindArcItem(GetAppId(app));
344 ASSERT_NE(nullptr, app_item); 349 ASSERT_NE(nullptr, app_item);
345 const float scale = ui::GetScaleForScaleFactor(scale_factor); 350 const float scale = ui::GetScaleForScaleFactor(scale_factor);
346 app_item->icon().GetRepresentation(scale); 351 app_item->icon().GetRepresentation(scale);
347 } 352 }
348 } 353 }
349 354
350 // Process pending tasks. 355 // Process pending tasks.
351 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 356 content::BrowserThread::GetBlockingPool()->FlushForTesting();
352 base::RunLoop().RunUntilIdle(); 357 base::RunLoop().RunUntilIdle();
358 // Normally just one call to RunUntilIdle() suffices to make sure
359 // all RequestAppIcon() calls are delivered, but on slower machines
360 // (especially when running under Valgrind), they might not get
361 // delivered on time. Wait for the remaining tasks individually.
362 const size_t expected_size = scale_factors.size() * fake_apps().size();
363 while (app_instance()->icon_requests().size() < expected_size) {
364 app_instance()->WaitForIncomingMethodCall();
365 }
353 366
354 // At this moment we should receive all requests for icon loading. 367 // At this moment we should receive all requests for icon loading.
355 const ScopedVector<arc::FakeAppInstance::IconRequest>& icon_requests = 368 const ScopedVector<arc::FakeAppInstance::IconRequest>& icon_requests =
356 app_instance()->icon_requests(); 369 app_instance()->icon_requests();
357 EXPECT_EQ(scale_factors.size() * fake_apps().size(), icon_requests.size()); 370 EXPECT_EQ(expected_size, icon_requests.size());
358 std::map<std::string, uint32_t> app_masks; 371 std::map<std::string, uint32_t> app_masks;
359 for (size_t i = 0; i < icon_requests.size(); ++i) { 372 for (size_t i = 0; i < icon_requests.size(); ++i) {
360 const arc::FakeAppInstance::IconRequest* icon_request = icon_requests[i]; 373 const arc::FakeAppInstance::IconRequest* icon_request = icon_requests[i];
361 const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(), 374 const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(),
362 icon_request->activity()); 375 icon_request->activity());
363 // Make sure no double requests. 376 // Make sure no double requests.
364 EXPECT_NE(app_masks[id], 377 EXPECT_NE(app_masks[id],
365 app_masks[id] | (1 << icon_request->scale_factor())); 378 app_masks[id] | (1 << icon_request->scale_factor()));
366 app_masks[id] |= (1 << icon_request->scale_factor()); 379 app_masks[id] |= (1 << icon_request->scale_factor());
367 } 380 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 434
422 // Validate that icons are installed, have right content and icon is 435 // Validate that icons are installed, have right content and icon is
423 // refreshed for ARC app item. 436 // refreshed for ARC app item.
424 EXPECT_EQ(true, base::PathExists(icon_path)); 437 EXPECT_EQ(true, base::PathExists(icon_path));
425 438
426 std::string icon_data; 439 std::string icon_data;
427 // Read the file from disk and compare with reference data. 440 // Read the file from disk and compare with reference data.
428 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data)); 441 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data));
429 ASSERT_EQ(icon_data, png_data); 442 ASSERT_EQ(icon_data, png_data);
430 } 443 }
OLDNEW
« no previous file with comments | « no previous file | components/arc/test/fake_app_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698