Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(851)

Side by Side Diff: chrome/browser/sync/test/integration/sync_errors_test.cc

Issue 2379433002: [Sync] Refactoring of sync integration test checkers to remove boilerplate await methods. (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" 8 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
9 #include "chrome/browser/sync/test/integration/passwords_helper.h" 9 #include "chrome/browser/sync/test/integration/passwords_helper.h"
10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
11 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h" 11 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h"
12 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
13 #include "chrome/browser/sync/test/integration/sync_test.h" 12 #include "chrome/browser/sync/test/integration/sync_test.h"
13 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h "
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "components/browser_sync/profile_sync_service.h" 15 #include "components/browser_sync/profile_sync_service.h"
16 #include "components/prefs/pref_member.h" 16 #include "components/prefs/pref_member.h"
17 #include "components/prefs/pref_service.h" 17 #include "components/prefs/pref_service.h"
18 #include "components/sync/protocol/sync_protocol_error.h" 18 #include "components/sync/protocol/sync_protocol_error.h"
19 #include "google_apis/gaia/google_service_auth_error.h" 19 #include "google_apis/gaia/google_service_auth_error.h"
20 20
21 using bookmarks::BookmarkNode; 21 using bookmarks::BookmarkNode;
22 using bookmarks_helper::AddFolder; 22 using bookmarks_helper::AddFolder;
23 using bookmarks_helper::SetTitle; 23 using bookmarks_helper::SetTitle;
24 using browser_sync::ProfileSyncService; 24 using browser_sync::ProfileSyncService;
25 using sync_integration_test_util::AwaitCommitActivityCompletion;
26 25
27 namespace { 26 namespace {
28 27
29 class SyncDisabledChecker : public SingleClientStatusChangeChecker { 28 class SyncDisabledChecker : public SingleClientStatusChangeChecker {
30 public: 29 public:
31 explicit SyncDisabledChecker(ProfileSyncService* service) 30 explicit SyncDisabledChecker(ProfileSyncService* service)
32 : SingleClientStatusChangeChecker(service) {} 31 : SingleClientStatusChangeChecker(service) {}
33 32
34 bool IsExitConditionSatisfied() override { 33 bool IsExitConditionSatisfied() override {
35 return !service()->IsSetupInProgress() && 34 return !service()->IsSetupInProgress() &&
36 !service()->IsFirstSetupComplete(); 35 !service()->IsFirstSetupComplete();
37 } 36 }
38 37
39 std::string GetDebugMessage() const override { return "Sync Disabled"; } 38 std::string GetDebugMessage() const override { return "Sync Disabled"; }
40 }; 39 };
41 40
42 class SyncBackendStoppedChecker : public SingleClientStatusChangeChecker { 41 class SyncBackendStoppedChecker : public SingleClientStatusChangeChecker {
43 public: 42 public:
44 explicit SyncBackendStoppedChecker(ProfileSyncService* service) 43 explicit SyncBackendStoppedChecker(ProfileSyncService* service)
45 : SingleClientStatusChangeChecker(service) {} 44 : SingleClientStatusChangeChecker(service) {}
46 45
46 // StatusChangeChecker implementation.
47 bool IsExitConditionSatisfied() override { 47 bool IsExitConditionSatisfied() override {
48 return !service()->IsBackendInitialized(); 48 return !service()->IsBackendInitialized();
49 } 49 }
50
51 std::string GetDebugMessage() const override { return "Sync stopped"; } 50 std::string GetDebugMessage() const override { return "Sync stopped"; }
52 }; 51 };
53 52
54 class TypeDisabledChecker : public SingleClientStatusChangeChecker { 53 class TypeDisabledChecker : public SingleClientStatusChangeChecker {
55 public: 54 public:
56 explicit TypeDisabledChecker(ProfileSyncService* service, 55 explicit TypeDisabledChecker(ProfileSyncService* service,
57 syncer::ModelType type) 56 syncer::ModelType type)
58 : SingleClientStatusChangeChecker(service), type_(type) {} 57 : SingleClientStatusChangeChecker(service), type_(type) {}
59 58
59 // StatusChangeChecker implementation.
60 bool IsExitConditionSatisfied() override { 60 bool IsExitConditionSatisfied() override {
61 return !service()->GetActiveDataTypes().Has(type_); 61 return !service()->GetActiveDataTypes().Has(type_);
62 } 62 }
63 std::string GetDebugMessage() const override { return "Type disabled"; }
63 64
64 std::string GetDebugMessage() const override { return "Type disabled"; }
65 private: 65 private:
66 syncer::ModelType type_; 66 syncer::ModelType type_;
67 }; 67 };
68 68
69 bool AwaitSyncDisabled(ProfileSyncService* service) {
70 SyncDisabledChecker checker(service);
71 checker.Wait();
72 return !checker.TimedOut();
73 }
74
75 bool AwaitSyncBackendStopped(ProfileSyncService* service) {
76 SyncBackendStoppedChecker checker(service);
77 checker.Wait();
78 return !checker.TimedOut();
79 }
80
81 bool AwaitTypeDisabled(ProfileSyncService* service,
82 syncer::ModelType type) {
83 TypeDisabledChecker checker(service, type);
84 checker.Wait();
85 return !checker.TimedOut();
86 }
87
88 class SyncErrorTest : public SyncTest { 69 class SyncErrorTest : public SyncTest {
89 public: 70 public:
90 SyncErrorTest() : SyncTest(SINGLE_CLIENT) {} 71 SyncErrorTest() : SyncTest(SINGLE_CLIENT) {}
91 ~SyncErrorTest() override {} 72 ~SyncErrorTest() override {}
92 73
93 private: 74 private:
94 DISALLOW_COPY_AND_ASSIGN(SyncErrorTest); 75 DISALLOW_COPY_AND_ASSIGN(SyncErrorTest);
95 }; 76 };
96 77
97 // Helper class that waits until the sync engine has hit an actionable error. 78 // Helper class that waits until the sync engine has hit an actionable error.
(...skipping 20 matching lines...) Expand all
118 private: 99 private:
119 DISALLOW_COPY_AND_ASSIGN(ActionableErrorChecker); 100 DISALLOW_COPY_AND_ASSIGN(ActionableErrorChecker);
120 }; 101 };
121 102
122 IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorTest) { 103 IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorTest) {
123 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 104 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
124 105
125 // Add an item, wait for sync, and trigger a birthday error on the server. 106 // Add an item, wait for sync, and trigger a birthday error on the server.
126 const BookmarkNode* node1 = AddFolder(0, 0, "title1"); 107 const BookmarkNode* node1 = AddFolder(0, 0, "title1");
127 SetTitle(0, node1, "new_title1"); 108 SetTitle(0, node1, "new_title1");
128 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); 109 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
129 GetFakeServer()->ClearServerData(); 110 GetFakeServer()->ClearServerData();
130 111
131 // Now make one more change so we will do another sync. 112 // Now make one more change so we will do another sync.
132 const BookmarkNode* node2 = AddFolder(0, 0, "title2"); 113 const BookmarkNode* node2 = AddFolder(0, 0, "title2");
133 SetTitle(0, node2, "new_title2"); 114 SetTitle(0, node2, "new_title2");
134 ASSERT_TRUE(AwaitSyncDisabled(GetSyncService(0))); 115 ASSERT_TRUE(SyncDisabledChecker(GetSyncService(0)).Wait());
135 } 116 }
136 117
137 IN_PROC_BROWSER_TEST_F(SyncErrorTest, ActionableErrorTest) { 118 IN_PROC_BROWSER_TEST_F(SyncErrorTest, ActionableErrorTest) {
138 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 119 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
139 120
140 const BookmarkNode* node1 = AddFolder(0, 0, "title1"); 121 const BookmarkNode* node1 = AddFolder(0, 0, "title1");
141 SetTitle(0, node1, "new_title1"); 122 SetTitle(0, node1, "new_title1");
142 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); 123 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
143 124
144 std::string description = "Not My Fault"; 125 std::string description = "Not My Fault";
145 std::string url = "www.google.com"; 126 std::string url = "www.google.com";
146 EXPECT_TRUE(GetFakeServer()->TriggerActionableError( 127 EXPECT_TRUE(GetFakeServer()->TriggerActionableError(
147 sync_pb::SyncEnums::TRANSIENT_ERROR, 128 sync_pb::SyncEnums::TRANSIENT_ERROR,
148 description, 129 description,
149 url, 130 url,
150 sync_pb::SyncEnums::UPGRADE_CLIENT)); 131 sync_pb::SyncEnums::UPGRADE_CLIENT));
151 132
152 // Now make one more change so we will do another sync. 133 // Now make one more change so we will do another sync.
153 const BookmarkNode* node2 = AddFolder(0, 0, "title2"); 134 const BookmarkNode* node2 = AddFolder(0, 0, "title2");
154 SetTitle(0, node2, "new_title2"); 135 SetTitle(0, node2, "new_title2");
155 136
156 // Wait until an actionable error is encountered. 137 // Wait until an actionable error is encountered.
157 ActionableErrorChecker actionable_error_checker(GetSyncService(0)); 138 ASSERT_TRUE(ActionableErrorChecker(GetSyncService(0)).Wait());
158 actionable_error_checker.Wait();
159 ASSERT_FALSE(actionable_error_checker.TimedOut());
160 139
161 ProfileSyncService::Status status; 140 ProfileSyncService::Status status;
162 GetSyncService(0)->QueryDetailedSyncStatus(&status); 141 GetSyncService(0)->QueryDetailedSyncStatus(&status);
163 ASSERT_EQ(status.sync_protocol_error.error_type, syncer::TRANSIENT_ERROR); 142 ASSERT_EQ(status.sync_protocol_error.error_type, syncer::TRANSIENT_ERROR);
164 ASSERT_EQ(status.sync_protocol_error.action, syncer::UPGRADE_CLIENT); 143 ASSERT_EQ(status.sync_protocol_error.action, syncer::UPGRADE_CLIENT);
165 ASSERT_EQ(status.sync_protocol_error.url, url); 144 ASSERT_EQ(status.sync_protocol_error.url, url);
166 ASSERT_EQ(status.sync_protocol_error.error_description, description); 145 ASSERT_EQ(status.sync_protocol_error.error_description, description);
167 } 146 }
168 147
169 // This test verifies that sync keeps retrying if it encounters error during 148 // This test verifies that sync keeps retrying if it encounters error during
(...skipping 22 matching lines...) Expand all
192 // recover and setup succesfully on the third attempt. 171 // recover and setup succesfully on the third attempt.
193 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(syncer::AUTOFILL)); 172 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(syncer::AUTOFILL));
194 #endif 173 #endif
195 } 174 }
196 175
197 IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorUsingActionableErrorTest) { 176 IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorUsingActionableErrorTest) {
198 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 177 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
199 178
200 const BookmarkNode* node1 = AddFolder(0, 0, "title1"); 179 const BookmarkNode* node1 = AddFolder(0, 0, "title1");
201 SetTitle(0, node1, "new_title1"); 180 SetTitle(0, node1, "new_title1");
202 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); 181 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
203 182
204 std::string description = "Not My Fault"; 183 std::string description = "Not My Fault";
205 std::string url = "www.google.com"; 184 std::string url = "www.google.com";
206 EXPECT_TRUE(GetFakeServer()->TriggerActionableError( 185 EXPECT_TRUE(GetFakeServer()->TriggerActionableError(
207 sync_pb::SyncEnums::NOT_MY_BIRTHDAY, 186 sync_pb::SyncEnums::NOT_MY_BIRTHDAY,
208 description, 187 description,
209 url, 188 url,
210 sync_pb::SyncEnums::DISABLE_SYNC_ON_CLIENT)); 189 sync_pb::SyncEnums::DISABLE_SYNC_ON_CLIENT));
211 190
212 // Now make one more change so we will do another sync. 191 // Now make one more change so we will do another sync.
213 const BookmarkNode* node2 = AddFolder(0, 0, "title2"); 192 const BookmarkNode* node2 = AddFolder(0, 0, "title2");
214 SetTitle(0, node2, "new_title2"); 193 SetTitle(0, node2, "new_title2");
215 ASSERT_TRUE(AwaitSyncDisabled(GetSyncService(0))); 194 ASSERT_TRUE(SyncDisabledChecker(GetSyncService(0)).Wait());
216 ProfileSyncService::Status status; 195 ProfileSyncService::Status status;
217 GetSyncService(0)->QueryDetailedSyncStatus(&status); 196 GetSyncService(0)->QueryDetailedSyncStatus(&status);
218 ASSERT_EQ(status.sync_protocol_error.error_type, syncer::NOT_MY_BIRTHDAY); 197 ASSERT_EQ(status.sync_protocol_error.error_type, syncer::NOT_MY_BIRTHDAY);
219 ASSERT_EQ(status.sync_protocol_error.action, syncer::DISABLE_SYNC_ON_CLIENT); 198 ASSERT_EQ(status.sync_protocol_error.action, syncer::DISABLE_SYNC_ON_CLIENT);
220 ASSERT_EQ(status.sync_protocol_error.url, url); 199 ASSERT_EQ(status.sync_protocol_error.url, url);
221 ASSERT_EQ(status.sync_protocol_error.error_description, description); 200 ASSERT_EQ(status.sync_protocol_error.error_description, description);
222 } 201 }
223 202
224 // Tests that on receiving CLIENT_DATA_OBSOLETE sync backend gets restarted and 203 // Tests that on receiving CLIENT_DATA_OBSOLETE sync backend gets restarted and
225 // initialized with different cache_guld. 204 // initialized with different cache_guld.
226 IN_PROC_BROWSER_TEST_F(SyncErrorTest, ClientDataObsoleteTest) { 205 IN_PROC_BROWSER_TEST_F(SyncErrorTest, ClientDataObsoleteTest) {
227 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 206 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
228 207
229 const BookmarkNode* node1 = AddFolder(0, 0, "title1"); 208 const BookmarkNode* node1 = AddFolder(0, 0, "title1");
230 SetTitle(0, node1, "new_title1"); 209 SetTitle(0, node1, "new_title1");
231 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); 210 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
232 211
233 std::string description = "Not My Fault"; 212 std::string description = "Not My Fault";
234 std::string url = "www.google.com"; 213 std::string url = "www.google.com";
235 214
236 // Remember cache_guid before actionable error. 215 // Remember cache_guid before actionable error.
237 ProfileSyncService::Status status; 216 ProfileSyncService::Status status;
238 GetSyncService(0)->QueryDetailedSyncStatus(&status); 217 GetSyncService(0)->QueryDetailedSyncStatus(&status);
239 std::string old_cache_guid = status.sync_id; 218 std::string old_cache_guid = status.sync_id;
240 219
241 EXPECT_TRUE( 220 EXPECT_TRUE(
242 GetFakeServer()->TriggerError(sync_pb::SyncEnums::CLIENT_DATA_OBSOLETE)); 221 GetFakeServer()->TriggerError(sync_pb::SyncEnums::CLIENT_DATA_OBSOLETE));
243 222
244 // Trigger sync by making one more change. 223 // Trigger sync by making one more change.
245 const BookmarkNode* node2 = AddFolder(0, 0, "title2"); 224 const BookmarkNode* node2 = AddFolder(0, 0, "title2");
246 SetTitle(0, node2, "new_title2"); 225 SetTitle(0, node2, "new_title2");
247 226
248 ASSERT_TRUE(AwaitSyncBackendStopped(GetSyncService(0))); 227 ASSERT_TRUE(SyncBackendStoppedChecker(GetSyncService(0)).Wait());
249 228
250 // Make server return SUCCESS so that sync can initialize. 229 // Make server return SUCCESS so that sync can initialize.
251 EXPECT_TRUE(GetFakeServer()->TriggerError(sync_pb::SyncEnums::SUCCESS)); 230 EXPECT_TRUE(GetFakeServer()->TriggerError(sync_pb::SyncEnums::SUCCESS));
252 231
253 ASSERT_TRUE(GetClient(0)->AwaitBackendInitialization()); 232 ASSERT_TRUE(GetClient(0)->AwaitBackendInitialization());
254 233
255 // Ensure cache_guid changed. 234 // Ensure cache_guid changed.
256 GetSyncService(0)->QueryDetailedSyncStatus(&status); 235 GetSyncService(0)->QueryDetailedSyncStatus(&status);
257 ASSERT_NE(old_cache_guid, status.sync_id); 236 ASSERT_NE(old_cache_guid, status.sync_id);
258 } 237 }
259 238
260 IN_PROC_BROWSER_TEST_F(SyncErrorTest, DisableDatatypeWhileRunning) { 239 IN_PROC_BROWSER_TEST_F(SyncErrorTest, DisableDatatypeWhileRunning) {
261 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 240 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
262 syncer::ModelTypeSet synced_datatypes = 241 syncer::ModelTypeSet synced_datatypes =
263 GetSyncService(0)->GetActiveDataTypes(); 242 GetSyncService(0)->GetActiveDataTypes();
264 ASSERT_TRUE(synced_datatypes.Has(syncer::TYPED_URLS)); 243 ASSERT_TRUE(synced_datatypes.Has(syncer::TYPED_URLS));
265 ASSERT_TRUE(synced_datatypes.Has(syncer::SESSIONS)); 244 ASSERT_TRUE(synced_datatypes.Has(syncer::SESSIONS));
266 GetProfile(0)->GetPrefs()->SetBoolean( 245 GetProfile(0)->GetPrefs()->SetBoolean(
267 prefs::kSavingBrowserHistoryDisabled, true); 246 prefs::kSavingBrowserHistoryDisabled, true);
268 247
269 // Wait for reconfigurations. 248 // Wait for reconfigurations.
270 ASSERT_TRUE(AwaitTypeDisabled(GetSyncService(0), syncer::TYPED_URLS)); 249 ASSERT_TRUE(
271 ASSERT_TRUE(AwaitTypeDisabled(GetSyncService(0), syncer::SESSIONS)); 250 TypeDisabledChecker(GetSyncService(0), syncer::TYPED_URLS).Wait());
251 ASSERT_TRUE(TypeDisabledChecker(GetSyncService(0), syncer::SESSIONS).Wait());
272 252
273 const BookmarkNode* node1 = AddFolder(0, 0, "title1"); 253 const BookmarkNode* node1 = AddFolder(0, 0, "title1");
274 SetTitle(0, node1, "new_title1"); 254 SetTitle(0, node1, "new_title1");
275 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); 255 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
276 // TODO(lipalani)" Verify initial sync ended for typed url is false. 256 // TODO(lipalani): Verify initial sync ended for typed url is false.
277 } 257 }
278 258
279 } // namespace 259 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698