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

Side by Side Diff: components/sync/syncable/directory_backing_store_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 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 "components/sync/syncable/directory_backing_store.h" 5 #include "components/sync/syncable/directory_backing_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "components/sync/base/node_ordinal.h" 21 #include "components/sync/base/node_ordinal.h"
22 #include "components/sync/base/time.h" 22 #include "components/sync/base/time.h"
23 #include "components/sync/protocol/bookmark_specifics.pb.h" 23 #include "components/sync/protocol/bookmark_specifics.pb.h"
24 #include "components/sync/protocol/sync.pb.h" 24 #include "components/sync/protocol/sync.pb.h"
25 #include "components/sync/syncable/directory.h" 25 #include "components/sync/syncable/directory.h"
26 #include "components/sync/syncable/on_disk_directory_backing_store.h" 26 #include "components/sync/syncable/on_disk_directory_backing_store.h"
27 #include "components/sync/syncable/syncable-inl.h"
28 #include "components/sync/test/directory_backing_store_corruption_testing.h" 27 #include "components/sync/test/directory_backing_store_corruption_testing.h"
29 #include "components/sync/test/test_directory_backing_store.h" 28 #include "components/sync/test/test_directory_backing_store.h"
30 #include "sql/connection.h" 29 #include "sql/connection.h"
31 #include "sql/statement.h" 30 #include "sql/statement.h"
32 #include "sql/test/test_helpers.h" 31 #include "sql/test/test_helpers.h"
33 #include "testing/gtest/include/gtest/gtest-param-test.h" 32 #include "testing/gtest/include/gtest/gtest-param-test.h"
34 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
35 34
36 namespace syncer { 35 namespace syncer {
37 namespace syncable { 36 namespace syncable {
(...skipping 4147 matching lines...) Expand 10 before | Expand all | Expand 10 after
4185 { 4184 {
4186 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs( 4185 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4187 new OnDiskDirectoryBackingStoreForTest(GetUsername(), 4186 new OnDiskDirectoryBackingStoreForTest(GetUsername(),
4188 GetDatabasePath())); 4187 GetDatabasePath()));
4189 dbs->SetCatastrophicErrorHandler(handler); 4188 dbs->SetCatastrophicErrorHandler(handler);
4190 ASSERT_TRUE(dbs->db_->has_error_callback()); 4189 ASSERT_TRUE(dbs->db_->has_error_callback());
4191 // Load the DB, and save one entry. 4190 // Load the DB, and save one entry.
4192 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4191 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4193 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt()); 4192 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt());
4194 Directory::SaveChangesSnapshot snapshot; 4193 Directory::SaveChangesSnapshot snapshot;
4195 snapshot.dirty_metas.insert(CreateEntry(2, "").release()); 4194 snapshot.dirty_metas.insert(CreateEntry(2, ""));
4196 ASSERT_TRUE(dbs->SaveChanges(snapshot)); 4195 ASSERT_TRUE(dbs->SaveChanges(snapshot));
4197 } 4196 }
4198 4197
4199 base::RunLoop().RunUntilIdle(); 4198 base::RunLoop().RunUntilIdle();
4200 // No catastrophic errors have happened. See that it hasn't be called yet. 4199 // No catastrophic errors have happened. See that it hasn't be called yet.
4201 ASSERT_FALSE(was_called); 4200 ASSERT_FALSE(was_called);
4202 4201
4203 // Corrupt the DB. Some forms of corruption (like this one) will be detected 4202 // Corrupt the DB. Some forms of corruption (like this one) will be detected
4204 // upon loading the Sync DB. 4203 // upon loading the Sync DB.
4205 ASSERT_TRUE(sql::test::CorruptSizeInHeader(GetDatabasePath())); 4204 ASSERT_TRUE(sql::test::CorruptSizeInHeader(GetDatabasePath()));
(...skipping 28 matching lines...) Expand all
4234 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs( 4233 std::unique_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
4235 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath())); 4234 new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath()));
4236 dbs->SetCatastrophicErrorHandler(handler); 4235 dbs->SetCatastrophicErrorHandler(handler);
4237 ASSERT_TRUE(dbs->db_->has_error_callback()); 4236 ASSERT_TRUE(dbs->db_->has_error_callback());
4238 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 4237 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
4239 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt()); 4238 ASSERT_FALSE(dbs->DidFailFirstOpenAttempt());
4240 Directory::SaveChangesSnapshot snapshot; 4239 Directory::SaveChangesSnapshot snapshot;
4241 const std::string suffix(400, 'o'); 4240 const std::string suffix(400, 'o');
4242 for (int i = 0; i < corruption_testing::kNumEntriesRequiredForCorruption; 4241 for (int i = 0; i < corruption_testing::kNumEntriesRequiredForCorruption;
4243 ++i) { 4242 ++i) {
4244 std::unique_ptr<EntryKernel> large_entry = CreateEntry(i, suffix); 4243 snapshot.dirty_metas.insert(CreateEntry(i, suffix));
4245 snapshot.dirty_metas.insert(large_entry.release());
4246 } 4244 }
4247 ASSERT_TRUE(dbs->SaveChanges(snapshot)); 4245 ASSERT_TRUE(dbs->SaveChanges(snapshot));
4248 // Corrupt it. 4246 // Corrupt it.
4249 ASSERT_TRUE(corruption_testing::CorruptDatabase(GetDatabasePath())); 4247 ASSERT_TRUE(corruption_testing::CorruptDatabase(GetDatabasePath()));
4250 // Attempt to save all those entries again. See that it fails (because of the 4248 // Attempt to save all those entries again. See that it fails (because of the
4251 // corruption). 4249 // corruption).
4252 // 4250 //
4253 // If this test fails because SaveChanges returned true, it may mean you need 4251 // If this test fails because SaveChanges returned true, it may mean you need
4254 // to increase the number of entries written to the DB. See also 4252 // to increase the number of entries written to the DB. See also
4255 // |kNumEntriesRequiredForCorruption|. 4253 // |kNumEntriesRequiredForCorruption|.
4256 ASSERT_FALSE(dbs->SaveChanges(snapshot)); 4254 ASSERT_FALSE(dbs->SaveChanges(snapshot));
4257 // At this point the handler has been posted but not executed. 4255 // At this point the handler has been posted but not executed.
4258 ASSERT_FALSE(was_called); 4256 ASSERT_FALSE(was_called);
4259 // Pump the message loop and see that it is executed. 4257 // Pump the message loop and see that it is executed.
4260 base::RunLoop().RunUntilIdle(); 4258 base::RunLoop().RunUntilIdle();
4261 ASSERT_TRUE(was_called); 4259 ASSERT_TRUE(was_called);
4262 } 4260 }
4263 4261
4264 } // namespace syncable 4262 } // namespace syncable
4265 } // namespace syncer 4263 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698