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

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

Issue 2424533002: Modify sync unit test to use standard sql::test:: helper. (Closed)
Patch Set: BUILD.gn merge 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
« no previous file with comments | « no previous file | components/sync/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/location.h" 5 #include "base/location.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" 13 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
14 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h" 14 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h"
15 #include "chrome/browser/sync/test/integration/sync_test.h" 15 #include "chrome/browser/sync/test/integration/sync_test.h"
16 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h " 16 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h "
17 #include "components/browser_sync/profile_sync_service.h" 17 #include "components/browser_sync/profile_sync_service.h"
18 #include "components/sync/syncable/directory.h" 18 #include "components/sync/syncable/directory.h"
19 #include "components/sync/test/directory_backing_store_corruption_testing.h"
20 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "sql/test/test_helpers.h"
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 using syncer::syncable::corruption_testing::kNumEntriesRequiredForCorruption;
25 using syncer::syncable::corruption_testing::CorruptDatabase;
26 24
27 class SingleClientDirectorySyncTest : public SyncTest { 25 class SingleClientDirectorySyncTest : public SyncTest {
28 public: 26 public:
29 SingleClientDirectorySyncTest() : SyncTest(SINGLE_CLIENT) {} 27 SingleClientDirectorySyncTest() : SyncTest(SINGLE_CLIENT) {}
30 ~SingleClientDirectorySyncTest() override {} 28 ~SingleClientDirectorySyncTest() override {}
31 29
32 private: 30 private:
33 DISALLOW_COPY_AND_ASSIGN(SingleClientDirectorySyncTest); 31 DISALLOW_COPY_AND_ASSIGN(SingleClientDirectorySyncTest);
34 }; 32 };
35 33
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // completes. 96 // completes.
99 browser_sync::ProfileSyncService* sync_service = GetSyncService(0); 97 browser_sync::ProfileSyncService* sync_service = GetSyncService(0);
100 sync_service->FlushDirectory(); 98 sync_service->FlushDirectory();
101 base::MessageLoop* sync_loop = sync_service->GetSyncLoopForTest(); 99 base::MessageLoop* sync_loop = sync_service->GetSyncLoopForTest();
102 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop)); 100 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop));
103 101
104 // Now corrupt the database. 102 // Now corrupt the database.
105 const base::FilePath directory_path(sync_service->GetDirectoryPathForTest()); 103 const base::FilePath directory_path(sync_service->GetDirectoryPathForTest());
106 const base::FilePath sync_db(directory_path.Append( 104 const base::FilePath sync_db(directory_path.Append(
107 syncer::syncable::Directory::kSyncDatabaseFilename)); 105 syncer::syncable::Directory::kSyncDatabaseFilename));
108 ASSERT_TRUE(CorruptDatabase(sync_db)); 106 ASSERT_TRUE(sql::test::CorruptSizeInHeaderWithLock(sync_db));
109 107
110 // Write a bunch of bookmarks and flush the directory to ensure sync notices 108 // Write some bookmarks and flush the directory to force sync to
111 // the corruption. The key here is to force sync to actually write a lot of 109 // notice the corruption.
112 // data to its DB so it will see the corruption we introduced above. 110 const GURL url("https://www.example.com");
113 const GURL url(
114 "https://"
115 "www."
116 "gooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
117 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
118 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
119 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
120 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
121 "oooooooooooooooooooogle.com");
122 const bookmarks::BookmarkNode* top = bookmarks_helper::AddFolder( 111 const bookmarks::BookmarkNode* top = bookmarks_helper::AddFolder(
123 0, bookmarks_helper::GetOtherNode(0), 0, "top"); 112 0, bookmarks_helper::GetOtherNode(0), 0, "top");
124 for (int i = 0; i < kNumEntriesRequiredForCorruption; ++i) { 113 for (int i = 0; i < 100; ++i) {
125 ASSERT_TRUE( 114 ASSERT_TRUE(
126 bookmarks_helper::AddURL(0, top, 0, base::Int64ToString(i), url)); 115 bookmarks_helper::AddURL(0, top, 0, base::Int64ToString(i), url));
127 } 116 }
128 sync_service->FlushDirectory(); 117 sync_service->FlushDirectory();
129 118
130 // Wait for an unrecoverable error to occur. 119 // Wait for an unrecoverable error to occur.
131 ASSERT_TRUE(SyncUnrecoverableErrorChecker(sync_service).Wait()); 120 ASSERT_TRUE(SyncUnrecoverableErrorChecker(sync_service).Wait());
132 ASSERT_TRUE(sync_service->HasUnrecoverableError()); 121 ASSERT_TRUE(sync_service->HasUnrecoverableError());
133 122
134 // Wait until the sync loop has processed any existing tasks and see that the 123 // Wait until the sync loop has processed any existing tasks and see that the
135 // directory no longer exists. 124 // directory no longer exists.
136 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop)); 125 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop));
137 ASSERT_FALSE(base::DirectoryExists(directory_path)); 126 ASSERT_FALSE(base::DirectoryExists(directory_path));
138 } 127 }
OLDNEW
« no previous file with comments | « no previous file | components/sync/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698