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

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/state_store_unittest.cc

Issue 1342873002: Small logic change to StateStore::Transaction::ClearAll (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit test Created 5 years, 3 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 | « chrome/browser/safe_browsing/incident_reporting/state_store.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/safe_browsing/incident_reporting/state_store.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/state_store.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (data.type == removed_type) { 178 if (data.type == removed_type) {
179 ASSERT_FALSE( 179 ASSERT_FALSE(
180 state_store.HasBeenReported(data.type, data.key, data.digest)); 180 state_store.HasBeenReported(data.type, data.key, data.digest));
181 } else { 181 } else {
182 ASSERT_TRUE( 182 ASSERT_TRUE(
183 state_store.HasBeenReported(data.type, data.key, data.digest)); 183 state_store.HasBeenReported(data.type, data.key, data.digest));
184 } 184 }
185 } 185 }
186 } 186 }
187 187
188 TEST_F(StateStoreTest, ClearAll) {
189 StateStore state_store(profile_);
190 // Write some state to the store.
191 {
192 StateStore::Transaction transaction(&state_store);
193 for (const auto& data : kTestData_)
194 transaction.MarkAsReported(data.type, data.key, data.digest);
195 }
196
197 StateStore::Transaction(&state_store).ClearAll();
198
199 for (const auto& data : kTestData_) {
200 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest));
201 }
202
203 // Run tasks to write prefs out to the JsonPrefStore.
204 task_runner_->RunUntilIdle();
205
206 // Delete the profile.
207 DeleteProfile();
208
209 // Recreate the profile.
210 CreateProfile();
211
212 StateStore store_2(profile_);
213 for (const auto& data : kTestData_) {
214 // Verify that the state did not survive through the Platform State Store.
215 ASSERT_FALSE(store_2.HasBeenReported(data.type, data.key, data.digest));
216 }
217 }
218
188 TEST_F(StateStoreTest, Persistence) { 219 TEST_F(StateStoreTest, Persistence) {
189 // Write some state to the store. 220 // Write some state to the store.
190 { 221 {
191 StateStore state_store(profile_); 222 StateStore state_store(profile_);
192 StateStore::Transaction transaction(&state_store); 223 StateStore::Transaction transaction(&state_store);
193 for (const auto& data : kTestData_) 224 for (const auto& data : kTestData_)
194 transaction.MarkAsReported(data.type, data.key, data.digest); 225 transaction.MarkAsReported(data.type, data.key, data.digest);
195 } 226 }
196 227
197 // Run tasks to write prefs out to the JsonPrefStore. 228 // Run tasks to write prefs out to the JsonPrefStore.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // Verify that the state survived. 267 // Verify that the state survived.
237 ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest)); 268 ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest));
238 #else 269 #else
239 // Verify that the state did not survive. 270 // Verify that the state did not survive.
240 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest)); 271 ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest));
241 #endif 272 #endif
242 } 273 }
243 } 274 }
244 275
245 } // namespace safe_browsing 276 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/incident_reporting/state_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698