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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc

Issue 8349018: Safe-browsing SBAddPrefix from vector to deque. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 2 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/safe_browsing_store_file.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h" 9 #include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 test_store.Init( 82 test_store.Init(
83 filename_, 83 filename_,
84 base::Bind(&SafeBrowsingStoreFileTest::OnCorruptionDetected, 84 base::Bind(&SafeBrowsingStoreFileTest::OnCorruptionDetected,
85 base::Unretained(this))); 85 base::Unretained(this)));
86 86
87 corruption_detected_ = false; 87 corruption_detected_ = false;
88 88
89 // Can successfully open and read the store. 89 // Can successfully open and read the store.
90 std::vector<SBAddFullHash> pending_adds; 90 std::vector<SBAddFullHash> pending_adds;
91 std::set<SBPrefix> prefix_misses; 91 std::set<SBPrefix> prefix_misses;
92 std::vector<SBAddPrefix> orig_prefixes; 92 SBAddPrefixContainer orig_prefixes;
93 std::vector<SBAddFullHash> orig_hashes; 93 std::vector<SBAddFullHash> orig_hashes;
94 EXPECT_TRUE(test_store.BeginUpdate()); 94 EXPECT_TRUE(test_store.BeginUpdate());
95 EXPECT_TRUE(test_store.FinishUpdate(pending_adds, prefix_misses, 95 EXPECT_TRUE(test_store.FinishUpdate(pending_adds, prefix_misses,
96 &orig_prefixes, &orig_hashes)); 96 &orig_prefixes, &orig_hashes));
97 EXPECT_GT(orig_prefixes.size(), 0U); 97 EXPECT_GT(orig_prefixes.size(), 0U);
98 EXPECT_GT(orig_hashes.size(), 0U); 98 EXPECT_GT(orig_hashes.size(), 0U);
99 EXPECT_FALSE(corruption_detected_); 99 EXPECT_FALSE(corruption_detected_);
100 100
101 // Corrupt the store. 101 // Corrupt the store.
102 file_util::ScopedFILE file(file_util::OpenFile(filename_, "rb+")); 102 file_util::ScopedFILE file(file_util::OpenFile(filename_, "rb+"));
103 const long kOffset = 60; 103 const long kOffset = 60;
104 EXPECT_EQ(fseek(file.get(), kOffset, SEEK_SET), 0); 104 EXPECT_EQ(fseek(file.get(), kOffset, SEEK_SET), 0);
105 const int32 kZero = 0; 105 const int32 kZero = 0;
106 int32 previous = kZero; 106 int32 previous = kZero;
107 EXPECT_EQ(fread(&previous, sizeof(previous), 1, file.get()), 1U); 107 EXPECT_EQ(fread(&previous, sizeof(previous), 1, file.get()), 1U);
108 EXPECT_NE(previous, kZero); 108 EXPECT_NE(previous, kZero);
109 EXPECT_EQ(fseek(file.get(), kOffset, SEEK_SET), 0); 109 EXPECT_EQ(fseek(file.get(), kOffset, SEEK_SET), 0);
110 EXPECT_EQ(fwrite(&kZero, sizeof(kZero), 1, file.get()), 1U); 110 EXPECT_EQ(fwrite(&kZero, sizeof(kZero), 1, file.get()), 1U);
111 file.reset(); 111 file.reset();
112 112
113 // Update fails and corruption callback is called. 113 // Update fails and corruption callback is called.
114 std::vector<SBAddPrefix> add_prefixes; 114 SBAddPrefixContainer add_prefixes;
115 std::vector<SBAddFullHash> add_hashes; 115 std::vector<SBAddFullHash> add_hashes;
116 corruption_detected_ = false; 116 corruption_detected_ = false;
117 EXPECT_TRUE(test_store.BeginUpdate()); 117 EXPECT_TRUE(test_store.BeginUpdate());
118 EXPECT_FALSE(test_store.FinishUpdate(pending_adds, prefix_misses, 118 EXPECT_FALSE(test_store.FinishUpdate(pending_adds, prefix_misses,
119 &add_prefixes, &add_hashes)); 119 &add_prefixes, &add_hashes));
120 EXPECT_TRUE(corruption_detected_); 120 EXPECT_TRUE(corruption_detected_);
121 EXPECT_EQ(add_prefixes.size(), 0U); 121 EXPECT_EQ(add_prefixes.size(), 0U);
122 EXPECT_EQ(add_hashes.size(), 0U); 122 EXPECT_EQ(add_hashes.size(), 0U);
123 123
124 // Make it look like there is a lot of add-chunks-seen data. 124 // Make it look like there is a lot of add-chunks-seen data.
125 const long kAddChunkCountOffset = 2 * sizeof(int32); 125 const long kAddChunkCountOffset = 2 * sizeof(int32);
126 const int32 kLargeCount = 1000 * 1000 * 1000; 126 const int32 kLargeCount = 1000 * 1000 * 1000;
127 file.reset(file_util::OpenFile(filename_, "rb+")); 127 file.reset(file_util::OpenFile(filename_, "rb+"));
128 EXPECT_EQ(fseek(file.get(), kAddChunkCountOffset, SEEK_SET), 0); 128 EXPECT_EQ(fseek(file.get(), kAddChunkCountOffset, SEEK_SET), 0);
129 EXPECT_EQ(fwrite(&kLargeCount, sizeof(kLargeCount), 1, file.get()), 1U); 129 EXPECT_EQ(fwrite(&kLargeCount, sizeof(kLargeCount), 1, file.get()), 1U);
130 file.reset(); 130 file.reset();
131 131
132 // Detects corruption and fails to even begin the update. 132 // Detects corruption and fails to even begin the update.
133 corruption_detected_ = false; 133 corruption_detected_ = false;
134 EXPECT_FALSE(test_store.BeginUpdate()); 134 EXPECT_FALSE(test_store.BeginUpdate());
135 EXPECT_TRUE(corruption_detected_); 135 EXPECT_TRUE(corruption_detected_);
136 } 136 }
137 137
138 } // namespace 138 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698