| 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 extensions::ExtensionRegistry* GetExtensionRegistry(Profile* profile) { |
| 48 return extensions::ExtensionRegistry::Get(profile); |
| 49 } |
| 50 |
| 51 ExtensionService* GetExtensionService(Profile* profile) { |
| 52 return extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 53 } |
| 54 |
| 55 } // namespace |
| 56 |
| 44 class TwoClientAppsSyncTest : public SyncTest { | 57 class TwoClientAppsSyncTest : public SyncTest { |
| 45 public: | 58 public: |
| 46 TwoClientAppsSyncTest() : SyncTest(TWO_CLIENT) {} | 59 TwoClientAppsSyncTest() : SyncTest(TWO_CLIENT) {} |
| 47 | 60 |
| 48 virtual ~TwoClientAppsSyncTest() {} | 61 virtual ~TwoClientAppsSyncTest() {} |
| 49 | 62 |
| 50 private: | 63 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(TwoClientAppsSyncTest); | 64 DISALLOW_COPY_AND_ASSIGN(TwoClientAppsSyncTest); |
| 52 }; | 65 }; |
| 53 | 66 |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 457 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 445 } | 458 } |
| 446 | 459 |
| 447 // Adjust the launch type on the first client and sync. Both clients should | 460 // Adjust the launch type on the first client and sync. Both clients should |
| 448 // have the same launch type values for the CWS. | 461 // have the same launch type values for the CWS. |
| 449 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateLaunchType) { | 462 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateLaunchType) { |
| 450 ASSERT_TRUE(SetupSync()); | 463 ASSERT_TRUE(SetupSync()); |
| 451 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 464 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 452 | 465 |
| 453 // Change the launch type to window. | 466 // Change the launch type to window. |
| 454 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(), | 467 extensions::SetLaunchType(GetExtensionService(GetProfile(1)), |
| 455 extension_misc::kWebStoreAppId, | 468 extension_misc::kWebStoreAppId, |
| 456 extensions::LAUNCH_TYPE_WINDOW); | 469 extensions::LAUNCH_TYPE_WINDOW); |
| 457 extensions::SetLaunchType(verifier()->GetExtensionService(), | 470 extensions::SetLaunchType(GetExtensionService(verifier()), |
| 458 extension_misc::kWebStoreAppId, | 471 extension_misc::kWebStoreAppId, |
| 459 extensions::LAUNCH_TYPE_WINDOW); | 472 extensions::LAUNCH_TYPE_WINDOW); |
| 460 ASSERT_TRUE(AwaitQuiescence()); | 473 ASSERT_TRUE(AwaitQuiescence()); |
| 461 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 474 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 462 | 475 |
| 463 // Change the launch type to regular tab. | 476 // Change the launch type to regular tab. |
| 464 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(), | 477 extensions::SetLaunchType(GetExtensionService(GetProfile(1)), |
| 465 extension_misc::kWebStoreAppId, | 478 extension_misc::kWebStoreAppId, |
| 466 extensions::LAUNCH_TYPE_REGULAR); | 479 extensions::LAUNCH_TYPE_REGULAR); |
| 467 ASSERT_FALSE(HasSameAppsAsVerifier(1)); | 480 ASSERT_FALSE(HasSameAppsAsVerifier(1)); |
| 468 extensions::SetLaunchType(verifier()->GetExtensionService(), | 481 extensions::SetLaunchType(GetExtensionService(verifier()), |
| 469 extension_misc::kWebStoreAppId, | 482 extension_misc::kWebStoreAppId, |
| 470 extensions::LAUNCH_TYPE_REGULAR); | 483 extensions::LAUNCH_TYPE_REGULAR); |
| 471 ASSERT_TRUE(AwaitQuiescence()); | 484 ASSERT_TRUE(AwaitQuiescence()); |
| 472 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 485 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 473 } | 486 } |
| 474 | 487 |
| 475 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UnexpectedLaunchType) { | 488 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UnexpectedLaunchType) { |
| 476 ASSERT_TRUE(SetupSync()); | 489 ASSERT_TRUE(SetupSync()); |
| 477 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 490 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 478 | 491 |
| 479 extensions::SetLaunchType(GetProfile(1)->GetExtensionService(), | 492 extensions::SetLaunchType(GetExtensionService(GetProfile(1)), |
| 480 extension_misc::kWebStoreAppId, | 493 extension_misc::kWebStoreAppId, |
| 481 extensions::LAUNCH_TYPE_REGULAR); | 494 extensions::LAUNCH_TYPE_REGULAR); |
| 482 extensions::SetLaunchType(verifier()->GetExtensionService(), | 495 extensions::SetLaunchType(GetExtensionService(verifier()), |
| 483 extension_misc::kWebStoreAppId, | 496 extension_misc::kWebStoreAppId, |
| 484 extensions::LAUNCH_TYPE_REGULAR); | 497 extensions::LAUNCH_TYPE_REGULAR); |
| 485 ASSERT_TRUE(AwaitQuiescence()); | 498 ASSERT_TRUE(AwaitQuiescence()); |
| 486 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 499 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 487 | 500 |
| 488 const extensions::Extension* extension = | 501 const extensions::Extension* extension = |
| 489 GetProfile(1)->GetExtensionService()-> | 502 GetExtensionRegistry(GetProfile(1))->GetExtensionById( |
| 490 GetInstalledExtension(extension_misc::kWebStoreAppId); | 503 extension_misc::kWebStoreAppId, |
| 504 extensions::ExtensionRegistry::EVERYTHING); |
| 491 ASSERT_TRUE(extension); | 505 ASSERT_TRUE(extension); |
| 492 | 506 |
| 493 ExtensionSyncService* extension_sync_service = | 507 ExtensionSyncService* extension_sync_service = |
| 494 ExtensionSyncService::Get(GetProfile(1)); | 508 ExtensionSyncService::Get(GetProfile(1)); |
| 495 | 509 |
| 496 extensions::AppSyncData original_data( | 510 extensions::AppSyncData original_data( |
| 497 extension_sync_service->GetAppSyncData(*extension)); | 511 extension_sync_service->GetAppSyncData(*extension)); |
| 498 | 512 |
| 499 // Create an invalid launch type and ensure it doesn't get down-synced. This | 513 // 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 | 514 // 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. | 526 // The launch type should remain the same. |
| 513 ASSERT_TRUE(AwaitQuiescence()); | 527 ASSERT_TRUE(AwaitQuiescence()); |
| 514 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 528 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 515 } | 529 } |
| 516 | 530 |
| 517 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, BookmarkApp) { | 531 IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, BookmarkApp) { |
| 518 ASSERT_TRUE(SetupSync()); | 532 ASSERT_TRUE(SetupSync()); |
| 519 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 533 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 520 | 534 |
| 521 size_t num_extensions = | 535 size_t num_extensions = |
| 522 GetProfile(0)->GetExtensionService()->extensions()->size(); | 536 GetExtensionRegistry(GetProfile(0))->enabled_extensions().size(); |
| 523 | 537 |
| 524 WebApplicationInfo web_app_info; | 538 WebApplicationInfo web_app_info; |
| 525 web_app_info.app_url = GURL("http://www.chromium.org"); | 539 web_app_info.app_url = GURL("http://www.chromium.org"); |
| 526 web_app_info.title = base::UTF8ToUTF16("Test name"); | 540 web_app_info.title = base::UTF8ToUTF16("Test name"); |
| 527 web_app_info.description = base::UTF8ToUTF16("Test description"); | 541 web_app_info.description = base::UTF8ToUTF16("Test description"); |
| 528 ++num_extensions; | 542 ++num_extensions; |
| 529 { | 543 { |
| 530 content::WindowedNotificationObserver windowed_observer( | 544 content::WindowedNotificationObserver windowed_observer( |
| 531 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 545 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 532 content::NotificationService::AllSources()); | 546 content::NotificationService::AllSources()); |
| 533 extensions::CreateOrUpdateBookmarkApp(GetProfile(0)->GetExtensionService(), | 547 extensions::CreateOrUpdateBookmarkApp(GetExtensionService(GetProfile(0)), |
| 534 web_app_info); | 548 web_app_info); |
| 535 windowed_observer.Wait(); | 549 windowed_observer.Wait(); |
| 536 EXPECT_EQ(num_extensions, | 550 EXPECT_EQ(num_extensions, |
| 537 extensions::ExtensionRegistry::Get(GetProfile(0)) | 551 GetExtensionRegistry(GetProfile(0))->enabled_extensions().size()); |
| 538 ->enabled_extensions() | |
| 539 .size()); | |
| 540 } | 552 } |
| 541 { | 553 { |
| 542 content::WindowedNotificationObserver windowed_observer( | 554 content::WindowedNotificationObserver windowed_observer( |
| 543 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 555 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 544 content::NotificationService::AllSources()); | 556 content::NotificationService::AllSources()); |
| 545 extensions::CreateOrUpdateBookmarkApp(verifier()->GetExtensionService(), | 557 extensions::CreateOrUpdateBookmarkApp(GetExtensionService(verifier()), |
| 546 web_app_info); | 558 web_app_info); |
| 547 windowed_observer.Wait(); | 559 windowed_observer.Wait(); |
| 548 EXPECT_EQ(num_extensions, | 560 EXPECT_EQ(num_extensions, |
| 549 extensions::ExtensionRegistry::Get(verifier()) | 561 GetExtensionRegistry(verifier())->enabled_extensions().size()); |
| 550 ->enabled_extensions() | |
| 551 .size()); | |
| 552 } | 562 } |
| 553 { | 563 { |
| 554 // Wait for the synced app to install. | 564 // Wait for the synced app to install. |
| 555 content::WindowedNotificationObserver windowed_observer( | 565 content::WindowedNotificationObserver windowed_observer( |
| 556 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 566 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 557 content::NotificationService::AllSources()); | 567 content::NotificationService::AllSources()); |
| 558 ASSERT_TRUE(AwaitQuiescence()); | 568 ASSERT_TRUE(AwaitQuiescence()); |
| 559 windowed_observer.Wait(); | 569 windowed_observer.Wait(); |
| 560 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); | 570 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); |
| 561 } | 571 } |
| 562 } | 572 } |
| 563 // TODO(akalin): Add tests exercising: | 573 // TODO(akalin): Add tests exercising: |
| 564 // - Offline installation/uninstallation behavior | 574 // - Offline installation/uninstallation behavior |
| 565 // - App-specific properties | 575 // - App-specific properties |
| OLD | NEW |