Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/extensions/app_sync_data.h" | 8 #include "chrome/browser/extensions/app_sync_data.h" |
| 9 #include "chrome/browser/extensions/bookmark_app_helper.h" | 9 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_sync_service.h" | 11 #include "chrome/browser/extensions/extension_sync_service.h" |
| 12 #include "chrome/browser/extensions/launch_util.h" | 12 #include "chrome/browser/extensions/launch_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sync/test/integration/apps_helper.h" | 14 #include "chrome/browser/sync/test/integration/apps_helper.h" |
| 15 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 15 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 16 #include "chrome/browser/sync/test/integration/sync_app_helper.h" | 16 #include "chrome/browser/sync/test/integration/sync_app_helper.h" |
| 17 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 17 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
| 18 #include "chrome/browser/sync/test/integration/sync_test.h" | 18 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
| 22 #include "extensions/browser/app_sorting.h" | 22 #include "extensions/browser/app_sorting.h" |
| 23 #include "extensions/browser/extension_prefs.h" | 23 #include "extensions/browser/extension_prefs.h" |
| 24 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 25 #include "extensions/browser/extension_system.h" | |
| 25 #include "sync/api/string_ordinal.h" | 26 #include "sync/api/string_ordinal.h" |
| 26 | 27 |
| 27 using apps_helper::AllProfilesHaveSameAppsAsVerifier; | 28 using apps_helper::AllProfilesHaveSameAppsAsVerifier; |
| 28 using apps_helper::CopyNTPOrdinals; | 29 using apps_helper::CopyNTPOrdinals; |
| 29 using apps_helper::DisableApp; | 30 using apps_helper::DisableApp; |
| 30 using apps_helper::EnableApp; | 31 using apps_helper::EnableApp; |
| 31 using apps_helper::FixNTPOrdinalCollisions; | 32 using apps_helper::FixNTPOrdinalCollisions; |
| 32 using apps_helper::GetAppLaunchOrdinalForApp; | 33 using apps_helper::GetAppLaunchOrdinalForApp; |
| 33 using apps_helper::HasSameAppsAsVerifier; | 34 using apps_helper::HasSameAppsAsVerifier; |
| 34 using apps_helper::IncognitoDisableApp; | 35 using apps_helper::IncognitoDisableApp; |
| 35 using apps_helper::IncognitoEnableApp; | 36 using apps_helper::IncognitoEnableApp; |
| 36 using apps_helper::InstallApp; | 37 using apps_helper::InstallApp; |
| 37 using apps_helper::InstallAppsPendingForSync; | 38 using apps_helper::InstallAppsPendingForSync; |
| 38 using apps_helper::InstallPlatformApp; | 39 using apps_helper::InstallPlatformApp; |
| 39 using apps_helper::SetAppLaunchOrdinalForApp; | 40 using apps_helper::SetAppLaunchOrdinalForApp; |
| 40 using apps_helper::SetPageOrdinalForApp; | 41 using apps_helper::SetPageOrdinalForApp; |
| 41 using apps_helper::UninstallApp; | 42 using apps_helper::UninstallApp; |
| 42 using sync_integration_test_util::AwaitCommitActivityCompletion; | 43 using sync_integration_test_util::AwaitCommitActivityCompletion; |
| 43 | 44 |
| 45 namespace { | |
| 46 | |
| 47 ExtensionService* GetExtensionService(Profile* profile) { | |
| 48 return extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 49 } | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 44 class TwoClientAppsSyncTest : public SyncTest { | 53 class TwoClientAppsSyncTest : public SyncTest { |
| 45 public: | 54 public: |
| 46 TwoClientAppsSyncTest() : SyncTest(TWO_CLIENT) {} | 55 TwoClientAppsSyncTest() : SyncTest(TWO_CLIENT) {} |
| 47 | 56 |
| 48 virtual ~TwoClientAppsSyncTest() {} | 57 virtual ~TwoClientAppsSyncTest() {} |
| 49 | 58 |
| 50 private: | 59 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(TwoClientAppsSyncTest); | 60 DISALLOW_COPY_AND_ASSIGN(TwoClientAppsSyncTest); |
| 52 }; | 61 }; |
| 53 | 62 |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 453 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 445 } | 454 } |
| 446 | 455 |
| 447 // Adjust the launch type on the first client and sync. Both clients should | 456 // Adjust the launch type on the first client and sync. Both clients should |
| 448 // have the same launch type values for the CWS. | 457 // have the same launch type values for the CWS. |
| 449 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateLaunchType) { | 458 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateLaunchType) { |
| 450 ASSERT_TRUE(SetupSync()); | 459 ASSERT_TRUE(SetupSync()); |
| 451 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 460 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 452 | 461 |
| 453 // Change the launch type to window. | 462 // Change the launch type to window. |
| 454 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(), | 463 extensions::SetLaunchType(GetExtensionService(GetProfile(1)), |
| 455 extension_misc::kWebStoreAppId, | 464 extension_misc::kWebStoreAppId, |
| 456 extensions::LAUNCH_TYPE_WINDOW); | 465 extensions::LAUNCH_TYPE_WINDOW); |
| 457 extensions::SetLaunchType(verifier()->GetExtensionService(), | 466 extensions::SetLaunchType(GetExtensionService(verifier()), |
| 458 extension_misc::kWebStoreAppId, | 467 extension_misc::kWebStoreAppId, |
| 459 extensions::LAUNCH_TYPE_WINDOW); | 468 extensions::LAUNCH_TYPE_WINDOW); |
| 460 ASSERT_TRUE(AwaitQuiescence()); | 469 ASSERT_TRUE(AwaitQuiescence()); |
| 461 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 470 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 462 | 471 |
| 463 // Change the launch type to regular tab. | 472 // Change the launch type to regular tab. |
| 464 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(), | 473 extensions::SetLaunchType(GetExtensionService(GetProfile(1)), |
| 465 extension_misc::kWebStoreAppId, | 474 extension_misc::kWebStoreAppId, |
| 466 extensions::LAUNCH_TYPE_REGULAR); | 475 extensions::LAUNCH_TYPE_REGULAR); |
| 467 ASSERT_FALSE(HasSameAppsAsVerifier(1)); | 476 ASSERT_FALSE(HasSameAppsAsVerifier(1)); |
| 468 extensions::SetLaunchType(verifier()->GetExtensionService(), | 477 extensions::SetLaunchType(GetExtensionService(verifier()), |
| 469 extension_misc::kWebStoreAppId, | 478 extension_misc::kWebStoreAppId, |
| 470 extensions::LAUNCH_TYPE_REGULAR); | 479 extensions::LAUNCH_TYPE_REGULAR); |
| 471 ASSERT_TRUE(AwaitQuiescence()); | 480 ASSERT_TRUE(AwaitQuiescence()); |
| 472 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 481 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 473 } | 482 } |
| 474 | 483 |
| 475 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UnexpectedLaunchType) { | 484 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UnexpectedLaunchType) { |
| 476 ASSERT_TRUE(SetupSync()); | 485 ASSERT_TRUE(SetupSync()); |
| 477 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 486 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 478 | 487 |
| 479 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(), | 488 extensions::SetLaunchType(GetExtensionService(GetProfile(1)), |
| 480 extension_misc::kWebStoreAppId, | 489 extension_misc::kWebStoreAppId, |
| 481 extensions::LAUNCH_TYPE_REGULAR); | 490 extensions::LAUNCH_TYPE_REGULAR); |
| 482 extensions::SetLaunchType(verifier()->GetExtensionService(), | 491 extensions::SetLaunchType(GetExtensionService(verifier()), |
| 483 extension_misc::kWebStoreAppId, | 492 extension_misc::kWebStoreAppId, |
| 484 extensions::LAUNCH_TYPE_REGULAR); | 493 extensions::LAUNCH_TYPE_REGULAR); |
| 485 ASSERT_TRUE(AwaitQuiescence()); | 494 ASSERT_TRUE(AwaitQuiescence()); |
| 486 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 495 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 487 | 496 |
| 488 const extensions::Extension* extension = | 497 const extensions::Extension* extension = |
| 489 GetProfile(1)->GetExtensionService()-> | 498 GetExtensionService(GetProfile(1))->GetInstalledExtension( |
|
Devlin
2014/06/25 19:38:48
nit: ExtensionRegistry::GetExtensionById(id, Exten
Lei Zhang
2014/06/25 19:58:31
Done.
| |
| 490 GetInstalledExtension(extension_misc::kWebStoreAppId); | 499 extension_misc::kWebStoreAppId); |
| 491 ASSERT_TRUE(extension); | 500 ASSERT_TRUE(extension); |
| 492 | 501 |
| 493 ExtensionSyncService* extension_sync_service = | 502 ExtensionSyncService* extension_sync_service = |
| 494 ExtensionSyncService::Get(GetProfile(1)); | 503 ExtensionSyncService::Get(GetProfile(1)); |
| 495 | 504 |
| 496 extensions::AppSyncData original_data( | 505 extensions::AppSyncData original_data( |
| 497 extension_sync_service->GetAppSyncData(*extension)); | 506 extension_sync_service->GetAppSyncData(*extension)); |
| 498 | 507 |
| 499 // Create an invalid launch type and ensure it doesn't get down-synced. This | 508 // Create an invalid launch type and ensure it doesn't get down-synced. This |
| 500 // simulates the case of a future launch type being added which old versions | 509 // simulates the case of a future launch type being added which old versions |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 512 // The launch type should remain the same. | 521 // The launch type should remain the same. |
| 513 ASSERT_TRUE(AwaitQuiescence()); | 522 ASSERT_TRUE(AwaitQuiescence()); |
| 514 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 523 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 515 } | 524 } |
| 516 | 525 |
| 517 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, BookmarkApp) { | 526 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, BookmarkApp) { |
| 518 ASSERT_TRUE(SetupSync()); | 527 ASSERT_TRUE(SetupSync()); |
| 519 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 528 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 520 | 529 |
| 521 size_t num_extensions = | 530 size_t num_extensions = |
| 522 GetProfile(0)->GetExtensionService()->extensions()->size(); | 531 GetExtensionService(GetProfile(0))->extensions()->size(); |
|
Devlin
2014/06/25 19:38:48
nit: ExtensionRegistry::enabled_extensions().size(
Lei Zhang
2014/06/25 19:58:31
Done.
| |
| 523 | 532 |
| 524 WebApplicationInfo web_app_info; | 533 WebApplicationInfo web_app_info; |
| 525 web_app_info.app_url = GURL("http://www.chromium.org"); | 534 web_app_info.app_url = GURL("http://www.chromium.org"); |
| 526 web_app_info.title = base::UTF8ToUTF16("Test name"); | 535 web_app_info.title = base::UTF8ToUTF16("Test name"); |
| 527 web_app_info.description = base::UTF8ToUTF16("Test description"); | 536 web_app_info.description = base::UTF8ToUTF16("Test description"); |
| 528 ++num_extensions; | 537 ++num_extensions; |
| 529 { | 538 { |
| 530 content::WindowedNotificationObserver windowed_observer( | 539 content::WindowedNotificationObserver windowed_observer( |
| 531 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 540 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 532 content::NotificationService::AllSources()); | 541 content::NotificationService::AllSources()); |
| 533 extensions::CreateOrUpdateBookmarkApp(GetProfile(0)->GetExtensionService(), | 542 extensions::CreateOrUpdateBookmarkApp(GetExtensionService(GetProfile(0)), |
| 534 web_app_info); | 543 web_app_info); |
| 535 windowed_observer.Wait(); | 544 windowed_observer.Wait(); |
| 536 EXPECT_EQ(num_extensions, | 545 EXPECT_EQ(num_extensions, |
| 537 extensions::ExtensionRegistry::Get(GetProfile(0)) | 546 extensions::ExtensionRegistry::Get(GetProfile(0)) |
| 538 ->enabled_extensions() | 547 ->enabled_extensions() |
| 539 .size()); | 548 .size()); |
| 540 } | 549 } |
| 541 { | 550 { |
| 542 content::WindowedNotificationObserver windowed_observer( | 551 content::WindowedNotificationObserver windowed_observer( |
| 543 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 552 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 544 content::NotificationService::AllSources()); | 553 content::NotificationService::AllSources()); |
| 545 extensions::CreateOrUpdateBookmarkApp(verifier()->GetExtensionService(), | 554 extensions::CreateOrUpdateBookmarkApp(GetExtensionService(verifier()), |
| 546 web_app_info); | 555 web_app_info); |
| 547 windowed_observer.Wait(); | 556 windowed_observer.Wait(); |
| 548 EXPECT_EQ(num_extensions, | 557 EXPECT_EQ(num_extensions, |
| 549 extensions::ExtensionRegistry::Get(verifier()) | 558 extensions::ExtensionRegistry::Get(verifier()) |
| 550 ->enabled_extensions() | 559 ->enabled_extensions() |
| 551 .size()); | 560 .size()); |
| 552 } | 561 } |
| 553 { | 562 { |
| 554 // Wait for the synced app to install. | 563 // Wait for the synced app to install. |
| 555 content::WindowedNotificationObserver windowed_observer( | 564 content::WindowedNotificationObserver windowed_observer( |
| 556 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 565 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 557 content::NotificationService::AllSources()); | 566 content::NotificationService::AllSources()); |
| 558 ASSERT_TRUE(AwaitQuiescence()); | 567 ASSERT_TRUE(AwaitQuiescence()); |
| 559 windowed_observer.Wait(); | 568 windowed_observer.Wait(); |
| 560 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 569 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 561 } | 570 } |
| 562 } | 571 } |
| 563 // TODO(akalin): Add tests exercising: | 572 // TODO(akalin): Add tests exercising: |
| 564 // - Offline installation/uninstallation behavior | 573 // - Offline installation/uninstallation behavior |
| 565 // - App-specific properties | 574 // - App-specific properties |
| OLD | NEW |