OLD | NEW |
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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 base::WaitableEvent e(base::WaitableEvent::ResetPolicy::MANUAL, | 42 base::WaitableEvent e(base::WaitableEvent::ResetPolicy::MANUAL, |
43 base::WaitableEvent::InitialState::NOT_SIGNALED); | 43 base::WaitableEvent::InitialState::NOT_SIGNALED); |
44 loop->task_runner()->PostTask(FROM_HERE, base::Bind(&SignalEvent, &e)); | 44 loop->task_runner()->PostTask(FROM_HERE, base::Bind(&SignalEvent, &e)); |
45 // Timeout stolen from StatusChangeChecker::GetTimeoutDuration(). | 45 // Timeout stolen from StatusChangeChecker::GetTimeoutDuration(). |
46 return e.TimedWait(base::TimeDelta::FromSeconds(45)); | 46 return e.TimedWait(base::TimeDelta::FromSeconds(45)); |
47 } | 47 } |
48 | 48 |
49 // A status change checker that waits for an unrecoverable sync error to occur. | 49 // A status change checker that waits for an unrecoverable sync error to occur. |
50 class SyncUnrecoverableErrorChecker : public SingleClientStatusChangeChecker { | 50 class SyncUnrecoverableErrorChecker : public SingleClientStatusChangeChecker { |
51 public: | 51 public: |
52 explicit SyncUnrecoverableErrorChecker(ProfileSyncService* service) | 52 explicit SyncUnrecoverableErrorChecker( |
| 53 browser_sync::ProfileSyncService* service) |
53 : SingleClientStatusChangeChecker(service) {} | 54 : SingleClientStatusChangeChecker(service) {} |
54 | 55 |
55 bool IsExitConditionSatisfied() override { | 56 bool IsExitConditionSatisfied() override { |
56 return service()->HasUnrecoverableError(); | 57 return service()->HasUnrecoverableError(); |
57 } | 58 } |
58 | 59 |
59 std::string GetDebugMessage() const override { | 60 std::string GetDebugMessage() const override { |
60 return "Sync Unrecoverable Error"; | 61 return "Sync Unrecoverable Error"; |
61 } | 62 } |
62 }; | 63 }; |
63 | 64 |
64 IN_PROC_BROWSER_TEST_F(SingleClientDirectorySyncTest, | 65 IN_PROC_BROWSER_TEST_F(SingleClientDirectorySyncTest, |
65 StopThenDisableDeletesDirectory) { | 66 StopThenDisableDeletesDirectory) { |
66 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 67 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
67 ProfileSyncService* sync_service = GetSyncService(0); | 68 browser_sync::ProfileSyncService* sync_service = GetSyncService(0); |
68 base::FilePath directory_path = sync_service->GetDirectoryPathForTest(); | 69 base::FilePath directory_path = sync_service->GetDirectoryPathForTest(); |
69 ASSERT_TRUE(base::DirectoryExists(directory_path)); | 70 ASSERT_TRUE(base::DirectoryExists(directory_path)); |
70 sync_service->RequestStop(ProfileSyncService::CLEAR_DATA); | 71 sync_service->RequestStop(browser_sync::ProfileSyncService::CLEAR_DATA); |
71 | 72 |
72 // Wait for StartupController::StartUp()'s tasks to finish. | 73 // Wait for StartupController::StartUp()'s tasks to finish. |
73 base::RunLoop run_loop; | 74 base::RunLoop run_loop; |
74 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 75 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
75 run_loop.QuitClosure()); | 76 run_loop.QuitClosure()); |
76 run_loop.Run(); | 77 run_loop.Run(); |
77 // Wait for the directory deletion to finish. | 78 // Wait for the directory deletion to finish. |
78 base::MessageLoop* sync_loop = sync_service->GetSyncLoopForTest(); | 79 base::MessageLoop* sync_loop = sync_service->GetSyncLoopForTest(); |
79 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop)); | 80 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop)); |
80 | 81 |
81 ASSERT_FALSE(base::DirectoryExists(directory_path)); | 82 ASSERT_FALSE(base::DirectoryExists(directory_path)); |
82 } | 83 } |
83 | 84 |
84 // Verify that when the sync directory's backing store becomes corrupted, we | 85 // Verify that when the sync directory's backing store becomes corrupted, we |
85 // trigger an unrecoverable error and delete the database. | 86 // trigger an unrecoverable error and delete the database. |
86 // | 87 // |
87 // If this test fails, see the definition of kNumEntriesRequiredForCorruption | 88 // If this test fails, see the definition of kNumEntriesRequiredForCorruption |
88 // for one possible cause. | 89 // for one possible cause. |
89 IN_PROC_BROWSER_TEST_F(SingleClientDirectorySyncTest, | 90 IN_PROC_BROWSER_TEST_F(SingleClientDirectorySyncTest, |
90 DeleteDirectoryWhenCorrupted) { | 91 DeleteDirectoryWhenCorrupted) { |
91 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | 92 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; |
92 // Sync and wait for syncing to complete. | 93 // Sync and wait for syncing to complete. |
93 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 94 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
94 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | 95 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
95 ASSERT_TRUE(bookmarks_helper::ModelMatchesVerifier(0)); | 96 ASSERT_TRUE(bookmarks_helper::ModelMatchesVerifier(0)); |
96 | 97 |
97 // Flush the directory to the backing store and wait until the flush | 98 // Flush the directory to the backing store and wait until the flush |
98 // completes. | 99 // completes. |
99 ProfileSyncService* sync_service = GetSyncService(0); | 100 browser_sync::ProfileSyncService* sync_service = GetSyncService(0); |
100 sync_service->FlushDirectory(); | 101 sync_service->FlushDirectory(); |
101 base::MessageLoop* sync_loop = sync_service->GetSyncLoopForTest(); | 102 base::MessageLoop* sync_loop = sync_service->GetSyncLoopForTest(); |
102 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop)); | 103 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop)); |
103 | 104 |
104 // Now corrupt the database. | 105 // Now corrupt the database. |
105 const base::FilePath directory_path(sync_service->GetDirectoryPathForTest()); | 106 const base::FilePath directory_path(sync_service->GetDirectoryPathForTest()); |
106 const base::FilePath sync_db(directory_path.Append( | 107 const base::FilePath sync_db(directory_path.Append( |
107 syncer::syncable::Directory::kSyncDatabaseFilename)); | 108 syncer::syncable::Directory::kSyncDatabaseFilename)); |
108 ASSERT_TRUE(CorruptDatabase(sync_db)); | 109 ASSERT_TRUE(CorruptDatabase(sync_db)); |
109 | 110 |
(...skipping 21 matching lines...) Expand all Loading... |
131 SyncUnrecoverableErrorChecker checker(sync_service); | 132 SyncUnrecoverableErrorChecker checker(sync_service); |
132 checker.Wait(); | 133 checker.Wait(); |
133 ASSERT_TRUE(!checker.TimedOut()); | 134 ASSERT_TRUE(!checker.TimedOut()); |
134 ASSERT_TRUE(sync_service->HasUnrecoverableError()); | 135 ASSERT_TRUE(sync_service->HasUnrecoverableError()); |
135 | 136 |
136 // Wait until the sync loop has processed any existing tasks and see that the | 137 // Wait until the sync loop has processed any existing tasks and see that the |
137 // directory no longer exists. | 138 // directory no longer exists. |
138 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop)); | 139 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop)); |
139 ASSERT_FALSE(base::DirectoryExists(directory_path)); | 140 ASSERT_FALSE(base::DirectoryExists(directory_path)); |
140 } | 141 } |
OLD | NEW |