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

Side by Side Diff: components/sync/syncable/directory_unittest.cc

Issue 2292393004: Remove stl_util from sync. (Closed)
Patch Set: rebase Created 4 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/sync/syncable/directory_unittest.h" 5 #include "components/sync/syncable/directory_unittest.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cstdlib> 10 #include <cstdlib>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/rand_util.h" 14 #include "base/rand_util.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/test/values_test_util.h" 17 #include "base/test/values_test_util.h"
17 #include "components/sync/base/attachment_id_proto.h" 18 #include "components/sync/base/attachment_id_proto.h"
18 #include "components/sync/base/mock_unrecoverable_error_handler.h" 19 #include "components/sync/base/mock_unrecoverable_error_handler.h"
19 #include "components/sync/syncable/syncable_proto_util.h" 20 #include "components/sync/syncable/syncable_proto_util.h"
20 #include "components/sync/syncable/syncable_util.h" 21 #include "components/sync/syncable/syncable_util.h"
21 #include "components/sync/syncable/syncable_write_transaction.h" 22 #include "components/sync/syncable/syncable_write_transaction.h"
22 #include "components/sync/test/engine/test_syncable_utils.h" 23 #include "components/sync/test/engine/test_syncable_utils.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 288 }
288 } 289 }
289 // Fake SaveChanges() and make sure we got what we expected. 290 // Fake SaveChanges() and make sure we got what we expected.
290 { 291 {
291 Directory::SaveChangesSnapshot snapshot; 292 Directory::SaveChangesSnapshot snapshot;
292 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); 293 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex);
293 dir()->TakeSnapshotForSaveChanges(&snapshot); 294 dir()->TakeSnapshotForSaveChanges(&snapshot);
294 // Make sure there's an entry for each new metahandle. Make sure all 295 // Make sure there's an entry for each new metahandle. Make sure all
295 // entries are marked dirty. 296 // entries are marked dirty.
296 ASSERT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); 297 ASSERT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size());
297 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); 298 for (auto i = snapshot.dirty_metas.begin(); i != snapshot.dirty_metas.end();
298 i != snapshot.dirty_metas.end(); ++i) { 299 ++i) {
299 ASSERT_TRUE((*i)->is_dirty()); 300 ASSERT_TRUE((*i)->is_dirty());
300 } 301 }
301 dir()->VacuumAfterSaveChanges(snapshot); 302 dir()->VacuumAfterSaveChanges(snapshot);
302 } 303 }
303 // Put a new value with existing transactions as well as adding new ones. 304 // Put a new value with existing transactions as well as adding new ones.
304 { 305 {
305 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); 306 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get());
306 std::vector<int64_t> new_dirty_metahandles; 307 std::vector<int64_t> new_dirty_metahandles;
307 for (std::vector<int64_t>::const_iterator i = 308 for (std::vector<int64_t>::const_iterator i =
308 expected_dirty_metahandles.begin(); 309 expected_dirty_metahandles.begin();
(...skipping 12 matching lines...) Expand all
321 new_dirty_metahandles.end()); 322 new_dirty_metahandles.end());
322 } 323 }
323 // Fake SaveChanges() and make sure we got what we expected. 324 // Fake SaveChanges() and make sure we got what we expected.
324 { 325 {
325 Directory::SaveChangesSnapshot snapshot; 326 Directory::SaveChangesSnapshot snapshot;
326 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); 327 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex);
327 dir()->TakeSnapshotForSaveChanges(&snapshot); 328 dir()->TakeSnapshotForSaveChanges(&snapshot);
328 // Make sure there's an entry for each new metahandle. Make sure all 329 // Make sure there's an entry for each new metahandle. Make sure all
329 // entries are marked dirty. 330 // entries are marked dirty.
330 EXPECT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); 331 EXPECT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size());
331 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); 332 for (auto i = snapshot.dirty_metas.begin(); i != snapshot.dirty_metas.end();
332 i != snapshot.dirty_metas.end(); ++i) { 333 ++i) {
333 EXPECT_TRUE((*i)->is_dirty()); 334 EXPECT_TRUE((*i)->is_dirty());
334 } 335 }
335 dir()->VacuumAfterSaveChanges(snapshot); 336 dir()->VacuumAfterSaveChanges(snapshot);
336 } 337 }
337 } 338 }
338 339
339 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { 340 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) {
340 const int metahandles_to_create = 100; 341 const int metahandles_to_create = 100;
341 342
342 // half of 2 * metahandles_to_create 343 // half of 2 * metahandles_to_create
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 412 }
412 } 413 }
413 // Fake SaveChanges() and make sure we got what we expected. 414 // Fake SaveChanges() and make sure we got what we expected.
414 { 415 {
415 Directory::SaveChangesSnapshot snapshot; 416 Directory::SaveChangesSnapshot snapshot;
416 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); 417 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex);
417 dir()->TakeSnapshotForSaveChanges(&snapshot); 418 dir()->TakeSnapshotForSaveChanges(&snapshot);
418 // Make sure there's an entry for each changed metahandle. Make sure all 419 // Make sure there's an entry for each changed metahandle. Make sure all
419 // entries are marked dirty. 420 // entries are marked dirty.
420 EXPECT_EQ(number_changed, snapshot.dirty_metas.size()); 421 EXPECT_EQ(number_changed, snapshot.dirty_metas.size());
421 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); 422 for (auto i = snapshot.dirty_metas.begin(); i != snapshot.dirty_metas.end();
422 i != snapshot.dirty_metas.end(); ++i) { 423 ++i) {
423 EXPECT_TRUE((*i)->is_dirty()); 424 EXPECT_TRUE((*i)->is_dirty());
424 } 425 }
425 dir()->VacuumAfterSaveChanges(snapshot); 426 dir()->VacuumAfterSaveChanges(snapshot);
426 } 427 }
427 } 428 }
428 429
429 // Test delete journals management. 430 // Test delete journals management.
430 TEST_F(SyncableDirectoryTest, ManageDeleteJournals) { 431 TEST_F(SyncableDirectoryTest, ManageDeleteJournals) {
431 sync_pb::EntitySpecifics bookmark_specifics; 432 sync_pb::EntitySpecifics bookmark_specifics;
432 AddDefaultFieldValue(BOOKMARKS, &bookmark_specifics); 433 AddDefaultFieldValue(BOOKMARKS, &bookmark_specifics);
(...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 EXPECT_EQ(Id(), item1.GetPredecessorId()); 2002 EXPECT_EQ(Id(), item1.GetPredecessorId());
2002 EXPECT_EQ(item2_id, item1.GetSuccessorId()); 2003 EXPECT_EQ(item2_id, item1.GetSuccessorId());
2003 2004
2004 Entry item2(&trans, GET_BY_ID, item2_id); 2005 Entry item2(&trans, GET_BY_ID, item2_id);
2005 EXPECT_EQ(item1_id, item2.GetPredecessorId()); 2006 EXPECT_EQ(item1_id, item2.GetPredecessorId());
2006 EXPECT_EQ(Id(), item2.GetSuccessorId()); 2007 EXPECT_EQ(Id(), item2.GetSuccessorId());
2007 } 2008 }
2008 } 2009 }
2009 2010
2010 TEST_F(SyncableDirectoryTest, SaveChangesSnapshot_HasUnsavedMetahandleChanges) { 2011 TEST_F(SyncableDirectoryTest, SaveChangesSnapshot_HasUnsavedMetahandleChanges) {
2011 EntryKernel kernel;
2012 Directory::SaveChangesSnapshot snapshot; 2012 Directory::SaveChangesSnapshot snapshot;
2013 EXPECT_FALSE(snapshot.HasUnsavedMetahandleChanges()); 2013 EXPECT_FALSE(snapshot.HasUnsavedMetahandleChanges());
2014 snapshot.dirty_metas.insert(&kernel); 2014 snapshot.dirty_metas.insert(base::MakeUnique<EntryKernel>());
2015 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges()); 2015 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges());
2016 snapshot.dirty_metas.clear(); 2016 snapshot.dirty_metas.clear();
2017 2017
2018 EXPECT_FALSE(snapshot.HasUnsavedMetahandleChanges()); 2018 EXPECT_FALSE(snapshot.HasUnsavedMetahandleChanges());
2019 snapshot.metahandles_to_purge.insert(1); 2019 snapshot.metahandles_to_purge.insert(1);
2020 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges()); 2020 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges());
2021 snapshot.metahandles_to_purge.clear(); 2021 snapshot.metahandles_to_purge.clear();
2022 2022
2023 EXPECT_FALSE(snapshot.HasUnsavedMetahandleChanges()); 2023 EXPECT_FALSE(snapshot.HasUnsavedMetahandleChanges());
2024 snapshot.delete_journals.insert(&kernel); 2024 snapshot.delete_journals.insert(base::MakeUnique<EntryKernel>());
2025 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges()); 2025 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges());
2026 snapshot.delete_journals.clear(); 2026 snapshot.delete_journals.clear();
2027 2027
2028 EXPECT_FALSE(snapshot.HasUnsavedMetahandleChanges()); 2028 EXPECT_FALSE(snapshot.HasUnsavedMetahandleChanges());
2029 snapshot.delete_journals_to_purge.insert(1); 2029 snapshot.delete_journals_to_purge.insert(1);
2030 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges()); 2030 EXPECT_TRUE(snapshot.HasUnsavedMetahandleChanges());
2031 snapshot.delete_journals_to_purge.clear(); 2031 snapshot.delete_journals_to_purge.clear();
2032 } 2032 }
2033 2033
2034 // Verify that Directory triggers an unrecoverable error when a catastrophic 2034 // Verify that Directory triggers an unrecoverable error when a catastrophic
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 2139
2140 const base::DictionaryValue* first_result; 2140 const base::DictionaryValue* first_result;
2141 ASSERT_TRUE(nodes->GetDictionary(0, &first_result)); 2141 ASSERT_TRUE(nodes->GetDictionary(0, &first_result));
2142 EXPECT_TRUE(first_result->HasKey("ID")); 2142 EXPECT_TRUE(first_result->HasKey("ID"));
2143 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME")); 2143 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME"));
2144 } 2144 }
2145 2145
2146 } // namespace syncable 2146 } // namespace syncable
2147 2147
2148 } // namespace syncer 2148 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698