OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "chrome/browser/sync/engine/apply_updates_command.h" | 10 #include "chrome/browser/sync/engine/apply_updates_command.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 string root_server_id = syncable::GetNullId().GetServerId(); | 155 string root_server_id = syncable::GetNullId().GetServerId(); |
156 CreateUnappliedNewItemWithParent("parent", | 156 CreateUnappliedNewItemWithParent("parent", |
157 DefaultBookmarkSpecifics(), | 157 DefaultBookmarkSpecifics(), |
158 root_server_id); | 158 root_server_id); |
159 CreateUnappliedNewItemWithParent("child", | 159 CreateUnappliedNewItemWithParent("child", |
160 DefaultBookmarkSpecifics(), | 160 DefaultBookmarkSpecifics(), |
161 "parent"); | 161 "parent"); |
162 | 162 |
163 apply_updates_command_.ExecuteImpl(session()); | 163 apply_updates_command_.ExecuteImpl(session()); |
164 | 164 |
165 sessions::StatusController* status = session()->status_controller(); | 165 sessions::StatusController* status = session()->mutable_status_controller(); |
166 | 166 |
167 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); | 167 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); |
168 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) | 168 ASSERT_TRUE(status->update_progress()); |
| 169 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize()) |
169 << "All updates should have been attempted"; | 170 << "All updates should have been attempted"; |
170 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 171 ASSERT_TRUE(status->conflict_progress()); |
| 172 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
171 << "Simple update shouldn't result in conflicts"; | 173 << "Simple update shouldn't result in conflicts"; |
172 EXPECT_EQ(2, status->update_progress().SuccessfullyAppliedUpdateCount()) | 174 EXPECT_EQ(2, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
173 << "All items should have been successfully applied"; | 175 << "All items should have been successfully applied"; |
174 } | 176 } |
175 | 177 |
176 TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) { | 178 TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) { |
177 // Set a bunch of updates which are difficult to apply in the order | 179 // Set a bunch of updates which are difficult to apply in the order |
178 // they're received due to dependencies on other unseen items. | 180 // they're received due to dependencies on other unseen items. |
179 string root_server_id = syncable::GetNullId().GetServerId(); | 181 string root_server_id = syncable::GetNullId().GetServerId(); |
180 CreateUnappliedNewItemWithParent("a_child_created_first", | 182 CreateUnappliedNewItemWithParent("a_child_created_first", |
181 DefaultBookmarkSpecifics(), | 183 DefaultBookmarkSpecifics(), |
182 "parent"); | 184 "parent"); |
183 CreateUnappliedNewItemWithParent("x_child_created_first", | 185 CreateUnappliedNewItemWithParent("x_child_created_first", |
184 DefaultBookmarkSpecifics(), | 186 DefaultBookmarkSpecifics(), |
185 "parent"); | 187 "parent"); |
186 CreateUnappliedNewItemWithParent("parent", | 188 CreateUnappliedNewItemWithParent("parent", |
187 DefaultBookmarkSpecifics(), | 189 DefaultBookmarkSpecifics(), |
188 root_server_id); | 190 root_server_id); |
189 CreateUnappliedNewItemWithParent("a_child_created_second", | 191 CreateUnappliedNewItemWithParent("a_child_created_second", |
190 DefaultBookmarkSpecifics(), | 192 DefaultBookmarkSpecifics(), |
191 "parent"); | 193 "parent"); |
192 CreateUnappliedNewItemWithParent("x_child_created_second", | 194 CreateUnappliedNewItemWithParent("x_child_created_second", |
193 DefaultBookmarkSpecifics(), | 195 DefaultBookmarkSpecifics(), |
194 "parent"); | 196 "parent"); |
195 | 197 |
196 apply_updates_command_.ExecuteImpl(session()); | 198 apply_updates_command_.ExecuteImpl(session()); |
197 | 199 |
198 sessions::StatusController* status = session()->status_controller(); | 200 sessions::StatusController* status = session()->mutable_status_controller(); |
199 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); | 201 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); |
200 EXPECT_EQ(5, status->update_progress().AppliedUpdatesSize()) | 202 ASSERT_TRUE(status->update_progress()); |
| 203 EXPECT_EQ(5, status->update_progress()->AppliedUpdatesSize()) |
201 << "All updates should have been attempted"; | 204 << "All updates should have been attempted"; |
202 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 205 ASSERT_TRUE(status->conflict_progress()); |
| 206 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
203 << "Simple update shouldn't result in conflicts, even if out-of-order"; | 207 << "Simple update shouldn't result in conflicts, even if out-of-order"; |
204 EXPECT_EQ(5, status->update_progress().SuccessfullyAppliedUpdateCount()) | 208 EXPECT_EQ(5, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
205 << "All updates should have been successfully applied"; | 209 << "All updates should have been successfully applied"; |
206 } | 210 } |
207 | 211 |
208 TEST_F(ApplyUpdatesCommandTest, NestedItemsWithUnknownParent) { | 212 TEST_F(ApplyUpdatesCommandTest, NestedItemsWithUnknownParent) { |
209 // We shouldn't be able to do anything with either of these items. | 213 // We shouldn't be able to do anything with either of these items. |
210 CreateUnappliedNewItemWithParent("some_item", | 214 CreateUnappliedNewItemWithParent("some_item", |
211 DefaultBookmarkSpecifics(), | 215 DefaultBookmarkSpecifics(), |
212 "unknown_parent"); | 216 "unknown_parent"); |
213 CreateUnappliedNewItemWithParent("some_other_item", | 217 CreateUnappliedNewItemWithParent("some_other_item", |
214 DefaultBookmarkSpecifics(), | 218 DefaultBookmarkSpecifics(), |
215 "some_item"); | 219 "some_item"); |
216 | 220 |
217 apply_updates_command_.ExecuteImpl(session()); | 221 apply_updates_command_.ExecuteImpl(session()); |
218 | 222 |
219 sessions::StatusController* status = session()->status_controller(); | 223 sessions::StatusController* status = session()->mutable_status_controller(); |
220 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); | 224 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); |
221 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) | 225 ASSERT_TRUE(status->update_progress()); |
| 226 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize()) |
222 << "All updates should have been attempted"; | 227 << "All updates should have been attempted"; |
223 EXPECT_EQ(2, status->conflict_progress().ConflictingItemsSize()) | 228 ASSERT_TRUE(status->conflict_progress()); |
| 229 EXPECT_EQ(2, status->conflict_progress()->ConflictingItemsSize()) |
224 << "All updates with an unknown ancestors should be in conflict"; | 230 << "All updates with an unknown ancestors should be in conflict"; |
225 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount()) | 231 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
226 << "No item with an unknown ancestor should be applied"; | 232 << "No item with an unknown ancestor should be applied"; |
227 } | 233 } |
228 | 234 |
229 TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) { | 235 TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) { |
230 // See what happens when there's a mixture of good and bad updates. | 236 // See what happens when there's a mixture of good and bad updates. |
231 string root_server_id = syncable::GetNullId().GetServerId(); | 237 string root_server_id = syncable::GetNullId().GetServerId(); |
232 CreateUnappliedNewItemWithParent("first_unknown_item", | 238 CreateUnappliedNewItemWithParent("first_unknown_item", |
233 DefaultBookmarkSpecifics(), | 239 DefaultBookmarkSpecifics(), |
234 "unknown_parent"); | 240 "unknown_parent"); |
235 CreateUnappliedNewItemWithParent("first_known_item", | 241 CreateUnappliedNewItemWithParent("first_known_item", |
236 DefaultBookmarkSpecifics(), | 242 DefaultBookmarkSpecifics(), |
237 root_server_id); | 243 root_server_id); |
238 CreateUnappliedNewItemWithParent("second_unknown_item", | 244 CreateUnappliedNewItemWithParent("second_unknown_item", |
239 DefaultBookmarkSpecifics(), | 245 DefaultBookmarkSpecifics(), |
240 "unknown_parent"); | 246 "unknown_parent"); |
241 CreateUnappliedNewItemWithParent("second_known_item", | 247 CreateUnappliedNewItemWithParent("second_known_item", |
242 DefaultBookmarkSpecifics(), | 248 DefaultBookmarkSpecifics(), |
243 "first_known_item"); | 249 "first_known_item"); |
244 CreateUnappliedNewItemWithParent("third_known_item", | 250 CreateUnappliedNewItemWithParent("third_known_item", |
245 DefaultBookmarkSpecifics(), | 251 DefaultBookmarkSpecifics(), |
246 "fourth_known_item"); | 252 "fourth_known_item"); |
247 CreateUnappliedNewItemWithParent("fourth_known_item", | 253 CreateUnappliedNewItemWithParent("fourth_known_item", |
248 DefaultBookmarkSpecifics(), | 254 DefaultBookmarkSpecifics(), |
249 root_server_id); | 255 root_server_id); |
250 | 256 |
251 apply_updates_command_.ExecuteImpl(session()); | 257 apply_updates_command_.ExecuteImpl(session()); |
252 | 258 |
253 sessions::StatusController* status = session()->status_controller(); | 259 sessions::StatusController* status = session()->mutable_status_controller(); |
254 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); | 260 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); |
255 EXPECT_EQ(6, status->update_progress().AppliedUpdatesSize()) | 261 ASSERT_TRUE(status->update_progress()); |
| 262 EXPECT_EQ(6, status->update_progress()->AppliedUpdatesSize()) |
256 << "All updates should have been attempted"; | 263 << "All updates should have been attempted"; |
257 EXPECT_EQ(2, status->conflict_progress().ConflictingItemsSize()) | 264 ASSERT_TRUE(status->conflict_progress()); |
| 265 EXPECT_EQ(2, status->conflict_progress()->ConflictingItemsSize()) |
258 << "The updates with unknown ancestors should be in conflict"; | 266 << "The updates with unknown ancestors should be in conflict"; |
259 EXPECT_EQ(4, status->update_progress().SuccessfullyAppliedUpdateCount()) | 267 EXPECT_EQ(4, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
260 << "The updates with known ancestors should be successfully applied"; | 268 << "The updates with known ancestors should be successfully applied"; |
261 } | 269 } |
262 | 270 |
263 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) { | 271 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) { |
264 // Decryptable password updates should be applied. | 272 // Decryptable password updates should be applied. |
265 Cryptographer* cryptographer; | 273 Cryptographer* cryptographer; |
266 { | 274 { |
267 // Storing the cryptographer separately is bad, but for this test we | 275 // Storing the cryptographer separately is bad, but for this test we |
268 // know it's safe. | 276 // know it's safe. |
269 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 277 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
270 ASSERT_TRUE(dir.good()); | 278 ASSERT_TRUE(dir.good()); |
271 ReadTransaction trans(FROM_HERE, dir); | 279 ReadTransaction trans(FROM_HERE, dir); |
272 cryptographer = | 280 cryptographer = |
273 session()->context()->directory_manager()->GetCryptographer(&trans); | 281 session()->context()->directory_manager()->GetCryptographer(&trans); |
274 } | 282 } |
275 | 283 |
276 browser_sync::KeyParams params = {"localhost", "dummy", "foobar"}; | 284 browser_sync::KeyParams params = {"localhost", "dummy", "foobar"}; |
277 cryptographer->AddKey(params); | 285 cryptographer->AddKey(params); |
278 | 286 |
279 sync_pb::EntitySpecifics specifics; | 287 sync_pb::EntitySpecifics specifics; |
280 sync_pb::PasswordSpecificsData data; | 288 sync_pb::PasswordSpecificsData data; |
281 data.set_origin("http://example.com"); | 289 data.set_origin("http://example.com"); |
282 | 290 |
283 cryptographer->Encrypt(data, | 291 cryptographer->Encrypt(data, |
284 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); | 292 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); |
285 CreateUnappliedNewItem("item", specifics, false); | 293 CreateUnappliedNewItem("item", specifics, false); |
286 | 294 |
287 apply_updates_command_.ExecuteImpl(session()); | 295 apply_updates_command_.ExecuteImpl(session()); |
288 | 296 |
289 sessions::StatusController* status = session()->status_controller(); | 297 sessions::StatusController* status = session()->mutable_status_controller(); |
290 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); | 298 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); |
291 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) | 299 ASSERT_TRUE(status->update_progress()); |
| 300 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
292 << "All updates should have been attempted"; | 301 << "All updates should have been attempted"; |
293 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 302 ASSERT_TRUE(status->conflict_progress()); |
| 303 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
294 << "No update should be in conflict because they're all decryptable"; | 304 << "No update should be in conflict because they're all decryptable"; |
295 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) | 305 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
296 << "The updates that can be decrypted should be applied"; | 306 << "The updates that can be decrypted should be applied"; |
297 } | 307 } |
298 | 308 |
299 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) { | 309 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) { |
300 // Undecryptable updates should not be applied. | 310 // Undecryptable updates should not be applied. |
301 sync_pb::EntitySpecifics encrypted_bookmark; | 311 sync_pb::EntitySpecifics encrypted_bookmark; |
302 encrypted_bookmark.mutable_encrypted(); | 312 encrypted_bookmark.mutable_encrypted(); |
303 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); | 313 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); |
304 string root_server_id = syncable::GetNullId().GetServerId(); | 314 string root_server_id = syncable::GetNullId().GetServerId(); |
305 CreateUnappliedNewItemWithParent("folder", | 315 CreateUnappliedNewItemWithParent("folder", |
306 encrypted_bookmark, | 316 encrypted_bookmark, |
307 root_server_id); | 317 root_server_id); |
308 CreateUnappliedNewItem("item2", encrypted_bookmark, false); | 318 CreateUnappliedNewItem("item2", encrypted_bookmark, false); |
309 sync_pb::EntitySpecifics encrypted_password; | 319 sync_pb::EntitySpecifics encrypted_password; |
310 encrypted_password.MutableExtension(sync_pb::password); | 320 encrypted_password.MutableExtension(sync_pb::password); |
311 CreateUnappliedNewItem("item3", encrypted_password, false); | 321 CreateUnappliedNewItem("item3", encrypted_password, false); |
312 | 322 |
313 apply_updates_command_.ExecuteImpl(session()); | 323 apply_updates_command_.ExecuteImpl(session()); |
314 | 324 |
315 sessions::StatusController* status = session()->status_controller(); | 325 sessions::StatusController* status = session()->mutable_status_controller(); |
316 EXPECT_TRUE(status->HasConflictingUpdates()) | 326 EXPECT_TRUE(status->HasConflictingUpdates()) |
317 << "Updates that can't be decrypted should trigger the syncer to have " | 327 << "Updates that can't be decrypted should trigger the syncer to have " |
318 << "conflicting updates."; | 328 << "conflicting updates."; |
319 { | 329 { |
320 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); | 330 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); |
321 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) | 331 ASSERT_TRUE(status->update_progress()); |
| 332 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize()) |
322 << "All updates should have been attempted"; | 333 << "All updates should have been attempted"; |
323 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 334 ASSERT_TRUE(status->conflict_progress()); |
| 335 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
324 << "The updates that can't be decrypted should not be in regular " | 336 << "The updates that can't be decrypted should not be in regular " |
325 << "conflict"; | 337 << "conflict"; |
326 EXPECT_EQ(2, status->conflict_progress().NonblockingConflictingItemsSize()) | 338 EXPECT_EQ(2, status->conflict_progress()->NonblockingConflictingItemsSize()) |
327 << "The updates that can't be decrypted should be in nonblocking " | 339 << "The updates that can't be decrypted should be in nonblocking " |
328 << "conflict"; | 340 << "conflict"; |
329 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount()) | 341 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
330 << "No update that can't be decrypted should be applied"; | 342 << "No update that can't be decrypted should be applied"; |
331 } | 343 } |
332 { | 344 { |
333 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); | 345 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); |
334 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) | 346 ASSERT_TRUE(status->update_progress()); |
| 347 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
335 << "All updates should have been attempted"; | 348 << "All updates should have been attempted"; |
336 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 349 ASSERT_TRUE(status->conflict_progress()); |
| 350 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
337 << "The updates that can't be decrypted should not be in regular " | 351 << "The updates that can't be decrypted should not be in regular " |
338 << "conflict"; | 352 << "conflict"; |
339 EXPECT_EQ(1, status->conflict_progress().NonblockingConflictingItemsSize()) | 353 EXPECT_EQ(1, status->conflict_progress()->NonblockingConflictingItemsSize()) |
340 << "The updates that can't be decrypted should be in nonblocking " | 354 << "The updates that can't be decrypted should be in nonblocking " |
341 << "conflict"; | 355 << "conflict"; |
342 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount()) | 356 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
343 << "No update that can't be decrypted should be applied"; | 357 << "No update that can't be decrypted should be applied"; |
344 } | 358 } |
345 } | 359 } |
346 | 360 |
347 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) { | 361 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) { |
348 // Only decryptable password updates should be applied. | 362 // Only decryptable password updates should be applied. |
349 { | 363 { |
350 sync_pb::EntitySpecifics specifics; | 364 sync_pb::EntitySpecifics specifics; |
351 sync_pb::PasswordSpecificsData data; | 365 sync_pb::PasswordSpecificsData data; |
352 data.set_origin("http://example.com/1"); | 366 data.set_origin("http://example.com/1"); |
(...skipping 22 matching lines...) Expand all Loading... |
375 sync_pb::PasswordSpecificsData data; | 389 sync_pb::PasswordSpecificsData data; |
376 data.set_origin("http://example.com/2"); | 390 data.set_origin("http://example.com/2"); |
377 | 391 |
378 cryptographer.Encrypt(data, | 392 cryptographer.Encrypt(data, |
379 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); | 393 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); |
380 CreateUnappliedNewItem("item2", specifics, false); | 394 CreateUnappliedNewItem("item2", specifics, false); |
381 } | 395 } |
382 | 396 |
383 apply_updates_command_.ExecuteImpl(session()); | 397 apply_updates_command_.ExecuteImpl(session()); |
384 | 398 |
385 sessions::StatusController* status = session()->status_controller(); | 399 sessions::StatusController* status = session()->mutable_status_controller(); |
386 EXPECT_TRUE(status->HasConflictingUpdates()) | 400 EXPECT_TRUE(status->HasConflictingUpdates()) |
387 << "Updates that can't be decrypted should trigger the syncer to have " | 401 << "Updates that can't be decrypted should trigger the syncer to have " |
388 << "conflicting updates."; | 402 << "conflicting updates."; |
389 { | 403 { |
390 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); | 404 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); |
391 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) | 405 ASSERT_TRUE(status->update_progress()); |
| 406 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize()) |
392 << "All updates should have been attempted"; | 407 << "All updates should have been attempted"; |
393 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 408 ASSERT_TRUE(status->conflict_progress()); |
| 409 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
394 << "The updates that can't be decrypted should not be in regular " | 410 << "The updates that can't be decrypted should not be in regular " |
395 << "conflict"; | 411 << "conflict"; |
396 EXPECT_EQ(1, status->conflict_progress().NonblockingConflictingItemsSize()) | 412 EXPECT_EQ(1, status->conflict_progress()->NonblockingConflictingItemsSize()) |
397 << "The updates that can't be decrypted should be in nonblocking " | 413 << "The updates that can't be decrypted should be in nonblocking " |
398 << "conflict"; | 414 << "conflict"; |
399 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) | 415 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
400 << "The undecryptable password update shouldn't be applied"; | 416 << "The undecryptable password update shouldn't be applied"; |
401 } | 417 } |
402 } | 418 } |
403 | 419 |
404 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { | 420 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { |
405 // Storing the cryptographer separately is bad, but for this test we | 421 // Storing the cryptographer separately is bad, but for this test we |
406 // know it's safe. | 422 // know it's safe. |
407 Cryptographer* cryptographer; | 423 Cryptographer* cryptographer; |
408 syncable::ModelTypeSet encrypted_types; | 424 syncable::ModelTypeSet encrypted_types; |
409 encrypted_types.insert(syncable::PASSWORDS); | 425 encrypted_types.insert(syncable::PASSWORDS); |
(...skipping 17 matching lines...) Expand all Loading... |
427 specifics.MutableExtension(sync_pb::nigori); | 443 specifics.MutableExtension(sync_pb::nigori); |
428 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 444 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
429 nigori->set_encrypt_bookmarks(true); | 445 nigori->set_encrypt_bookmarks(true); |
430 encrypted_types.insert(syncable::BOOKMARKS); | 446 encrypted_types.insert(syncable::BOOKMARKS); |
431 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), | 447 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), |
432 specifics, true); | 448 specifics, true); |
433 EXPECT_FALSE(cryptographer->has_pending_keys()); | 449 EXPECT_FALSE(cryptographer->has_pending_keys()); |
434 | 450 |
435 apply_updates_command_.ExecuteImpl(session()); | 451 apply_updates_command_.ExecuteImpl(session()); |
436 | 452 |
437 sessions::StatusController* status = session()->status_controller(); | 453 sessions::StatusController* status = session()->mutable_status_controller(); |
438 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 454 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
439 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) | 455 ASSERT_TRUE(status->update_progress()); |
| 456 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
440 << "All updates should have been attempted"; | 457 << "All updates should have been attempted"; |
441 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 458 ASSERT_TRUE(status->conflict_progress()); |
| 459 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
442 << "The nigori update shouldn't be in conflict"; | 460 << "The nigori update shouldn't be in conflict"; |
443 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) | 461 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
444 << "The nigori update should be applied"; | 462 << "The nigori update should be applied"; |
445 | 463 |
446 EXPECT_FALSE(cryptographer->is_ready()); | 464 EXPECT_FALSE(cryptographer->is_ready()); |
447 EXPECT_TRUE(cryptographer->has_pending_keys()); | 465 EXPECT_TRUE(cryptographer->has_pending_keys()); |
448 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); | 466 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); |
449 } | 467 } |
450 | 468 |
451 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) { | 469 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) { |
452 // Storing the cryptographer separately is bad, but for this test we | 470 // Storing the cryptographer separately is bad, but for this test we |
453 // know it's safe. | 471 // know it's safe. |
(...skipping 22 matching lines...) Expand all Loading... |
476 nigori->set_encrypt_sessions(true); | 494 nigori->set_encrypt_sessions(true); |
477 nigori->set_encrypt_themes(true); | 495 nigori->set_encrypt_themes(true); |
478 encrypted_types.insert(syncable::SESSIONS); | 496 encrypted_types.insert(syncable::SESSIONS); |
479 encrypted_types.insert(syncable::THEMES); | 497 encrypted_types.insert(syncable::THEMES); |
480 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), | 498 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), |
481 specifics, true); | 499 specifics, true); |
482 EXPECT_FALSE(cryptographer->has_pending_keys()); | 500 EXPECT_FALSE(cryptographer->has_pending_keys()); |
483 | 501 |
484 apply_updates_command_.ExecuteImpl(session()); | 502 apply_updates_command_.ExecuteImpl(session()); |
485 | 503 |
486 sessions::StatusController* status = session()->status_controller(); | 504 sessions::StatusController* status = session()->mutable_status_controller(); |
487 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 505 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
488 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) | 506 ASSERT_TRUE(status->update_progress()); |
| 507 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
489 << "All updates should have been attempted"; | 508 << "All updates should have been attempted"; |
490 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 509 ASSERT_TRUE(status->conflict_progress()); |
| 510 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
491 << "The nigori update shouldn't be in conflict"; | 511 << "The nigori update shouldn't be in conflict"; |
492 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) | 512 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
493 << "The nigori update should be applied"; | 513 << "The nigori update should be applied"; |
494 | 514 |
495 EXPECT_FALSE(cryptographer->is_ready()); | 515 EXPECT_FALSE(cryptographer->is_ready()); |
496 EXPECT_TRUE(cryptographer->has_pending_keys()); | 516 EXPECT_TRUE(cryptographer->has_pending_keys()); |
497 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); | 517 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); |
498 } | 518 } |
499 | 519 |
500 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { | 520 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { |
501 // Storing the cryptographer separately is bad, but for this test we | 521 // Storing the cryptographer separately is bad, but for this test we |
502 // know it's safe. | 522 // know it's safe. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 ReadTransaction trans(FROM_HERE, dir); | 581 ReadTransaction trans(FROM_HERE, dir); |
562 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 582 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
563 | 583 |
564 Syncer::UnsyncedMetaHandles handles; | 584 Syncer::UnsyncedMetaHandles handles; |
565 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 585 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
566 EXPECT_EQ(2*batch_s+1, handles.size()); | 586 EXPECT_EQ(2*batch_s+1, handles.size()); |
567 } | 587 } |
568 | 588 |
569 apply_updates_command_.ExecuteImpl(session()); | 589 apply_updates_command_.ExecuteImpl(session()); |
570 | 590 |
571 sessions::StatusController* status = session()->status_controller(); | 591 sessions::StatusController* status = session()->mutable_status_controller(); |
572 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 592 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
573 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) | 593 ASSERT_TRUE(status->update_progress()); |
| 594 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
574 << "All updates should have been attempted"; | 595 << "All updates should have been attempted"; |
575 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 596 ASSERT_TRUE(status->conflict_progress()); |
| 597 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
576 << "No updates should be in conflict"; | 598 << "No updates should be in conflict"; |
577 EXPECT_EQ(0, status->conflict_progress().NonblockingConflictingItemsSize()) | 599 EXPECT_EQ(0, status->conflict_progress()->NonblockingConflictingItemsSize()) |
578 << "No updates should be in conflict"; | 600 << "No updates should be in conflict"; |
579 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) | 601 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
580 << "The nigori update should be applied"; | 602 << "The nigori update should be applied"; |
581 EXPECT_FALSE(cryptographer->has_pending_keys()); | 603 EXPECT_FALSE(cryptographer->has_pending_keys()); |
582 EXPECT_TRUE(cryptographer->is_ready()); | 604 EXPECT_TRUE(cryptographer->is_ready()); |
583 { | 605 { |
584 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 606 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
585 ASSERT_TRUE(dir.good()); | 607 ASSERT_TRUE(dir.good()); |
586 ReadTransaction trans(FROM_HERE, dir); | 608 ReadTransaction trans(FROM_HERE, dir); |
587 | 609 |
588 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes | 610 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes |
589 // should be encrypted now. | 611 // should be encrypted now. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 ASSERT_TRUE(dir.good()); | 683 ASSERT_TRUE(dir.good()); |
662 ReadTransaction trans(FROM_HERE, dir); | 684 ReadTransaction trans(FROM_HERE, dir); |
663 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 685 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
664 Syncer::UnsyncedMetaHandles handles; | 686 Syncer::UnsyncedMetaHandles handles; |
665 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 687 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
666 EXPECT_EQ(2*batch_s+1, handles.size()); | 688 EXPECT_EQ(2*batch_s+1, handles.size()); |
667 } | 689 } |
668 | 690 |
669 apply_updates_command_.ExecuteImpl(session()); | 691 apply_updates_command_.ExecuteImpl(session()); |
670 | 692 |
671 sessions::StatusController* status = session()->status_controller(); | 693 sessions::StatusController* status = session()->mutable_status_controller(); |
672 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 694 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
673 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize()) | 695 ASSERT_TRUE(status->update_progress()); |
| 696 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
674 << "All updates should have been attempted"; | 697 << "All updates should have been attempted"; |
675 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 698 ASSERT_TRUE(status->conflict_progress()); |
| 699 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
676 << "The unsynced changes don't trigger a blocking conflict with the " | 700 << "The unsynced changes don't trigger a blocking conflict with the " |
677 << "nigori update."; | 701 << "nigori update."; |
678 EXPECT_EQ(1, status->conflict_progress().NonblockingConflictingItemsSize()) | 702 EXPECT_EQ(1, status->conflict_progress()->NonblockingConflictingItemsSize()) |
679 << "The unsynced changes trigger a non-blocking conflict with the " | 703 << "The unsynced changes trigger a non-blocking conflict with the " |
680 << "nigori update."; | 704 << "nigori update."; |
681 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount()) | 705 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
682 << "The nigori update should not be applied"; | 706 << "The nigori update should not be applied"; |
683 EXPECT_FALSE(cryptographer->is_ready()); | 707 EXPECT_FALSE(cryptographer->is_ready()); |
684 EXPECT_TRUE(cryptographer->has_pending_keys()); | 708 EXPECT_TRUE(cryptographer->has_pending_keys()); |
685 { | 709 { |
686 // Ensure the unsynced nodes are still not encrypted. | 710 // Ensure the unsynced nodes are still not encrypted. |
687 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 711 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
688 ASSERT_TRUE(dir.good()); | 712 ASSERT_TRUE(dir.good()); |
689 ReadTransaction trans(FROM_HERE, dir); | 713 ReadTransaction trans(FROM_HERE, dir); |
690 | 714 |
691 // Since we're in conflict, the specifics don't reflect the unapplied | 715 // Since we're in conflict, the specifics don't reflect the unapplied |
692 // changes. | 716 // changes. |
693 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 717 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
694 encrypted_types.clear(); | 718 encrypted_types.clear(); |
695 encrypted_types.insert(syncable::PASSWORDS); | 719 encrypted_types.insert(syncable::PASSWORDS); |
696 encrypted_types.insert(syncable::BOOKMARKS); | 720 encrypted_types.insert(syncable::BOOKMARKS); |
697 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); | 721 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); |
698 | 722 |
699 Syncer::UnsyncedMetaHandles handles; | 723 Syncer::UnsyncedMetaHandles handles; |
700 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 724 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
701 EXPECT_EQ(2*batch_s+1, handles.size()); | 725 EXPECT_EQ(2*batch_s+1, handles.size()); |
702 } | 726 } |
703 } | 727 } |
704 | 728 |
705 } // namespace browser_sync | 729 } // namespace browser_sync |
OLD | NEW |