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