| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 305 } |
| 306 | 306 |
| 307 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { | 307 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { |
| 308 arc_test_.RemovePackage(package); | 308 arc_test_.RemovePackage(package); |
| 309 } | 309 } |
| 310 | 310 |
| 311 AppListControllerDelegate* controller() { return controller_.get(); } | 311 AppListControllerDelegate* controller() { return controller_.get(); } |
| 312 | 312 |
| 313 Profile* profile() { return profile_.get(); } | 313 Profile* profile() { return profile_.get(); } |
| 314 | 314 |
| 315 ArcAppTest* arc_test() { return &arc_test_; } |
| 316 |
| 315 const std::vector<arc::mojom::AppInfo>& fake_apps() const { | 317 const std::vector<arc::mojom::AppInfo>& fake_apps() const { |
| 316 return arc_test_.fake_apps(); | 318 return arc_test_.fake_apps(); |
| 317 } | 319 } |
| 318 | 320 |
| 319 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const { | 321 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const { |
| 320 return arc_test_.fake_packages(); | 322 return arc_test_.fake_packages(); |
| 321 } | 323 } |
| 322 | 324 |
| 323 const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const { | 325 const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const { |
| 324 return arc_test_.fake_shortcuts(); | 326 return arc_test_.fake_shortcuts(); |
| 325 } | 327 } |
| 326 | 328 |
| 327 arc::FakeArcBridgeService* bridge_service() { | |
| 328 return arc_test_.bridge_service(); | |
| 329 } | |
| 330 | |
| 331 arc::FakeAppInstance* app_instance() { | 329 arc::FakeAppInstance* app_instance() { |
| 332 return arc_test_.app_instance(); | 330 return arc_test_.app_instance(); |
| 333 } | 331 } |
| 334 | 332 |
| 335 private: | 333 private: |
| 336 ArcAppTest arc_test_; | 334 ArcAppTest arc_test_; |
| 337 std::unique_ptr<app_list::AppListModel> model_; | 335 std::unique_ptr<app_list::AppListModel> model_; |
| 338 std::unique_ptr<test::TestAppListControllerDelegate> controller_; | 336 std::unique_ptr<test::TestAppListControllerDelegate> controller_; |
| 339 std::unique_ptr<ArcAppModelBuilder> builder_; | 337 std::unique_ptr<ArcAppModelBuilder> builder_; |
| 340 | 338 |
| 341 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); | 339 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); |
| 342 }; | 340 }; |
| 343 | 341 |
| 344 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { | 342 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { |
| 345 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); | 343 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); |
| 346 bridge_service()->SetReady(); | |
| 347 app_instance()->SendRefreshPackageList(fake_packages()); | 344 app_instance()->SendRefreshPackageList(fake_packages()); |
| 348 ValidateHavePackages(fake_packages()); | 345 ValidateHavePackages(fake_packages()); |
| 349 | 346 |
| 350 arc::mojom::ArcPackageInfo package; | 347 arc::mojom::ArcPackageInfo package; |
| 351 package.package_name = kTestPackageName; | 348 package.package_name = kTestPackageName; |
| 352 package.package_version = 2; | 349 package.package_version = 2; |
| 353 package.last_backup_android_id = 2; | 350 package.last_backup_android_id = 2; |
| 354 package.last_backup_time = 2; | 351 package.last_backup_time = 2; |
| 355 package.sync = true; | 352 package.sync = true; |
| 356 | 353 |
| 357 RemovePackage(package); | 354 RemovePackage(package); |
| 358 app_instance()->SendPackageUninstalled(package.package_name); | 355 app_instance()->SendPackageUninstalled(package.package_name); |
| 359 ValidateHavePackages(fake_packages()); | 356 ValidateHavePackages(fake_packages()); |
| 360 | 357 |
| 361 AddPackage(package); | 358 AddPackage(package); |
| 362 app_instance()->SendPackageAdded(package); | 359 app_instance()->SendPackageAdded(package); |
| 363 ValidateHavePackages(fake_packages()); | 360 ValidateHavePackages(fake_packages()); |
| 364 } | 361 } |
| 365 | 362 |
| 366 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { | 363 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { |
| 367 // There should already have been one call, when the interface was | 364 // There should already have been one call, when the interface was |
| 368 // registered. | 365 // registered. |
| 369 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); | 366 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); |
| 370 bridge_service()->SetReady(); | |
| 371 app_instance()->RefreshAppList(); | 367 app_instance()->RefreshAppList(); |
| 372 EXPECT_EQ(2, app_instance()->refresh_app_list_count()); | 368 EXPECT_EQ(2, app_instance()->refresh_app_list_count()); |
| 373 } | 369 } |
| 374 | 370 |
| 375 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { | 371 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { |
| 376 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); | 372 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); |
| 377 bridge_service()->SetReady(); | |
| 378 app_instance()->RefreshAppList(); | 373 app_instance()->RefreshAppList(); |
| 379 app_instance()->SendRefreshAppList(fake_apps()); | 374 app_instance()->SendRefreshAppList(fake_apps()); |
| 380 ValidateHaveApps(fake_apps()); | 375 ValidateHaveApps(fake_apps()); |
| 381 } | 376 } |
| 382 | 377 |
| 383 TEST_F(ArcAppModelBuilderTest, InstallShortcut) { | 378 TEST_F(ArcAppModelBuilderTest, InstallShortcut) { |
| 384 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); | 379 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); |
| 385 bridge_service()->SetReady(); | |
| 386 | 380 |
| 387 app_instance()->SendInstallShortcuts(fake_shortcuts()); | 381 app_instance()->SendInstallShortcuts(fake_shortcuts()); |
| 388 ValidateHaveShortcuts(fake_shortcuts()); | 382 ValidateHaveShortcuts(fake_shortcuts()); |
| 389 } | 383 } |
| 390 | 384 |
| 391 TEST_F(ArcAppModelBuilderTest, RefreshAllPreservesShortcut) { | 385 TEST_F(ArcAppModelBuilderTest, RefreshAllPreservesShortcut) { |
| 392 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); | 386 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); |
| 393 bridge_service()->SetReady(); | |
| 394 app_instance()->RefreshAppList(); | 387 app_instance()->RefreshAppList(); |
| 395 app_instance()->SendRefreshAppList(fake_apps()); | 388 app_instance()->SendRefreshAppList(fake_apps()); |
| 396 ValidateHaveApps(fake_apps()); | 389 ValidateHaveApps(fake_apps()); |
| 397 | 390 |
| 398 app_instance()->SendInstallShortcuts(fake_shortcuts()); | 391 app_instance()->SendInstallShortcuts(fake_shortcuts()); |
| 399 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); | 392 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); |
| 400 | 393 |
| 401 app_instance()->RefreshAppList(); | 394 app_instance()->RefreshAppList(); |
| 402 app_instance()->SendRefreshAppList(fake_apps()); | 395 app_instance()->SendRefreshAppList(fake_apps()); |
| 403 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); | 396 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); |
| 404 } | 397 } |
| 405 | 398 |
| 406 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { | 399 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { |
| 407 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); | 400 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); |
| 408 bridge_service()->SetReady(); | |
| 409 app_instance()->RefreshAppList(); | 401 app_instance()->RefreshAppList(); |
| 410 // Send info about all fake apps except last. | 402 // Send info about all fake apps except last. |
| 411 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), | 403 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), |
| 412 fake_apps().end() - 1); | 404 fake_apps().end() - 1); |
| 413 app_instance()->SendRefreshAppList(apps1); | 405 app_instance()->SendRefreshAppList(apps1); |
| 414 // At this point all apps (except last) should exist and be ready. | 406 // At this point all apps (except last) should exist and be ready. |
| 415 ValidateHaveApps(apps1); | 407 ValidateHaveApps(apps1); |
| 416 ValidateAppReadyState(apps1, true); | 408 ValidateAppReadyState(apps1, true); |
| 417 | 409 |
| 418 // Send info about all fake apps except first. | 410 // Send info about all fake apps except first. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 433 std::vector<arc::mojom::AppInfo> no_apps; | 425 std::vector<arc::mojom::AppInfo> no_apps; |
| 434 app_instance()->SendRefreshAppList(no_apps); | 426 app_instance()->SendRefreshAppList(no_apps); |
| 435 // At this point no app should exist. | 427 // At this point no app should exist. |
| 436 ValidateHaveApps(no_apps); | 428 ValidateHaveApps(no_apps); |
| 437 } | 429 } |
| 438 | 430 |
| 439 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveApps) { | 431 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveApps) { |
| 440 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 432 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 441 ASSERT_NE(nullptr, prefs); | 433 ASSERT_NE(nullptr, prefs); |
| 442 | 434 |
| 443 bridge_service()->SetReady(); | |
| 444 app_instance()->RefreshAppList(); | 435 app_instance()->RefreshAppList(); |
| 445 EXPECT_EQ(0u, GetArcItemCount()); | 436 EXPECT_EQ(0u, GetArcItemCount()); |
| 446 EXPECT_EQ(0u, prefs->GetAppIds().size()); | 437 EXPECT_EQ(0u, prefs->GetAppIds().size()); |
| 447 | 438 |
| 448 app_instance()->SendRefreshAppList(fake_apps()); | 439 app_instance()->SendRefreshAppList(fake_apps()); |
| 449 std::vector<std::string> ids = prefs->GetAppIds(); | 440 std::vector<std::string> ids = prefs->GetAppIds(); |
| 450 EXPECT_EQ(fake_apps().size(), ids.size()); | 441 EXPECT_EQ(fake_apps().size(), ids.size()); |
| 451 ValidateAppReadyState(fake_apps(), true); | 442 ValidateAppReadyState(fake_apps(), true); |
| 452 | 443 |
| 453 // Stopping service does not delete items. It makes them non-ready. | 444 // Stopping service does not delete items. It makes them non-ready. |
| 454 bridge_service()->SetStopped(); | 445 arc_test()->StopArcInstance(); |
| 455 // Ids should be the same. | 446 // Ids should be the same. |
| 456 EXPECT_EQ(ids, prefs->GetAppIds()); | 447 EXPECT_EQ(ids, prefs->GetAppIds()); |
| 457 ValidateAppReadyState(fake_apps(), false); | 448 ValidateAppReadyState(fake_apps(), false); |
| 458 | 449 |
| 459 // Setting service ready does not change anything because RefreshAppList is | |
| 460 // not called. | |
| 461 bridge_service()->SetReady(); | |
| 462 // Ids should be the same. | 450 // Ids should be the same. |
| 463 EXPECT_EQ(ids, prefs->GetAppIds()); | 451 EXPECT_EQ(ids, prefs->GetAppIds()); |
| 464 ValidateAppReadyState(fake_apps(), false); | 452 ValidateAppReadyState(fake_apps(), false); |
| 465 | 453 |
| 466 // Refreshing app list makes apps available. | 454 // Refreshing app list makes apps available. |
| 467 app_instance()->SendRefreshAppList(fake_apps()); | 455 app_instance()->SendRefreshAppList(fake_apps()); |
| 468 EXPECT_EQ(ids, prefs->GetAppIds()); | 456 EXPECT_EQ(ids, prefs->GetAppIds()); |
| 469 ValidateAppReadyState(fake_apps(), true); | 457 ValidateAppReadyState(fake_apps(), true); |
| 470 } | 458 } |
| 471 | 459 |
| 472 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveShortcuts) { | 460 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveShortcuts) { |
| 473 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 461 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 474 ASSERT_NE(nullptr, prefs); | 462 ASSERT_NE(nullptr, prefs); |
| 475 | 463 |
| 476 bridge_service()->SetReady(); | |
| 477 app_instance()->RefreshAppList(); | 464 app_instance()->RefreshAppList(); |
| 478 EXPECT_EQ(0u, GetArcItemCount()); | 465 EXPECT_EQ(0u, GetArcItemCount()); |
| 479 EXPECT_EQ(0u, prefs->GetAppIds().size()); | 466 EXPECT_EQ(0u, prefs->GetAppIds().size()); |
| 480 | 467 |
| 481 app_instance()->SendInstallShortcuts(fake_shortcuts()); | 468 app_instance()->SendInstallShortcuts(fake_shortcuts()); |
| 482 std::vector<std::string> ids = prefs->GetAppIds(); | 469 std::vector<std::string> ids = prefs->GetAppIds(); |
| 483 EXPECT_EQ(fake_shortcuts().size(), ids.size()); | 470 EXPECT_EQ(fake_shortcuts().size(), ids.size()); |
| 484 ValidateShortcutReadyState(fake_shortcuts(), true); | 471 ValidateShortcutReadyState(fake_shortcuts(), true); |
| 485 | 472 |
| 486 // Stopping service does not delete items. It makes them non-ready. | 473 // Stopping service does not delete items. It makes them non-ready. |
| 487 bridge_service()->SetStopped(); | 474 arc_test()->StopArcInstance(); |
| 488 // Ids should be the same. | 475 // Ids should be the same. |
| 489 EXPECT_EQ(ids, prefs->GetAppIds()); | 476 EXPECT_EQ(ids, prefs->GetAppIds()); |
| 490 ValidateShortcutReadyState(fake_shortcuts(), false); | 477 ValidateShortcutReadyState(fake_shortcuts(), false); |
| 491 | 478 |
| 492 // Setting service ready does not change anything because RefreshAppList is | |
| 493 // not called. | |
| 494 bridge_service()->SetReady(); | |
| 495 // Ids should be the same. | 479 // Ids should be the same. |
| 496 EXPECT_EQ(ids, prefs->GetAppIds()); | 480 EXPECT_EQ(ids, prefs->GetAppIds()); |
| 497 ValidateShortcutReadyState(fake_shortcuts(), false); | 481 ValidateShortcutReadyState(fake_shortcuts(), false); |
| 498 | 482 |
| 499 // Refreshing app list makes apps available. | 483 // Refreshing app list makes apps available. |
| 500 app_instance()->RefreshAppList(); | 484 app_instance()->RefreshAppList(); |
| 501 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>()); | 485 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>()); |
| 502 EXPECT_EQ(ids, prefs->GetAppIds()); | 486 EXPECT_EQ(ids, prefs->GetAppIds()); |
| 503 ValidateShortcutReadyState(fake_shortcuts(), true); | 487 ValidateShortcutReadyState(fake_shortcuts(), true); |
| 504 } | 488 } |
| 505 | 489 |
| 506 TEST_F(ArcAppModelBuilderTest, RestartPreserveApps) { | 490 TEST_F(ArcAppModelBuilderTest, RestartPreserveApps) { |
| 507 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 491 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 508 ASSERT_NE(nullptr, prefs); | 492 ASSERT_NE(nullptr, prefs); |
| 509 | 493 |
| 510 // Start from scratch and fill with apps. | 494 // Start from scratch and fill with apps. |
| 511 bridge_service()->SetReady(); | |
| 512 app_instance()->SendRefreshAppList(fake_apps()); | 495 app_instance()->SendRefreshAppList(fake_apps()); |
| 513 std::vector<std::string> ids = prefs->GetAppIds(); | 496 std::vector<std::string> ids = prefs->GetAppIds(); |
| 514 EXPECT_EQ(fake_apps().size(), ids.size()); | 497 EXPECT_EQ(fake_apps().size(), ids.size()); |
| 515 ValidateAppReadyState(fake_apps(), true); | 498 ValidateAppReadyState(fake_apps(), true); |
| 516 | 499 |
| 517 // This recreates model and ARC apps will be read from prefs. | 500 // This recreates model and ARC apps will be read from prefs. |
| 518 bridge_service()->SetStopped(); | 501 arc_test()->StopArcInstance(); |
| 519 CreateBuilder(); | 502 CreateBuilder(); |
| 520 ValidateAppReadyState(fake_apps(), false); | 503 ValidateAppReadyState(fake_apps(), false); |
| 521 } | 504 } |
| 522 | 505 |
| 523 TEST_F(ArcAppModelBuilderTest, RestartPreserveShortcuts) { | 506 TEST_F(ArcAppModelBuilderTest, RestartPreserveShortcuts) { |
| 524 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 507 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 525 ASSERT_NE(nullptr, prefs); | 508 ASSERT_NE(nullptr, prefs); |
| 526 | 509 |
| 527 // Start from scratch and install shortcuts. | 510 // Start from scratch and install shortcuts. |
| 528 bridge_service()->SetReady(); | |
| 529 app_instance()->SendInstallShortcuts(fake_shortcuts()); | 511 app_instance()->SendInstallShortcuts(fake_shortcuts()); |
| 530 std::vector<std::string> ids = prefs->GetAppIds(); | 512 std::vector<std::string> ids = prefs->GetAppIds(); |
| 531 EXPECT_EQ(fake_apps().size(), ids.size()); | 513 EXPECT_EQ(fake_apps().size(), ids.size()); |
| 532 ValidateShortcutReadyState(fake_shortcuts(), true); | 514 ValidateShortcutReadyState(fake_shortcuts(), true); |
| 533 | 515 |
| 534 // This recreates model and ARC apps and shortcuts will be read from prefs. | 516 // This recreates model and ARC apps and shortcuts will be read from prefs. |
| 535 bridge_service()->SetStopped(); | 517 arc_test()->StopArcInstance(); |
| 536 CreateBuilder(); | 518 CreateBuilder(); |
| 537 ValidateShortcutReadyState(fake_shortcuts(), false); | 519 ValidateShortcutReadyState(fake_shortcuts(), false); |
| 538 } | 520 } |
| 539 | 521 |
| 540 TEST_F(ArcAppModelBuilderTest, LaunchApps) { | 522 TEST_F(ArcAppModelBuilderTest, LaunchApps) { |
| 541 // Disable attempts to dismiss app launcher view. | 523 // Disable attempts to dismiss app launcher view. |
| 542 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); | 524 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); |
| 543 | 525 |
| 544 bridge_service()->SetReady(); | |
| 545 app_instance()->RefreshAppList(); | 526 app_instance()->RefreshAppList(); |
| 546 app_instance()->SendRefreshAppList(fake_apps()); | 527 app_instance()->SendRefreshAppList(fake_apps()); |
| 547 | 528 |
| 548 // Simulate item activate. | 529 // Simulate item activate. |
| 549 const arc::mojom::AppInfo& app_first = fake_apps()[0]; | 530 const arc::mojom::AppInfo& app_first = fake_apps()[0]; |
| 550 const arc::mojom::AppInfo& app_last = fake_apps()[0]; | 531 const arc::mojom::AppInfo& app_last = fake_apps()[0]; |
| 551 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); | 532 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); |
| 552 ArcAppItem* item_last = FindArcItem(ArcAppTest::GetAppId(app_last)); | 533 ArcAppItem* item_last = FindArcItem(ArcAppTest::GetAppId(app_last)); |
| 553 ASSERT_NE(nullptr, item_first); | 534 ASSERT_NE(nullptr, item_first); |
| 554 ASSERT_NE(nullptr, item_last); | 535 ASSERT_NE(nullptr, item_last); |
| 555 item_first->Activate(0); | 536 item_first->Activate(0); |
| 556 item_last->Activate(0); | 537 item_last->Activate(0); |
| 557 item_first->Activate(0); | 538 item_first->Activate(0); |
| 558 | 539 |
| 559 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = | 540 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = |
| 560 app_instance()->launch_requests(); | 541 app_instance()->launch_requests(); |
| 561 ASSERT_EQ(3u, launch_requests.size()); | 542 ASSERT_EQ(3u, launch_requests.size()); |
| 562 EXPECT_TRUE(launch_requests[0]->IsForApp(app_first)); | 543 EXPECT_TRUE(launch_requests[0]->IsForApp(app_first)); |
| 563 EXPECT_TRUE(launch_requests[1]->IsForApp(app_last)); | 544 EXPECT_TRUE(launch_requests[1]->IsForApp(app_last)); |
| 564 EXPECT_TRUE(launch_requests[2]->IsForApp(app_first)); | 545 EXPECT_TRUE(launch_requests[2]->IsForApp(app_first)); |
| 565 | 546 |
| 566 // Test an attempt to launch of a not-ready app. | 547 // Test an attempt to launch of a not-ready app. |
| 567 bridge_service()->SetStopped(); | 548 arc_test()->StopArcInstance(); |
| 568 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); | 549 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); |
| 569 ASSERT_NE(nullptr, item_first); | 550 ASSERT_NE(nullptr, item_first); |
| 570 size_t launch_request_count_before = app_instance()->launch_requests().size(); | 551 size_t launch_request_count_before = app_instance()->launch_requests().size(); |
| 571 item_first->Activate(0); | 552 item_first->Activate(0); |
| 572 // Number of launch requests must not change. | 553 // Number of launch requests must not change. |
| 573 EXPECT_EQ(launch_request_count_before, | 554 EXPECT_EQ(launch_request_count_before, |
| 574 app_instance()->launch_requests().size()); | 555 app_instance()->launch_requests().size()); |
| 575 } | 556 } |
| 576 | 557 |
| 577 TEST_F(ArcAppModelBuilderTest, LaunchShortcuts) { | 558 TEST_F(ArcAppModelBuilderTest, LaunchShortcuts) { |
| 578 // Disable attempts to dismiss app launcher view. | 559 // Disable attempts to dismiss app launcher view. |
| 579 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); | 560 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); |
| 580 | 561 |
| 581 bridge_service()->SetReady(); | |
| 582 app_instance()->RefreshAppList(); | 562 app_instance()->RefreshAppList(); |
| 583 app_instance()->SendInstallShortcuts(fake_shortcuts()); | 563 app_instance()->SendInstallShortcuts(fake_shortcuts()); |
| 584 | 564 |
| 585 // Simulate item activate. | 565 // Simulate item activate. |
| 586 const arc::mojom::ShortcutInfo& app_first = fake_shortcuts()[0]; | 566 const arc::mojom::ShortcutInfo& app_first = fake_shortcuts()[0]; |
| 587 const arc::mojom::ShortcutInfo& app_last = fake_shortcuts()[0]; | 567 const arc::mojom::ShortcutInfo& app_last = fake_shortcuts()[0]; |
| 588 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); | 568 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); |
| 589 ArcAppItem* item_last = FindArcItem(ArcAppTest::GetAppId(app_last)); | 569 ArcAppItem* item_last = FindArcItem(ArcAppTest::GetAppId(app_last)); |
| 590 ASSERT_NE(nullptr, item_first); | 570 ASSERT_NE(nullptr, item_first); |
| 591 ASSERT_NE(nullptr, item_last); | 571 ASSERT_NE(nullptr, item_last); |
| 592 item_first->Activate(0); | 572 item_first->Activate(0); |
| 593 item_last->Activate(0); | 573 item_last->Activate(0); |
| 594 item_first->Activate(0); | 574 item_first->Activate(0); |
| 595 | 575 |
| 596 const ScopedVector<mojo::String>& launch_intents = | 576 const ScopedVector<mojo::String>& launch_intents = |
| 597 app_instance()->launch_intents(); | 577 app_instance()->launch_intents(); |
| 598 ASSERT_EQ(3u, launch_intents.size()); | 578 ASSERT_EQ(3u, launch_intents.size()); |
| 599 EXPECT_EQ(app_first.intent_uri, *launch_intents[0]); | 579 EXPECT_EQ(app_first.intent_uri, *launch_intents[0]); |
| 600 EXPECT_EQ(app_last.intent_uri, *launch_intents[1]); | 580 EXPECT_EQ(app_last.intent_uri, *launch_intents[1]); |
| 601 EXPECT_EQ(app_first.intent_uri, *launch_intents[2]); | 581 EXPECT_EQ(app_first.intent_uri, *launch_intents[2]); |
| 602 | 582 |
| 603 // Test an attempt to launch of a not-ready shortcut. | 583 // Test an attempt to launch of a not-ready shortcut. |
| 604 bridge_service()->SetStopped(); | 584 arc_test()->StopArcInstance(); |
| 605 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); | 585 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); |
| 606 ASSERT_NE(nullptr, item_first); | 586 ASSERT_NE(nullptr, item_first); |
| 607 size_t launch_request_count_before = app_instance()->launch_intents().size(); | 587 size_t launch_request_count_before = app_instance()->launch_intents().size(); |
| 608 item_first->Activate(0); | 588 item_first->Activate(0); |
| 609 // Number of launch requests must not change. | 589 // Number of launch requests must not change. |
| 610 EXPECT_EQ(launch_request_count_before, | 590 EXPECT_EQ(launch_request_count_before, |
| 611 app_instance()->launch_intents().size()); | 591 app_instance()->launch_intents().size()); |
| 612 } | 592 } |
| 613 | 593 |
| 614 TEST_F(ArcAppModelBuilderTest, RequestIcons) { | 594 TEST_F(ArcAppModelBuilderTest, RequestIcons) { |
| 615 // Make sure we are on UI thread. | 595 // Make sure we are on UI thread. |
| 616 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 596 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 617 | 597 |
| 618 bridge_service()->SetReady(); | |
| 619 app_instance()->RefreshAppList(); | 598 app_instance()->RefreshAppList(); |
| 620 app_instance()->SendRefreshAppList(fake_apps()); | 599 app_instance()->SendRefreshAppList(fake_apps()); |
| 621 | 600 |
| 622 // Validate that no icon exists at the beginning and request icon for | 601 // Validate that no icon exists at the beginning and request icon for |
| 623 // each supported scale factor. This will start asynchronous loading. | 602 // each supported scale factor. This will start asynchronous loading. |
| 624 uint32_t expected_mask = 0; | 603 uint32_t expected_mask = 0; |
| 625 const std::vector<ui::ScaleFactor>& scale_factors = | 604 const std::vector<ui::ScaleFactor>& scale_factors = |
| 626 ui::GetSupportedScaleFactors(); | 605 ui::GetSupportedScaleFactors(); |
| 627 for (auto& scale_factor : scale_factors) { | 606 for (auto& scale_factor : scale_factors) { |
| 628 expected_mask |= 1 << scale_factor; | 607 expected_mask |= 1 << scale_factor; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 const std::string id = ArcAppTest::GetAppId(app); | 642 const std::string id = ArcAppTest::GetAppId(app); |
| 664 ASSERT_NE(app_masks.find(id), app_masks.end()); | 643 ASSERT_NE(app_masks.find(id), app_masks.end()); |
| 665 EXPECT_EQ(app_masks[id], expected_mask); | 644 EXPECT_EQ(app_masks[id], expected_mask); |
| 666 } | 645 } |
| 667 } | 646 } |
| 668 | 647 |
| 669 TEST_F(ArcAppModelBuilderTest, RequestShortcutIcons) { | 648 TEST_F(ArcAppModelBuilderTest, RequestShortcutIcons) { |
| 670 // Make sure we are on UI thread. | 649 // Make sure we are on UI thread. |
| 671 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 650 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 672 | 651 |
| 673 bridge_service()->SetReady(); | |
| 674 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0]; | 652 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0]; |
| 675 app_instance()->SendInstallShortcut(shortcut); | 653 app_instance()->SendInstallShortcut(shortcut); |
| 676 | 654 |
| 677 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 655 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 678 ASSERT_NE(nullptr, prefs); | 656 ASSERT_NE(nullptr, prefs); |
| 679 | 657 |
| 680 // Validate that no icon exists at the beginning and request icon for | 658 // Validate that no icon exists at the beginning and request icon for |
| 681 // each supported scale factor. This will start asynchronous loading. | 659 // each supported scale factor. This will start asynchronous loading. |
| 682 uint32_t expected_mask = 0; | 660 uint32_t expected_mask = 0; |
| 683 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(shortcut)); | 661 ArcAppItem* app_item = FindArcItem(ArcAppTest::GetAppId(shortcut)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 const base::FilePath icon_path = | 698 const base::FilePath icon_path = |
| 721 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor); | 699 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor); |
| 722 EXPECT_TRUE(base::PathExists(icon_path)); | 700 EXPECT_TRUE(base::PathExists(icon_path)); |
| 723 } | 701 } |
| 724 } | 702 } |
| 725 | 703 |
| 726 TEST_F(ArcAppModelBuilderTest, InstallIcon) { | 704 TEST_F(ArcAppModelBuilderTest, InstallIcon) { |
| 727 // Make sure we are on UI thread. | 705 // Make sure we are on UI thread. |
| 728 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 706 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 729 | 707 |
| 730 bridge_service()->SetReady(); | |
| 731 app_instance()->RefreshAppList(); | 708 app_instance()->RefreshAppList(); |
| 732 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( | 709 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 733 fake_apps().begin(), fake_apps().begin() + 1)); | 710 fake_apps().begin(), fake_apps().begin() + 1)); |
| 734 const arc::mojom::AppInfo& app = fake_apps()[0]; | 711 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 735 | 712 |
| 736 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 713 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 737 ASSERT_NE(nullptr, prefs); | 714 ASSERT_NE(nullptr, prefs); |
| 738 | 715 |
| 739 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; | 716 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; |
| 740 const float scale = ui::GetScaleForScaleFactor(scale_factor); | 717 const float scale = ui::GetScaleForScaleFactor(scale_factor); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 760 std::string icon_data; | 737 std::string icon_data; |
| 761 // Read the file from disk and compare with reference data. | 738 // Read the file from disk and compare with reference data. |
| 762 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data)); | 739 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data)); |
| 763 ASSERT_EQ(icon_data, png_data); | 740 ASSERT_EQ(icon_data, png_data); |
| 764 } | 741 } |
| 765 | 742 |
| 766 TEST_F(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) { | 743 TEST_F(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) { |
| 767 // Make sure we are on UI thread. | 744 // Make sure we are on UI thread. |
| 768 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 745 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 769 | 746 |
| 770 bridge_service()->SetReady(); | |
| 771 app_instance()->RefreshAppList(); | 747 app_instance()->RefreshAppList(); |
| 772 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( | 748 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 773 fake_apps().begin(), fake_apps().begin() + 1)); | 749 fake_apps().begin(), fake_apps().begin() + 1)); |
| 774 const arc::mojom::AppInfo& app = fake_apps()[0]; | 750 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 775 | 751 |
| 776 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 752 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 777 ASSERT_NE(nullptr, prefs); | 753 ASSERT_NE(nullptr, prefs); |
| 778 | 754 |
| 779 const std::string app_id = ArcAppTest::GetAppId(app); | 755 const std::string app_id = ArcAppTest::GetAppId(app); |
| 780 const base::FilePath app_path = prefs->GetAppPath(app_id); | 756 const base::FilePath app_path = prefs->GetAppPath(app_id); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 803 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 779 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 804 base::RunLoop().RunUntilIdle(); | 780 base::RunLoop().RunUntilIdle(); |
| 805 } while (base::PathExists(app_path)); | 781 } while (base::PathExists(app_path)); |
| 806 EXPECT_FALSE(base::PathExists(app_path)); | 782 EXPECT_FALSE(base::PathExists(app_path)); |
| 807 } | 783 } |
| 808 | 784 |
| 809 TEST_F(ArcAppModelBuilderTest, LastLaunchTime) { | 785 TEST_F(ArcAppModelBuilderTest, LastLaunchTime) { |
| 810 // Make sure we are on UI thread. | 786 // Make sure we are on UI thread. |
| 811 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 787 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 812 | 788 |
| 813 bridge_service()->SetReady(); | |
| 814 app_instance()->RefreshAppList(); | 789 app_instance()->RefreshAppList(); |
| 815 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( | 790 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 816 fake_apps().begin(), fake_apps().begin() + 2)); | 791 fake_apps().begin(), fake_apps().begin() + 2)); |
| 817 const arc::mojom::AppInfo& app1 = fake_apps()[0]; | 792 const arc::mojom::AppInfo& app1 = fake_apps()[0]; |
| 818 const arc::mojom::AppInfo& app2 = fake_apps()[1]; | 793 const arc::mojom::AppInfo& app2 = fake_apps()[1]; |
| 819 const std::string id1 = ArcAppTest::GetAppId(app1); | 794 const std::string id1 = ArcAppTest::GetAppId(app1); |
| 820 const std::string id2 = ArcAppTest::GetAppId(app2); | 795 const std::string id2 = ArcAppTest::GetAppId(app2); |
| 821 | 796 |
| 822 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 797 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 823 ASSERT_NE(nullptr, prefs); | 798 ASSERT_NE(nullptr, prefs); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 851 } | 826 } |
| 852 | 827 |
| 853 // TODO(crbug.com/628425) -- reenable once this test is less flaky. | 828 // TODO(crbug.com/628425) -- reenable once this test is less flaky. |
| 854 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { | 829 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { |
| 855 const arc::mojom::AppInfo& app = fake_apps()[0]; | 830 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 856 const std::string app_id = ArcAppTest::GetAppId(app); | 831 const std::string app_id = ArcAppTest::GetAppId(app); |
| 857 | 832 |
| 858 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 833 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 859 ASSERT_NE(nullptr, prefs); | 834 ASSERT_NE(nullptr, prefs); |
| 860 | 835 |
| 861 bridge_service()->SetReady(); | |
| 862 app_instance()->RefreshAppList(); | 836 app_instance()->RefreshAppList(); |
| 863 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( | 837 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 864 fake_apps().begin(), fake_apps().begin() + 1)); | 838 fake_apps().begin(), fake_apps().begin() + 1)); |
| 865 | 839 |
| 866 FakeAppIconLoaderDelegate delegate; | 840 FakeAppIconLoaderDelegate delegate; |
| 867 ArcAppIconLoader icon_loader(profile(), | 841 ArcAppIconLoader icon_loader(profile(), |
| 868 app_list::kListIconSize, | 842 app_list::kListIconSize, |
| 869 &delegate); | 843 &delegate); |
| 870 EXPECT_EQ(0UL, delegate.update_image_cnt()); | 844 EXPECT_EQ(0UL, delegate.update_image_cnt()); |
| 871 icon_loader.FetchImage(app_id); | 845 icon_loader.FetchImage(app_id); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 const arc::mojom::AppInfo& app2 = fake_apps()[1]; | 879 const arc::mojom::AppInfo& app2 = fake_apps()[1]; |
| 906 const arc::mojom::AppInfo& app3 = fake_apps()[2]; | 880 const arc::mojom::AppInfo& app3 = fake_apps()[2]; |
| 907 const std::string id1 = ArcAppTest::GetAppId(app1); | 881 const std::string id1 = ArcAppTest::GetAppId(app1); |
| 908 const std::string id2 = ArcAppTest::GetAppId(app2); | 882 const std::string id2 = ArcAppTest::GetAppId(app2); |
| 909 const std::string id3 = ArcAppTest::GetAppId(app3); | 883 const std::string id3 = ArcAppTest::GetAppId(app3); |
| 910 | 884 |
| 911 ArcAppLauncher launcher1(profile(), id1, true); | 885 ArcAppLauncher launcher1(profile(), id1, true); |
| 912 EXPECT_FALSE(launcher1.app_launched()); | 886 EXPECT_FALSE(launcher1.app_launched()); |
| 913 EXPECT_TRUE(prefs->HasObserver(&launcher1)); | 887 EXPECT_TRUE(prefs->HasObserver(&launcher1)); |
| 914 | 888 |
| 915 bridge_service()->SetReady(); | |
| 916 | |
| 917 ArcAppLauncher launcher3(profile(), id3, true); | 889 ArcAppLauncher launcher3(profile(), id3, true); |
| 918 EXPECT_FALSE(launcher1.app_launched()); | 890 EXPECT_FALSE(launcher1.app_launched()); |
| 919 EXPECT_TRUE(prefs->HasObserver(&launcher1)); | 891 EXPECT_TRUE(prefs->HasObserver(&launcher1)); |
| 920 EXPECT_FALSE(launcher3.app_launched()); | 892 EXPECT_FALSE(launcher3.app_launched()); |
| 921 EXPECT_TRUE(prefs->HasObserver(&launcher3)); | 893 EXPECT_TRUE(prefs->HasObserver(&launcher3)); |
| 922 | 894 |
| 923 EXPECT_EQ(0u, app_instance()->launch_requests().size()); | 895 EXPECT_EQ(0u, app_instance()->launch_requests().size()); |
| 924 | 896 |
| 925 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin(), | 897 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin(), |
| 926 fake_apps().begin() + 2); | 898 fake_apps().begin() + 2); |
| 927 app_instance()->SendRefreshAppList(apps); | 899 app_instance()->SendRefreshAppList(apps); |
| 928 | 900 |
| 929 EXPECT_TRUE(launcher1.app_launched()); | 901 EXPECT_TRUE(launcher1.app_launched()); |
| 930 ASSERT_EQ(1u, app_instance()->launch_requests().size()); | 902 ASSERT_EQ(1u, app_instance()->launch_requests().size()); |
| 931 EXPECT_TRUE(app_instance()->launch_requests()[0]->IsForApp(app1)); | 903 EXPECT_TRUE(app_instance()->launch_requests()[0]->IsForApp(app1)); |
| 932 EXPECT_FALSE(launcher3.app_launched()); | 904 EXPECT_FALSE(launcher3.app_launched()); |
| 933 EXPECT_FALSE(prefs->HasObserver(&launcher1)); | 905 EXPECT_FALSE(prefs->HasObserver(&launcher1)); |
| 934 EXPECT_TRUE(prefs->HasObserver(&launcher3)); | 906 EXPECT_TRUE(prefs->HasObserver(&launcher3)); |
| 935 | 907 |
| 936 ArcAppLauncher launcher2(profile(), id2, true); | 908 ArcAppLauncher launcher2(profile(), id2, true); |
| 937 EXPECT_TRUE(launcher2.app_launched()); | 909 EXPECT_TRUE(launcher2.app_launched()); |
| 938 EXPECT_FALSE(prefs->HasObserver(&launcher2)); | 910 EXPECT_FALSE(prefs->HasObserver(&launcher2)); |
| 939 ASSERT_EQ(2u, app_instance()->launch_requests().size()); | 911 ASSERT_EQ(2u, app_instance()->launch_requests().size()); |
| 940 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); | 912 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); |
| 941 } | 913 } |
| OLD | NEW |