OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
10 #include "components/safe_browsing_db/v4_database.h" | 10 #include "components/safe_browsing_db/v4_database.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 void ForceDisableLocalDatabaseManager() { | 76 void ForceDisableLocalDatabaseManager() { |
77 v4_local_database_manager_->enabled_ = false; | 77 v4_local_database_manager_->enabled_ = false; |
78 } | 78 } |
79 | 79 |
80 const V4LocalDatabaseManager::QueuedChecks& GetQueuedChecks() { | 80 const V4LocalDatabaseManager::QueuedChecks& GetQueuedChecks() { |
81 return v4_local_database_manager_->queued_checks_; | 81 return v4_local_database_manager_->queued_checks_; |
82 } | 82 } |
83 | 83 |
84 void ReplaceV4Database(const StoreAndHashPrefixes& store_and_hash_prefixes) { | 84 void ReplaceV4Database(const StoreAndHashPrefixes& store_and_hash_prefixes) { |
| 85 // Make sure that VerifyChecksum runs before we reset. |
| 86 task_runner_->RunPendingTasks(); |
| 87 base::RunLoop().RunUntilIdle(); |
| 88 |
85 v4_local_database_manager_->v4_database_.reset(new FakeV4Database( | 89 v4_local_database_manager_->v4_database_.reset(new FakeV4Database( |
86 task_runner_, base::MakeUnique<StoreMap>(), store_and_hash_prefixes)); | 90 task_runner_, base::MakeUnique<StoreMap>(), store_and_hash_prefixes)); |
87 } | 91 } |
88 | 92 |
89 void ResetV4Database() { v4_local_database_manager_->v4_database_.reset(); } | 93 void ResetV4Database() { |
| 94 // Make sure that VerifyChecksum runs before we reset. |
| 95 task_runner_->RunPendingTasks(); |
| 96 base::RunLoop().RunUntilIdle(); |
| 97 |
| 98 v4_local_database_manager_->v4_database_.reset(); |
| 99 } |
90 | 100 |
91 void StartLocalDatabaseManager() { | 101 void StartLocalDatabaseManager() { |
92 v4_local_database_manager_->StartOnIOThread(NULL, V4ProtocolConfig()); | 102 v4_local_database_manager_->StartOnIOThread(NULL, V4ProtocolConfig()); |
93 | 103 |
94 task_runner_->RunPendingTasks(); | 104 task_runner_->RunPendingTasks(); |
95 base::RunLoop().RunUntilIdle(); | 105 base::RunLoop().RunUntilIdle(); |
96 } | 106 } |
97 | 107 |
98 void StopLocalDatabaseManager() { | 108 void StopLocalDatabaseManager() { |
99 v4_local_database_manager_->StopOnIOThread(true); | 109 v4_local_database_manager_->StopOnIOThread(true); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 ResetV4Database(); | 219 ResetV4Database(); |
210 v4_local_database_manager_->CheckBrowseUrl(url, &client); | 220 v4_local_database_manager_->CheckBrowseUrl(url, &client); |
211 // The database is unavailable so the check should get queued. | 221 // The database is unavailable so the check should get queued. |
212 EXPECT_EQ(1ul, GetQueuedChecks().size()); | 222 EXPECT_EQ(1ul, GetQueuedChecks().size()); |
213 | 223 |
214 StopLocalDatabaseManager(); | 224 StopLocalDatabaseManager(); |
215 EXPECT_TRUE(GetQueuedChecks().empty()); | 225 EXPECT_TRUE(GetQueuedChecks().empty()); |
216 } | 226 } |
217 | 227 |
218 } // namespace safe_browsing | 228 } // namespace safe_browsing |
OLD | NEW |