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

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: Minor: Add the explicit keyword for UpdateListIdentifier constructor 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 std::unique_ptr<ListUpdateResponse> list_update_response(
124 list_update_response.set_response_type(ListUpdateResponse::PARTIAL_UPDATE); 124 new ListUpdateResponse);
125 EXPECT_EQ( 125 list_update_response->set_response_type(ListUpdateResponse::PARTIAL_UPDATE);
126 INVALID_RESPONSE_TYPE_FAILURE, 126 EXPECT_EQ(INVALID_RESPONSE_TYPE_FAILURE,
127 V4Store(task_runner_, store_path_).WriteToDisk(list_update_response)); 127 V4Store(task_runner_, store_path_)
128 .WriteToDisk(std::move(list_update_response)));
128 } 129 }
129 130
130 TEST_F(V4StoreTest, TestWriteFullResponseType) { 131 TEST_F(V4StoreTest, TestWriteFullResponseType) {
131 ListUpdateResponse list_update_response; 132 std::unique_ptr<ListUpdateResponse> list_update_response(
132 list_update_response.set_response_type(ListUpdateResponse::FULL_UPDATE); 133 new ListUpdateResponse);
133 list_update_response.set_new_client_state("test_client_state"); 134 list_update_response->set_response_type(ListUpdateResponse::FULL_UPDATE);
134 EXPECT_EQ( 135 list_update_response->set_new_client_state("test_client_state");
135 WRITE_SUCCESS, 136 EXPECT_EQ(WRITE_SUCCESS, V4Store(task_runner_, store_path_)
136 V4Store(task_runner_, store_path_).WriteToDisk(list_update_response)); 137 .WriteToDisk(std::move(list_update_response)));
137 138
138 std::unique_ptr<V4Store> read_store(new V4Store(task_runner_, store_path_)); 139 std::unique_ptr<V4Store> read_store(new V4Store(task_runner_, store_path_));
139 EXPECT_EQ(READ_SUCCESS, read_store->ReadFromDisk()); 140 EXPECT_EQ(READ_SUCCESS, read_store->ReadFromDisk());
140 EXPECT_EQ("test_client_state", read_store->state_); 141 EXPECT_EQ("test_client_state", read_store->state_);
141 } 142 }
142 143
143 } // namespace safe_browsing 144 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_store.cc ('k') | components/safe_browsing_db/v4_update_protocol_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698