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