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

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

Issue 2103693002: SafeBrowsing PVer4: Send mutable response to the database and the stores (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_ReadFromDisk
Patch Set: 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
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/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 8 #include "base/run_loop.h"
8 #include "base/test/test_simple_task_runner.h" 9 #include "base/test/test_simple_task_runner.h"
9 #include "base/time/time.h" 10 #include "base/time/time.h"
10 #include "components/safe_browsing_db/v4_store.h" 11 #include "components/safe_browsing_db/v4_store.h"
11 #include "components/safe_browsing_db/v4_store.pb.h" 12 #include "components/safe_browsing_db/v4_store.pb.h"
12 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
14 15
15 namespace safe_browsing { 16 namespace safe_browsing {
16 17
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 107 }
107 108
108 TEST_F(V4StoreTest, TestReadFromNoHashPrefixesFile) { 109 TEST_F(V4StoreTest, TestReadFromNoHashPrefixesFile) {
109 ListUpdateResponse list_update_response; 110 ListUpdateResponse list_update_response;
110 list_update_response.set_platform_type(LINUX_PLATFORM); 111 list_update_response.set_platform_type(LINUX_PLATFORM);
111 WriteFileFormatProtoToFile(0x600D71FE, 9, &list_update_response); 112 WriteFileFormatProtoToFile(0x600D71FE, 9, &list_update_response);
112 EXPECT_EQ(READ_SUCCESS, V4Store(task_runner_, store_path_).ReadFromDisk()); 113 EXPECT_EQ(READ_SUCCESS, V4Store(task_runner_, store_path_).ReadFromDisk());
113 } 114 }
114 115
115 TEST_F(V4StoreTest, TestWriteNoResponseType) { 116 TEST_F(V4StoreTest, TestWriteNoResponseType) {
116 ListUpdateResponse list_update_response; 117 EXPECT_EQ(INVALID_RESPONSE_TYPE_FAILURE,
117 EXPECT_EQ( 118 V4Store(task_runner_, store_path_)
118 INVALID_RESPONSE_TYPE_FAILURE, 119 .WriteToDisk(base::WrapUnique(new ListUpdateResponse)));
119 V4Store(task_runner_, store_path_).WriteToDisk(list_update_response));
120 } 120 }
121 121
122 TEST_F(V4StoreTest, TestWritePartialResponseType) { 122 TEST_F(V4StoreTest, TestWritePartialResponseType) {
123 ListUpdateResponse list_update_response; 123 ListUpdateResponse* list_update_response = new ListUpdateResponse;
Scott Hess - ex-Googler 2016/06/28 03:58:43 This leaves the pointer unowned for a bit. Instea
vakh (use Gerrit instead) 2016/06/28 21:34:14 Done.
124 list_update_response.set_response_type(ListUpdateResponse::PARTIAL_UPDATE); 124 list_update_response->set_response_type(ListUpdateResponse::PARTIAL_UPDATE);
125 EXPECT_EQ( 125 EXPECT_EQ(INVALID_RESPONSE_TYPE_FAILURE,
126 INVALID_RESPONSE_TYPE_FAILURE, 126 V4Store(task_runner_, store_path_)
127 V4Store(task_runner_, store_path_).WriteToDisk(list_update_response)); 127 .WriteToDisk(base::WrapUnique(list_update_response)));
128 } 128 }
129 129
130 TEST_F(V4StoreTest, TestWriteFullResponseType) { 130 TEST_F(V4StoreTest, TestWriteFullResponseType) {
131 ListUpdateResponse list_update_response; 131 ListUpdateResponse* list_update_response = new ListUpdateResponse;
Scott Hess - ex-Googler 2016/06/28 03:58:43 Likewise here.
vakh (use Gerrit instead) 2016/06/28 21:34:14 Done.
132 list_update_response.set_response_type(ListUpdateResponse::FULL_UPDATE); 132 list_update_response->set_response_type(ListUpdateResponse::FULL_UPDATE);
133 list_update_response.set_new_client_state("test_client_state"); 133 list_update_response->set_new_client_state("test_client_state");
134 V4Store* write_store = new V4Store(task_runner_, store_path_); 134 V4Store* write_store = new V4Store(task_runner_, store_path_);
135 EXPECT_EQ(WRITE_SUCCESS, write_store->WriteToDisk(list_update_response)); 135 EXPECT_EQ(WRITE_SUCCESS,
136 write_store->WriteToDisk(base::WrapUnique(list_update_response)));
136 137
137 V4Store* read_store = new V4Store(task_runner_, store_path_); 138 V4Store* read_store = new V4Store(task_runner_, store_path_);
138 EXPECT_EQ(READ_SUCCESS, read_store->ReadFromDisk()); 139 EXPECT_EQ(READ_SUCCESS, read_store->ReadFromDisk());
139 EXPECT_EQ("test_client_state", read_store->state_); 140 EXPECT_EQ("test_client_state", read_store->state_);
140 } 141 }
141 142
142 } // namespace safe_browsing 143 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698