OLD | NEW |
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 Loading... |
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 | 63 |
70 // Check initial conditions. | 64 // Check initial conditions. |
71 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); | 65 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); |
72 EXPECT_EQ(true, !arc::ArcBridgeService::Get()->available()); | 66 EXPECT_EQ(true, !arc::ArcBridgeService::Get()->available()); |
73 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, | 67 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, |
74 arc::ArcBridgeService::Get()->state()); | 68 arc::ArcBridgeService::Get()->state()); |
75 | 69 |
76 CreateBuilder(); | 70 CreateBuilder(); |
77 | 71 |
78 // 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 Loading... |
188 | 182 |
189 // Process the rest of the apps. | 183 // Process the rest of the apps. |
190 for (auto& id : ids) { | 184 for (auto& id : ids) { |
191 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id); | 185 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id); |
192 ASSERT_NE(nullptr, app_info.get()); | 186 ASSERT_NE(nullptr, app_info.get()); |
193 EXPECT_NE(ready, app_info->ready); | 187 EXPECT_NE(ready, app_info->ready); |
194 const ArcAppItem* app_item = FindArcItem(id); | 188 const ArcAppItem* app_item = FindArcItem(id); |
195 ASSERT_NE(nullptr, app_item); | 189 ASSERT_NE(nullptr, app_item); |
196 EXPECT_NE(ready, app_item->ready()); | 190 EXPECT_NE(ready, app_item->ready()); |
197 } | 191 } |
| 192 |
198 } | 193 } |
199 | 194 |
200 AppListControllerDelegate* controller() { return controller_.get(); } | 195 AppListControllerDelegate* controller() { return controller_.get(); } |
201 | 196 |
202 arc::FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } | 197 arc::FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } |
203 | 198 |
204 arc::FakeAppInstance* app_instance() { return app_instance_.get(); } | |
205 | |
206 const std::vector<arc::AppInfo>& fake_apps() const { return fake_apps_; } | 199 const std::vector<arc::AppInfo>& fake_apps() const { return fake_apps_; } |
207 | 200 |
208 private: | 201 private: |
209 scoped_ptr<app_list::AppListModel> model_; | 202 scoped_ptr<app_list::AppListModel> model_; |
210 scoped_ptr<test::TestAppListControllerDelegate> controller_; | 203 scoped_ptr<test::TestAppListControllerDelegate> controller_; |
211 scoped_ptr<ArcAppModelBuilder> builder_; | 204 scoped_ptr<ArcAppModelBuilder> builder_; |
212 scoped_ptr<arc::FakeArcBridgeService> bridge_service_; | 205 scoped_ptr<arc::FakeArcBridgeService> bridge_service_; |
213 scoped_ptr<arc::FakeAppInstance> app_instance_; | |
214 std::vector<arc::AppInfo> fake_apps_; | 206 std::vector<arc::AppInfo> fake_apps_; |
215 | 207 |
216 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); | 208 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); |
217 }; | 209 }; |
218 | 210 |
219 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { | 211 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { |
220 EXPECT_EQ(0, app_instance()->refresh_app_list_count()); | 212 EXPECT_EQ(0, bridge_service()->refresh_app_list_count()); |
221 bridge_service()->SetReady(); | 213 bridge_service()->SetReady(); |
222 app_instance()->RefreshAppList(); | 214 EXPECT_EQ(1, bridge_service()->refresh_app_list_count()); |
223 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); | |
224 } | 215 } |
225 | 216 |
226 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { | 217 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { |
227 ValidateHaveApps(std::vector<arc::AppInfo>()); | 218 ValidateHaveApps(std::vector<arc::AppInfo>()); |
228 bridge_service()->SetReady(); | 219 bridge_service()->SetReady(); |
229 app_instance()->RefreshAppList(); | 220 bridge_service()->SendRefreshAppList(fake_apps()); |
230 app_instance()->SendRefreshAppList(fake_apps()); | |
231 ValidateHaveApps(fake_apps()); | 221 ValidateHaveApps(fake_apps()); |
232 } | 222 } |
233 | 223 |
234 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { | 224 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { |
235 ValidateHaveApps(std::vector<arc::AppInfo>()); | 225 ValidateHaveApps(std::vector<arc::AppInfo>()); |
236 bridge_service()->SetReady(); | 226 bridge_service()->SetReady(); |
237 app_instance()->RefreshAppList(); | |
238 // Send info about all fake apps except last. | 227 // Send info about all fake apps except last. |
239 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); |
240 app_instance()->SendRefreshAppList(apps1); | 229 bridge_service()->SendRefreshAppList(apps1); |
241 // 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. |
242 ValidateHaveApps(apps1); | 231 ValidateHaveApps(apps1); |
243 ValidateAppReadyState(apps1, true); | 232 ValidateAppReadyState(apps1, true); |
244 | 233 |
245 // Send info about all fake apps except first. | 234 // Send info about all fake apps except first. |
246 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()); |
247 app_instance()->SendRefreshAppList(apps2); | 236 bridge_service()->SendRefreshAppList(apps2); |
248 // 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. |
249 ValidateHaveApps(fake_apps()); | 238 ValidateHaveApps(fake_apps()); |
250 ValidateAppReadyState(apps2, true); | 239 ValidateAppReadyState(apps2, true); |
251 | 240 |
252 // Send info about all fake apps. | 241 // Send info about all fake apps. |
253 app_instance()->SendRefreshAppList(fake_apps()); | 242 bridge_service()->SendRefreshAppList(fake_apps()); |
254 // At this point all apps should exist and be ready. | 243 // At this point all apps should exist and be ready. |
255 ValidateHaveApps(fake_apps()); | 244 ValidateHaveApps(fake_apps()); |
256 ValidateAppReadyState(fake_apps(), true); | 245 ValidateAppReadyState(fake_apps(), true); |
257 | 246 |
258 // Send info no app available. | 247 // Send info no app available. |
259 app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>()); | 248 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>()); |
260 // At this point all apps should exist and be non-ready. | 249 // At this point all apps should exist and be non-ready. |
261 ValidateHaveApps(fake_apps()); | 250 ValidateHaveApps(fake_apps()); |
262 ValidateAppReadyState(fake_apps(), false); | 251 ValidateAppReadyState(fake_apps(), false); |
263 } | 252 } |
264 | 253 |
265 TEST_F(ArcAppModelBuilderTest, StopServiceDisablesApps) { | 254 TEST_F(ArcAppModelBuilderTest, StopServiceDisablesApps) { |
266 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 255 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
267 ASSERT_NE(nullptr, prefs); | 256 ASSERT_NE(nullptr, prefs); |
268 | 257 |
269 bridge_service()->SetReady(); | 258 bridge_service()->SetReady(); |
270 app_instance()->RefreshAppList(); | |
271 EXPECT_EQ(static_cast<size_t>(0), GetArcItemCount()); | 259 EXPECT_EQ(static_cast<size_t>(0), GetArcItemCount()); |
272 EXPECT_EQ(static_cast<size_t>(0), prefs->GetAppIds().size()); | 260 EXPECT_EQ(static_cast<size_t>(0), prefs->GetAppIds().size()); |
273 | 261 |
274 app_instance()->SendRefreshAppList(fake_apps()); | 262 bridge_service()->SendRefreshAppList(fake_apps()); |
275 std::vector<std::string> ids = prefs->GetAppIds(); | 263 std::vector<std::string> ids = prefs->GetAppIds(); |
276 EXPECT_EQ(fake_apps().size(), ids.size()); | 264 EXPECT_EQ(fake_apps().size(), ids.size()); |
277 ValidateAppReadyState(fake_apps(), true); | 265 ValidateAppReadyState(fake_apps(), true); |
278 | 266 |
279 // Stopping service does not delete items. It makes them non-ready. | 267 // Stopping service does not delete items. It makes them non-ready. |
280 bridge_service()->SetStopped(); | 268 bridge_service()->SetStopped(); |
281 // Ids should be the same. | 269 // Ids should be the same. |
282 EXPECT_EQ(ids, prefs->GetAppIds()); | 270 EXPECT_EQ(ids, prefs->GetAppIds()); |
283 ValidateAppReadyState(fake_apps(), false); | 271 ValidateAppReadyState(fake_apps(), false); |
284 } | 272 } |
285 | 273 |
286 TEST_F(ArcAppModelBuilderTest, LaunchApps) { | 274 TEST_F(ArcAppModelBuilderTest, LaunchApps) { |
287 // Disable attempts to dismiss app launcher view. | 275 // Disable attempts to dismiss app launcher view. |
288 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); | 276 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); |
289 | 277 |
290 bridge_service()->SetReady(); | 278 bridge_service()->SetReady(); |
291 app_instance()->RefreshAppList(); | 279 bridge_service()->SendRefreshAppList(fake_apps()); |
292 app_instance()->SendRefreshAppList(fake_apps()); | |
293 | 280 |
294 // Simulate item activate. | 281 // Simulate item activate. |
295 const arc::AppInfo& app_first = fake_apps()[0]; | 282 const arc::AppInfo& app_first = fake_apps()[0]; |
296 const arc::AppInfo& app_last = fake_apps()[0]; | 283 const arc::AppInfo& app_last = fake_apps()[0]; |
297 ArcAppItem* item_first = FindArcItem(GetAppId(app_first)); | 284 ArcAppItem* item_first = FindArcItem(GetAppId(app_first)); |
298 ArcAppItem* item_last = FindArcItem(GetAppId(app_last)); | 285 ArcAppItem* item_last = FindArcItem(GetAppId(app_last)); |
299 ASSERT_NE(nullptr, item_first); | 286 ASSERT_NE(nullptr, item_first); |
300 ASSERT_NE(nullptr, item_last); | 287 ASSERT_NE(nullptr, item_last); |
301 item_first->Activate(0); | 288 item_first->Activate(0); |
302 item_last->Activate(0); | 289 item_last->Activate(0); |
303 item_first->Activate(0); | 290 item_first->Activate(0); |
304 | 291 |
305 // Process pending tasks. | 292 const ScopedVector<arc::FakeArcBridgeService::Request>& launch_requests = |
306 base::RunLoop().RunUntilIdle(); | 293 bridge_service()->launch_requests(); |
307 | 294 EXPECT_EQ(static_cast<size_t>(3), launch_requests.size()); |
308 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = | |
309 app_instance()->launch_requests(); | |
310 ASSERT_EQ(static_cast<size_t>(3), launch_requests.size()); | |
311 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first)); | 295 EXPECT_EQ(true, launch_requests[0]->IsForApp(app_first)); |
312 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last)); | 296 EXPECT_EQ(true, launch_requests[1]->IsForApp(app_last)); |
313 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first)); | 297 EXPECT_EQ(true, launch_requests[2]->IsForApp(app_first)); |
314 | 298 |
315 // Test an attempt to launch of a not-ready app. | 299 // Test an attempt to launch of a not-ready app. |
316 app_instance()->SendRefreshAppList(std::vector<arc::AppInfo>()); | 300 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>()); |
317 item_first = FindArcItem(GetAppId(app_first)); | 301 item_first = FindArcItem(GetAppId(app_first)); |
318 ASSERT_NE(nullptr, item_first); | 302 ASSERT_NE(nullptr, item_first); |
319 size_t launch_request_count_before = app_instance()->launch_requests().size(); | 303 size_t launch_request_count_before = |
| 304 bridge_service()->launch_requests().size(); |
320 item_first->Activate(0); | 305 item_first->Activate(0); |
321 // Number of launch requests must not change. | 306 // Number of launch requests must not change. |
322 EXPECT_EQ(launch_request_count_before, | 307 EXPECT_EQ(launch_request_count_before, |
323 app_instance()->launch_requests().size()); | 308 bridge_service()->launch_requests().size()); |
324 } | 309 } |
325 | 310 |
326 TEST_F(ArcAppModelBuilderTest, RequestIcons) { | 311 TEST_F(ArcAppModelBuilderTest, RequestIcons) { |
327 // Make sure we are on UI thread. | 312 // Make sure we are on UI thread. |
328 ASSERT_EQ(true, | 313 ASSERT_EQ(true, |
329 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 314 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
330 | 315 |
331 bridge_service()->SetReady(); | 316 bridge_service()->SetReady(); |
332 app_instance()->RefreshAppList(); | 317 bridge_service()->SendRefreshAppList(fake_apps()); |
333 app_instance()->SendRefreshAppList(fake_apps()); | |
334 | 318 |
335 // 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 |
336 // each supported scale factor. This will start asynchronous loading. | 320 // each supported scale factor. This will start asynchronous loading. |
337 uint32_t expected_mask = 0; | 321 uint32_t expected_mask = 0; |
338 const std::vector<ui::ScaleFactor>& scale_factors = | 322 const std::vector<ui::ScaleFactor>& scale_factors = |
339 ui::GetSupportedScaleFactors(); | 323 ui::GetSupportedScaleFactors(); |
340 for (auto& scale_factor : scale_factors) { | 324 for (auto& scale_factor : scale_factors) { |
341 expected_mask |= 1 << scale_factor; | 325 expected_mask |= 1 << scale_factor; |
342 for (auto& app : fake_apps()) { | 326 for (auto& app : fake_apps()) { |
343 ArcAppItem* app_item = FindArcItem(GetAppId(app)); | 327 ArcAppItem* app_item = FindArcItem(GetAppId(app)); |
344 ASSERT_NE(nullptr, app_item); | 328 ASSERT_NE(nullptr, app_item); |
345 const float scale = ui::GetScaleForScaleFactor(scale_factor); | 329 const float scale = ui::GetScaleForScaleFactor(scale_factor); |
346 app_item->icon().GetRepresentation(scale); | 330 app_item->icon().GetRepresentation(scale); |
347 } | 331 } |
348 } | 332 } |
349 | 333 |
350 // Process pending tasks. | 334 // Process pending tasks. |
351 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 335 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
352 base::RunLoop().RunUntilIdle(); | 336 base::RunLoop().RunUntilIdle(); |
353 | 337 |
354 // At this moment we should receive all requests for icon loading. | 338 // At this moment we should receive all requests for icon loading. |
355 const ScopedVector<arc::FakeAppInstance::IconRequest>& icon_requests = | 339 const ScopedVector<arc::FakeArcBridgeService::IconRequest>& icon_requests = |
356 app_instance()->icon_requests(); | 340 bridge_service()->icon_requests(); |
357 EXPECT_EQ(scale_factors.size() * fake_apps().size(), icon_requests.size()); | 341 EXPECT_EQ(scale_factors.size() * fake_apps().size(), icon_requests.size()); |
358 std::map<std::string, uint32_t> app_masks; | 342 std::map<std::string, uint32_t> app_masks; |
359 for (size_t i = 0; i < icon_requests.size(); ++i) { | 343 for (size_t i = 0; i < icon_requests.size(); ++i) { |
360 const arc::FakeAppInstance::IconRequest* icon_request = icon_requests[i]; | 344 const arc::FakeArcBridgeService::IconRequest* icon_request = |
| 345 icon_requests[i]; |
361 const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(), | 346 const std::string id = ArcAppListPrefs::GetAppId(icon_request->package(), |
362 icon_request->activity()); | 347 icon_request->activity()); |
363 // Make sure no double requests. | 348 // Make sure no double requests. |
364 EXPECT_NE(app_masks[id], | 349 EXPECT_NE(app_masks[id], |
365 app_masks[id] | (1 << icon_request->scale_factor())); | 350 app_masks[id] | (1 << icon_request->scale_factor())); |
366 app_masks[id] |= (1 << icon_request->scale_factor()); | 351 app_masks[id] |= (1 << icon_request->scale_factor()); |
367 } | 352 } |
368 | 353 |
369 // 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 |
370 // factor. | 355 // factor. |
371 EXPECT_EQ(fake_apps().size(), app_masks.size()); | 356 EXPECT_EQ(fake_apps().size(), app_masks.size()); |
372 for (auto& app : fake_apps()) { | 357 for (auto& app : fake_apps()) { |
373 const std::string id = GetAppId(app); | 358 const std::string id = GetAppId(app); |
374 ASSERT_NE(app_masks.find(id), app_masks.end()); | 359 ASSERT_NE(app_masks.find(id), app_masks.end()); |
375 EXPECT_EQ(app_masks[id], expected_mask); | 360 EXPECT_EQ(app_masks[id], expected_mask); |
376 } | 361 } |
377 } | 362 } |
378 | 363 |
379 TEST_F(ArcAppModelBuilderTest, InstallIcon) { | 364 TEST_F(ArcAppModelBuilderTest, InstallIcon) { |
380 // Make sure we are on UI thread. | 365 // Make sure we are on UI thread. |
381 ASSERT_EQ(true, | 366 ASSERT_EQ(true, |
382 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 367 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
383 | 368 |
384 | 369 |
385 bridge_service()->SetReady(); | 370 bridge_service()->SetReady(); |
386 app_instance()->RefreshAppList(); | 371 bridge_service()->SendRefreshAppList(std::vector<arc::AppInfo>( |
387 app_instance()->SendRefreshAppList( | 372 fake_apps().begin(), fake_apps().begin() + 1)); |
388 std::vector<arc::AppInfo>(fake_apps().begin(), fake_apps().begin() + 1)); | |
389 const arc::AppInfo& app = fake_apps()[0]; | 373 const arc::AppInfo& app = fake_apps()[0]; |
390 | 374 |
391 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 375 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
392 ASSERT_NE(nullptr, prefs); | 376 ASSERT_NE(nullptr, prefs); |
393 | 377 |
394 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; | 378 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; |
395 const float scale = ui::GetScaleForScaleFactor(scale_factor); | 379 const float scale = ui::GetScaleForScaleFactor(scale_factor); |
396 const base::FilePath icon_path = prefs->GetIconPath(GetAppId(app), | 380 const base::FilePath icon_path = prefs->GetIconPath(GetAppId(app), |
397 scale_factor); | 381 scale_factor); |
398 EXPECT_EQ(true, !base::PathExists(icon_path)); | 382 EXPECT_EQ(true, !base::PathExists(icon_path)); |
399 | 383 |
400 const ArcAppItem* app_item = FindArcItem(GetAppId(app)); | 384 const ArcAppItem* app_item = FindArcItem(GetAppId(app)); |
401 EXPECT_NE(nullptr, app_item); | 385 EXPECT_NE(nullptr, app_item); |
402 // This initiates async loading. | 386 // This initiates async loading. |
403 app_item->icon().GetRepresentation(scale); | 387 app_item->icon().GetRepresentation(scale); |
404 | 388 |
405 // Process pending tasks. | 389 // Process pending tasks. |
406 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 390 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
407 base::RunLoop().RunUntilIdle(); | 391 base::RunLoop().RunUntilIdle(); |
408 | 392 |
409 // Validating decoded content does not fit well for unit tests. | 393 // Validating decoded content does not fit well for unit tests. |
410 ArcAppIcon::DisableDecodingForTesting(); | 394 ArcAppIcon::DisableDecodingForTesting(); |
411 | 395 |
412 // Now send generated icon for the app. | 396 // Now send generated icon for the app. |
413 std::string png_data; | 397 std::string png_data; |
414 EXPECT_EQ(true, | 398 EXPECT_EQ(true, bridge_service()->GenerateAndSendIcon( |
415 app_instance()->GenerateAndSendIcon( | 399 app, |
416 app, static_cast<arc::ScaleFactor>(scale_factor), &png_data)); | 400 static_cast<arc::ScaleFactor>(scale_factor), |
| 401 &png_data)); |
417 | 402 |
418 // Process pending tasks. | 403 // Process pending tasks. |
419 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 404 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
420 base::RunLoop().RunUntilIdle(); | 405 base::RunLoop().RunUntilIdle(); |
421 | 406 |
422 // Validate that icons are installed, have right content and icon is | 407 // Validate that icons are installed, have right content and icon is |
423 // refreshed for ARC app item. | 408 // refreshed for ARC app item. |
424 EXPECT_EQ(true, base::PathExists(icon_path)); | 409 EXPECT_EQ(true, base::PathExists(icon_path)); |
425 | 410 |
426 std::string icon_data; | 411 std::string icon_data; |
427 // Read the file from disk and compare with reference data. | 412 // Read the file from disk and compare with reference data. |
428 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data)); | 413 EXPECT_EQ(true, base::ReadFileToString(icon_path, &icon_data)); |
429 ASSERT_EQ(icon_data, png_data); | 414 ASSERT_EQ(icon_data, png_data); |
430 } | 415 } |
OLD | NEW |