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

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

Issue 10905087: Revert 154861 - Run safebrowsing_service_test through the net testserver code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
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 // This test uses the safebrowsing test server published at 5 // This test uses the safebrowsing test server published at
6 // http://code.google.com/p/google-safe-browsing/ to test the safebrowsing 6 // http://code.google.com/p/google-safe-browsing/ to test the safebrowsing
7 // protocol implemetation. Details of the safebrowsing testing flow is 7 // protocol implemetation. Details of the safebrowsing testing flow is
8 // documented at 8 // documented at
9 // http://code.google.com/p/google-safe-browsing/wiki/ProtocolTesting 9 // http://code.google.com/p/google-safe-browsing/wiki/ProtocolTesting
10 // 10 //
(...skipping 13 matching lines...) Expand all
24 #include "base/string_number_conversions.h" 24 #include "base/string_number_conversions.h"
25 #include "base/string_split.h" 25 #include "base/string_split.h"
26 #include "base/stringprintf.h" 26 #include "base/stringprintf.h"
27 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
28 #include "base/test/test_timeouts.h" 28 #include "base/test/test_timeouts.h"
29 #include "base/threading/platform_thread.h" 29 #include "base/threading/platform_thread.h"
30 #include "base/threading/thread.h" 30 #include "base/threading/thread.h"
31 #include "base/time.h" 31 #include "base/time.h"
32 #include "base/utf_string_conversions.h" 32 #include "base/utf_string_conversions.h"
33 #include "chrome/browser/browser_process.h" 33 #include "chrome/browser/browser_process.h"
34 #include "chrome/browser/safe_browsing/local_safebrowsing_test_server.h"
35 #include "chrome/browser/safe_browsing/protocol_manager.h" 34 #include "chrome/browser/safe_browsing/protocol_manager.h"
36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
37 #include "chrome/common/chrome_notification_types.h" 36 #include "chrome/common/chrome_notification_types.h"
38 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/url_constants.h" 38 #include "chrome/common/url_constants.h"
40 #include "chrome/test/base/in_process_browser_test.h" 39 #include "chrome/test/base/in_process_browser_test.h"
41 #include "chrome/test/base/ui_test_utils.h" 40 #include "chrome/test/base/ui_test_utils.h"
42 #include "content/public/browser/browser_context.h" 41 #include "content/public/browser/browser_context.h"
43 #include "content/public/test/test_browser_thread.h" 42 #include "content/public/test/test_browser_thread.h"
44 #include "net/base/host_resolver.h" 43 #include "net/base/host_resolver.h"
45 #include "net/base/load_flags.h" 44 #include "net/base/load_flags.h"
46 #include "net/base/net_log.h" 45 #include "net/base/net_log.h"
47 #include "net/test/python_utils.h" 46 #include "net/test/python_utils.h"
48 #include "net/url_request/url_fetcher.h" 47 #include "net/url_request/url_fetcher.h"
49 #include "net/url_request/url_fetcher_delegate.h" 48 #include "net/url_request/url_fetcher_delegate.h"
50 #include "net/url_request/url_request_status.h" 49 #include "net/url_request/url_request_status.h"
51 #include "testing/gtest/include/gtest/gtest.h" 50 #include "testing/gtest/include/gtest/gtest.h"
52 51
53 using content::BrowserThread; 52 using content::BrowserThread;
54 53
55 namespace { 54 namespace {
56 55
57 const FilePath::CharType kDataFile[] = 56 const FilePath::CharType kDataFile[] =
58 FILE_PATH_LITERAL("testing_input_nomac.dat"); 57 FILE_PATH_LITERAL("testing_input_nomac.dat");
59 const char kUrlVerifyPath[] = "safebrowsing/verify_urls"; 58 const char kUrlVerifyPath[] = "/safebrowsing/verify_urls";
60 const char kDBVerifyPath[] = "safebrowsing/verify_database"; 59 const char kDBVerifyPath[] = "/safebrowsing/verify_database";
61 const char kTestCompletePath[] = "test_complete"; 60 const char kDBResetPath[] = "/reset";
61 const char kTestCompletePath[] = "/test_complete";
62 62
63 struct PhishingUrl { 63 struct PhishingUrl {
64 std::string url; 64 std::string url;
65 std::string list_name; 65 std::string list_name;
66 bool is_phishing; 66 bool is_phishing;
67 }; 67 };
68 68
69 // Parses server response for verify_urls. The expected format is: 69 // Parses server response for verify_urls. The expected format is:
70 // 70 //
71 // first.random.url.com/ internal-test-shavar yes 71 // first.random.url.com/ internal-test-shavar yes
(...skipping 29 matching lines...) Expand all
101 << ": " << record_parts[2]; 101 << ": " << record_parts[2];
102 return false; 102 return false;
103 } 103 }
104 phishing_urls->push_back(phishing_url); 104 phishing_urls->push_back(phishing_url);
105 } 105 }
106 return true; 106 return true;
107 } 107 }
108 108
109 } // namespace 109 } // namespace
110 110
111 class SafeBrowsingTestServer {
112 public:
113 explicit SafeBrowsingTestServer(const FilePath& datafile)
114 : datafile_(datafile),
115 server_handle_(base::kNullProcessHandle) {
116 }
117
118 ~SafeBrowsingTestServer() {
119 EXPECT_EQ(base::kNullProcessHandle, server_handle_);
120 }
121
122 // Start the python server test suite.
123 bool Start() {
124 // Get path to python server script
125 FilePath testserver_path;
126 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)) {
127 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
128 return false;
129 }
130 testserver_path = testserver_path
131 .Append(FILE_PATH_LITERAL("third_party"))
132 .Append(FILE_PATH_LITERAL("safe_browsing"))
133 .Append(FILE_PATH_LITERAL("testing"));
134 AppendToPythonPath(testserver_path);
135 FilePath testserver = testserver_path.Append(
136 FILE_PATH_LITERAL("safebrowsing_test_server.py"));
137
138 FilePath pyproto_code_dir;
139 if (!GetPyProtoPath(&pyproto_code_dir)) {
140 LOG(ERROR) << "Failed to get generated python protobuf dir";
141 return false;
142 }
143 AppendToPythonPath(pyproto_code_dir);
144 pyproto_code_dir = pyproto_code_dir.Append(FILE_PATH_LITERAL("google"));
145 AppendToPythonPath(pyproto_code_dir);
146
147 FilePath python_runtime;
148 EXPECT_TRUE(GetPythonRunTime(&python_runtime));
149 CommandLine cmd_line(python_runtime);
150 // Make python stdout and stderr unbuffered, to prevent incomplete stderr on
151 // win bots, and also fix mixed up ordering of stdout and stderr.
152 cmd_line.AppendSwitch("-u");
153 FilePath datafile = testserver_path.Append(datafile_);
154 cmd_line.AppendArgPath(testserver);
155 cmd_line.AppendArg(base::StringPrintf("--port=%d", kPort_));
156 cmd_line.AppendArgNative(FILE_PATH_LITERAL("--datafile=") +
157 datafile.value());
158
159 base::LaunchOptions options;
160 #if defined(OS_WIN)
161 options.start_hidden = true;
162 #endif
163 if (!base::LaunchProcess(cmd_line, options, &server_handle_)) {
164 LOG(ERROR) << "Failed to launch server: "
165 << cmd_line.GetCommandLineString();
166 return false;
167 }
168 return true;
169 }
170
171 // Stop the python server test suite.
172 bool Stop() {
173 if (server_handle_ == base::kNullProcessHandle)
174 return true;
175
176 // First check if the process has already terminated.
177 if (!base::WaitForSingleProcess(server_handle_, base::TimeDelta()) &&
178 !base::KillProcess(server_handle_, 1, true)) {
179 VLOG(1) << "Kill failed?";
180 return false;
181 }
182
183 base::CloseProcessHandle(server_handle_);
184 server_handle_ = base::kNullProcessHandle;
185 VLOG(1) << "Stopped.";
186 return true;
187 }
188
189 static const char* Host() {
190 return kHost_;
191 }
192
193 static int Port() {
194 return kPort_;
195 }
196
197 private:
198 static const char kHost_[];
199 static const int kPort_;
200 FilePath datafile_;
201 base::ProcessHandle server_handle_;
202 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingTestServer);
203 };
204
205 const char SafeBrowsingTestServer::kHost_[] = "localhost";
206 const int SafeBrowsingTestServer::kPort_ = 40102;
207
111 // This starts the browser and keeps status of states related to SafeBrowsing. 208 // This starts the browser and keeps status of states related to SafeBrowsing.
112 class SafeBrowsingServiceTest : public InProcessBrowserTest { 209 class SafeBrowsingServiceTest : public InProcessBrowserTest {
113 public: 210 public:
114 SafeBrowsingServiceTest() 211 SafeBrowsingServiceTest()
115 : safe_browsing_service_(NULL), 212 : safe_browsing_service_(NULL),
116 is_database_ready_(true), 213 is_database_ready_(true),
117 is_update_scheduled_(false), 214 is_update_scheduled_(false),
118 is_checked_url_in_db_(false), 215 is_checked_url_in_db_(false),
119 is_checked_url_safe_(false) { 216 is_checked_url_safe_(false) {
120 } 217 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 290
194 bool is_update_scheduled() { 291 bool is_update_scheduled() {
195 base::AutoLock l(update_status_mutex_); 292 base::AutoLock l(update_status_mutex_);
196 return is_update_scheduled_; 293 return is_update_scheduled_;
197 } 294 }
198 295
199 MessageLoop* SafeBrowsingMessageLoop() { 296 MessageLoop* SafeBrowsingMessageLoop() {
200 return safe_browsing_service_->safe_browsing_thread_->message_loop(); 297 return safe_browsing_service_->safe_browsing_thread_->message_loop();
201 } 298 }
202 299
203 const net::TestServer& test_server() const {
204 return *test_server_;
205 }
206
207 protected: 300 protected:
208 bool InitSafeBrowsingService() { 301 bool InitSafeBrowsingService() {
209 safe_browsing_service_ = g_browser_process->safe_browsing_service(); 302 safe_browsing_service_ = g_browser_process->safe_browsing_service();
210 return safe_browsing_service_ != NULL; 303 return safe_browsing_service_ != NULL;
211 } 304 }
212 305
213 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 306 virtual void SetUpCommandLine(CommandLine* command_line) {
214 FilePath datafile_path;
215 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &datafile_path));
216
217 datafile_path = datafile_path.Append(FILE_PATH_LITERAL("third_party"))
218 .Append(FILE_PATH_LITERAL("safe_browsing"))
219 .Append(FILE_PATH_LITERAL("testing"))
220 .Append(kDataFile);
221 test_server_.reset(new LocalSafeBrowsingTestServer(datafile_path));
222 ASSERT_TRUE(test_server_->Start());
223 LOG(INFO) << "server is " << test_server_->host_port_pair().ToString();
224
225 // Makes sure the auto update is not triggered. This test will force the 307 // Makes sure the auto update is not triggered. This test will force the
226 // update when needed. 308 // update when needed.
227 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); 309 command_line->AppendSwitch(switches::kSbDisableAutoUpdate);
228 310
229 // This test uses loopback. No need to use IPv6 especially it makes 311 // This test uses loopback. No need to use IPv6 especially it makes
230 // local requests slow on Windows trybot when ipv6 local address [::1] 312 // local requests slow on Windows trybot when ipv6 local address [::1]
231 // is not setup. 313 // is not setup.
232 command_line->AppendSwitch(switches::kDisableIPv6); 314 command_line->AppendSwitch(switches::kDisableIPv6);
233 315
234 // TODO(lzheng): The test server does not understand download related 316 // TODO(lzheng): The test server does not understand download related
235 // requests. We need to fix the server. 317 // requests. We need to fix the server.
236 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); 318 command_line->AppendSwitch(switches::kSbDisableDownloadProtection);
237 319
238 // TODO(gcasto): Generate new testing data that includes the 320 // TODO(gcasto): Generate new testing data that includes the
239 // client-side phishing whitelist. 321 // client-side phishing whitelist.
240 command_line->AppendSwitch( 322 command_line->AppendSwitch(
241 switches::kDisableClientSidePhishingDetection); 323 switches::kDisableClientSidePhishingDetection);
242 324
243 // Point to the testing server for all SafeBrowsing requests. 325 // Point to the testing server for all SafeBrowsing requests.
244 std::string url_prefix = test_server_->GetURL("safebrowsing").spec(); 326 std::string url_prefix =
327 base::StringPrintf("http://%s:%d/safebrowsing",
328 SafeBrowsingTestServer::Host(),
329 SafeBrowsingTestServer::Port());
245 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); 330 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix);
246 } 331 }
247 332
248 void SetTestStep(int step) { 333 void SetTestStep(int step) {
249 std::string test_step = base::StringPrintf("test_step=%d", step); 334 std::string test_step = base::StringPrintf("test_step=%d", step);
250 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); 335 safe_browsing_service_->protocol_manager_->set_additional_query(test_step);
251 } 336 }
252 337
253 private: 338 private:
254 SafeBrowsingService* safe_browsing_service_; 339 SafeBrowsingService* safe_browsing_service_;
255 340
256 scoped_ptr<net::TestServer> test_server_;
257
258 // Protects all variables below since they are read on UI thread 341 // Protects all variables below since they are read on UI thread
259 // but updated on IO thread or safebrowsing thread. 342 // but updated on IO thread or safebrowsing thread.
260 base::Lock update_status_mutex_; 343 base::Lock update_status_mutex_;
261 344
262 // States associated with safebrowsing service updates. 345 // States associated with safebrowsing service updates.
263 bool is_database_ready_; 346 bool is_database_ready_;
264 base::Time last_update_; 347 base::Time last_update_;
265 bool is_update_scheduled_; 348 bool is_update_scheduled_;
266 // Indicates if there is a match between a URL's prefix and safebrowsing 349 // Indicates if there is a match between a URL's prefix and safebrowsing
267 // database (thus potentially it is a phishing URL). 350 // database (thus potentially it is a phishing URL).
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 void UpdateStatus() { 441 void UpdateStatus() {
359 BrowserThread::PostTask( 442 BrowserThread::PostTask(
360 BrowserThread::IO, 443 BrowserThread::IO,
361 FROM_HERE, 444 FROM_HERE,
362 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, 445 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread,
363 this)); 446 this));
364 // Will continue after OnWaitForStatusUpdateDone(). 447 // Will continue after OnWaitForStatusUpdateDone().
365 content::RunMessageLoop(); 448 content::RunMessageLoop();
366 } 449 }
367 450
451 void WaitTillServerReady(const char* host, int port) {
452 response_status_ = net::URLRequestStatus::FAILED;
453 GURL url(base::StringPrintf("http://%s:%d%s?test_step=0",
454 host, port, kDBResetPath));
455 // TODO(lzheng): We should have a way to reliably tell when a server is
456 // ready so we could get rid of the Sleep and retry loop.
457 while (true) {
458 if (FetchUrl(url) == net::URLRequestStatus::SUCCESS)
459 break;
460 // Wait and try again if last fetch was failed. The loop will hit the
461 // timeout in OutOfProcTestRunner if the fetch can not get success
462 // response.
463 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
464 }
465 }
466
368 // Calls test server to fetch database for verification. 467 // Calls test server to fetch database for verification.
369 net::URLRequestStatus::Status FetchDBToVerify( 468 net::URLRequestStatus::Status FetchDBToVerify(const char* host, int port,
370 const net::TestServer& test_server, 469 int test_step) {
371 int test_step) {
372 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. 470 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server.
373 std::string path = base::StringPrintf( 471 GURL url(base::StringPrintf(
374 "%s?client=chromium&appver=1.0&pver=2.2&test_step=%d&chunk_type=add", 472 "http://%s:%d%s?"
375 kDBVerifyPath, test_step); 473 "client=chromium&appver=1.0&pver=2.2&test_step=%d&"
376 return FetchUrl(test_server.GetURL(path)); 474 "chunk_type=add",
475 host, port, kDBVerifyPath, test_step));
476 return FetchUrl(url);
377 } 477 }
378 478
379 // Calls test server to fetch URLs for verification. 479 // Calls test server to fetch URLs for verification.
380 net::URLRequestStatus::Status FetchUrlsToVerify( 480 net::URLRequestStatus::Status FetchUrlsToVerify(const char* host, int port,
381 const net::TestServer& test_server, 481 int test_step) {
382 int test_step) { 482 GURL url(base::StringPrintf(
383 std::string path = base::StringPrintf( 483 "http://%s:%d%s?"
384 "%s?client=chromium&appver=1.0&pver=2.2&test_step=%d", 484 "client=chromium&appver=1.0&pver=2.2&test_step=%d",
385 kUrlVerifyPath, test_step); 485 host, port, kUrlVerifyPath, test_step));
386 return FetchUrl(test_server.GetURL(path)); 486 return FetchUrl(url);
387 } 487 }
388 488
389 // Calls test server to check if test data is done. E.g.: if there is a 489 // Calls test server to check if test data is done. E.g.: if there is a
390 // bad URL that server expects test to fetch full hash but the test didn't, 490 // bad URL that server expects test to fetch full hash but the test didn't,
391 // this verification will fail. 491 // this verification will fail.
392 net::URLRequestStatus::Status VerifyTestComplete( 492 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port,
393 const net::TestServer& test_server, 493 int test_step) {
394 int test_step) { 494 GURL url(StringPrintf("http://%s:%d%s?test_step=%d",
395 std::string path = base::StringPrintf( 495 host, port, kTestCompletePath, test_step));
396 "%s?test_step=%d", kTestCompletePath, test_step); 496 return FetchUrl(url);
397 return FetchUrl(test_server.GetURL(path));
398 } 497 }
399 498
400 // Callback for URLFetcher. 499 // Callback for URLFetcher.
401 virtual void OnURLFetchComplete(const net::URLFetcher* source) { 500 virtual void OnURLFetchComplete(const net::URLFetcher* source) {
402 source->GetResponseAsString(&response_data_); 501 source->GetResponseAsString(&response_data_);
403 response_status_ = source->GetStatus().status(); 502 response_status_ = source->GetStatus().status();
404 StopUILoop(); 503 StopUILoop();
405 } 504 }
406 505
407 const std::string& response_data() { 506 const std::string& response_data() {
(...skipping 26 matching lines...) Expand all
434 SafeBrowsingServiceTest* safe_browsing_test_; 533 SafeBrowsingServiceTest* safe_browsing_test_;
435 scoped_ptr<net::URLFetcher> url_fetcher_; 534 scoped_ptr<net::URLFetcher> url_fetcher_;
436 std::string response_data_; 535 std::string response_data_;
437 net::URLRequestStatus::Status response_status_; 536 net::URLRequestStatus::Status response_status_;
438 net::URLRequestContextGetter* request_context_; 537 net::URLRequestContextGetter* request_context_;
439 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); 538 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper);
440 }; 539 };
441 540
442 // See http://crbug.com/96459 541 // See http://crbug.com/96459
443 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, 542 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest,
444 SafeBrowsingSystemTest) { 543 DISABLED_SafeBrowsingSystemTest) {
445 LOG(INFO) << "Start test"; 544 LOG(INFO) << "Start test";
545 const char* server_host = SafeBrowsingTestServer::Host();
546 int server_port = SafeBrowsingTestServer::Port();
446 ASSERT_TRUE(InitSafeBrowsingService()); 547 ASSERT_TRUE(InitSafeBrowsingService());
447 548
448 net::URLRequestContextGetter* request_context = 549 net::URLRequestContextGetter* request_context =
449 GetBrowserContext()->GetRequestContext(); 550 GetBrowserContext()->GetRequestContext();
450 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( 551 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper(
451 new SafeBrowsingServiceTestHelper(this, request_context)); 552 new SafeBrowsingServiceTestHelper(this, request_context));
452 int last_step = 0; 553 int last_step = 0;
554 FilePath datafile_path = FilePath(kDataFile);
555 SafeBrowsingTestServer test_server(datafile_path);
556 ASSERT_TRUE(test_server.Start());
557
558 // Make sure the server is running.
559 safe_browsing_helper->WaitTillServerReady(server_host, server_port);
453 560
454 // Waits and makes sure safebrowsing update is not happening. 561 // Waits and makes sure safebrowsing update is not happening.
455 // The wait will stop once OnWaitForStatusUpdateDone in 562 // The wait will stop once OnWaitForStatusUpdateDone in
456 // safe_browsing_helper is called and status from safe_browsing_service_ 563 // safe_browsing_helper is called and status from safe_browsing_service_
457 // is checked. 564 // is checked.
458 safe_browsing_helper->UpdateStatus(); 565 safe_browsing_helper->UpdateStatus();
459 EXPECT_TRUE(is_database_ready()); 566 EXPECT_TRUE(is_database_ready());
460 EXPECT_FALSE(is_update_scheduled()); 567 EXPECT_FALSE(is_update_scheduled());
461 EXPECT_TRUE(last_update().is_null()); 568 EXPECT_TRUE(last_update().is_null());
462 // Starts updates. After each update, the test will fetch a list of URLs with 569 // Starts updates. After each update, the test will fetch a list of URLs with
(...skipping 16 matching lines...) Expand all
479 EXPECT_TRUE(is_database_ready()); 586 EXPECT_TRUE(is_database_ready());
480 EXPECT_FALSE(is_update_scheduled()); 587 EXPECT_FALSE(is_update_scheduled());
481 EXPECT_FALSE(last_update().is_null()); 588 EXPECT_FALSE(last_update().is_null());
482 if (last_update() < now) { 589 if (last_update() < now) {
483 // This means no data available anymore. 590 // This means no data available anymore.
484 break; 591 break;
485 } 592 }
486 593
487 // Fetches URLs to verify and waits till server responses with data. 594 // Fetches URLs to verify and waits till server responses with data.
488 EXPECT_EQ(net::URLRequestStatus::SUCCESS, 595 EXPECT_EQ(net::URLRequestStatus::SUCCESS,
489 safe_browsing_helper->FetchUrlsToVerify(test_server(), step)); 596 safe_browsing_helper->FetchUrlsToVerify(server_host,
597 server_port,
598 step));
490 599
491 std::vector<PhishingUrl> phishing_urls; 600 std::vector<PhishingUrl> phishing_urls;
492 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), 601 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(),
493 &phishing_urls)); 602 &phishing_urls));
494 EXPECT_GT(phishing_urls.size(), 0U); 603 EXPECT_GT(phishing_urls.size(), 0U);
495 for (size_t j = 0; j < phishing_urls.size(); ++j) { 604 for (size_t j = 0; j < phishing_urls.size(); ++j) {
496 // Verifes with server if a URL is a phishing URL and waits till server 605 // Verifes with server if a URL is a phishing URL and waits till server
497 // responses. 606 // responses.
498 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); 607 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url));
499 if (phishing_urls[j].is_phishing) { 608 if (phishing_urls[j].is_phishing) {
500 EXPECT_TRUE(is_checked_url_in_db()) 609 EXPECT_TRUE(is_checked_url_in_db())
501 << phishing_urls[j].url 610 << phishing_urls[j].url
502 << " is_phishing: " << phishing_urls[j].is_phishing 611 << " is_phishing: " << phishing_urls[j].is_phishing
503 << " test step: " << step; 612 << " test step: " << step;
504 EXPECT_FALSE(is_checked_url_safe()) 613 EXPECT_FALSE(is_checked_url_safe())
505 << phishing_urls[j].url 614 << phishing_urls[j].url
506 << " is_phishing: " << phishing_urls[j].is_phishing 615 << " is_phishing: " << phishing_urls[j].is_phishing
507 << " test step: " << step; 616 << " test step: " << step;
508 } else { 617 } else {
509 EXPECT_TRUE(is_checked_url_safe()) 618 EXPECT_TRUE(is_checked_url_safe())
510 << phishing_urls[j].url 619 << phishing_urls[j].url
511 << " is_phishing: " << phishing_urls[j].is_phishing 620 << " is_phishing: " << phishing_urls[j].is_phishing
512 << " test step: " << step; 621 << " test step: " << step;
513 } 622 }
514 } 623 }
515 // TODO(lzheng): We should verify the fetched database with local 624 // TODO(lzheng): We should verify the fetched database with local
516 // database to make sure they match. 625 // database to make sure they match.
517 EXPECT_EQ(net::URLRequestStatus::SUCCESS, 626 EXPECT_EQ(net::URLRequestStatus::SUCCESS,
518 safe_browsing_helper->FetchDBToVerify(test_server(), step)); 627 safe_browsing_helper->FetchDBToVerify(server_host,
628 server_port,
629 step));
519 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); 630 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U);
520 last_step = step; 631 last_step = step;
521 } 632 }
522 633
523 // Verifies with server if test is done and waits till server responses. 634 // Verifies with server if test is done and waits till server responses.
524 EXPECT_EQ(net::URLRequestStatus::SUCCESS, 635 EXPECT_EQ(net::URLRequestStatus::SUCCESS,
525 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); 636 safe_browsing_helper->VerifyTestComplete(server_host,
637 server_port,
638 last_step));
526 EXPECT_EQ("yes", safe_browsing_helper->response_data()); 639 EXPECT_EQ("yes", safe_browsing_helper->response_data());
640 test_server.Stop();
527 } 641 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698