two_client_apps_sync_test.cc revision f2477e01787aa58f445919b809d89e252beef54f
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 3// found in the LICENSE file. 4 5#include "base/basictypes.h" 6#include "chrome/browser/extensions/extension_service.h" 7#include "chrome/browser/profiles/profile.h" 8#include "chrome/browser/sync/profile_sync_service_harness.h" 9#include "chrome/browser/sync/test/integration/apps_helper.h" 10#include "chrome/browser/sync/test/integration/sync_app_helper.h" 11#include "chrome/browser/sync/test/integration/sync_test.h" 12#include "chrome/common/extensions/extension_constants.h" 13#include "extensions/browser/app_sorting.h" 14#include "sync/api/string_ordinal.h" 15 16using apps_helper::AllProfilesHaveSameAppsAsVerifier; 17using apps_helper::CopyNTPOrdinals; 18using apps_helper::DisableApp; 19using apps_helper::EnableApp; 20using apps_helper::FixNTPOrdinalCollisions; 21using apps_helper::GetAppLaunchOrdinalForApp; 22using apps_helper::HasSameAppsAsVerifier; 23using apps_helper::IncognitoDisableApp; 24using apps_helper::IncognitoEnableApp; 25using apps_helper::InstallApp; 26using apps_helper::InstallAppsPendingForSync; 27using apps_helper::InstallPlatformApp; 28using apps_helper::SetAppLaunchOrdinalForApp; 29using apps_helper::SetPageOrdinalForApp; 30using apps_helper::UninstallApp; 31 32class TwoClientAppsSyncTest : public SyncTest { 33 public: 34 TwoClientAppsSyncTest() : SyncTest(TWO_CLIENT) {} 35 36 virtual ~TwoClientAppsSyncTest() {} 37 38 private: 39 DISALLOW_COPY_AND_ASSIGN(TwoClientAppsSyncTest); 40}; 41 42IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithNoApps) { 43 ASSERT_TRUE(SetupSync()); 44 45 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 46} 47 48IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithSameApps) { 49 ASSERT_TRUE(SetupClients()); 50 51 const int kNumApps = 5; 52 for (int i = 0; i < kNumApps; ++i) { 53 InstallApp(GetProfile(0), i); 54 InstallApp(GetProfile(1), i); 55 InstallApp(verifier(), i); 56 } 57 58 ASSERT_TRUE(SetupSync()); 59 60 ASSERT_TRUE(AwaitQuiescence()); 61 62 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 63} 64 65// Install some apps on both clients, some on only one client, some on only the 66// other, and sync. Both clients should end up with all apps, and the app and 67// page ordinals should be identical. 68IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, StartWithDifferentApps) { 69 ASSERT_TRUE(SetupClients()); 70 71 int i = 0; 72 73 const int kNumCommonApps = 5; 74 for (int j = 0; j < kNumCommonApps; ++i, ++j) { 75 InstallApp(GetProfile(0), i); 76 InstallApp(GetProfile(1), i); 77 InstallApp(verifier(), i); 78 } 79 80 const int kNumProfile0Apps = 10; 81 for (int j = 0; j < kNumProfile0Apps; ++i, ++j) { 82 InstallApp(GetProfile(0), i); 83 InstallApp(verifier(), i); 84 CopyNTPOrdinals(GetProfile(0), verifier(), i); 85 } 86 87 const int kNumProfile1Apps = 10; 88 for (int j = 0; j < kNumProfile1Apps; ++i, ++j) { 89 InstallApp(GetProfile(1), i); 90 InstallApp(verifier(), i); 91 CopyNTPOrdinals(GetProfile(1), verifier(), i); 92 } 93 94 const int kNumPlatformApps = 5; 95 for (int j = 0; j < kNumPlatformApps; ++i, ++j) { 96 InstallPlatformApp(GetProfile(1), i); 97 InstallPlatformApp(verifier(), i); 98 CopyNTPOrdinals(GetProfile(1), verifier(), i); 99 } 100 101 FixNTPOrdinalCollisions(verifier()); 102 103 ASSERT_TRUE(SetupSync()); 104 105 ASSERT_TRUE(AwaitQuiescence()); 106 107 InstallAppsPendingForSync(GetProfile(0)); 108 InstallAppsPendingForSync(GetProfile(1)); 109 110 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 111} 112 113// Install some apps on both clients, then sync. Then install some apps on only 114// one client, some on only the other, and then sync again. Both clients should 115// end up with all apps, and the app and page ordinals should be identical. 116IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, InstallDifferentApps) { 117 ASSERT_TRUE(SetupClients()); 118 119 int i = 0; 120 121 const int kNumCommonApps = 5; 122 for (int j = 0; j < kNumCommonApps; ++i, ++j) { 123 InstallApp(GetProfile(0), i); 124 InstallApp(GetProfile(1), i); 125 InstallApp(verifier(), i); 126 } 127 128 ASSERT_TRUE(SetupSync()); 129 130 ASSERT_TRUE(AwaitQuiescence()); 131 132 const int kNumProfile0Apps = 10; 133 for (int j = 0; j < kNumProfile0Apps; ++i, ++j) { 134 InstallApp(GetProfile(0), i); 135 InstallApp(verifier(), i); 136 CopyNTPOrdinals(GetProfile(0), verifier(), i); 137 } 138 139 const int kNumProfile1Apps = 10; 140 for (int j = 0; j < kNumProfile1Apps; ++i, ++j) { 141 InstallApp(GetProfile(1), i); 142 InstallApp(verifier(), i); 143 CopyNTPOrdinals(GetProfile(1), verifier(), i); 144 } 145 146 FixNTPOrdinalCollisions(verifier()); 147 148 ASSERT_TRUE(AwaitQuiescence()); 149 150 InstallAppsPendingForSync(GetProfile(0)); 151 InstallAppsPendingForSync(GetProfile(1)); 152 153 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 154} 155 156// TCM ID - 3711279. 157IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, Add) { 158 ASSERT_TRUE(SetupSync()); 159 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 160 161 InstallApp(GetProfile(0), 0); 162 InstallApp(verifier(), 0); 163 ASSERT_TRUE(AwaitQuiescence()); 164 165 InstallAppsPendingForSync(GetProfile(0)); 166 InstallAppsPendingForSync(GetProfile(1)); 167 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 168} 169 170// TCM ID - 3706267. 171IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, Uninstall) { 172 ASSERT_TRUE(SetupSync()); 173 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 174 175 InstallApp(GetProfile(0), 0); 176 InstallApp(verifier(), 0); 177 ASSERT_TRUE(AwaitQuiescence()); 178 179 InstallAppsPendingForSync(GetProfile(0)); 180 InstallAppsPendingForSync(GetProfile(1)); 181 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 182 183 UninstallApp(GetProfile(0), 0); 184 UninstallApp(verifier(), 0); 185 ASSERT_TRUE(AwaitQuiescence()); 186 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 187} 188 189// Install an app on one client, then sync. Then uninstall the app on the first 190// client and sync again. Now install a new app on the first client and sync. 191// Both client should only have the second app, with identical app and page 192// ordinals. 193IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UninstallThenInstall) { 194 ASSERT_TRUE(SetupSync()); 195 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 196 197 InstallApp(GetProfile(0), 0); 198 InstallApp(verifier(), 0); 199 ASSERT_TRUE(AwaitQuiescence()); 200 201 InstallAppsPendingForSync(GetProfile(0)); 202 InstallAppsPendingForSync(GetProfile(1)); 203 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 204 205 UninstallApp(GetProfile(0), 0); 206 UninstallApp(verifier(), 0); 207 ASSERT_TRUE(AwaitQuiescence()); 208 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 209 210 InstallApp(GetProfile(0), 1); 211 InstallApp(verifier(), 1); 212 ASSERT_TRUE(AwaitQuiescence()); 213 InstallAppsPendingForSync(GetProfile(0)); 214 InstallAppsPendingForSync(GetProfile(1)); 215 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 216} 217 218// TCM ID - 3699295. 219IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, Merge) { 220 ASSERT_TRUE(SetupSync()); 221 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 222 223 InstallApp(GetProfile(0), 0); 224 InstallApp(GetProfile(1), 0); 225 ASSERT_TRUE(AwaitQuiescence()); 226 227 UninstallApp(GetProfile(0), 0); 228 InstallApp(GetProfile(0), 1); 229 InstallApp(verifier(), 1); 230 231 InstallApp(GetProfile(0), 2); 232 InstallApp(GetProfile(1), 2); 233 InstallApp(verifier(), 2); 234 235 InstallApp(GetProfile(1), 3); 236 InstallApp(verifier(), 3); 237 238 ASSERT_TRUE(AwaitQuiescence()); 239 InstallAppsPendingForSync(GetProfile(0)); 240 InstallAppsPendingForSync(GetProfile(1)); 241 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 242} 243 244// TCM ID - 7723126. 245IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateEnableDisableApp) { 246 ASSERT_TRUE(SetupSync()); 247 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 248 249 InstallApp(GetProfile(0), 0); 250 InstallApp(GetProfile(1), 0); 251 InstallApp(verifier(), 0); 252 ASSERT_TRUE(AwaitQuiescence()); 253 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 254 255 DisableApp(GetProfile(0), 0); 256 DisableApp(verifier(), 0); 257 ASSERT_TRUE(HasSameAppsAsVerifier(0)); 258 ASSERT_FALSE(HasSameAppsAsVerifier(1)); 259 260 ASSERT_TRUE(AwaitQuiescence()); 261 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 262 263 EnableApp(GetProfile(1), 0); 264 EnableApp(verifier(), 0); 265 ASSERT_TRUE(HasSameAppsAsVerifier(1)); 266 ASSERT_FALSE(HasSameAppsAsVerifier(0)); 267 268 ASSERT_TRUE(AwaitQuiescence()); 269 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 270} 271 272// TCM ID - 7706637. 273IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateIncognitoEnableDisable) { 274 ASSERT_TRUE(SetupSync()); 275 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 276 277 InstallApp(GetProfile(0), 0); 278 InstallApp(GetProfile(1), 0); 279 InstallApp(verifier(), 0); 280 ASSERT_TRUE(AwaitQuiescence()); 281 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 282 283 IncognitoEnableApp(GetProfile(0), 0); 284 IncognitoEnableApp(verifier(), 0); 285 ASSERT_TRUE(HasSameAppsAsVerifier(0)); 286 ASSERT_FALSE(HasSameAppsAsVerifier(1)); 287 288 ASSERT_TRUE(AwaitQuiescence()); 289 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 290 291 IncognitoDisableApp(GetProfile(1), 0); 292 IncognitoDisableApp(verifier(), 0); 293 ASSERT_TRUE(HasSameAppsAsVerifier(1)); 294 ASSERT_FALSE(HasSameAppsAsVerifier(0)); 295 296 ASSERT_TRUE(AwaitQuiescence()); 297 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 298} 299 300// TCM ID - 3718276. 301IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, DisableApps) { 302 ASSERT_TRUE(SetupSync()); 303 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 304 305 ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::APPS)); 306 InstallApp(GetProfile(0), 0); 307 InstallApp(verifier(), 0); 308 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Installed an app.")); 309 ASSERT_TRUE(HasSameAppsAsVerifier(0)); 310 ASSERT_FALSE(HasSameAppsAsVerifier(1)); 311 312 ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::APPS)); 313 ASSERT_TRUE(AwaitQuiescence()); 314 315 InstallAppsPendingForSync(GetProfile(0)); 316 InstallAppsPendingForSync(GetProfile(1)); 317 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 318} 319 320// Disable sync for the second client and then install an app on the first 321// client, then enable sync on the second client. Both clients should have the 322// same app with identical app and page ordinals. 323// TCM ID - 3720303. 324IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, DisableSync) { 325 ASSERT_TRUE(SetupSync()); 326 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 327 328 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes()); 329 InstallApp(GetProfile(0), 0); 330 InstallApp(verifier(), 0); 331 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Installed an app.")); 332 ASSERT_TRUE(HasSameAppsAsVerifier(0)); 333 ASSERT_FALSE(HasSameAppsAsVerifier(1)); 334 335 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes()); 336 ASSERT_TRUE(AwaitQuiescence()); 337 338 InstallAppsPendingForSync(GetProfile(0)); 339 InstallAppsPendingForSync(GetProfile(1)); 340 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 341} 342 343// Install the same app on both clients, then sync. Change the page ordinal on 344// one client and sync. Both clients should have the updated page ordinal for 345// the app. 346IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdatePageOrdinal) { 347 ASSERT_TRUE(SetupSync()); 348 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 349 350 syncer::StringOrdinal initial_page = 351 syncer::StringOrdinal::CreateInitialOrdinal(); 352 InstallApp(GetProfile(0), 0); 353 InstallApp(GetProfile(1), 0); 354 InstallApp(verifier(), 0); 355 ASSERT_TRUE(AwaitQuiescence()); 356 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 357 358 syncer::StringOrdinal second_page = initial_page.CreateAfter(); 359 SetPageOrdinalForApp(GetProfile(0), 0, second_page); 360 SetPageOrdinalForApp(verifier(), 0, second_page); 361 ASSERT_TRUE(AwaitQuiescence()); 362 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 363} 364 365// Install the same app on both clients, then sync. Change the app launch 366// ordinal on one client and sync. Both clients should have the updated app 367// launch ordinal for the app. 368IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateAppLaunchOrdinal) { 369 ASSERT_TRUE(SetupSync()); 370 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 371 372 InstallApp(GetProfile(0), 0); 373 InstallApp(GetProfile(1), 0); 374 InstallApp(verifier(), 0); 375 ASSERT_TRUE(AwaitQuiescence()); 376 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 377 378 syncer::StringOrdinal initial_position = 379 GetAppLaunchOrdinalForApp(GetProfile(0), 0); 380 381 syncer::StringOrdinal second_position = initial_position.CreateAfter(); 382 SetAppLaunchOrdinalForApp(GetProfile(0), 0, second_position); 383 SetAppLaunchOrdinalForApp(verifier(), 0, second_position); 384 ASSERT_TRUE(AwaitQuiescence()); 385 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 386} 387 388// Adjust the CWS location within a page on the first client and sync. Adjust 389// which page the CWS appears on and sync. Both clients should have the same 390// page and app launch ordinal values for the CWS. 391IN_PROC_BROWSER_TEST_F(TwoClientAppsSyncTest, UpdateCWSOrdinals) { 392 ASSERT_TRUE(SetupSync()); 393 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 394 395 // Change the app launch ordinal. 396 syncer::StringOrdinal cws_app_launch_ordinal = 397 GetProfile(0)->GetExtensionService()-> 398 extension_prefs()->app_sorting()->GetAppLaunchOrdinal( 399 extension_misc::kWebStoreAppId); 400 GetProfile(0)->GetExtensionService()->extension_prefs()->app_sorting()-> 401 SetAppLaunchOrdinal( 402 extension_misc::kWebStoreAppId, cws_app_launch_ordinal.CreateAfter()); 403 verifier()->GetExtensionService()->extension_prefs()->app_sorting()-> 404 SetAppLaunchOrdinal( 405 extension_misc::kWebStoreAppId, cws_app_launch_ordinal.CreateAfter()); 406 ASSERT_TRUE(AwaitQuiescence()); 407 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 408 409 // Change the page ordinal. 410 syncer::StringOrdinal cws_page_ordinal = 411 GetProfile(1)->GetExtensionService()-> 412 extension_prefs()->app_sorting()->GetPageOrdinal( 413 extension_misc::kWebStoreAppId); 414 GetProfile(1)->GetExtensionService()->extension_prefs()-> 415 app_sorting()->SetPageOrdinal(extension_misc::kWebStoreAppId, 416 cws_page_ordinal.CreateAfter()); 417 verifier()->GetExtensionService()->extension_prefs()-> 418 app_sorting()->SetPageOrdinal(extension_misc::kWebStoreAppId, 419 cws_page_ordinal.CreateAfter()); 420 ASSERT_TRUE(AwaitQuiescence()); 421 ASSERT_TRUE(AllProfilesHaveSameAppsAsVerifier()); 422} 423 424// TODO(akalin): Add tests exercising: 425// - Offline installation/uninstallation behavior 426// - App-specific properties 427