OLD | NEW |
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 Loading... |
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" |
34 #include "chrome/browser/safe_browsing/protocol_manager.h" | 35 #include "chrome/browser/safe_browsing/protocol_manager.h" |
35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
36 #include "chrome/common/chrome_notification_types.h" | 37 #include "chrome/common/chrome_notification_types.h" |
37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
39 #include "chrome/test/base/in_process_browser_test.h" | 40 #include "chrome/test/base/in_process_browser_test.h" |
40 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
41 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
42 #include "content/public/test/test_browser_thread.h" | 43 #include "content/public/test/test_browser_thread.h" |
43 #include "net/base/host_resolver.h" | 44 #include "net/base/host_resolver.h" |
44 #include "net/base/load_flags.h" | 45 #include "net/base/load_flags.h" |
45 #include "net/base/net_log.h" | 46 #include "net/base/net_log.h" |
46 #include "net/test/python_utils.h" | 47 #include "net/test/python_utils.h" |
47 #include "net/url_request/url_fetcher.h" | 48 #include "net/url_request/url_fetcher.h" |
48 #include "net/url_request/url_fetcher_delegate.h" | 49 #include "net/url_request/url_fetcher_delegate.h" |
49 #include "net/url_request/url_request_status.h" | 50 #include "net/url_request/url_request_status.h" |
50 #include "testing/gtest/include/gtest/gtest.h" | 51 #include "testing/gtest/include/gtest/gtest.h" |
51 | 52 |
52 using content::BrowserThread; | 53 using content::BrowserThread; |
53 | 54 |
54 namespace { | 55 namespace { |
55 | 56 |
56 const FilePath::CharType kDataFile[] = | 57 const FilePath::CharType kDataFile[] = |
57 FILE_PATH_LITERAL("testing_input_nomac.dat"); | 58 FILE_PATH_LITERAL("testing_input_nomac.dat"); |
58 const char kUrlVerifyPath[] = "/safebrowsing/verify_urls"; | 59 const char kUrlVerifyPath[] = "safebrowsing/verify_urls"; |
59 const char kDBVerifyPath[] = "/safebrowsing/verify_database"; | 60 const char kDBVerifyPath[] = "safebrowsing/verify_database"; |
60 const char kDBResetPath[] = "/reset"; | 61 const char kTestCompletePath[] = "test_complete"; |
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 Loading... |
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 | |
208 // This starts the browser and keeps status of states related to SafeBrowsing. | 111 // This starts the browser and keeps status of states related to SafeBrowsing. |
209 class SafeBrowsingServiceTest : public InProcessBrowserTest { | 112 class SafeBrowsingServiceTest : public InProcessBrowserTest { |
210 public: | 113 public: |
211 SafeBrowsingServiceTest() | 114 SafeBrowsingServiceTest() |
212 : safe_browsing_service_(NULL), | 115 : safe_browsing_service_(NULL), |
213 is_database_ready_(true), | 116 is_database_ready_(true), |
214 is_update_scheduled_(false), | 117 is_update_scheduled_(false), |
215 is_checked_url_in_db_(false), | 118 is_checked_url_in_db_(false), |
216 is_checked_url_safe_(false) { | 119 is_checked_url_safe_(false) { |
217 } | 120 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 193 |
291 bool is_update_scheduled() { | 194 bool is_update_scheduled() { |
292 base::AutoLock l(update_status_mutex_); | 195 base::AutoLock l(update_status_mutex_); |
293 return is_update_scheduled_; | 196 return is_update_scheduled_; |
294 } | 197 } |
295 | 198 |
296 MessageLoop* SafeBrowsingMessageLoop() { | 199 MessageLoop* SafeBrowsingMessageLoop() { |
297 return safe_browsing_service_->safe_browsing_thread_->message_loop(); | 200 return safe_browsing_service_->safe_browsing_thread_->message_loop(); |
298 } | 201 } |
299 | 202 |
| 203 const net::TestServer& test_server() const { |
| 204 return *test_server_; |
| 205 } |
| 206 |
300 protected: | 207 protected: |
301 bool InitSafeBrowsingService() { | 208 bool InitSafeBrowsingService() { |
302 safe_browsing_service_ = g_browser_process->safe_browsing_service(); | 209 safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
303 return safe_browsing_service_ != NULL; | 210 return safe_browsing_service_ != NULL; |
304 } | 211 } |
305 | 212 |
306 virtual void SetUpCommandLine(CommandLine* command_line) { | 213 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 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 |
307 // Makes sure the auto update is not triggered. This test will force the | 225 // Makes sure the auto update is not triggered. This test will force the |
308 // update when needed. | 226 // update when needed. |
309 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); | 227 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); |
310 | 228 |
311 // This test uses loopback. No need to use IPv6 especially it makes | 229 // This test uses loopback. No need to use IPv6 especially it makes |
312 // local requests slow on Windows trybot when ipv6 local address [::1] | 230 // local requests slow on Windows trybot when ipv6 local address [::1] |
313 // is not setup. | 231 // is not setup. |
314 command_line->AppendSwitch(switches::kDisableIPv6); | 232 command_line->AppendSwitch(switches::kDisableIPv6); |
315 | 233 |
316 // TODO(lzheng): The test server does not understand download related | 234 // TODO(lzheng): The test server does not understand download related |
317 // requests. We need to fix the server. | 235 // requests. We need to fix the server. |
318 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); | 236 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); |
319 | 237 |
320 // TODO(gcasto): Generate new testing data that includes the | 238 // TODO(gcasto): Generate new testing data that includes the |
321 // client-side phishing whitelist. | 239 // client-side phishing whitelist. |
322 command_line->AppendSwitch( | 240 command_line->AppendSwitch( |
323 switches::kDisableClientSidePhishingDetection); | 241 switches::kDisableClientSidePhishingDetection); |
324 | 242 |
325 // Point to the testing server for all SafeBrowsing requests. | 243 // Point to the testing server for all SafeBrowsing requests. |
326 std::string url_prefix = | 244 std::string url_prefix = test_server_->GetURL("safebrowsing").spec(); |
327 base::StringPrintf("http://%s:%d/safebrowsing", | |
328 SafeBrowsingTestServer::Host(), | |
329 SafeBrowsingTestServer::Port()); | |
330 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); | 245 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); |
331 } | 246 } |
332 | 247 |
333 void SetTestStep(int step) { | 248 void SetTestStep(int step) { |
334 std::string test_step = base::StringPrintf("test_step=%d", step); | 249 std::string test_step = base::StringPrintf("test_step=%d", step); |
335 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); | 250 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); |
336 } | 251 } |
337 | 252 |
338 private: | 253 private: |
339 SafeBrowsingService* safe_browsing_service_; | 254 SafeBrowsingService* safe_browsing_service_; |
340 | 255 |
| 256 scoped_ptr<net::TestServer> test_server_; |
| 257 |
341 // Protects all variables below since they are read on UI thread | 258 // Protects all variables below since they are read on UI thread |
342 // but updated on IO thread or safebrowsing thread. | 259 // but updated on IO thread or safebrowsing thread. |
343 base::Lock update_status_mutex_; | 260 base::Lock update_status_mutex_; |
344 | 261 |
345 // States associated with safebrowsing service updates. | 262 // States associated with safebrowsing service updates. |
346 bool is_database_ready_; | 263 bool is_database_ready_; |
347 base::Time last_update_; | 264 base::Time last_update_; |
348 bool is_update_scheduled_; | 265 bool is_update_scheduled_; |
349 // Indicates if there is a match between a URL's prefix and safebrowsing | 266 // Indicates if there is a match between a URL's prefix and safebrowsing |
350 // database (thus potentially it is a phishing URL). | 267 // database (thus potentially it is a phishing URL). |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 void UpdateStatus() { | 358 void UpdateStatus() { |
442 BrowserThread::PostTask( | 359 BrowserThread::PostTask( |
443 BrowserThread::IO, | 360 BrowserThread::IO, |
444 FROM_HERE, | 361 FROM_HERE, |
445 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, | 362 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, |
446 this)); | 363 this)); |
447 // Will continue after OnWaitForStatusUpdateDone(). | 364 // Will continue after OnWaitForStatusUpdateDone(). |
448 content::RunMessageLoop(); | 365 content::RunMessageLoop(); |
449 } | 366 } |
450 | 367 |
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 | |
467 // Calls test server to fetch database for verification. | 368 // Calls test server to fetch database for verification. |
468 net::URLRequestStatus::Status FetchDBToVerify(const char* host, int port, | 369 net::URLRequestStatus::Status FetchDBToVerify( |
469 int test_step) { | 370 const net::TestServer& test_server, |
| 371 int test_step) { |
470 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. | 372 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. |
471 GURL url(base::StringPrintf( | 373 std::string path = base::StringPrintf( |
472 "http://%s:%d%s?" | 374 "%s?client=chromium&appver=1.0&pver=2.2&test_step=%d&chunk_type=add", |
473 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" | 375 kDBVerifyPath, test_step); |
474 "chunk_type=add", | 376 return FetchUrl(test_server.GetURL(path)); |
475 host, port, kDBVerifyPath, test_step)); | |
476 return FetchUrl(url); | |
477 } | 377 } |
478 | 378 |
479 // Calls test server to fetch URLs for verification. | 379 // Calls test server to fetch URLs for verification. |
480 net::URLRequestStatus::Status FetchUrlsToVerify(const char* host, int port, | 380 net::URLRequestStatus::Status FetchUrlsToVerify( |
481 int test_step) { | 381 const net::TestServer& test_server, |
482 GURL url(base::StringPrintf( | 382 int test_step) { |
483 "http://%s:%d%s?" | 383 std::string path = base::StringPrintf( |
484 "client=chromium&appver=1.0&pver=2.2&test_step=%d", | 384 "%s?client=chromium&appver=1.0&pver=2.2&test_step=%d", |
485 host, port, kUrlVerifyPath, test_step)); | 385 kUrlVerifyPath, test_step); |
486 return FetchUrl(url); | 386 return FetchUrl(test_server.GetURL(path)); |
487 } | 387 } |
488 | 388 |
489 // Calls test server to check if test data is done. E.g.: if there is a | 389 // Calls test server to check if test data is done. E.g.: if there is a |
490 // bad URL that server expects test to fetch full hash but the test didn't, | 390 // bad URL that server expects test to fetch full hash but the test didn't, |
491 // this verification will fail. | 391 // this verification will fail. |
492 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port, | 392 net::URLRequestStatus::Status VerifyTestComplete( |
493 int test_step) { | 393 const net::TestServer& test_server, |
494 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", | 394 int test_step) { |
495 host, port, kTestCompletePath, test_step)); | 395 std::string path = base::StringPrintf( |
496 return FetchUrl(url); | 396 "%s?test_step=%d", kTestCompletePath, test_step); |
| 397 return FetchUrl(test_server.GetURL(path)); |
497 } | 398 } |
498 | 399 |
499 // Callback for URLFetcher. | 400 // Callback for URLFetcher. |
500 virtual void OnURLFetchComplete(const net::URLFetcher* source) { | 401 virtual void OnURLFetchComplete(const net::URLFetcher* source) { |
501 source->GetResponseAsString(&response_data_); | 402 source->GetResponseAsString(&response_data_); |
502 response_status_ = source->GetStatus().status(); | 403 response_status_ = source->GetStatus().status(); |
503 StopUILoop(); | 404 StopUILoop(); |
504 } | 405 } |
505 | 406 |
506 const std::string& response_data() { | 407 const std::string& response_data() { |
(...skipping 26 matching lines...) Expand all Loading... |
533 SafeBrowsingServiceTest* safe_browsing_test_; | 434 SafeBrowsingServiceTest* safe_browsing_test_; |
534 scoped_ptr<net::URLFetcher> url_fetcher_; | 435 scoped_ptr<net::URLFetcher> url_fetcher_; |
535 std::string response_data_; | 436 std::string response_data_; |
536 net::URLRequestStatus::Status response_status_; | 437 net::URLRequestStatus::Status response_status_; |
537 net::URLRequestContextGetter* request_context_; | 438 net::URLRequestContextGetter* request_context_; |
538 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); | 439 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); |
539 }; | 440 }; |
540 | 441 |
541 // See http://crbug.com/96459 | 442 // See http://crbug.com/96459 |
542 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, | 443 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
543 DISABLED_SafeBrowsingSystemTest) { | 444 SafeBrowsingSystemTest) { |
544 LOG(INFO) << "Start test"; | 445 LOG(INFO) << "Start test"; |
545 const char* server_host = SafeBrowsingTestServer::Host(); | |
546 int server_port = SafeBrowsingTestServer::Port(); | |
547 ASSERT_TRUE(InitSafeBrowsingService()); | 446 ASSERT_TRUE(InitSafeBrowsingService()); |
548 | 447 |
549 net::URLRequestContextGetter* request_context = | 448 net::URLRequestContextGetter* request_context = |
550 GetBrowserContext()->GetRequestContext(); | 449 GetBrowserContext()->GetRequestContext(); |
551 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( | 450 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( |
552 new SafeBrowsingServiceTestHelper(this, request_context)); | 451 new SafeBrowsingServiceTestHelper(this, request_context)); |
553 int last_step = 0; | 452 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); | |
560 | 453 |
561 // Waits and makes sure safebrowsing update is not happening. | 454 // Waits and makes sure safebrowsing update is not happening. |
562 // The wait will stop once OnWaitForStatusUpdateDone in | 455 // The wait will stop once OnWaitForStatusUpdateDone in |
563 // safe_browsing_helper is called and status from safe_browsing_service_ | 456 // safe_browsing_helper is called and status from safe_browsing_service_ |
564 // is checked. | 457 // is checked. |
565 safe_browsing_helper->UpdateStatus(); | 458 safe_browsing_helper->UpdateStatus(); |
566 EXPECT_TRUE(is_database_ready()); | 459 EXPECT_TRUE(is_database_ready()); |
567 EXPECT_FALSE(is_update_scheduled()); | 460 EXPECT_FALSE(is_update_scheduled()); |
568 EXPECT_TRUE(last_update().is_null()); | 461 EXPECT_TRUE(last_update().is_null()); |
569 // Starts updates. After each update, the test will fetch a list of URLs with | 462 // Starts updates. After each update, the test will fetch a list of URLs with |
(...skipping 16 matching lines...) Expand all Loading... |
586 EXPECT_TRUE(is_database_ready()); | 479 EXPECT_TRUE(is_database_ready()); |
587 EXPECT_FALSE(is_update_scheduled()); | 480 EXPECT_FALSE(is_update_scheduled()); |
588 EXPECT_FALSE(last_update().is_null()); | 481 EXPECT_FALSE(last_update().is_null()); |
589 if (last_update() < now) { | 482 if (last_update() < now) { |
590 // This means no data available anymore. | 483 // This means no data available anymore. |
591 break; | 484 break; |
592 } | 485 } |
593 | 486 |
594 // Fetches URLs to verify and waits till server responses with data. | 487 // Fetches URLs to verify and waits till server responses with data. |
595 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 488 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
596 safe_browsing_helper->FetchUrlsToVerify(server_host, | 489 safe_browsing_helper->FetchUrlsToVerify(test_server(), step)); |
597 server_port, | |
598 step)); | |
599 | 490 |
600 std::vector<PhishingUrl> phishing_urls; | 491 std::vector<PhishingUrl> phishing_urls; |
601 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), | 492 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), |
602 &phishing_urls)); | 493 &phishing_urls)); |
603 EXPECT_GT(phishing_urls.size(), 0U); | 494 EXPECT_GT(phishing_urls.size(), 0U); |
604 for (size_t j = 0; j < phishing_urls.size(); ++j) { | 495 for (size_t j = 0; j < phishing_urls.size(); ++j) { |
605 // Verifes with server if a URL is a phishing URL and waits till server | 496 // Verifes with server if a URL is a phishing URL and waits till server |
606 // responses. | 497 // responses. |
607 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); | 498 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); |
608 if (phishing_urls[j].is_phishing) { | 499 if (phishing_urls[j].is_phishing) { |
609 EXPECT_TRUE(is_checked_url_in_db()) | 500 EXPECT_TRUE(is_checked_url_in_db()) |
610 << phishing_urls[j].url | 501 << phishing_urls[j].url |
611 << " is_phishing: " << phishing_urls[j].is_phishing | 502 << " is_phishing: " << phishing_urls[j].is_phishing |
612 << " test step: " << step; | 503 << " test step: " << step; |
613 EXPECT_FALSE(is_checked_url_safe()) | 504 EXPECT_FALSE(is_checked_url_safe()) |
614 << phishing_urls[j].url | 505 << phishing_urls[j].url |
615 << " is_phishing: " << phishing_urls[j].is_phishing | 506 << " is_phishing: " << phishing_urls[j].is_phishing |
616 << " test step: " << step; | 507 << " test step: " << step; |
617 } else { | 508 } else { |
618 EXPECT_TRUE(is_checked_url_safe()) | 509 EXPECT_TRUE(is_checked_url_safe()) |
619 << phishing_urls[j].url | 510 << phishing_urls[j].url |
620 << " is_phishing: " << phishing_urls[j].is_phishing | 511 << " is_phishing: " << phishing_urls[j].is_phishing |
621 << " test step: " << step; | 512 << " test step: " << step; |
622 } | 513 } |
623 } | 514 } |
624 // TODO(lzheng): We should verify the fetched database with local | 515 // TODO(lzheng): We should verify the fetched database with local |
625 // database to make sure they match. | 516 // database to make sure they match. |
626 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 517 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
627 safe_browsing_helper->FetchDBToVerify(server_host, | 518 safe_browsing_helper->FetchDBToVerify(test_server(), step)); |
628 server_port, | |
629 step)); | |
630 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); | 519 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); |
631 last_step = step; | 520 last_step = step; |
632 } | 521 } |
633 | 522 |
634 // Verifies with server if test is done and waits till server responses. | 523 // Verifies with server if test is done and waits till server responses. |
635 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 524 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
636 safe_browsing_helper->VerifyTestComplete(server_host, | 525 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); |
637 server_port, | |
638 last_step)); | |
639 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 526 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
640 test_server.Stop(); | |
641 } | 527 } |
OLD | NEW |