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

Side by Side Diff: components/safe_browsing_db/v4_database_unittest.cc

Issue 2128173003: Merge the hash prefixes from the old store and the additions in the partial (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit: s/soace/space Created 4 years, 5 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 | « components/safe_browsing_db/v4_database.cc ('k') | components/safe_browsing_db/v4_store.h » ('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 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/bind.h" 5 #include "base/bind.h"
6 #include "base/debug/leak_annotations.h" 6 #include "base/debug/leak_annotations.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 EXPECT_EQ(expected_resets_successfully_, v4_database->ResetDatabase()); 121 EXPECT_EQ(expected_resets_successfully_, v4_database->ResetDatabase());
122 122
123 EXPECT_FALSE(created_and_called_back_); 123 EXPECT_FALSE(created_and_called_back_);
124 created_and_called_back_ = true; 124 created_and_called_back_ = true;
125 125
126 v4_database_ = std::move(v4_database); 126 v4_database_ = std::move(v4_database);
127 } 127 }
128 128
129 std::unique_ptr<ParsedServerResponse> CreateFakeServerResponse( 129 std::unique_ptr<ParsedServerResponse> CreateFakeServerResponse(
130 StoreStateMap store_state_map) { 130 StoreStateMap store_state_map,
131 bool use_valid_response_type) {
131 std::unique_ptr<ParsedServerResponse> parsed_server_response( 132 std::unique_ptr<ParsedServerResponse> parsed_server_response(
132 new ParsedServerResponse); 133 new ParsedServerResponse);
133 for (const auto& store_state_iter : store_state_map) { 134 for (const auto& store_state_iter : store_state_map) {
134 UpdateListIdentifier identifier = store_state_iter.first; 135 UpdateListIdentifier identifier = store_state_iter.first;
135 ListUpdateResponse* list_update_response = new ListUpdateResponse; 136 ListUpdateResponse* lur = new ListUpdateResponse;
136 list_update_response->set_platform_type(identifier.platform_type); 137 lur->set_platform_type(identifier.platform_type);
137 list_update_response->set_threat_entry_type(identifier.threat_entry_type); 138 lur->set_threat_entry_type(identifier.threat_entry_type);
138 list_update_response->set_threat_type(identifier.threat_type); 139 lur->set_threat_type(identifier.threat_type);
139 list_update_response->set_new_client_state(store_state_iter.second); 140 lur->set_new_client_state(store_state_iter.second);
140 parsed_server_response->push_back(base::WrapUnique(list_update_response)); 141 if (use_valid_response_type) {
142 lur->set_response_type(ListUpdateResponse::FULL_UPDATE);
143 } else {
144 lur->set_response_type(ListUpdateResponse::RESPONSE_TYPE_UNSPECIFIED);
145 }
146 parsed_server_response->push_back(base::WrapUnique(lur));
141 } 147 }
142 return parsed_server_response; 148 return parsed_server_response;
143 } 149 }
144 150
145 void VerifyExpectedStoresState(bool expect_new_stores) { 151 void VerifyExpectedStoresState(bool expect_new_stores) {
146 const StoreMap* new_store_map = v4_database_->store_map_.get(); 152 const StoreMap* new_store_map = v4_database_->store_map_.get();
147 std::unique_ptr<StoreStateMap> new_store_state_map = 153 std::unique_ptr<StoreStateMap> new_store_state_map =
148 v4_database_->GetStoreStateMap(); 154 v4_database_->GetStoreStateMap();
149 EXPECT_EQ(expected_store_state_map_.size(), new_store_map->size()); 155 EXPECT_EQ(expected_store_state_map_.size(), new_store_map->size());
150 EXPECT_EQ(expected_store_state_map_.size(), new_store_state_map->size()); 156 EXPECT_EQ(expected_store_state_map_.size(), new_store_state_map->size());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // The database has now been created. Time to try to update it. 236 // The database has now been created. Time to try to update it.
231 EXPECT_TRUE(v4_database_); 237 EXPECT_TRUE(v4_database_);
232 const StoreMap* db_stores = v4_database_->store_map_.get(); 238 const StoreMap* db_stores = v4_database_->store_map_.get();
233 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); 239 EXPECT_EQ(expected_store_paths_.size(), db_stores->size());
234 for (const auto& store_iter : *db_stores) { 240 for (const auto& store_iter : *db_stores) {
235 V4Store* store = store_iter.second.get(); 241 V4Store* store = store_iter.second.get();
236 expected_store_state_map_[store_iter.first] = store->state() + "_fake"; 242 expected_store_state_map_[store_iter.first] = store->state() + "_fake";
237 old_stores_map_[store_iter.first] = store; 243 old_stores_map_[store_iter.first] = store;
238 } 244 }
239 245
240 v4_database_->ApplyUpdate(CreateFakeServerResponse(expected_store_state_map_), 246 v4_database_->ApplyUpdate(
241 callback_db_updated_); 247 CreateFakeServerResponse(expected_store_state_map_, true),
248 callback_db_updated_);
242 249
243 task_runner_->RunPendingTasks(); 250 task_runner_->RunPendingTasks();
244 base::RunLoop().RunUntilIdle(); 251 base::RunLoop().RunUntilIdle();
245 252
246 VerifyExpectedStoresState(true); 253 VerifyExpectedStoresState(true);
247 } 254 }
248 255
249 // Test to ensure no state updates leads to no store updates. 256 // Test to ensure no state updates leads to no store updates.
250 TEST_F(V4DatabaseTest, TestApplyUpdateWithNoNewState) { 257 TEST_F(V4DatabaseTest, TestApplyUpdateWithNoNewState) {
251 expected_resets_successfully_ = true; 258 expected_resets_successfully_ = true;
252 RegisterFactory(!expected_resets_successfully_); 259 RegisterFactory(!expected_resets_successfully_);
253 260
254 V4Database::Create(task_runner_, database_dirname_, store_file_name_map_, 261 V4Database::Create(task_runner_, database_dirname_, store_file_name_map_,
255 callback_db_ready_); 262 callback_db_ready_);
256 created_but_not_called_back_ = true; 263 created_but_not_called_back_ = true;
257 task_runner_->RunPendingTasks(); 264 task_runner_->RunPendingTasks();
258 base::RunLoop().RunUntilIdle(); 265 base::RunLoop().RunUntilIdle();
259 266
260 // The database has now been created. Time to try to update it. 267 // The database has now been created. Time to try to update it.
261 EXPECT_TRUE(v4_database_); 268 EXPECT_TRUE(v4_database_);
262 const StoreMap* db_stores = v4_database_->store_map_.get(); 269 const StoreMap* db_stores = v4_database_->store_map_.get();
263 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); 270 EXPECT_EQ(expected_store_paths_.size(), db_stores->size());
264 for (const auto& store_iter : *db_stores) { 271 for (const auto& store_iter : *db_stores) {
265 V4Store* store = store_iter.second.get(); 272 V4Store* store = store_iter.second.get();
266 expected_store_state_map_[store_iter.first] = store->state(); 273 expected_store_state_map_[store_iter.first] = store->state();
267 old_stores_map_[store_iter.first] = store; 274 old_stores_map_[store_iter.first] = store;
268 } 275 }
269 276
270 v4_database_->ApplyUpdate(CreateFakeServerResponse(expected_store_state_map_), 277 v4_database_->ApplyUpdate(
271 callback_db_updated_); 278 CreateFakeServerResponse(expected_store_state_map_, true),
279 callback_db_updated_);
272 280
273 task_runner_->RunPendingTasks(); 281 task_runner_->RunPendingTasks();
274 base::RunLoop().RunUntilIdle(); 282 base::RunLoop().RunUntilIdle();
275 283
276 VerifyExpectedStoresState(false); 284 VerifyExpectedStoresState(false);
277 } 285 }
278 286
279 // Test to ensure no updates leads to no store updates. 287 // Test to ensure no updates leads to no store updates.
280 TEST_F(V4DatabaseTest, TestApplyUpdateWithEmptyUpdate) { 288 TEST_F(V4DatabaseTest, TestApplyUpdateWithEmptyUpdate) {
281 expected_resets_successfully_ = true; 289 expected_resets_successfully_ = true;
(...skipping 19 matching lines...) Expand all
301 new ParsedServerResponse); 309 new ParsedServerResponse);
302 v4_database_->ApplyUpdate(std::move(parsed_server_response), 310 v4_database_->ApplyUpdate(std::move(parsed_server_response),
303 callback_db_updated_); 311 callback_db_updated_);
304 312
305 task_runner_->RunPendingTasks(); 313 task_runner_->RunPendingTasks();
306 base::RunLoop().RunUntilIdle(); 314 base::RunLoop().RunUntilIdle();
307 315
308 VerifyExpectedStoresState(false); 316 VerifyExpectedStoresState(false);
309 } 317 }
310 318
319 // Test to ensure invalid update leads to no store changes.
320 TEST_F(V4DatabaseTest, TestApplyUpdateWithInvalidUpdate) {
321 expected_resets_successfully_ = true;
322 RegisterFactory(!expected_resets_successfully_);
323
324 V4Database::Create(task_runner_, database_dirname_, store_file_name_map_,
325 callback_db_ready_);
326 created_but_not_called_back_ = true;
327 task_runner_->RunPendingTasks();
328 base::RunLoop().RunUntilIdle();
329
330 // The database has now been created. Time to try to update it.
331 EXPECT_TRUE(v4_database_);
332 const StoreMap* db_stores = v4_database_->store_map_.get();
333 EXPECT_EQ(expected_store_paths_.size(), db_stores->size());
334 for (const auto& store_iter : *db_stores) {
335 V4Store* store = store_iter.second.get();
336 expected_store_state_map_[store_iter.first] = store->state();
337 old_stores_map_[store_iter.first] = store;
338 }
339
340 v4_database_->ApplyUpdate(
341 CreateFakeServerResponse(expected_store_state_map_, false),
342 callback_db_updated_);
343 task_runner_->RunPendingTasks();
344 base::RunLoop().RunUntilIdle();
345
346 VerifyExpectedStoresState(false);
347 }
348
311 } // namespace safe_browsing 349 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_database.cc ('k') | components/safe_browsing_db/v4_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698