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

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

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Remove '// namespace safe_browsing' for a small fwd decl block. Created 5 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 5
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/test/test_simple_task_runner.h" 9 #include "base/test/test_simple_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 '\x08', // field 1, wire format varint 57 '\x08', // field 1, wire format varint
58 '\x05', // chunk_number varint 5 58 '\x05', // chunk_number varint 5
59 '\x22', // field 4, wire format length-delimited 59 '\x22', // field 4, wire format length-delimited
60 '\x04', // varint length 4 60 '\x04', // varint length 4
61 'e', 'f', 'g', 'h' // 4-byte prefix 61 'e', 'f', 'g', 'h' // 4-byte prefix
62 }; 62 };
63 const std::string kChunkPayload2(kRawChunkPayload2, sizeof(kRawChunkPayload2)); 63 const std::string kChunkPayload2(kRawChunkPayload2, sizeof(kRawChunkPayload2));
64 64
65 } // namespace 65 } // namespace
66 66
67 namespace safe_browsing {
68
67 class SafeBrowsingProtocolManagerTest : public testing::Test { 69 class SafeBrowsingProtocolManagerTest : public testing::Test {
68 protected: 70 protected:
69 std::string key_param_; 71 std::string key_param_;
70 72
71 void SetUp() override { 73 void SetUp() override {
72 std::string key = google_apis::GetAPIKey(); 74 std::string key = google_apis::GetAPIKey();
73 if (!key.empty()) { 75 if (!key.empty()) {
74 key_param_ = base::StringPrintf( 76 key_param_ = base::StringPrintf(
75 "&key=%s", 77 "&key=%s",
76 net::EscapeQueryParamValue(key, true).c_str()); 78 net::EscapeQueryParamValue(key, true).c_str());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 173
172 TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) { 174 TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) {
173 scoped_ptr<SafeBrowsingProtocolManager> pm(CreateProtocolManager(NULL)); 175 scoped_ptr<SafeBrowsingProtocolManager> pm(CreateProtocolManager(NULL));
174 176
175 // Add and Sub chunks. 177 // Add and Sub chunks.
176 SBListChunkRanges phish(kDefaultPhishList); 178 SBListChunkRanges phish(kDefaultPhishList);
177 phish.adds = "1,4,6,8-20,99"; 179 phish.adds = "1,4,6,8-20,99";
178 phish.subs = "16,32,64-96"; 180 phish.subs = "16,32,64-96";
179 EXPECT_EQ(base::StringPrintf("%s;a:1,4,6,8-20,99:s:16,32,64-96\n", 181 EXPECT_EQ(base::StringPrintf("%s;a:1,4,6,8-20,99:s:16,32,64-96\n",
180 kDefaultPhishList), 182 kDefaultPhishList),
181 safe_browsing::FormatList(phish)); 183 FormatList(phish));
182 184
183 // Add chunks only. 185 // Add chunks only.
184 phish.subs = ""; 186 phish.subs = "";
185 EXPECT_EQ(base::StringPrintf("%s;a:1,4,6,8-20,99\n", 187 EXPECT_EQ(base::StringPrintf("%s;a:1,4,6,8-20,99\n", kDefaultPhishList),
186 kDefaultPhishList), 188 FormatList(phish));
187 safe_browsing::FormatList(phish));
188 189
189 // Sub chunks only. 190 // Sub chunks only.
190 phish.adds = ""; 191 phish.adds = "";
191 phish.subs = "16,32,64-96"; 192 phish.subs = "16,32,64-96";
192 EXPECT_EQ(base::StringPrintf("%s;s:16,32,64-96\n", 193 EXPECT_EQ(base::StringPrintf("%s;s:16,32,64-96\n", kDefaultPhishList),
193 kDefaultPhishList), 194 FormatList(phish));
194 safe_browsing::FormatList(phish));
195 195
196 // No chunks of either type. 196 // No chunks of either type.
197 phish.adds = ""; 197 phish.adds = "";
198 phish.subs = ""; 198 phish.subs = "";
199 EXPECT_EQ(base::StringPrintf("%s;\n", kDefaultPhishList), 199 EXPECT_EQ(base::StringPrintf("%s;\n", kDefaultPhishList), FormatList(phish));
200 safe_browsing::FormatList(phish));
201 } 200 }
202 201
203 TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes) { 202 TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes) {
204 scoped_ptr<SafeBrowsingProtocolManager> pm(CreateProtocolManager(NULL)); 203 scoped_ptr<SafeBrowsingProtocolManager> pm(CreateProtocolManager(NULL));
205 204
206 // No errors or back off time yet. 205 // No errors or back off time yet.
207 EXPECT_EQ(0U, pm->gethash_error_count_); 206 EXPECT_EQ(0U, pm->gethash_error_count_);
208 EXPECT_TRUE(pm->next_gethash_time_.is_null()); 207 EXPECT_TRUE(pm->next_gethash_time_.is_null());
209 208
210 Time now = Time::Now(); 209 Time now = Time::Now();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // Tests the contents of the POST body when there are contents in the 400 // Tests the contents of the POST body when there are contents in the
402 // local database. This is not exhaustive, as the actual list formatting 401 // local database. This is not exhaustive, as the actual list formatting
403 // is covered by SafeBrowsingProtocolManagerTest.TestChunkStrings. 402 // is covered by SafeBrowsingProtocolManagerTest.TestChunkStrings.
404 TEST_F(SafeBrowsingProtocolManagerTest, ExistingDatabase) { 403 TEST_F(SafeBrowsingProtocolManagerTest, ExistingDatabase) {
405 scoped_refptr<base::TestSimpleTaskRunner> runner( 404 scoped_refptr<base::TestSimpleTaskRunner> runner(
406 new base::TestSimpleTaskRunner()); 405 new base::TestSimpleTaskRunner());
407 base::ThreadTaskRunnerHandle runner_handler(runner); 406 base::ThreadTaskRunnerHandle runner_handler(runner);
408 net::TestURLFetcherFactory url_fetcher_factory; 407 net::TestURLFetcherFactory url_fetcher_factory;
409 408
410 std::vector<SBListChunkRanges> ranges; 409 std::vector<SBListChunkRanges> ranges;
411 SBListChunkRanges range_phish(safe_browsing::kPhishingList); 410 SBListChunkRanges range_phish(kPhishingList);
412 range_phish.adds = "adds_phish"; 411 range_phish.adds = "adds_phish";
413 range_phish.subs = "subs_phish"; 412 range_phish.subs = "subs_phish";
414 ranges.push_back(range_phish); 413 ranges.push_back(range_phish);
415 414
416 SBListChunkRanges range_unknown("unknown_list"); 415 SBListChunkRanges range_unknown("unknown_list");
417 range_unknown.adds = "adds_unknown"; 416 range_unknown.adds = "adds_unknown";
418 range_unknown.subs = "subs_unknown"; 417 range_unknown.subs = "subs_unknown";
419 ranges.push_back(range_unknown); 418 ranges.push_back(range_unknown);
420 419
421 testing::StrictMock<MockProtocolDelegate> test_delegate; 420 testing::StrictMock<MockProtocolDelegate> test_delegate;
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 second_chunk_url_fetcher->delegate()->OnURLFetchComplete( 1123 second_chunk_url_fetcher->delegate()->OnURLFetchComplete(
1125 second_chunk_url_fetcher); 1124 second_chunk_url_fetcher);
1126 1125
1127 EXPECT_FALSE(pm->IsUpdateScheduled()); 1126 EXPECT_FALSE(pm->IsUpdateScheduled());
1128 1127
1129 // Invoke the AddChunksCallback to finish the update. 1128 // Invoke the AddChunksCallback to finish the update.
1130 runner->RunPendingTasks(); 1129 runner->RunPendingTasks();
1131 1130
1132 EXPECT_TRUE(pm->IsUpdateScheduled()); 1131 EXPECT_TRUE(pm->IsUpdateScheduled());
1133 } 1132 }
1133
1134 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager_helper.cc ('k') | chrome/browser/safe_browsing/protocol_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698