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::AwaitAllProfilesHaveSameExtensionsAsVerifier
;
12 using extensions_helper::AllProfilesHaveSameExtensionsAsVerifier
;
13 using extensions_helper::DisableExtension
;
14 using extensions_helper::EnableExtension
;
15 using extensions_helper::HasSameExtensionsAsVerifier
;
16 using extensions_helper::IncognitoDisableExtension
;
17 using extensions_helper::IncognitoEnableExtension
;
18 using extensions_helper::InstallExtension
;
19 using extensions_helper::UninstallExtension
;
21 class TwoClientExtensionsSyncTest
: public SyncTest
{
23 TwoClientExtensionsSyncTest() : SyncTest(TWO_CLIENT
) {}
25 ~TwoClientExtensionsSyncTest() override
{}
26 bool TestUsesSelfNotifications() override
{ return false; }
29 DISALLOW_COPY_AND_ASSIGN(TwoClientExtensionsSyncTest
);
32 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
, StartWithNoExtensions
) {
33 ASSERT_TRUE(SetupSync());
34 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
37 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
, StartWithSameExtensions
) {
38 ASSERT_TRUE(SetupClients());
40 const int kNumExtensions
= 5;
41 for (int i
= 0; i
< kNumExtensions
; ++i
) {
42 InstallExtension(GetProfile(0), i
);
43 InstallExtension(GetProfile(1), i
);
44 InstallExtension(verifier(), i
);
47 ASSERT_TRUE(SetupSync());
48 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
51 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
52 StartWithDifferentExtensions
) {
53 ASSERT_TRUE(SetupClients());
57 const int kNumCommonExtensions
= 5;
58 for (int j
= 0; j
< kNumCommonExtensions
; ++i
, ++j
) {
59 InstallExtension(GetProfile(0), i
);
60 InstallExtension(GetProfile(1), i
);
61 InstallExtension(verifier(), i
);
64 const int kNumProfile0Extensions
= 10;
65 for (int j
= 0; j
< kNumProfile0Extensions
; ++i
, ++j
) {
66 InstallExtension(GetProfile(0), i
);
67 InstallExtension(verifier(), i
);
70 const int kNumProfile1Extensions
= 10;
71 for (int j
= 0; j
< kNumProfile1Extensions
; ++i
, ++j
) {
72 InstallExtension(GetProfile(1), i
);
73 InstallExtension(verifier(), i
);
76 ASSERT_TRUE(SetupSync());
77 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
80 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
81 InstallDifferentExtensions
) {
82 ASSERT_TRUE(SetupClients());
86 const int kNumCommonExtensions
= 5;
87 for (int j
= 0; j
< kNumCommonExtensions
; ++i
, ++j
) {
88 InstallExtension(GetProfile(0), i
);
89 InstallExtension(GetProfile(1), i
);
90 InstallExtension(verifier(), i
);
93 ASSERT_TRUE(SetupSync());
94 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
96 const int kNumProfile0Extensions
= 10;
97 for (int j
= 0; j
< kNumProfile0Extensions
; ++i
, ++j
) {
98 InstallExtension(GetProfile(0), i
);
99 InstallExtension(verifier(), i
);
102 const int kNumProfile1Extensions
= 10;
103 for (int j
= 0; j
< kNumProfile1Extensions
; ++i
, ++j
) {
104 InstallExtension(GetProfile(1), i
);
105 InstallExtension(verifier(), i
);
108 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
112 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
, Add
) {
113 ASSERT_TRUE(SetupSync());
114 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
116 InstallExtension(GetProfile(0), 0);
117 InstallExtension(verifier(), 0);
119 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
123 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
, Uninstall
) {
124 ASSERT_TRUE(SetupSync());
125 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
127 InstallExtension(GetProfile(0), 0);
128 InstallExtension(verifier(), 0);
129 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
131 UninstallExtension(GetProfile(0), 0);
132 UninstallExtension(verifier(), 0);
133 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
137 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
138 UpdateEnableDisableExtension
) {
139 ASSERT_TRUE(SetupSync());
140 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
142 InstallExtension(GetProfile(0), 0);
143 InstallExtension(verifier(), 0);
144 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
146 DisableExtension(GetProfile(0), 0);
147 DisableExtension(verifier(), 0);
148 ASSERT_TRUE(HasSameExtensionsAsVerifier(0));
149 ASSERT_FALSE(HasSameExtensionsAsVerifier(1));
151 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
153 EnableExtension(GetProfile(1), 0);
154 EnableExtension(verifier(), 0);
155 ASSERT_TRUE(HasSameExtensionsAsVerifier(1));
156 ASSERT_FALSE(HasSameExtensionsAsVerifier(0));
158 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
162 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
163 UpdateIncognitoEnableDisable
) {
164 ASSERT_TRUE(SetupSync());
165 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
167 InstallExtension(GetProfile(0), 0);
168 InstallExtension(verifier(), 0);
169 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
171 IncognitoEnableExtension(GetProfile(0), 0);
172 IncognitoEnableExtension(verifier(), 0);
173 ASSERT_TRUE(HasSameExtensionsAsVerifier(0));
174 ASSERT_FALSE(HasSameExtensionsAsVerifier(1));
176 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
178 IncognitoDisableExtension(GetProfile(1), 0);
179 IncognitoDisableExtension(verifier(), 0);
180 ASSERT_TRUE(HasSameExtensionsAsVerifier(1));
181 ASSERT_FALSE(HasSameExtensionsAsVerifier(0));
183 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
186 // Regression test for bug 104399: ensure that an extension installed prior to
187 // setting up sync, when uninstalled, is also uninstalled from sync.
188 IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest
,
189 UninstallPreinstalledExtensions
) {
190 ASSERT_TRUE(SetupClients());
191 ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
193 InstallExtension(GetProfile(0), 0);
194 InstallExtension(verifier(), 0);
196 ASSERT_TRUE(SetupSync());
198 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
200 UninstallExtension(GetProfile(0), 0);
201 UninstallExtension(verifier(), 0);
203 ASSERT_TRUE(AwaitAllProfilesHaveSameExtensionsAsVerifier());
206 // TODO(akalin): Add tests exercising:
207 // - Offline installation/uninstallation behavior