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

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

Issue 1542003002: Revert of Reland "arc-bridge: Move most methods to Mojo interfaces" (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: 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 | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | components/arc.gypi » ('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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
16 #include "chrome/browser/ui/app_list/app_list_test_util.h" 16 #include "chrome/browser/ui/app_list/app_list_test_util.h"
17 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" 17 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h"
18 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" 18 #include "chrome/browser/ui/app_list/arc/arc_app_item.h"
19 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 19 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
20 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" 20 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h"
21 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" 21 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h"
22 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "components/arc/arc_bridge_service.h" 23 #include "components/arc/arc_bridge_service.h"
24 #include "components/arc/test/fake_app_instance.h"
25 #include "components/arc/test/fake_arc_bridge_service.h" 24 #include "components/arc/test/fake_arc_bridge_service.h"
26 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
27 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/app_list/app_list_model.h" 27 #include "ui/app_list/app_list_model.h"
29 #include "ui/gfx/image/image_skia.h" 28 #include "ui/gfx/image/image_skia.h"
30 29
31 namespace { 30 namespace {
32 31
33 std::string GetAppId(const arc::AppInfo& app_info) { 32 std::string GetAppId(const arc::AppInfo& app_info) {
34 return ArcAppListPrefs::GetAppId(app_info.package, app_info.activity); 33 return ArcAppListPrefs::GetAppId(app_info.package, app_info.activity);
(...skipping 19 matching lines...) Expand all
54 base::snprintf(buffer, arraysize(buffer), "Fake App %d", i); 53 base::snprintf(buffer, arraysize(buffer), "Fake App %d", i);
55 app.name = buffer; 54 app.name = buffer;
56 base::snprintf(buffer, arraysize(buffer), "fake.app.%d", i); 55 base::snprintf(buffer, arraysize(buffer), "fake.app.%d", i);
57 app.package = buffer; 56 app.package = buffer;
58 base::snprintf(buffer, arraysize(buffer), "fake.app.%d.activity", i); 57 base::snprintf(buffer, arraysize(buffer), "fake.app.%d.activity", i);
59 app.activity = buffer; 58 app.activity = buffer;
60 fake_apps_.push_back(app); 59 fake_apps_.push_back(app);
61 } 60 }
62 61
63 bridge_service_.reset(new arc::FakeArcBridgeService()); 62 bridge_service_.reset(new arc::FakeArcBridgeService());
64 app_instance_.reset(
65 new arc::FakeAppInstance(ArcAppListPrefs::Get(profile_.get())));
66 arc::AppInstancePtr instance;
67 app_instance_->Bind(mojo::GetProxy(&instance));
68 bridge_service_->OnAppInstanceReady(std::move(instance));
69 app_instance_->WaitForOnAppInstanceReady();
70 63
71 // Check initial conditions. 64 // Check initial conditions.
72 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); 65 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get());
73 EXPECT_EQ(true, !arc::ArcBridgeService::Get()->available()); 66 EXPECT_EQ(true, !arc::ArcBridgeService::Get()->available());
74 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, 67 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED,
75 arc::ArcBridgeService::Get()->state()); 68 arc::ArcBridgeService::Get()->state());
76 69
77 CreateBuilder(); 70 CreateBuilder();
78 71
79 // At this point we should have ArcAppListPrefs as observer of service. 72 // At this point we should have ArcAppListPrefs as observer of service.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 182
190 // Process the rest of the apps. 183 // Process the rest of the apps.
191 for (auto& id : ids) { 184 for (auto& id : ids) {
192 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id); 185 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id);
193 ASSERT_NE(nullptr, app_info.get()); 186 ASSERT_NE(nullptr, app_info.get());
194 EXPECT_NE(ready, app_info->ready); 187 EXPECT_NE(ready, app_info->ready);
195 const ArcAppItem* app_item = FindArcItem(id); 188 const ArcAppItem* app_item = FindArcItem(id);
196 ASSERT_NE(nullptr, app_item); 189 ASSERT_NE(nullptr, app_item);
197 EXPECT_NE(ready, app_item->ready()); 190 EXPECT_NE(ready, app_item->ready());
198 } 191 }
192
199 } 193 }
200 194
201 AppListControllerDelegate* controller() { return controller_.get(); } 195 AppListControllerDelegate* controller() { return controller_.get(); }
202 196
203 arc::FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } 197 arc::FakeArcBridgeService* bridge_service() { return bridge_service_.get(); }
204 198
205 arc::FakeAppInstance* app_instance() { return app_instance_.get(); }
206
207 const std::vector<arc::AppInfo>& fake_apps() const { return fake_apps_; } 199 const std::vector<arc::AppInfo>& fake_apps() const { return fake_apps_; }
208 200
209 private: 201 private:
210 scoped_ptr<app_list::AppListModel> model_; 202 scoped_ptr<app_list::AppListModel> model_;
211 scoped_ptr<test::TestAppListControllerDelegate> controller_; 203 scoped_ptr<test::TestAppListControllerDelegate> controller_;
212 scoped_ptr<ArcAppModelBuilder> builder_; 204 scoped_ptr<ArcAppModelBuilder> builder_;
213 scoped_ptr<arc::FakeArcBridgeService> bridge_service_; 205 scoped_ptr<arc::FakeArcBridgeService> bridge_service_;
214 scoped_ptr<arc::FakeAppInstance> app_instance_;
215 std::vector<arc::AppInfo> fake_apps_; 206 std::vector<arc::AppInfo> fake_apps_;
216 207
217 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); 208 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest);
218 }; 209 };
219 210
220 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { 211 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) {
221 // There should already have been one call, when the interface was 212 EXPECT_EQ(0, bridge_service()->refresh_app_list_count());
222 // registered.
223 EXPECT_EQ(1, app_instance()->refresh_app_list_count());
224 bridge_service()->SetReady(); 213 bridge_service()->SetReady();
225 app_instance()->RefreshAppList(); 214 EXPECT_EQ(1, bridge_service()->refresh_app_list_count());
226 EXPECT_EQ(2, app_instance()->refresh_app_list_count());
227 } 215 }
228 216
229 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { 217 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) {
230 ValidateHaveApps(std::vector<arc::AppInfo>()); 218 ValidateHaveApps(std::vector<arc::AppInfo>());
231 bridge_service()->SetReady(); 219 bridge_service()->SetReady();
232 app_instance()->RefreshAppList(); 220 bridge_service()->SendRefreshAppList(fake_apps());
233 app_instance()->SendRefreshAppList(fake_apps());
234 ValidateHaveApps(fake_apps()); 221 ValidateHaveApps(fake_apps());
235 } 222 }
236 223
237 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { 224 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) {
238 ValidateHaveApps(std::vector<arc::AppInfo>()); 225 ValidateHaveApps(std::vector<arc::AppInfo>());
239 bridge_service()->SetReady(); 226 bridge_service()->SetReady();
240 app_instance()->RefreshAppList();
241 // Send info about all fake apps except last. 227 // Send info about all fake apps except last.
242 std::vector<arc::AppInfo> apps1(fake_apps().begin(), fake_apps().end() - 1); 228 std::vector<arc::AppInfo> apps1(fake_apps().begin(), fake_apps().end() - 1);
243 app_instance()->SendRefreshAppList(apps1); 229 bridge_service()->SendRefreshAppList(apps1);
244 // At this point all apps (except last) should exist and be ready. 230 // At this point all apps (except last) should exist and be ready.
245 ValidateHaveApps(apps1); 231 ValidateHaveApps(apps1);
246 ValidateAppReadyState(apps1, true); 232 ValidateAppReadyState(apps1, true);
247 233
248 // Send info about all fake apps except first. 234 // Send info about all fake apps except first.
249 std::vector<arc::AppInfo> apps2(fake_apps().begin() + 1, fake_apps().end()); 235 std::vector<arc::AppInfo> apps2(fake_apps().begin() + 1, fake_apps().end());
250 app_instance()->SendRefreshAppList(apps2); 236 bridge_service()->SendRefreshAppList(apps2);
251 // At this point all apps should exist but first one should be non-ready. 237 // At this point all apps should exist but first one should be non-ready.
252 ValidateHaveApps(fake_apps()); 238 ValidateHaveApps(fake_apps());
253 ValidateAppReadyState(apps2, true); 239 ValidateAppReadyState(apps2, true);
254 240
255 // Send info about all fake apps. 241 // Send info about all fake apps.
256 app_instance()->SendRefreshAppList(fake_apps()); 242 bridge_service()->SendRefreshAppList(fake_apps());
257 // At this point all apps should exist and be ready. 243 // At this point all apps should exist and be ready.
258 ValidateHaveApps(fake_apps()); 244 ValidateHaveApps(fake_apps());
259 ValidateAppReadyState(fake_apps(), true); 245 ValidateAppReadyState(fake_apps(), true);
260 246
261 // Send info no app available. 247 // Send info no app available.
262 app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>()); 248 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>());
263 // At this point all apps should exist and be non-ready. 249 // At this point all apps should exist and be non-ready.
264 ValidateHaveApps(fake_apps()); 250 ValidateHaveApps(fake_apps());
265 ValidateAppReadyState(fake_apps(), false); 251 ValidateAppReadyState(fake_apps(), false);
266 } 252 }
267 253
268 TEST_F(ArcAppModelBuilderTest, StopServiceDisablesApps) { 254 TEST_F(ArcAppModelBuilderTest, StopServiceDisablesApps) {
269 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 255 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
270 ASSERT_NE(nullptr, prefs); 256 ASSERT_NE(nullptr, prefs);
271 257
272 bridge_service()->SetReady(); 258 bridge_service()->SetReady();
273 app_instance()->RefreshAppList();
274 EXPECT_EQ(static_cast<size_t>(0), GetArcItemCount()); 259 EXPECT_EQ(static_cast<size_t>(0), GetArcItemCount());
275 EXPECT_EQ(static_cast<size_t>(0), prefs->GetAppIds().size()); 260 EXPECT_EQ(static_cast<size_t>(0), prefs->GetAppIds().size());
276 261
277 app_instance()->SendRefreshAppList(fake_apps()); 262 bridge_service()->SendRefreshAppList(fake_apps());
278 std::vector<std::string> ids = prefs->GetAppIds(); 263 std::vector<std::string> ids = prefs->GetAppIds();
279 EXPECT_EQ(fake_apps().size(), ids.size()); 264 EXPECT_EQ(fake_apps().size(), ids.size());
280 ValidateAppReadyState(fake_apps(), true); 265 ValidateAppReadyState(fake_apps(), true);
281 266
282 // Stopping service does not delete items. It makes them non-ready. 267 // Stopping service does not delete items. It makes them non-ready.
283 bridge_service()->SetStopped(); 268 bridge_service()->SetStopped();
284 // Ids should be the same. 269 // Ids should be the same.
285 EXPECT_EQ(ids, prefs->GetAppIds()); 270 EXPECT_EQ(ids, prefs->GetAppIds());
286 ValidateAppReadyState(fake_apps(), false); 271 ValidateAppReadyState(fake_apps(), false);
287 } 272 }
288 273
289 TEST_F(ArcAppModelBuilderTest, LaunchApps) { 274 TEST_F(ArcAppModelBuilderTest, LaunchApps) {
290 // Disable attempts to dismiss app launcher view. 275 // Disable attempts to dismiss app launcher view.
291 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); 276 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller());
292 277
293 bridge_service()->SetReady(); 278 bridge_service()->SetReady();
294 app_instance()->RefreshAppList(); 279 bridge_service()->SendRefreshAppList(fake_apps());
295 app_instance()->SendRefreshAppList(fake_apps());
296 280
297 // Simulate item activate. 281 // Simulate item activate.
298 const arc::AppInfo& app_first = fake_apps()[0]; 282 const arc::AppInfo& app_first = fake_apps()[0];
299 const arc::AppInfo& app_last = fake_apps()[0]; 283 const arc::AppInfo& app_last = fake_apps()[0];
300 ArcAppItem* item_first = FindArcItem(GetAppId(app_first)); 284 ArcAppItem* item_first = FindArcItem(GetAppId(app_first));
301 ArcAppItem* item_last = FindArcItem(GetAppId(app_last)); 285 ArcAppItem* item_last = FindArcItem(GetAppId(app_last));
302 ASSERT_NE(nullptr, item_first); 286 ASSERT_NE(nullptr, item_first);
303 ASSERT_NE(nullptr, item_last); 287 ASSERT_NE(nullptr, item_last);
304 item_first->Activate(0); 288 item_first->Activate(0);
305 app_instance()->WaitForIncomingMethodCall();
306 item_last->Activate(0); 289 item_last->Activate(0);
307 app_instance()->WaitForIncomingMethodCall();
308 item_first->Activate(0); 290 item_first->Activate(0);
309 app_instance()->WaitForIncomingMethodCall();
310 291
311 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = 292 const ScopedVector<arc::FakeArcBridgeService::Request>& launch_requests =
312 app_instance()->launch_requests(); 293 bridge_service()->launch_requests();
313 ASSERT_EQ(static_cast<size_t>(3), launch_requests.size()); 294 EXPECT_EQ(static_cast<size_t>(3), launch_requests.size());
314 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first)); 295 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first));
315 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last)); 296 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last));
316 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first)); 297 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first));
317 298
318 // Test an attempt to launch of a not-ready app. 299 // Test an attempt to launch of a not-ready app.
319 app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>()); 300 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>());
320 item_first = FindArcItem(GetAppId(app_first)); 301 item_first = FindArcItem(GetAppId(app_first));
321 ASSERT_NE(nullptr, item_first); 302 ASSERT_NE(nullptr, item_first);
322 size_t launch_request_count_before = app_instance()->launch_requests().size(); 303 size_t launch_request_count_before =
304 bridge_service()->launch_requests().size();
323 item_first->Activate(0); 305 item_first->Activate(0);
324 // Number of launch requests must not change. 306 // Number of launch requests must not change.
325 EXPECT_EQ(launch_request_count_before, 307 EXPECT_EQ(launch_request_count_before,
326 app_instance()->launch_requests().size()); 308 bridge_service()->launch_requests().size());
327 } 309 }
328 310
329 TEST_F(ArcAppModelBuilderTest, RequestIcons) { 311 TEST_F(ArcAppModelBuilderTest, RequestIcons) {
330 // Make sure we are on UI thread. 312 // Make sure we are on UI thread.
331 ASSERT_EQ(true, 313 ASSERT_EQ(true,
332 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 314 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
333 315
334 bridge_service()->SetReady(); 316 bridge_service()->SetReady();
335 app_instance()->RefreshAppList(); 317 bridge_service()->SendRefreshAppList(fake_apps());
336 app_instance()->SendRefreshAppList(fake_apps());
337 318
338 // Validate that no icon exists at the beginning and request icon for 319 // Validate that no icon exists at the beginning and request icon for
339 // each supported scale factor. This will start asynchronous loading. 320 // each supported scale factor. This will start asynchronous loading.
340 uint32_t expected_mask = 0; 321 uint32_t expected_mask = 0;
341 const std::vector<ui::ScaleFactor>& scale_factors = 322 const std::vector<ui::ScaleFactor>& scale_factors =
342 ui::GetSupportedScaleFactors(); 323 ui::GetSupportedScaleFactors();
343 for (auto& scale_factor : scale_factors) { 324 for (auto& scale_factor : scale_factors) {
344 expected_mask |= 1 << scale_factor; 325 expected_mask |= 1 << scale_factor;
345 for (auto& app : fake_apps()) { 326 for (auto& app : fake_apps()) {
346 ArcAppItem* app_item = FindArcItem(GetAppId(app)); 327 ArcAppItem* app_item = FindArcItem(GetAppId(app));
347 ASSERT_NE(nullptr, app_item); 328 ASSERT_NE(nullptr, app_item);
348 const float scale = ui::GetScaleForScaleFactor(scale_factor); 329 const float scale = ui::GetScaleForScaleFactor(scale_factor);
349 app_item->icon().GetRepresentation(scale); 330 app_item->icon().GetRepresentation(scale);
350 } 331 }
351 } 332 }
352 333
353 // Process pending tasks. 334 // Process pending tasks.
354 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 335 content::BrowserThread::GetBlockingPool()->FlushForTesting();
355 base::RunLoop().RunUntilIdle(); 336 base::RunLoop().RunUntilIdle();
356 // Normally just one call to RunUntilIdle() suffices to make sure
357 // all RequestAppIcon() calls are delivered, but on slower machines
358 // (especially when running under Valgrind), they might not get
359 // delivered on time. Wait for the remaining tasks individually.
360 const size_t expected_size = scale_factors.size() * fake_apps().size();
361 while (app_instance()->icon_requests().size() < expected_size) {
362 app_instance()->WaitForIncomingMethodCall();
363 }
364 337
365 // At this moment we should receive all requests for icon loading. 338 // At this moment we should receive all requests for icon loading.
366 const ScopedVector<arc::FakeAppInstance::IconRequest>& icon_requests = 339 const ScopedVector<arc::FakeArcBridgeService::IconRequest>& icon_requests =
367 app_instance()->icon_requests(); 340 bridge_service()->icon_requests();
368 EXPECT_EQ(expected_size, icon_requests.size()); 341 EXPECT_EQ(scale_factors.size() * fake_apps().size(), icon_requests.size());
369 std::map<std::string, uint32_t> app_masks; 342 std::map<std::string, uint32_t> app_masks;
370 for (size_t i = 0; i < icon_requests.size(); ++i) { 343 for (size_t i = 0; i < icon_requests.size(); ++i) {
371 const arc::FakeAppInstance::IconRequest* icon_request = icon_requests[i]; 344 const arc::FakeArcBridgeService::IconRequest* icon_request =
345 icon_requests[i];
372 const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(), 346 const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(),
373 icon_request->activity()); 347 icon_request->activity());
374 // Make sure no double requests. 348 // Make sure no double requests.
375 EXPECT_NE(app_masks[id], 349 EXPECT_NE(app_masks[id],
376 app_masks[id] | (1 << icon_request->scale_factor())); 350 app_masks[id] | (1 << icon_request->scale_factor()));
377 app_masks[id] |= (1 << icon_request->scale_factor()); 351 app_masks[id] |= (1 << icon_request->scale_factor());
378 } 352 }
379 353
380 // Validate that we have a request for each icon for each supported scale 354 // Validate that we have a request for each icon for each supported scale
381 // factor. 355 // factor.
382 EXPECT_EQ(fake_apps().size(), app_masks.size()); 356 EXPECT_EQ(fake_apps().size(), app_masks.size());
383 for (auto& app : fake_apps()) { 357 for (auto& app : fake_apps()) {
384 const std::string id = GetAppId(app); 358 const std::string id = GetAppId(app);
385 ASSERT_NE(app_masks.find(id), app_masks.end()); 359 ASSERT_NE(app_masks.find(id), app_masks.end());
386 EXPECT_EQ(app_masks[id], expected_mask); 360 EXPECT_EQ(app_masks[id], expected_mask);
387 } 361 }
388 } 362 }
389 363
390 TEST_F(ArcAppModelBuilderTest, InstallIcon) { 364 TEST_F(ArcAppModelBuilderTest, InstallIcon) {
391 // Make sure we are on UI thread. 365 // Make sure we are on UI thread.
392 ASSERT_EQ(true, 366 ASSERT_EQ(true,
393 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 367 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
394 368
395 369
396 bridge_service()->SetReady(); 370 bridge_service()->SetReady();
397 app_instance()->RefreshAppList(); 371 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>(
398 app_instance()->SendRefreshAppList( 372 fake_apps().begin(), fake_apps().begin() + 1));
399 std::vector<arc::AppInfo>(fake_apps().begin(), fake_apps().begin() + 1));
400 const arc::AppInfo& app = fake_apps()[0]; 373 const arc::AppInfo& app = fake_apps()[0];
401 374
402 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 375 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
403 ASSERT_NE(nullptr, prefs); 376 ASSERT_NE(nullptr, prefs);
404 377
405 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; 378 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0];
406 const float scale = ui::GetScaleForScaleFactor(scale_factor); 379 const float scale = ui::GetScaleForScaleFactor(scale_factor);
407 const base::FilePath icon_path = prefs->GetIconPath(GetAppId(app), 380 const base::FilePath icon_path = prefs->GetIconPath(GetAppId(app),
408 scale_factor); 381 scale_factor);
409 EXPECT_EQ(true, !base::PathExists(icon_path)); 382 EXPECT_EQ(true, !base::PathExists(icon_path));
410 383
411 const ArcAppItem* app_item = FindArcItem(GetAppId(app)); 384 const ArcAppItem* app_item = FindArcItem(GetAppId(app));
412 EXPECT_NE(nullptr, app_item); 385 EXPECT_NE(nullptr, app_item);
413 // This initiates async loading. 386 // This initiates async loading.
414 app_item->icon().GetRepresentation(scale); 387 app_item->icon().GetRepresentation(scale);
415 388
416 // Process pending tasks. 389 // Process pending tasks.
417 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 390 content::BrowserThread::GetBlockingPool()->FlushForTesting();
418 base::RunLoop().RunUntilIdle(); 391 base::RunLoop().RunUntilIdle();
419 392
420 // Validating decoded content does not fit well for unit tests. 393 // Validating decoded content does not fit well for unit tests.
421 ArcAppIcon::DisableDecodingForTesting(); 394 ArcAppIcon::DisableDecodingForTesting();
422 395
423 // Now send generated icon for the app. 396 // Now send generated icon for the app.
424 std::string png_data; 397 std::string png_data;
425 EXPECT_EQ(true, 398 EXPECT_EQ(true, bridge_service()->GenerateAndSendIcon(
426 app_instance()->GenerateAndSendIcon( 399 app,
427 app, static_cast<arc::ScaleFactor>(scale_factor), &png_data)); 400 static_cast<arc::ScaleFactor>(scale_factor),
401 &png_data));
428 402
429 // Process pending tasks. 403 // Process pending tasks.
430 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 404 content::BrowserThread::GetBlockingPool()->FlushForTesting();
431 base::RunLoop().RunUntilIdle(); 405 base::RunLoop().RunUntilIdle();
432 406
433 // Validate that icons are installed, have right content and icon is 407 // Validate that icons are installed, have right content and icon is
434 // refreshed for ARC app item. 408 // refreshed for ARC app item.
435 EXPECT_EQ(true, base::PathExists(icon_path)); 409 EXPECT_EQ(true, base::PathExists(icon_path));
436 410
437 std::string icon_data; 411 std::string icon_data;
438 // Read the file from disk and compare with reference data. 412 // Read the file from disk and compare with reference data.
439 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data)); 413 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data));
440 ASSERT_EQ(icon_data, png_data); 414 ASSERT_EQ(icon_data, png_data);
441 } 415 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | components/arc.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698