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 // |
(...skipping 30 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 std::string& server_host() const { | |
204 return test_server_->host_port_pair().host(); | |
205 } | |
206 | |
207 int server_port() const { | |
208 return test_server_->host_port_pair().port(); | |
209 } | |
210 | |
300 protected: | 211 protected: |
301 bool InitSafeBrowsingService() { | 212 bool InitSafeBrowsingService() { |
302 safe_browsing_service_ = g_browser_process->safe_browsing_service(); | 213 safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
303 return safe_browsing_service_ != NULL; | 214 return safe_browsing_service_ != NULL; |
304 } | 215 } |
305 | 216 |
306 virtual void SetUpCommandLine(CommandLine* command_line) { | 217 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
218 FilePath datafile_path; | |
219 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &datafile_path)); | |
220 | |
221 datafile_path = datafile_path.Append(FILE_PATH_LITERAL("third_party")) | |
222 .Append(FILE_PATH_LITERAL("safe_browsing")) | |
223 .Append(FILE_PATH_LITERAL("testing")) | |
224 .Append(kDataFile); | |
225 test_server_.reset(new LocalSafeBrowsingTestServer(datafile_path)); | |
226 ASSERT_TRUE(test_server_->Start()); | |
227 LOG(INFO) << "server is " << server_host() << ":" << server_port(); | |
228 | |
307 // Makes sure the auto update is not triggered. This test will force the | 229 // Makes sure the auto update is not triggered. This test will force the |
308 // update when needed. | 230 // update when needed. |
309 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); | 231 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); |
310 | 232 |
311 // This test uses loopback. No need to use IPv6 especially it makes | 233 // This test uses loopback. No need to use IPv6 especially it makes |
312 // local requests slow on Windows trybot when ipv6 local address [::1] | 234 // local requests slow on Windows trybot when ipv6 local address [::1] |
313 // is not setup. | 235 // is not setup. |
314 command_line->AppendSwitch(switches::kDisableIPv6); | 236 command_line->AppendSwitch(switches::kDisableIPv6); |
315 | 237 |
316 // TODO(lzheng): The test server does not understand download related | 238 // TODO(lzheng): The test server does not understand download related |
317 // requests. We need to fix the server. | 239 // requests. We need to fix the server. |
318 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); | 240 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); |
319 | 241 |
320 // TODO(gcasto): Generate new testing data that includes the | 242 // TODO(gcasto): Generate new testing data that includes the |
321 // client-side phishing whitelist. | 243 // client-side phishing whitelist. |
322 command_line->AppendSwitch( | 244 command_line->AppendSwitch( |
323 switches::kDisableClientSidePhishingDetection); | 245 switches::kDisableClientSidePhishingDetection); |
324 | 246 |
325 // Point to the testing server for all SafeBrowsing requests. | 247 // Point to the testing server for all SafeBrowsing requests. |
326 std::string url_prefix = | 248 std::string url_prefix = |
327 base::StringPrintf("http://%s:%d/safebrowsing", | 249 base::StringPrintf("http://%s:%d/safebrowsing", |
328 SafeBrowsingTestServer::Host(), | 250 server_host().c_str(), |
329 SafeBrowsingTestServer::Port()); | 251 server_port()); |
Ryan Sleevi
2012/08/31 21:48:39
Minimally, this should be
base::StringPrintf("htt
mattm
2012/09/01 01:44:54
Done.
| |
330 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); | 252 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); |
331 } | 253 } |
332 | 254 |
333 void SetTestStep(int step) { | 255 void SetTestStep(int step) { |
334 std::string test_step = base::StringPrintf("test_step=%d", step); | 256 std::string test_step = base::StringPrintf("test_step=%d", step); |
335 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); | 257 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); |
336 } | 258 } |
337 | 259 |
338 private: | 260 private: |
339 SafeBrowsingService* safe_browsing_service_; | 261 SafeBrowsingService* safe_browsing_service_; |
340 | 262 |
263 scoped_ptr<net::TestServer> test_server_; | |
264 | |
341 // Protects all variables below since they are read on UI thread | 265 // Protects all variables below since they are read on UI thread |
342 // but updated on IO thread or safebrowsing thread. | 266 // but updated on IO thread or safebrowsing thread. |
343 base::Lock update_status_mutex_; | 267 base::Lock update_status_mutex_; |
344 | 268 |
345 // States associated with safebrowsing service updates. | 269 // States associated with safebrowsing service updates. |
346 bool is_database_ready_; | 270 bool is_database_ready_; |
347 base::Time last_update_; | 271 base::Time last_update_; |
348 bool is_update_scheduled_; | 272 bool is_update_scheduled_; |
349 // Indicates if there is a match between a URL's prefix and safebrowsing | 273 // Indicates if there is a match between a URL's prefix and safebrowsing |
350 // database (thus potentially it is a phishing URL). | 274 // database (thus potentially it is a phishing URL). |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 void UpdateStatus() { | 365 void UpdateStatus() { |
442 BrowserThread::PostTask( | 366 BrowserThread::PostTask( |
443 BrowserThread::IO, | 367 BrowserThread::IO, |
444 FROM_HERE, | 368 FROM_HERE, |
445 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, | 369 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, |
446 this)); | 370 this)); |
447 // Will continue after OnWaitForStatusUpdateDone(). | 371 // Will continue after OnWaitForStatusUpdateDone(). |
448 content::RunMessageLoop(); | 372 content::RunMessageLoop(); |
449 } | 373 } |
450 | 374 |
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. | 375 // Calls test server to fetch database for verification. |
468 net::URLRequestStatus::Status FetchDBToVerify(const char* host, int port, | 376 net::URLRequestStatus::Status FetchDBToVerify( |
469 int test_step) { | 377 const std::string& host, int port, int test_step) { |
470 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. | 378 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. |
471 GURL url(base::StringPrintf( | 379 GURL url(base::StringPrintf( |
472 "http://%s:%d%s?" | 380 "http://%s:%d%s?" |
473 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" | 381 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" |
474 "chunk_type=add", | 382 "chunk_type=add", |
475 host, port, kDBVerifyPath, test_step)); | 383 host.c_str(), port, kDBVerifyPath, test_step)); |
476 return FetchUrl(url); | 384 return FetchUrl(url); |
477 } | 385 } |
478 | 386 |
479 // Calls test server to fetch URLs for verification. | 387 // Calls test server to fetch URLs for verification. |
480 net::URLRequestStatus::Status FetchUrlsToVerify(const char* host, int port, | 388 net::URLRequestStatus::Status FetchUrlsToVerify( |
481 int test_step) { | 389 const std::string& host, int port, int test_step) { |
482 GURL url(base::StringPrintf( | 390 GURL url(base::StringPrintf( |
483 "http://%s:%d%s?" | 391 "http://%s:%d%s?" |
484 "client=chromium&appver=1.0&pver=2.2&test_step=%d", | 392 "client=chromium&appver=1.0&pver=2.2&test_step=%d", |
485 host, port, kUrlVerifyPath, test_step)); | 393 host.c_str(), port, kUrlVerifyPath, test_step)); |
486 return FetchUrl(url); | 394 return FetchUrl(url); |
487 } | 395 } |
488 | 396 |
489 // Calls test server to check if test data is done. E.g.: if there is a | 397 // 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, | 398 // bad URL that server expects test to fetch full hash but the test didn't, |
491 // this verification will fail. | 399 // this verification will fail. |
492 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port, | 400 net::URLRequestStatus::Status VerifyTestComplete( |
493 int test_step) { | 401 const std::string& host, int port, int test_step) { |
494 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", | 402 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", |
495 host, port, kTestCompletePath, test_step)); | 403 host.c_str(), port, kTestCompletePath, test_step)); |
496 return FetchUrl(url); | 404 return FetchUrl(url); |
497 } | 405 } |
498 | 406 |
499 // Callback for URLFetcher. | 407 // Callback for URLFetcher. |
500 virtual void OnURLFetchComplete(const net::URLFetcher* source) { | 408 virtual void OnURLFetchComplete(const net::URLFetcher* source) { |
501 source->GetResponseAsString(&response_data_); | 409 source->GetResponseAsString(&response_data_); |
502 response_status_ = source->GetStatus().status(); | 410 response_status_ = source->GetStatus().status(); |
503 StopUILoop(); | 411 StopUILoop(); |
504 } | 412 } |
505 | 413 |
(...skipping 27 matching lines...) Expand all Loading... | |
533 SafeBrowsingServiceTest* safe_browsing_test_; | 441 SafeBrowsingServiceTest* safe_browsing_test_; |
534 scoped_ptr<net::URLFetcher> url_fetcher_; | 442 scoped_ptr<net::URLFetcher> url_fetcher_; |
535 std::string response_data_; | 443 std::string response_data_; |
536 net::URLRequestStatus::Status response_status_; | 444 net::URLRequestStatus::Status response_status_; |
537 net::URLRequestContextGetter* request_context_; | 445 net::URLRequestContextGetter* request_context_; |
538 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); | 446 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); |
539 }; | 447 }; |
540 | 448 |
541 // See http://crbug.com/96459 | 449 // See http://crbug.com/96459 |
542 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, | 450 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
543 DISABLED_SafeBrowsingSystemTest) { | 451 SafeBrowsingSystemTest) { |
544 LOG(INFO) << "Start test"; | 452 LOG(INFO) << "Start test"; |
545 const char* server_host = SafeBrowsingTestServer::Host(); | |
546 int server_port = SafeBrowsingTestServer::Port(); | |
547 ASSERT_TRUE(InitSafeBrowsingService()); | 453 ASSERT_TRUE(InitSafeBrowsingService()); |
548 | 454 |
549 net::URLRequestContextGetter* request_context = | 455 net::URLRequestContextGetter* request_context = |
550 GetBrowserContext()->GetRequestContext(); | 456 GetBrowserContext()->GetRequestContext(); |
551 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( | 457 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( |
552 new SafeBrowsingServiceTestHelper(this, request_context)); | 458 new SafeBrowsingServiceTestHelper(this, request_context)); |
553 int last_step = 0; | 459 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 | 460 |
561 // Waits and makes sure safebrowsing update is not happening. | 461 // Waits and makes sure safebrowsing update is not happening. |
562 // The wait will stop once OnWaitForStatusUpdateDone in | 462 // The wait will stop once OnWaitForStatusUpdateDone in |
563 // safe_browsing_helper is called and status from safe_browsing_service_ | 463 // safe_browsing_helper is called and status from safe_browsing_service_ |
564 // is checked. | 464 // is checked. |
565 safe_browsing_helper->UpdateStatus(); | 465 safe_browsing_helper->UpdateStatus(); |
566 EXPECT_TRUE(is_database_ready()); | 466 EXPECT_TRUE(is_database_ready()); |
567 EXPECT_FALSE(is_update_scheduled()); | 467 EXPECT_FALSE(is_update_scheduled()); |
568 EXPECT_TRUE(last_update().is_null()); | 468 EXPECT_TRUE(last_update().is_null()); |
569 // Starts updates. After each update, the test will fetch a list of URLs with | 469 // 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()); | 486 EXPECT_TRUE(is_database_ready()); |
587 EXPECT_FALSE(is_update_scheduled()); | 487 EXPECT_FALSE(is_update_scheduled()); |
588 EXPECT_FALSE(last_update().is_null()); | 488 EXPECT_FALSE(last_update().is_null()); |
589 if (last_update() < now) { | 489 if (last_update() < now) { |
590 // This means no data available anymore. | 490 // This means no data available anymore. |
591 break; | 491 break; |
592 } | 492 } |
593 | 493 |
594 // Fetches URLs to verify and waits till server responses with data. | 494 // Fetches URLs to verify and waits till server responses with data. |
595 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 495 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
596 safe_browsing_helper->FetchUrlsToVerify(server_host, | 496 safe_browsing_helper->FetchUrlsToVerify(server_host(), |
597 server_port, | 497 server_port(), |
598 step)); | 498 step)); |
599 | 499 |
600 std::vector<PhishingUrl> phishing_urls; | 500 std::vector<PhishingUrl> phishing_urls; |
601 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), | 501 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), |
602 &phishing_urls)); | 502 &phishing_urls)); |
603 EXPECT_GT(phishing_urls.size(), 0U); | 503 EXPECT_GT(phishing_urls.size(), 0U); |
604 for (size_t j = 0; j < phishing_urls.size(); ++j) { | 504 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 | 505 // Verifes with server if a URL is a phishing URL and waits till server |
606 // responses. | 506 // responses. |
607 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); | 507 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); |
608 if (phishing_urls[j].is_phishing) { | 508 if (phishing_urls[j].is_phishing) { |
609 EXPECT_TRUE(is_checked_url_in_db()) | 509 EXPECT_TRUE(is_checked_url_in_db()) |
610 << phishing_urls[j].url | 510 << phishing_urls[j].url |
611 << " is_phishing: " << phishing_urls[j].is_phishing | 511 << " is_phishing: " << phishing_urls[j].is_phishing |
612 << " test step: " << step; | 512 << " test step: " << step; |
613 EXPECT_FALSE(is_checked_url_safe()) | 513 EXPECT_FALSE(is_checked_url_safe()) |
614 << phishing_urls[j].url | 514 << phishing_urls[j].url |
615 << " is_phishing: " << phishing_urls[j].is_phishing | 515 << " is_phishing: " << phishing_urls[j].is_phishing |
616 << " test step: " << step; | 516 << " test step: " << step; |
617 } else { | 517 } else { |
618 EXPECT_TRUE(is_checked_url_safe()) | 518 EXPECT_TRUE(is_checked_url_safe()) |
619 << phishing_urls[j].url | 519 << phishing_urls[j].url |
620 << " is_phishing: " << phishing_urls[j].is_phishing | 520 << " is_phishing: " << phishing_urls[j].is_phishing |
621 << " test step: " << step; | 521 << " test step: " << step; |
622 } | 522 } |
623 } | 523 } |
624 // TODO(lzheng): We should verify the fetched database with local | 524 // TODO(lzheng): We should verify the fetched database with local |
625 // database to make sure they match. | 525 // database to make sure they match. |
626 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 526 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
627 safe_browsing_helper->FetchDBToVerify(server_host, | 527 safe_browsing_helper->FetchDBToVerify(server_host(), |
628 server_port, | 528 server_port(), |
629 step)); | 529 step)); |
630 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); | 530 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); |
631 last_step = step; | 531 last_step = step; |
632 } | 532 } |
633 | 533 |
634 // Verifies with server if test is done and waits till server responses. | 534 // Verifies with server if test is done and waits till server responses. |
635 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 535 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
636 safe_browsing_helper->VerifyTestComplete(server_host, | 536 safe_browsing_helper->VerifyTestComplete(server_host(), |
637 server_port, | 537 server_port(), |
638 last_step)); | 538 last_step)); |
639 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 539 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
640 test_server.Stop(); | |
641 } | 540 } |
OLD | NEW |