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.
5 #include "base/basictypes.h"
6 #include "chrome/browser/sync/test/integration/extensions_helper.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
9 #include "chrome/browser/sync/test/integration/sync_test.h"
11 using extensions_helper::AwaitAllProfilesHaveSameExtensions
;
12 using extensions_helper::AllProfilesHaveSameExtensions
;
13 using extensions_helper::DisableExtension
;
14 using extensions_helper::EnableExtension
;
15 using extensions_helper::GetInstalledExtensions
;
16 using extensions_helper::HasSameExtensions
;
17 using extensions_helper::IncognitoDisableExtension
;
18 using extensions_helper::IncognitoEnableExtension
;
19 using extensions_helper::InstallExtension
;
20 using extensions_helper::UninstallExtension
;
22 class TwoClientExtensionsSyncTest
: public SyncTest
{
24 TwoClientExtensionsSyncTest() : SyncTest(TWO_CLIENT
) {}
26 ~TwoClientExtensionsSyncTest() override
{}
27 bool TestUsesSelfNotifications() override
{ return false; }
30 DISALLOW_COPY_AND_ASSIGN(TwoClientExtensionsSyncTest
);
33 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
34 StartWithNoExtensions_E2ETest
) {
35 ASSERT_TRUE(SetupSync());
36 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
39 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
40 StartWithSameExtensions_E2ETest
) {
41 ASSERT_TRUE(SetupClients());
43 const int kNumExtensions
= 5;
44 for (int i
= 0; i
< kNumExtensions
; ++i
) {
45 InstallExtension(GetProfile(0), i
);
46 InstallExtension(GetProfile(1), i
);
49 ASSERT_TRUE(SetupSync());
50 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
51 EXPECT_EQ(kNumExtensions
,
52 static_cast<int>(GetInstalledExtensions(GetProfile(0)).size()));
55 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
56 StartWithDifferentExtensions_E2ETest
) {
57 ASSERT_TRUE(SetupClients());
59 int extension_index
= 0;
61 const int kNumCommonExtensions
= 5;
62 for (int i
= 0; i
< kNumCommonExtensions
; ++extension_index
, ++i
) {
63 InstallExtension(GetProfile(0), extension_index
);
64 InstallExtension(GetProfile(1), extension_index
);
67 const int kNumProfile0Extensions
= 10;
68 for (int i
= 0; i
< kNumProfile0Extensions
; ++extension_index
, ++i
) {
69 InstallExtension(GetProfile(0), extension_index
);
72 const int kNumProfile1Extensions
= 10;
73 for (int i
= 0; i
< kNumProfile1Extensions
; ++extension_index
, ++i
) {
74 InstallExtension(GetProfile(1), extension_index
);
77 ASSERT_TRUE(SetupSync());
78 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
80 kNumCommonExtensions
+ kNumProfile0Extensions
+ kNumProfile1Extensions
,
81 static_cast<int>(GetInstalledExtensions(GetProfile(0)).size()));
84 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
85 InstallDifferentExtensions_E2ETest
) {
86 ASSERT_TRUE(SetupClients());
88 int extension_index
= 0;
90 const int kNumCommonExtensions
= 5;
91 for (int i
= 0; i
< kNumCommonExtensions
; ++extension_index
, ++i
) {
92 InstallExtension(GetProfile(0), extension_index
);
93 InstallExtension(GetProfile(1), extension_index
);
96 ASSERT_TRUE(SetupSync());
97 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
99 const int kNumProfile0Extensions
= 10;
100 for (int i
= 0; i
< kNumProfile0Extensions
; ++extension_index
, ++i
) {
101 InstallExtension(GetProfile(0), extension_index
);
104 const int kNumProfile1Extensions
= 10;
105 for (int i
= 0; i
< kNumProfile1Extensions
; ++extension_index
, ++i
) {
106 InstallExtension(GetProfile(1), extension_index
);
109 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
111 kNumCommonExtensions
+ kNumProfile0Extensions
+ kNumProfile1Extensions
,
112 static_cast<int>(GetInstalledExtensions(GetProfile(0)).size()));
116 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
, Add_E2ETest
) {
117 ASSERT_TRUE(SetupSync());
118 ASSERT_TRUE(AllProfilesHaveSameExtensions());
120 InstallExtension(GetProfile(0), 0);
122 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
123 EXPECT_EQ(1u, GetInstalledExtensions(GetProfile(0)).size());
127 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
, Uninstall
) {
128 ASSERT_TRUE(SetupSync());
129 ASSERT_TRUE(AllProfilesHaveSameExtensions());
131 InstallExtension(GetProfile(0), 0);
132 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
134 UninstallExtension(GetProfile(0), 0);
135 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
136 EXPECT_TRUE(GetInstalledExtensions(GetProfile(0)).empty());
140 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
141 UpdateEnableDisableExtension
) {
142 ASSERT_TRUE(SetupSync());
143 ASSERT_TRUE(AllProfilesHaveSameExtensions());
145 InstallExtension(GetProfile(0), 0);
146 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
148 DisableExtension(GetProfile(0), 0);
149 ASSERT_FALSE(HasSameExtensions(0, 1));
151 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
153 EnableExtension(GetProfile(1), 0);
154 ASSERT_FALSE(HasSameExtensions(0, 1));
156 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
160 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
161 UpdateIncognitoEnableDisable
) {
162 ASSERT_TRUE(SetupSync());
163 ASSERT_TRUE(AllProfilesHaveSameExtensions());
165 InstallExtension(GetProfile(0), 0);
166 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
168 IncognitoEnableExtension(GetProfile(0), 0);
169 ASSERT_FALSE(HasSameExtensions(0, 1));
171 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
173 IncognitoDisableExtension(GetProfile(1), 0);
174 ASSERT_FALSE(HasSameExtensions(0, 1));
176 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
179 // Regression test for bug 104399: ensure that an extension installed prior to
180 // setting up sync, when uninstalled, is also uninstalled from sync.
181 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
182 UninstallPreinstalledExtensions
) {
183 ASSERT_TRUE(SetupClients());
184 ASSERT_TRUE(AllProfilesHaveSameExtensions());
186 InstallExtension(GetProfile(0), 0);
188 ASSERT_TRUE(SetupSync());
190 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
191 ASSERT_EQ(1u, GetInstalledExtensions(GetProfile(0)).size());
193 UninstallExtension(GetProfile(0), 0);
195 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensions());
196 EXPECT_TRUE(GetInstalledExtensions(GetProfile(0)).empty());
199 // TODO(akalin): Add tests exercising:
200 // - Offline installation/uninstallation behavior