This source file includes following definitions.
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/basictypes.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/test/integration/apps_helper.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/sync_app_helper.h"
#include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/common/extensions/extension_constants.h"
#include "extensions/browser/app_sorting.h"
#include "extensions/browser/extension_prefs.h"
#include "sync/api/string_ordinal.h"
using apps_helper::AllProfilesHaveSameAppsAsVerifier;
using apps_helper::CopyNTPOrdinals;
using apps_helper::DisableApp;
using apps_helper::EnableApp;
using apps_helper::FixNTPOrdinalCollisions;
using apps_helper::GetAppLaunchOrdinalForApp;
using apps_helper::HasSameAppsAsVerifier;
using apps_helper::IncognitoDisableApp;
using apps_helper::IncognitoEnableApp;
using apps_helper::InstallApp;
using apps_helper::InstallAppsPendingForSync;
using apps_helper::InstallPlatformApp;
using apps_helper::SetAppLaunchOrdinalForApp;
using apps_helper::SetPageOrdinalForApp;
using apps_helper::UninstallApp;
using sync_integration_test_util::AwaitCommitActivityCompletion;
class TwoClientAppsSyncTest : public SyncTest {
public:
TwoClientAppsSyncTest() : SyncTest(TWO_CLIENT) {}
virtual ~TwoClientAppsSyncTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(TwoClientAppsSyncTest);
};
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithNoApps) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithSameApps) {
ASSERT_TRUE(SetupClients());
const int kNumApps = 5;
for (int i = 0; i < kNumApps; ++i) {
InstallApp(GetProfile(0), i);
InstallApp(GetProfile(1), i);
InstallApp(verifier(), i);
}
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithDifferentApps) {
ASSERT_TRUE(SetupClients());
int i = 0;
const int kNumCommonApps = 5;
for (int j = 0; j < kNumCommonApps; ++i, ++j) {
InstallApp(GetProfile(0), i);
InstallApp(GetProfile(1), i);
InstallApp(verifier(), i);
}
const int kNumProfile0Apps = 10;
for (int j = 0; j < kNumProfile0Apps; ++i, ++j) {
InstallApp(GetProfile(0), i);
InstallApp(verifier(), i);
CopyNTPOrdinals(GetProfile(0), verifier(), i);
}
const int kNumProfile1Apps = 10;
for (int j = 0; j < kNumProfile1Apps; ++i, ++j) {
InstallApp(GetProfile(1), i);
InstallApp(verifier(), i);
CopyNTPOrdinals(GetProfile(1), verifier(), i);
}
const int kNumPlatformApps = 5;
for (int j = 0; j < kNumPlatformApps; ++i, ++j) {
InstallPlatformApp(GetProfile(1), i);
InstallPlatformApp(verifier(), i);
CopyNTPOrdinals(GetProfile(1), verifier(), i);
}
FixNTPOrdinalCollisions(verifier());
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, InstallDifferentApps) {
ASSERT_TRUE(SetupClients());
int i = 0;
const int kNumCommonApps = 5;
for (int j = 0; j < kNumCommonApps; ++i, ++j) {
InstallApp(GetProfile(0), i);
InstallApp(GetProfile(1), i);
InstallApp(verifier(), i);
}
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AwaitQuiescence());
const int kNumProfile0Apps = 10;
for (int j = 0; j < kNumProfile0Apps; ++i, ++j) {
InstallApp(GetProfile(0), i);
InstallApp(verifier(), i);
CopyNTPOrdinals(GetProfile(0), verifier(), i);
}
const int kNumProfile1Apps = 10;
for (int j = 0; j < kNumProfile1Apps; ++i, ++j) {
InstallApp(GetProfile(1), i);
InstallApp(verifier(), i);
CopyNTPOrdinals(GetProfile(1), verifier(), i);
}
FixNTPOrdinalCollisions(verifier());
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, Add) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
InstallApp(GetProfile(0), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, Uninstall) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
InstallApp(GetProfile(0), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
UninstallApp(GetProfile(0), 0);
UninstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UninstallThenInstall) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
InstallApp(GetProfile(0), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
UninstallApp(GetProfile(0), 0);
UninstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
InstallApp(GetProfile(0), 1);
InstallApp(verifier(), 1);
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, DISABLED_Merge) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
InstallApp(GetProfile(0), 0);
InstallApp(GetProfile(1), 0);
ASSERT_TRUE(AwaitQuiescence());
UninstallApp(GetProfile(0), 0);
InstallApp(GetProfile(0), 1);
InstallApp(verifier(), 1);
InstallApp(GetProfile(0), 2);
InstallApp(GetProfile(1), 2);
InstallApp(verifier(), 2);
InstallApp(GetProfile(1), 3);
InstallApp(verifier(), 3);
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateEnableDisableApp) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
InstallApp(GetProfile(0), 0);
InstallApp(GetProfile(1), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
DisableApp(GetProfile(0), 0);
DisableApp(verifier(), 0);
ASSERT_TRUE(HasSameAppsAsVerifier(0));
ASSERT_FALSE(HasSameAppsAsVerifier(1));
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
EnableApp(GetProfile(1), 0);
EnableApp(verifier(), 0);
ASSERT_TRUE(HasSameAppsAsVerifier(1));
ASSERT_FALSE(HasSameAppsAsVerifier(0));
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateIncognitoEnableDisable) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
InstallApp(GetProfile(0), 0);
InstallApp(GetProfile(1), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
IncognitoEnableApp(GetProfile(0), 0);
IncognitoEnableApp(verifier(), 0);
ASSERT_TRUE(HasSameAppsAsVerifier(0));
ASSERT_FALSE(HasSameAppsAsVerifier(1));
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
IncognitoDisableApp(GetProfile(1), 0);
IncognitoDisableApp(verifier(), 0);
ASSERT_TRUE(HasSameAppsAsVerifier(1));
ASSERT_FALSE(HasSameAppsAsVerifier(0));
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, DisableApps) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::APPS));
InstallApp(GetProfile(0), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
ASSERT_TRUE(HasSameAppsAsVerifier(0));
ASSERT_FALSE(HasSameAppsAsVerifier(1));
ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::APPS));
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, DisableSync) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
InstallApp(GetProfile(0), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
ASSERT_TRUE(HasSameAppsAsVerifier(0));
ASSERT_FALSE(HasSameAppsAsVerifier(1));
ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
ASSERT_TRUE(AwaitQuiescence());
InstallAppsPendingForSync(GetProfile(0));
InstallAppsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdatePageOrdinal) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
syncer::StringOrdinal initial_page =
syncer::StringOrdinal::CreateInitialOrdinal();
InstallApp(GetProfile(0), 0);
InstallApp(GetProfile(1), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
syncer::StringOrdinal second_page = initial_page.CreateAfter();
SetPageOrdinalForApp(GetProfile(0), 0, second_page);
SetPageOrdinalForApp(verifier(), 0, second_page);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateAppLaunchOrdinal) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
InstallApp(GetProfile(0), 0);
InstallApp(GetProfile(1), 0);
InstallApp(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
syncer::StringOrdinal initial_position =
GetAppLaunchOrdinalForApp(GetProfile(0), 0);
syncer::StringOrdinal second_position = initial_position.CreateAfter();
SetAppLaunchOrdinalForApp(GetProfile(0), 0, second_position);
SetAppLaunchOrdinalForApp(verifier(), 0, second_position);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateCWSOrdinals) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
syncer::StringOrdinal cws_app_launch_ordinal =
extensions::ExtensionPrefs::Get(GetProfile(0))
->app_sorting()
->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId);
extensions::ExtensionPrefs::Get(GetProfile(0))
->app_sorting()
->SetAppLaunchOrdinal(extension_misc::kWebStoreAppId,
cws_app_launch_ordinal.CreateAfter());
extensions::ExtensionPrefs::Get(verifier())
->app_sorting()
->SetAppLaunchOrdinal(extension_misc::kWebStoreAppId,
cws_app_launch_ordinal.CreateAfter());
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
syncer::StringOrdinal cws_page_ordinal =
extensions::ExtensionPrefs::Get(GetProfile(1))
->app_sorting()
->GetPageOrdinal(extension_misc::kWebStoreAppId);
extensions::ExtensionPrefs::Get(GetProfile(1))->app_sorting()->SetPageOrdinal(
extension_misc::kWebStoreAppId, cws_page_ordinal.CreateAfter());
extensions::ExtensionPrefs::Get(verifier())->app_sorting()->SetPageOrdinal(
extension_misc::kWebStoreAppId, cws_page_ordinal.CreateAfter());
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateLaunchType) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
extensions::SetLaunchType(GetProfile(1)->GetExtensionService(),
extension_misc::kWebStoreAppId,
extensions::LAUNCH_TYPE_WINDOW);
extensions::SetLaunchType(verifier()->GetExtensionService(),
extension_misc::kWebStoreAppId,
extensions::LAUNCH_TYPE_WINDOW);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
extensions::SetLaunchType(GetProfile(1)->GetExtensionService(),
extension_misc::kWebStoreAppId,
extensions::LAUNCH_TYPE_REGULAR);
ASSERT_FALSE(HasSameAppsAsVerifier(1));
extensions::SetLaunchType(verifier()->GetExtensionService(),
extension_misc::kWebStoreAppId,
extensions::LAUNCH_TYPE_REGULAR);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}
IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UnexpectedLaunchType) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
extensions::SetLaunchType(GetProfile(1)->GetExtensionService(),
extension_misc::kWebStoreAppId,
extensions::LAUNCH_TYPE_REGULAR);
extensions::SetLaunchType(verifier()->GetExtensionService(),
extension_misc::kWebStoreAppId,
extensions::LAUNCH_TYPE_REGULAR);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
const extensions::Extension* extension =
GetProfile(1)->GetExtensionService()->
GetInstalledExtension(extension_misc::kWebStoreAppId);
ASSERT_TRUE(extension);
ExtensionSyncService* extension_sync_service =
ExtensionSyncService::Get(GetProfile(1));
extensions::AppSyncData original_data(
extension_sync_service->GetAppSyncData(*extension));
extensions::AppSyncData invalid_launch_type_data(
*extension,
original_data.extension_sync_data().enabled(),
original_data.extension_sync_data().incognito_enabled(),
original_data.app_launch_ordinal(),
original_data.page_ordinal(),
extensions::NUM_LAUNCH_TYPES);
extension_sync_service->ProcessAppSyncData(invalid_launch_type_data);
ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier());
}