| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "chrome/browser/profiles/profile.h" |
| 6 #include "chrome/browser/sync/test/integration/sync_arc_package_helper.h" |
| 7 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
| 8 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 9 |
| 10 namespace arc { |
| 11 |
| 12 namespace { |
| 13 |
| 14 bool AllProfilesHaveSameArcPackageDetails() { |
| 15 return SyncArcPackageHelper::GetInstance() |
| 16 ->AllProfilesHaveSamePackageDetails(); |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 21 class TwoClientArcPackageSyncTest : public SyncTest { |
| 22 public: |
| 23 TwoClientArcPackageSyncTest() |
| 24 : SyncTest(TWO_CLIENT_LEGACY), sync_helper_(nullptr) { |
| 25 DisableVerifier(); |
| 26 } |
| 27 |
| 28 ~TwoClientArcPackageSyncTest() override {} |
| 29 |
| 30 bool SetupClients() override { |
| 31 if (!SyncTest::SetupClients()) |
| 32 return false; |
| 33 |
| 34 // Init SyncArcPackageHelper to ensure that the arc services are initialized |
| 35 // for each Profile. |
| 36 sync_helper_ = SyncArcPackageHelper::GetInstance(); |
| 37 return sync_helper_ != nullptr; |
| 38 } |
| 39 |
| 40 void TearDownOnMainThread() override { |
| 41 sync_helper_->CleanUp(); |
| 42 sync_helper_ = nullptr; |
| 43 SyncTest::TearDownOnMainThread(); |
| 44 } |
| 45 |
| 46 SyncArcPackageHelper* sync_helper() { return sync_helper_; } |
| 47 |
| 48 private: |
| 49 SyncArcPackageHelper* sync_helper_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(TwoClientArcPackageSyncTest); |
| 52 }; |
| 53 |
| 54 IN_PROC_BROWSER_TEST_F(TwoClientArcPackageSyncTest, StartWithNoPackages) { |
| 55 ASSERT_TRUE(SetupSync()); |
| 56 |
| 57 ASSERT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 58 } |
| 59 |
| 60 IN_PROC_BROWSER_TEST_F(TwoClientArcPackageSyncTest, StartWithSamePackages) { |
| 61 ASSERT_TRUE(SetupClients()); |
| 62 |
| 63 constexpr size_t kNumPackages = 5; |
| 64 for (size_t i = 0; i < kNumPackages; ++i) { |
| 65 sync_helper()->InstallPackageWithIndex(GetProfile(0), i); |
| 66 sync_helper()->InstallPackageWithIndex(GetProfile(1), i); |
| 67 } |
| 68 |
| 69 ASSERT_TRUE(SetupSync()); |
| 70 |
| 71 ASSERT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 72 } |
| 73 |
| 74 // In this test, packages are installed before sync started. Client1 will have |
| 75 // package 0 to 4 installed while client2 has no package installed. |
| 76 IN_PROC_BROWSER_TEST_F(TwoClientArcPackageSyncTest, |
| 77 OneClientHasPackagesAnotherHasNone) { |
| 78 ASSERT_TRUE(SetupClients()); |
| 79 |
| 80 constexpr size_t kNumPackages = 5; |
| 81 for (size_t i = 0; i < kNumPackages; ++i) { |
| 82 sync_helper()->InstallPackageWithIndex(GetProfile(0), i); |
| 83 } |
| 84 |
| 85 ASSERT_FALSE(AllProfilesHaveSameArcPackageDetails()); |
| 86 |
| 87 ASSERT_TRUE(SetupSync()); |
| 88 |
| 89 ASSERT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 90 } |
| 91 |
| 92 // In this test, packages are installed before sync started. Client1 will have |
| 93 // package 0 to 9 installed and client2 will have package 0 to 4 installed. |
| 94 IN_PROC_BROWSER_TEST_F(TwoClientArcPackageSyncTest, |
| 95 OneClientHasPackagesAnotherHasSubSet) { |
| 96 ASSERT_TRUE(SetupClients()); |
| 97 |
| 98 constexpr size_t kNumPackages = 5; |
| 99 for (size_t i = 0; i < kNumPackages; ++i) { |
| 100 sync_helper()->InstallPackageWithIndex(GetProfile(0), i); |
| 101 sync_helper()->InstallPackageWithIndex(GetProfile(1), i); |
| 102 } |
| 103 |
| 104 for (size_t i = 0; i < kNumPackages; ++i) { |
| 105 sync_helper()->InstallPackageWithIndex(GetProfile(0), i + kNumPackages); |
| 106 } |
| 107 |
| 108 ASSERT_FALSE(AllProfilesHaveSameArcPackageDetails()); |
| 109 |
| 110 ASSERT_TRUE(SetupSync()); |
| 111 |
| 112 EXPECT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 113 } |
| 114 |
| 115 // In this test, packages are installed before sync started. Client1 will have |
| 116 // package 0 to 4 installed and client2 will have package 1 to 5 installed. |
| 117 IN_PROC_BROWSER_TEST_F(TwoClientArcPackageSyncTest, |
| 118 StartWithDifferentPackages) { |
| 119 ASSERT_TRUE(SetupClients()); |
| 120 |
| 121 constexpr size_t kNumPackages = 5; |
| 122 constexpr size_t kPackageIdDiff = 1; |
| 123 for (size_t i = 0; i < kNumPackages; ++i) { |
| 124 sync_helper()->InstallPackageWithIndex(GetProfile(0), i); |
| 125 sync_helper()->InstallPackageWithIndex(GetProfile(1), i + kPackageIdDiff); |
| 126 } |
| 127 |
| 128 EXPECT_FALSE(AllProfilesHaveSameArcPackageDetails()); |
| 129 |
| 130 ASSERT_TRUE(SetupSync()); |
| 131 |
| 132 EXPECT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 133 } |
| 134 |
| 135 // Tests package installaton after sync started. |
| 136 IN_PROC_BROWSER_TEST_F(TwoClientArcPackageSyncTest, Install) { |
| 137 ASSERT_TRUE(SetupSync()); |
| 138 ASSERT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 139 |
| 140 sync_helper()->InstallPackageWithIndex(GetProfile(0), 0); |
| 141 ASSERT_TRUE(AwaitQuiescence()); |
| 142 EXPECT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 143 } |
| 144 |
| 145 // In this test, packages are installed after sync started. Client1 installs |
| 146 // package 0 to 4 and client2 installs package 3 to 7. |
| 147 IN_PROC_BROWSER_TEST_F(TwoClientArcPackageSyncTest, InstallDifferent) { |
| 148 ASSERT_TRUE(SetupSync()); |
| 149 ASSERT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 150 |
| 151 constexpr size_t kNumPackages = 5; |
| 152 constexpr size_t kPackageIdDiff = 3; |
| 153 for (size_t i = 0; i < kNumPackages; ++i) { |
| 154 sync_helper()->InstallPackageWithIndex(GetProfile(0), i); |
| 155 sync_helper()->InstallPackageWithIndex(GetProfile(1), i + kPackageIdDiff); |
| 156 } |
| 157 |
| 158 ASSERT_TRUE(AwaitQuiescence()); |
| 159 EXPECT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 160 } |
| 161 |
| 162 // Installs package from one client and uninstalls from another after sync |
| 163 // started. |
| 164 IN_PROC_BROWSER_TEST_F(TwoClientArcPackageSyncTest, Uninstall) { |
| 165 ASSERT_TRUE(SetupSync()); |
| 166 ASSERT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 167 |
| 168 sync_helper()->InstallPackageWithIndex(GetProfile(0), 1); |
| 169 ASSERT_TRUE(AwaitQuiescence()); |
| 170 EXPECT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 171 |
| 172 sync_helper()->UninstallPackageWithIndex(GetProfile(1), 1); |
| 173 EXPECT_FALSE(AllProfilesHaveSameArcPackageDetails()); |
| 174 ASSERT_TRUE(AwaitQuiescence()); |
| 175 EXPECT_TRUE(AllProfilesHaveSameArcPackageDetails()); |
| 176 } |
| 177 |
| 178 } // namespace arc |
| OLD | NEW |