Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_search_engines_sync_test.cc
blob9030f5575dff4463e6d81445a0eba64135b6d4c4
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/strings/utf_string_conversions.h"
6 #include "chrome/browser/search_engines/template_url_service_factory.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/search_engines_helper.h"
9 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
10 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
11 #include "chrome/browser/sync/test/integration/sync_test.h"
12 #include "components/search_engines/template_url.h"
13 #include "components/search_engines/template_url_service.h"
15 using base::ASCIIToUTF16;
16 using sync_integration_test_util::AwaitCommitActivityCompletion;
18 class TwoClientSearchEnginesSyncTest : public SyncTest {
19 public:
20 TwoClientSearchEnginesSyncTest() : SyncTest(TWO_CLIENT) {}
21 ~TwoClientSearchEnginesSyncTest() override {}
23 private:
24 DISALLOW_COPY_AND_ASSIGN(TwoClientSearchEnginesSyncTest);
27 // TCM ID - 8898628.
28 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, Add) {
29 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
30 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
32 search_engines_helper::AddSearchEngine(0, 0);
34 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
35 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
38 // TCM ID - 8912240.
39 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, AddMultiple) {
40 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
41 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
43 // Add a few entries.
44 for (int i = 0; i < 3; ++i)
45 search_engines_helper::AddSearchEngine(0, i);
47 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
48 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
51 // TCM ID - 9011135.
52 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, Duplicates) {
53 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
54 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
56 // Add two entries with the same Name and URL (but different keywords).
57 // Note that we have to change the GUID of the duplicate.
58 search_engines_helper::AddSearchEngine(0, 0);
59 Profile* profile = sync_datatype_helper::test()->GetProfile(0);
60 TemplateURLServiceFactory::GetForProfile(profile)->Add(
61 search_engines_helper::CreateTestTemplateURL(profile, 0,
62 ASCIIToUTF16("somethingelse"), "newguid"));
63 search_engines_helper::GetVerifierService()->Add(
64 search_engines_helper::CreateTestTemplateURL(profile, 0,
65 ASCIIToUTF16("somethingelse"), "newguid"));
66 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
67 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
70 // TCM ID - 9004201.
71 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateKeyword) {
72 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
73 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
75 search_engines_helper::AddSearchEngine(0, 0);
77 // Change the keyword.
78 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
79 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
81 search_engines_helper::EditSearchEngine(0, ASCIIToUTF16("test0"),
82 ASCIIToUTF16("test0"), ASCIIToUTF16("newkeyword"),
83 "http://www.test0.com/");
85 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
86 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
89 // TCM ID - 8894859.
90 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateUrl) {
91 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
92 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
94 search_engines_helper::AddSearchEngine(0, 0);
96 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
97 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
99 // Change the URL.
100 search_engines_helper::EditSearchEngine(0, ASCIIToUTF16("test0"),
101 ASCIIToUTF16("test0"), ASCIIToUTF16("test0"),
102 "http://www.wikipedia.org/q=%s");
104 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
105 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
108 // TCM ID - 8910490.
109 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateName) {
110 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
111 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
113 search_engines_helper::AddSearchEngine(0, 0);
115 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
116 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
118 // Change the short name.
119 search_engines_helper::EditSearchEngine(0, ASCIIToUTF16("test0"),
120 ASCIIToUTF16("New Name"), ASCIIToUTF16("test0"), "http://www.test0.com/");
122 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
123 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
126 // TCM ID - 8898660.
127 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, Delete) {
128 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
129 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
131 search_engines_helper::AddSearchEngine(0, 0);
133 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
134 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
136 search_engines_helper::DeleteSearchEngineBySeed(0, 0);
138 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
139 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
142 // TCM ID - 9004196.
143 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, ConflictKeyword) {
144 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
145 DisableVerifier();
146 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
148 // Add a different search engine to each client, but make their keywords
149 // conflict.
150 search_engines_helper::AddSearchEngine(0, 0);
151 search_engines_helper::AddSearchEngine(1, 1);
152 TemplateURLService* service =
153 search_engines_helper::GetServiceForBrowserContext(1);
154 TemplateURL* turl = service->GetTemplateURLForKeyword(ASCIIToUTF16("test1"));
155 EXPECT_TRUE(turl);
156 service->ResetTemplateURL(turl, turl->short_name(), ASCIIToUTF16("test0"),
157 turl->url());
159 ASSERT_TRUE(AwaitQuiescence());
160 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
163 // TCM ID - 9004187.
164 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, MergeMultiple) {
165 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
166 DisableVerifier();
167 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
169 // Set up some different search engines on each client, with some interesting
170 // conflicts.
171 // client0: { SE0, SE1, SE2 }
172 for (int i = 0; i < 3; ++i)
173 search_engines_helper::AddSearchEngine(0, i);
175 // client1: { SE0, SE2, SE3, SE0 + different URL }
176 search_engines_helper::AddSearchEngine(1, 0);
177 search_engines_helper::AddSearchEngine(1, 2);
178 search_engines_helper::AddSearchEngine(1, 3);
179 Profile* profile = sync_datatype_helper::test()->GetProfile(1);
180 TemplateURLServiceFactory::GetForProfile(profile)->Add(
181 search_engines_helper::CreateTestTemplateURL(profile, 0,
182 ASCIIToUTF16("somethingelse.com"), "http://www.somethingelse.com/",
183 "somethingelse"));
185 ASSERT_TRUE(AwaitQuiescence());
186 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
189 // TCM ID - 8906436.
190 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, DisableSync) {
191 ASSERT_TRUE(SetupSync());
192 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
194 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
195 search_engines_helper::AddSearchEngine(0, 0);
196 ASSERT_TRUE(
197 AwaitCommitActivityCompletion(GetSyncService((0))));
198 ASSERT_TRUE(search_engines_helper::ServiceMatchesVerifier(0));
199 ASSERT_FALSE(search_engines_helper::ServiceMatchesVerifier(1));
201 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
202 ASSERT_TRUE(AwaitQuiescence());
203 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
206 // TCM ID - 8891809.
207 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, SyncDefault) {
208 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
209 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
211 search_engines_helper::AddSearchEngine(0, 0);
212 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
214 // Change the default to the new search engine, sync, and ensure that it
215 // changed in the second client. AllServicesMatch does a default search
216 // provider check.
217 search_engines_helper::ChangeDefaultSearchProvider(0, 0);
218 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
220 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
223 // Ensure that we can change the search engine and immediately delete it
224 // without putting the clients out of sync.
225 IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, DeleteSyncedDefault) {
226 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
227 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
229 search_engines_helper::AddSearchEngine(0, 0);
230 search_engines_helper::AddSearchEngine(0, 1);
231 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
233 search_engines_helper::ChangeDefaultSearchProvider(0, 0);
234 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
235 ASSERT_TRUE(search_engines_helper::AllServicesMatch());
237 // Change the default on the first client and delete the old default.
238 search_engines_helper::ChangeDefaultSearchProvider(0, 1);
239 search_engines_helper::DeleteSearchEngineBySeed(0, 0);
240 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
242 ASSERT_TRUE(search_engines_helper::AllServicesMatch());