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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/synchronization/condition_variable.h" 18 #include "base/synchronization/condition_variable.h"
19 #include "base/test/values_test_util.h" 19 #include "base/test/values_test_util.h"
20 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "sync/protocol/bookmark_specifics.pb.h" 23 #include "components/sync/base/test_unrecoverable_error_handler.h"
24 #include "sync/syncable/directory_backing_store.h" 24 #include "components/sync/protocol/bookmark_specifics.pb.h"
25 #include "sync/syncable/directory_change_delegate.h" 25 #include "components/sync/syncable/directory_backing_store.h"
26 #include "sync/syncable/directory_unittest.h" 26 #include "components/sync/syncable/directory_change_delegate.h"
27 #include "sync/syncable/in_memory_directory_backing_store.h" 27 #include "components/sync/syncable/directory_unittest.h"
28 #include "sync/syncable/metahandle_set.h" 28 #include "components/sync/syncable/in_memory_directory_backing_store.h"
29 #include "sync/syncable/mutable_entry.h" 29 #include "components/sync/syncable/metahandle_set.h"
30 #include "sync/syncable/on_disk_directory_backing_store.h" 30 #include "components/sync/syncable/mutable_entry.h"
31 #include "sync/syncable/syncable_proto_util.h" 31 #include "components/sync/syncable/on_disk_directory_backing_store.h"
32 #include "sync/syncable/syncable_read_transaction.h" 32 #include "components/sync/syncable/syncable_proto_util.h"
33 #include "sync/syncable/syncable_util.h" 33 #include "components/sync/syncable/syncable_read_transaction.h"
34 #include "sync/syncable/syncable_write_transaction.h" 34 #include "components/sync/syncable/syncable_util.h"
35 #include "sync/test/engine/test_id_factory.h" 35 #include "components/sync/syncable/syncable_write_transaction.h"
36 #include "sync/test/engine/test_syncable_utils.h" 36 #include "components/sync/test/engine/test_id_factory.h"
37 #include "sync/test/fake_encryptor.h" 37 #include "components/sync/test/engine/test_syncable_utils.h"
38 #include "sync/test/null_directory_change_delegate.h" 38 #include "components/sync/test/fake_encryptor.h"
39 #include "sync/test/null_transaction_observer.h" 39 #include "components/sync/test/null_directory_change_delegate.h"
40 #include "sync/util/test_unrecoverable_error_handler.h" 40 #include "components/sync/test/null_transaction_observer.h"
41 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
42 42
43 namespace syncer { 43 namespace syncer {
44 namespace syncable { 44 namespace syncable {
45 45
46 using base::ExpectDictBooleanValue; 46 using base::ExpectDictBooleanValue;
47 using base::ExpectDictStringValue; 47 using base::ExpectDictStringValue;
48 48
49 // An OnDiskDirectoryBackingStore that can be set to always fail SaveChanges. 49 // An OnDiskDirectoryBackingStore that can be set to always fail SaveChanges.
50 class TestBackingStore : public OnDiskDirectoryBackingStore { 50 class TestBackingStore : public OnDiskDirectoryBackingStore {
51 public: 51 public:
52 TestBackingStore(const std::string& dir_name, 52 TestBackingStore(const std::string& dir_name,
53 const base::FilePath& backing_filepath); 53 const base::FilePath& backing_filepath);
54 54
55 ~TestBackingStore() override; 55 ~TestBackingStore() override;
56 56
57 bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) override; 57 bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) override;
58 58
59 void StartFailingSaveChanges() { fail_save_changes_ = true; } 59 void StartFailingSaveChanges() { fail_save_changes_ = true; }
60 60
61 private: 61 private:
62 bool fail_save_changes_; 62 bool fail_save_changes_;
63 }; 63 };
64 64
65 TestBackingStore::TestBackingStore(const std::string& dir_name, 65 TestBackingStore::TestBackingStore(const std::string& dir_name,
66 const base::FilePath& backing_filepath) 66 const base::FilePath& backing_filepath)
67 : OnDiskDirectoryBackingStore(dir_name, backing_filepath), 67 : OnDiskDirectoryBackingStore(dir_name, backing_filepath),
68 fail_save_changes_(false) { 68 fail_save_changes_(false) {}
69 }
70 69
71 TestBackingStore::~TestBackingStore() { } 70 TestBackingStore::~TestBackingStore() {}
72 71
73 bool TestBackingStore::SaveChanges( 72 bool TestBackingStore::SaveChanges(
74 const Directory::SaveChangesSnapshot& snapshot) { 73 const Directory::SaveChangesSnapshot& snapshot) {
75 if (fail_save_changes_) { 74 if (fail_save_changes_) {
76 return false; 75 return false;
77 } else { 76 } else {
78 return OnDiskDirectoryBackingStore::SaveChanges(snapshot); 77 return OnDiskDirectoryBackingStore::SaveChanges(snapshot);
79 } 78 }
80 } 79 }
81 80
82 // A directory whose Save() function can be set to always fail. 81 // A directory whose Save() function can be set to always fail.
83 class TestDirectory : public Directory { 82 class TestDirectory : public Directory {
84 public: 83 public:
85 // A factory function used to work around some initialization order issues. 84 // A factory function used to work around some initialization order issues.
86 static TestDirectory* Create( 85 static TestDirectory* Create(
87 Encryptor* encryptor, 86 Encryptor* encryptor,
88 const WeakHandle<UnrecoverableErrorHandler>& handler, 87 const WeakHandle<UnrecoverableErrorHandler>& handler,
89 const std::string& dir_name, 88 const std::string& dir_name,
90 const base::FilePath& backing_filepath); 89 const base::FilePath& backing_filepath);
91 90
92 ~TestDirectory() override; 91 ~TestDirectory() override;
93 92
94 void StartFailingSaveChanges() { 93 void StartFailingSaveChanges() { backing_store_->StartFailingSaveChanges(); }
95 backing_store_->StartFailingSaveChanges();
96 }
97 94
98 private: 95 private:
99 TestDirectory(Encryptor* encryptor, 96 TestDirectory(Encryptor* encryptor,
100 const WeakHandle<UnrecoverableErrorHandler>& handler, 97 const WeakHandle<UnrecoverableErrorHandler>& handler,
101 TestBackingStore* backing_store); 98 TestBackingStore* backing_store);
102 99
103 TestBackingStore* backing_store_; 100 TestBackingStore* backing_store_;
104 }; 101 };
105 102
106 TestDirectory* TestDirectory::Create( 103 TestDirectory* TestDirectory::Create(
107 Encryptor* encryptor, 104 Encryptor* encryptor,
108 const WeakHandle<UnrecoverableErrorHandler>& handler, 105 const WeakHandle<UnrecoverableErrorHandler>& handler,
109 const std::string& dir_name, 106 const std::string& dir_name,
110 const base::FilePath& backing_filepath) { 107 const base::FilePath& backing_filepath) {
111 TestBackingStore* backing_store = 108 TestBackingStore* backing_store =
112 new TestBackingStore(dir_name, backing_filepath); 109 new TestBackingStore(dir_name, backing_filepath);
113 return new TestDirectory(encryptor, handler, backing_store); 110 return new TestDirectory(encryptor, handler, backing_store);
114 } 111 }
115 112
116 TestDirectory::TestDirectory( 113 TestDirectory::TestDirectory(
117 Encryptor* encryptor, 114 Encryptor* encryptor,
118 const WeakHandle<UnrecoverableErrorHandler>& handler, 115 const WeakHandle<UnrecoverableErrorHandler>& handler,
119 TestBackingStore* backing_store) 116 TestBackingStore* backing_store)
120 : Directory(backing_store, handler, base::Closure(), NULL, NULL), 117 : Directory(backing_store, handler, base::Closure(), NULL, NULL),
121 backing_store_(backing_store) {} 118 backing_store_(backing_store) {}
122 119
123 TestDirectory::~TestDirectory() { } 120 TestDirectory::~TestDirectory() {}
124 121
125 // crbug.com/144422 122 // crbug.com/144422
126 #if defined(OS_ANDROID) 123 #if defined(OS_ANDROID)
127 #define MAYBE_FailInitialWrite DISABLED_FailInitialWrite 124 #define MAYBE_FailInitialWrite DISABLED_FailInitialWrite
128 #else 125 #else
129 #define MAYBE_FailInitialWrite FailInitialWrite 126 #define MAYBE_FailInitialWrite FailInitialWrite
130 #endif 127 #endif
131 TEST(OnDiskSyncableDirectory, MAYBE_FailInitialWrite) { 128 TEST(OnDiskSyncableDirectory, MAYBE_FailInitialWrite) {
132 base::MessageLoop message_loop; 129 base::MessageLoop message_loop;
133 FakeEncryptor encryptor; 130 FakeEncryptor encryptor;
134 TestUnrecoverableErrorHandler handler; 131 TestUnrecoverableErrorHandler handler;
135 base::ScopedTempDir temp_dir; 132 base::ScopedTempDir temp_dir;
136 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 133 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
137 base::FilePath file_path = temp_dir.path().Append( 134 base::FilePath file_path =
138 FILE_PATH_LITERAL("Test.sqlite3")); 135 temp_dir.path().Append(FILE_PATH_LITERAL("Test.sqlite3"));
139 std::string name = "user@x.com"; 136 std::string name = "user@x.com";
140 NullDirectoryChangeDelegate delegate; 137 NullDirectoryChangeDelegate delegate;
141 138
142 std::unique_ptr<TestDirectory> test_dir(TestDirectory::Create( 139 std::unique_ptr<TestDirectory> test_dir(TestDirectory::Create(
143 &encryptor, MakeWeakHandle(handler.GetWeakPtr()), name, file_path)); 140 &encryptor, MakeWeakHandle(handler.GetWeakPtr()), name, file_path));
144 141
145 test_dir->StartFailingSaveChanges(); 142 test_dir->StartFailingSaveChanges();
146 ASSERT_EQ(FAILED_INITIAL_WRITE, test_dir->Open(name, &delegate, 143 ASSERT_EQ(FAILED_INITIAL_WRITE,
147 NullTransactionObserver())); 144 test_dir->Open(name, &delegate, NullTransactionObserver()));
148 } 145 }
149 146
150 // A variant of SyncableDirectoryTest that uses a real sqlite database. 147 // A variant of SyncableDirectoryTest that uses a real sqlite database.
151 class OnDiskSyncableDirectoryTest : public SyncableDirectoryTest { 148 class OnDiskSyncableDirectoryTest : public SyncableDirectoryTest {
152 protected: 149 protected:
153 // SetUp() is called before each test case is run. 150 // SetUp() is called before each test case is run.
154 // The sqlite3 DB is deleted before each test is run. 151 // The sqlite3 DB is deleted before each test is run.
155 void SetUp() override { 152 void SetUp() override {
156 SyncableDirectoryTest::SetUp(); 153 SyncableDirectoryTest::SetUp();
157 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 154 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
158 file_path_ = temp_dir_.path().Append( 155 file_path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("Test.sqlite3"));
159 FILE_PATH_LITERAL("Test.sqlite3"));
160 base::DeleteFile(file_path_, false); 156 base::DeleteFile(file_path_, false);
161 CreateDirectory(); 157 CreateDirectory();
162 } 158 }
163 159
164 void TearDown() override { 160 void TearDown() override {
165 // This also closes file handles. 161 // This also closes file handles.
166 dir()->SaveChanges(); 162 dir()->SaveChanges();
167 dir().reset(); 163 dir().reset();
168 base::DeleteFile(file_path_, false); 164 base::DeleteFile(file_path_, false);
169 SyncableDirectoryTest::TearDown(); 165 SyncableDirectoryTest::TearDown();
170 } 166 }
171 167
172 // Creates a new directory. Deletes the old directory, if it exists. 168 // Creates a new directory. Deletes the old directory, if it exists.
173 void CreateDirectory() { 169 void CreateDirectory() {
174 test_directory_ = TestDirectory::Create( 170 test_directory_ = TestDirectory::Create(
175 encryptor(), 171 encryptor(),
176 MakeWeakHandle(unrecoverable_error_handler()->GetWeakPtr()), 172 MakeWeakHandle(unrecoverable_error_handler()->GetWeakPtr()),
177 kDirectoryName, file_path_); 173 kDirectoryName, file_path_);
178 dir().reset(test_directory_); 174 dir().reset(test_directory_);
179 ASSERT_TRUE(dir().get()); 175 ASSERT_TRUE(dir().get());
180 ASSERT_EQ(OPENED, 176 ASSERT_EQ(OPENED, dir()->Open(kDirectoryName, directory_change_delegate(),
181 dir()->Open(kDirectoryName, 177 NullTransactionObserver()));
182 directory_change_delegate(),
183 NullTransactionObserver()));
184 ASSERT_TRUE(dir()->good()); 178 ASSERT_TRUE(dir()->good());
185 } 179 }
186 180
187 void SaveAndReloadDir() { 181 void SaveAndReloadDir() {
188 dir()->SaveChanges(); 182 dir()->SaveChanges();
189 CreateDirectory(); 183 CreateDirectory();
190 } 184 }
191 185
192 void StartFailingSaveChanges() { 186 void StartFailingSaveChanges() { test_directory_->StartFailingSaveChanges(); }
193 test_directory_->StartFailingSaveChanges();
194 }
195 187
196 TestDirectory* test_directory_; // mirrors std::unique_ptr<Directory> dir_ 188 TestDirectory* test_directory_; // mirrors std::unique_ptr<Directory> dir_
197 base::ScopedTempDir temp_dir_; 189 base::ScopedTempDir temp_dir_;
198 base::FilePath file_path_; 190 base::FilePath file_path_;
199 }; 191 };
200 192
201 sync_pb::DataTypeContext BuildContext(ModelType type) { 193 sync_pb::DataTypeContext BuildContext(ModelType type) {
202 sync_pb::DataTypeContext context; 194 sync_pb::DataTypeContext context;
203 context.set_context("context"); 195 context.set_context("context");
204 context.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); 196 context.set_data_type_id(GetSpecificsFieldNumberFromModelType(type));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ASSERT_TRUE(item1.good()); 232 ASSERT_TRUE(item1.good());
241 item1.PutServerSpecifics(bookmark_specs); 233 item1.PutServerSpecifics(bookmark_specs);
242 item1.PutIsUnsynced(true); 234 item1.PutIsUnsynced(true);
243 235
244 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM, 236 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM,
245 id_factory.NewServerId()); 237 id_factory.NewServerId());
246 ASSERT_TRUE(item2.good()); 238 ASSERT_TRUE(item2.good());
247 item2.PutServerSpecifics(bookmark_specs); 239 item2.PutServerSpecifics(bookmark_specs);
248 item2.PutIsUnappliedUpdate(true); 240 item2.PutIsUnappliedUpdate(true);
249 241
250 MutableEntry item3(&trans, CREATE, PREFERENCES, 242 MutableEntry item3(&trans, CREATE, PREFERENCES, trans.root_id(), "Item");
251 trans.root_id(), "Item");
252 ASSERT_TRUE(item3.good()); 243 ASSERT_TRUE(item3.good());
253 item3.PutSpecifics(preference_specs); 244 item3.PutSpecifics(preference_specs);
254 item3.PutServerSpecifics(preference_specs); 245 item3.PutServerSpecifics(preference_specs);
255 item3.PutIsUnsynced(true); 246 item3.PutIsUnsynced(true);
256 247
257 MutableEntry item4(&trans, CREATE_NEW_UPDATE_ITEM, 248 MutableEntry item4(&trans, CREATE_NEW_UPDATE_ITEM,
258 id_factory.NewServerId()); 249 id_factory.NewServerId());
259 ASSERT_TRUE(item4.good()); 250 ASSERT_TRUE(item4.good());
260 item4.PutServerSpecifics(preference_specs); 251 item4.PutServerSpecifics(preference_specs);
261 item4.PutIsUnappliedUpdate(true); 252 item4.PutIsUnappliedUpdate(true);
262 253
263 MutableEntry item5(&trans, CREATE, AUTOFILL, 254 MutableEntry item5(&trans, CREATE, AUTOFILL, trans.root_id(), "Item");
264 trans.root_id(), "Item");
265 ASSERT_TRUE(item5.good()); 255 ASSERT_TRUE(item5.good());
266 item5.PutSpecifics(autofill_specs); 256 item5.PutSpecifics(autofill_specs);
267 item5.PutServerSpecifics(autofill_specs); 257 item5.PutServerSpecifics(autofill_specs);
268 item5.PutIsUnsynced(true); 258 item5.PutIsUnsynced(true);
269 259
270 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM, 260 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM,
271 id_factory.NewServerId()); 261 id_factory.NewServerId());
272 ASSERT_TRUE(item6.good()); 262 ASSERT_TRUE(item6.good());
273 item6.PutServerSpecifics(autofill_specs); 263 item6.PutServerSpecifics(autofill_specs);
274 item6.PutIsUnappliedUpdate(true); 264 item6.PutIsUnappliedUpdate(true);
275 } 265 }
276 266
277 dir()->SaveChanges(); 267 dir()->SaveChanges();
278 { 268 {
279 ReadTransaction trans(FROM_HERE, dir().get()); 269 ReadTransaction trans(FROM_HERE, dir().get());
280 MetahandleSet all_set; 270 MetahandleSet all_set;
281 GetAllMetaHandles(&trans, &all_set); 271 GetAllMetaHandles(&trans, &all_set);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 EXPECT_EQ(bag_of_chips3_string, dir()->bag_of_chips()); 315 EXPECT_EQ(bag_of_chips3_string, dir()->bag_of_chips());
326 } 316 }
327 } 317 }
328 318
329 TEST_F(OnDiskSyncableDirectoryTest, 319 TEST_F(OnDiskSyncableDirectoryTest,
330 TestSimpleFieldsPreservedDuringSaveChanges) { 320 TestSimpleFieldsPreservedDuringSaveChanges) {
331 Id update_id = TestIdFactory::FromNumber(1); 321 Id update_id = TestIdFactory::FromNumber(1);
332 Id create_id; 322 Id create_id;
333 EntryKernel create_pre_save, update_pre_save; 323 EntryKernel create_pre_save, update_pre_save;
334 EntryKernel create_post_save, update_post_save; 324 EntryKernel create_post_save, update_post_save;
335 std::string create_name = "Create"; 325 std::string create_name = "Create";
336 326
337 { 327 {
338 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); 328 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get());
339 MutableEntry create( 329 MutableEntry create(&trans, CREATE, BOOKMARKS, trans.root_id(),
340 &trans, CREATE, BOOKMARKS, trans.root_id(), create_name); 330 create_name);
341 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id); 331 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id);
342 create.PutIsUnsynced(true); 332 create.PutIsUnsynced(true);
343 update.PutIsUnappliedUpdate(true); 333 update.PutIsUnappliedUpdate(true);
344 sync_pb::EntitySpecifics specifics; 334 sync_pb::EntitySpecifics specifics;
345 specifics.mutable_bookmark()->set_favicon("PNG"); 335 specifics.mutable_bookmark()->set_favicon("PNG");
346 specifics.mutable_bookmark()->set_url("http://nowhere"); 336 specifics.mutable_bookmark()->set_url("http://nowhere");
347 create.PutSpecifics(specifics); 337 create.PutSpecifics(specifics);
348 update.PutServerSpecifics(specifics); 338 update.PutServerSpecifics(specifics);
349 create_pre_save = create.GetKernelCopy(); 339 create_pre_save = create.GetKernelCopy();
350 update_pre_save = update.GetKernelCopy(); 340 update_pre_save = update.GetKernelCopy();
351 create_id = create.GetId(); 341 create_id = create.GetId();
352 } 342 }
353 343
354 dir()->SaveChanges(); 344 dir()->SaveChanges();
355 dir().reset( 345 dir().reset(
356 new Directory(new OnDiskDirectoryBackingStore(kDirectoryName, file_path_), 346 new Directory(new OnDiskDirectoryBackingStore(kDirectoryName, file_path_),
357 MakeWeakHandle(unrecoverable_error_handler()->GetWeakPtr()), 347 MakeWeakHandle(unrecoverable_error_handler()->GetWeakPtr()),
358 base::Closure(), NULL, NULL)); 348 base::Closure(), NULL, NULL));
359 349
360 ASSERT_TRUE(dir().get()); 350 ASSERT_TRUE(dir().get());
361 ASSERT_EQ(OPENED, 351 ASSERT_EQ(OPENED, dir()->Open(kDirectoryName, directory_change_delegate(),
362 dir()->Open(kDirectoryName, 352 NullTransactionObserver()));
363 directory_change_delegate(),
364 NullTransactionObserver()));
365 ASSERT_TRUE(dir()->good()); 353 ASSERT_TRUE(dir()->good());
366 354
367 { 355 {
368 ReadTransaction trans(FROM_HERE, dir().get()); 356 ReadTransaction trans(FROM_HERE, dir().get());
369 Entry create(&trans, GET_BY_ID, create_id); 357 Entry create(&trans, GET_BY_ID, create_id);
370 EXPECT_EQ(1, CountEntriesWithName(&trans, trans.root_id(), create_name)); 358 EXPECT_EQ(1, CountEntriesWithName(&trans, trans.root_id(), create_name));
371 Entry update(&trans, GET_BY_ID, update_id); 359 Entry update(&trans, GET_BY_ID, update_id);
372 create_post_save = create.GetKernelCopy(); 360 create_post_save = create.GetKernelCopy();
373 update_post_save = update.GetKernelCopy(); 361 update_post_save = update.GetKernelCopy();
374 } 362 }
375 int i = BEGIN_FIELDS; 363 int i = BEGIN_FIELDS;
376 for ( ; i < INT64_FIELDS_END ; ++i) { 364 for (; i < INT64_FIELDS_END; ++i) {
377 EXPECT_EQ( 365 EXPECT_EQ(
378 create_pre_save.ref((Int64Field)i) + (i == TRANSACTION_VERSION ? 1 : 0), 366 create_pre_save.ref((Int64Field)i) + (i == TRANSACTION_VERSION ? 1 : 0),
379 create_post_save.ref((Int64Field)i)) 367 create_post_save.ref((Int64Field)i))
380 << "int64_t field #" << i << " changed during save/load"; 368 << "int64_t field #" << i << " changed during save/load";
381 EXPECT_EQ(update_pre_save.ref((Int64Field)i), 369 EXPECT_EQ(update_pre_save.ref((Int64Field)i),
382 update_post_save.ref((Int64Field)i)) 370 update_post_save.ref((Int64Field)i))
383 << "int64_t field #" << i << " changed during save/load"; 371 << "int64_t field #" << i << " changed during save/load";
384 } 372 }
385 for ( ; i < TIME_FIELDS_END ; ++i) { 373 for (; i < TIME_FIELDS_END; ++i) {
386 EXPECT_EQ(create_pre_save.ref((TimeField)i), 374 EXPECT_EQ(create_pre_save.ref((TimeField)i),
387 create_post_save.ref((TimeField)i)) 375 create_post_save.ref((TimeField)i))
388 << "time field #" << i << " changed during save/load"; 376 << "time field #" << i << " changed during save/load";
389 EXPECT_EQ(update_pre_save.ref((TimeField)i), 377 EXPECT_EQ(update_pre_save.ref((TimeField)i),
390 update_post_save.ref((TimeField)i)) 378 update_post_save.ref((TimeField)i))
391 << "time field #" << i << " changed during save/load"; 379 << "time field #" << i << " changed during save/load";
392 } 380 }
393 for ( ; i < ID_FIELDS_END ; ++i) { 381 for (; i < ID_FIELDS_END; ++i) {
394 EXPECT_EQ(create_pre_save.ref((IdField)i), 382 EXPECT_EQ(create_pre_save.ref((IdField)i), create_post_save.ref((IdField)i))
395 create_post_save.ref((IdField)i)) 383 << "id field #" << i << " changed during save/load";
396 << "id field #" << i << " changed during save/load"; 384 EXPECT_EQ(update_pre_save.ref((IdField)i), update_pre_save.ref((IdField)i))
397 EXPECT_EQ(update_pre_save.ref((IdField)i), 385 << "id field #" << i << " changed during save/load";
398 update_pre_save.ref((IdField)i))
399 << "id field #" << i << " changed during save/load";
400 } 386 }
401 for ( ; i < BIT_FIELDS_END ; ++i) { 387 for (; i < BIT_FIELDS_END; ++i) {
402 EXPECT_EQ(create_pre_save.ref((BitField)i), 388 EXPECT_EQ(create_pre_save.ref((BitField)i),
403 create_post_save.ref((BitField)i)) 389 create_post_save.ref((BitField)i))
404 << "Bit field #" << i << " changed during save/load"; 390 << "Bit field #" << i << " changed during save/load";
405 EXPECT_EQ(update_pre_save.ref((BitField)i), 391 EXPECT_EQ(update_pre_save.ref((BitField)i),
406 update_post_save.ref((BitField)i)) 392 update_post_save.ref((BitField)i))
407 << "Bit field #" << i << " changed during save/load"; 393 << "Bit field #" << i << " changed during save/load";
408 } 394 }
409 for ( ; i < STRING_FIELDS_END ; ++i) { 395 for (; i < STRING_FIELDS_END; ++i) {
410 EXPECT_EQ(create_pre_save.ref((StringField)i), 396 EXPECT_EQ(create_pre_save.ref((StringField)i),
411 create_post_save.ref((StringField)i)) 397 create_post_save.ref((StringField)i))
412 << "String field #" << i << " changed during save/load"; 398 << "String field #" << i << " changed during save/load";
413 EXPECT_EQ(update_pre_save.ref((StringField)i), 399 EXPECT_EQ(update_pre_save.ref((StringField)i),
414 update_post_save.ref((StringField)i)) 400 update_post_save.ref((StringField)i))
415 << "String field #" << i << " changed during save/load"; 401 << "String field #" << i << " changed during save/load";
416 } 402 }
417 for ( ; i < PROTO_FIELDS_END; ++i) { 403 for (; i < PROTO_FIELDS_END; ++i) {
418 EXPECT_EQ(create_pre_save.ref((ProtoField)i).SerializeAsString(), 404 EXPECT_EQ(create_pre_save.ref((ProtoField)i).SerializeAsString(),
419 create_post_save.ref((ProtoField)i).SerializeAsString()) 405 create_post_save.ref((ProtoField)i).SerializeAsString())
420 << "Blob field #" << i << " changed during save/load"; 406 << "Blob field #" << i << " changed during save/load";
421 EXPECT_EQ(update_pre_save.ref((ProtoField)i).SerializeAsString(), 407 EXPECT_EQ(update_pre_save.ref((ProtoField)i).SerializeAsString(),
422 update_post_save.ref((ProtoField)i).SerializeAsString()) 408 update_post_save.ref((ProtoField)i).SerializeAsString())
423 << "Blob field #" << i << " changed during save/load"; 409 << "Blob field #" << i << " changed during save/load";
424 } 410 }
425 for ( ; i < UNIQUE_POSITION_FIELDS_END; ++i) { 411 for (; i < UNIQUE_POSITION_FIELDS_END; ++i) {
426 EXPECT_TRUE(create_pre_save.ref((UniquePositionField)i).Equals( 412 EXPECT_TRUE(create_pre_save.ref((UniquePositionField)i)
427 create_post_save.ref((UniquePositionField)i))) 413 .Equals(create_post_save.ref((UniquePositionField)i)))
428 << "Position field #" << i << " changed during save/load"; 414 << "Position field #" << i << " changed during save/load";
429 EXPECT_TRUE(update_pre_save.ref((UniquePositionField)i).Equals( 415 EXPECT_TRUE(update_pre_save.ref((UniquePositionField)i)
430 update_post_save.ref((UniquePositionField)i))) 416 .Equals(update_post_save.ref((UniquePositionField)i)))
431 << "Position field #" << i << " changed during save/load"; 417 << "Position field #" << i << " changed during save/load";
432 } 418 }
433 } 419 }
434 420
435 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) { 421 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) {
436 int64_t handle1 = 0; 422 int64_t handle1 = 0;
437 // Set up an item using a regular, saveable directory. 423 // Set up an item using a regular, saveable directory.
438 { 424 {
439 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); 425 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get());
440 426
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 ASSERT_TRUE(aguilera.good()); 463 ASSERT_TRUE(aguilera.good());
478 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); 464 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty());
479 EXPECT_EQ(aguilera.GetNonUniqueName(), "overwritten"); 465 EXPECT_EQ(aguilera.GetNonUniqueName(), "overwritten");
480 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); 466 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty());
481 EXPECT_FALSE(IsInDirtyMetahandles(handle1)); 467 EXPECT_FALSE(IsInDirtyMetahandles(handle1));
482 aguilera.PutNonUniqueName("christina"); 468 aguilera.PutNonUniqueName("christina");
483 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty()); 469 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty());
484 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 470 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
485 471
486 // New item. 472 // New item.
487 MutableEntry kids_on_block( 473 MutableEntry kids_on_block(&trans, CREATE, BOOKMARKS, trans.root_id(),
488 &trans, CREATE, BOOKMARKS, trans.root_id(), "kids"); 474 "kids");
489 ASSERT_TRUE(kids_on_block.good()); 475 ASSERT_TRUE(kids_on_block.good());
490 handle2 = kids_on_block.GetMetahandle(); 476 handle2 = kids_on_block.GetMetahandle();
491 kids_on_block.PutBaseVersion(1); 477 kids_on_block.PutBaseVersion(1);
492 kids_on_block.PutIsDir(true); 478 kids_on_block.PutIsDir(true);
493 kids_on_block.PutId(TestIdFactory::FromNumber(102)); 479 kids_on_block.PutId(TestIdFactory::FromNumber(102));
494 EXPECT_TRUE(kids_on_block.GetKernelCopy().is_dirty()); 480 EXPECT_TRUE(kids_on_block.GetKernelCopy().is_dirty());
495 EXPECT_TRUE(IsInDirtyMetahandles(handle2)); 481 EXPECT_TRUE(IsInDirtyMetahandles(handle2));
496 } 482 }
497 483
498 // We are using an unsaveable directory, so this can't succeed. However, 484 // We are using an unsaveable directory, so this can't succeed. However,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 class SyncableClientTagTest : public SyncableDirectoryTest { 569 class SyncableClientTagTest : public SyncableDirectoryTest {
584 public: 570 public:
585 static const int kBaseVersion = 1; 571 static const int kBaseVersion = 1;
586 const char* test_name_; 572 const char* test_name_;
587 const char* test_tag_; 573 const char* test_tag_;
588 574
589 SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {} 575 SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {}
590 576
591 bool CreateWithDefaultTag(Id id, bool deleted) { 577 bool CreateWithDefaultTag(Id id, bool deleted) {
592 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir().get()); 578 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir().get());
593 MutableEntry me(&wtrans, CREATE, PREFERENCES, 579 MutableEntry me(&wtrans, CREATE, PREFERENCES, wtrans.root_id(), test_name_);
594 wtrans.root_id(), test_name_);
595 CHECK(me.good()); 580 CHECK(me.good());
596 me.PutId(id); 581 me.PutId(id);
597 if (id.ServerKnows()) { 582 if (id.ServerKnows()) {
598 me.PutBaseVersion(kBaseVersion); 583 me.PutBaseVersion(kBaseVersion);
599 } 584 }
600 me.PutIsUnsynced(true); 585 me.PutIsUnsynced(true);
601 me.PutIsDel(deleted); 586 me.PutIsDel(deleted);
602 me.PutIsDir(false); 587 me.PutIsDir(false);
603 return me.PutUniqueClientTag(test_tag_); 588 return me.PutUniqueClientTag(test_tag_);
604 } 589 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 655 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
671 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 656 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
672 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 657 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
673 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 658 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
674 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 659 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
675 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 660 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
676 } 661 }
677 662
678 } // namespace syncable 663 } // namespace syncable
679 } // namespace syncer 664 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/syncable_read_transaction.cc ('k') | components/sync/syncable/syncable_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698