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 27 matching lines...) Expand all Loading... | |
38 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
39 #include "chrome/test/base/in_process_browser_test.h" | 39 #include "chrome/test/base/in_process_browser_test.h" |
40 #include "chrome/test/base/ui_test_utils.h" | 40 #include "chrome/test/base/ui_test_utils.h" |
41 #include "content/public/common/url_fetcher.h" | 41 #include "content/public/common/url_fetcher.h" |
42 #include "content/public/common/url_fetcher_delegate.h" | 42 #include "content/public/common/url_fetcher_delegate.h" |
43 #include "content/test/test_browser_thread.h" | 43 #include "content/test/test_browser_thread.h" |
44 #include "net/base/host_resolver.h" | 44 #include "net/base/host_resolver.h" |
45 #include "net/base/load_flags.h" | 45 #include "net/base/load_flags.h" |
46 #include "net/base/net_log.h" | 46 #include "net/base/net_log.h" |
47 #include "net/test/python_utils.h" | 47 #include "net/test/python_utils.h" |
48 #include "net/test/test_server.h" | |
48 #include "net/url_request/url_request_status.h" | 49 #include "net/url_request/url_request_status.h" |
49 #include "testing/gtest/include/gtest/gtest.h" | 50 #include "testing/gtest/include/gtest/gtest.h" |
50 | 51 |
51 using content::BrowserThread; | 52 using content::BrowserThread; |
52 | 53 |
53 namespace { | 54 namespace { |
54 | 55 |
55 const FilePath::CharType kDataFile[] = | 56 const FilePath::CharType kDataFile[] = |
56 FILE_PATH_LITERAL("testing_input_nomac.dat"); | 57 FILE_PATH_LITERAL("testing_input_nomac.dat"); |
57 const char kUrlVerifyPath[] = "/safebrowsing/verify_urls"; | 58 const char kUrlVerifyPath[] = "/safebrowsing/verify_urls"; |
58 const char kDBVerifyPath[] = "/safebrowsing/verify_database"; | 59 const char kDBVerifyPath[] = "/safebrowsing/verify_database"; |
59 const char kDBResetPath[] = "/reset"; | |
60 const char kTestCompletePath[] = "/test_complete"; | 60 const char kTestCompletePath[] = "/test_complete"; |
61 | 61 |
62 struct PhishingUrl { | 62 struct PhishingUrl { |
63 std::string url; | 63 std::string url; |
64 std::string list_name; | 64 std::string list_name; |
65 bool is_phishing; | 65 bool is_phishing; |
66 }; | 66 }; |
67 | 67 |
68 // Parses server response for verify_urls. The expected format is: | 68 // Parses server response for verify_urls. The expected format is: |
69 // | 69 // |
(...skipping 30 matching lines...) Expand all Loading... | |
100 << ": " << record_parts[2]; | 100 << ": " << record_parts[2]; |
101 return false; | 101 return false; |
102 } | 102 } |
103 phishing_urls->push_back(phishing_url); | 103 phishing_urls->push_back(phishing_url); |
104 } | 104 } |
105 return true; | 105 return true; |
106 } | 106 } |
107 | 107 |
108 } // namespace | 108 } // namespace |
109 | 109 |
110 class SafeBrowsingTestServer { | |
111 public: | |
112 explicit SafeBrowsingTestServer(const FilePath& datafile) | |
113 : datafile_(datafile), | |
114 server_handle_(base::kNullProcessHandle) { | |
115 } | |
116 | |
117 ~SafeBrowsingTestServer() { | |
118 EXPECT_EQ(base::kNullProcessHandle, server_handle_); | |
119 } | |
120 | |
121 // Start the python server test suite. | |
122 bool Start() { | |
123 // Get path to python server script | |
124 FilePath testserver_path; | |
125 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)) { | |
126 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | |
127 return false; | |
128 } | |
129 testserver_path = testserver_path | |
130 .Append(FILE_PATH_LITERAL("third_party")) | |
131 .Append(FILE_PATH_LITERAL("safe_browsing")) | |
132 .Append(FILE_PATH_LITERAL("testing")); | |
133 AppendToPythonPath(testserver_path); | |
134 FilePath testserver = testserver_path.Append( | |
135 FILE_PATH_LITERAL("safebrowsing_test_server.py")); | |
136 | |
137 FilePath pyproto_code_dir; | |
138 if (!GetPyProtoPath(&pyproto_code_dir)) { | |
139 LOG(ERROR) << "Failed to get generated python protobuf dir"; | |
140 return false; | |
141 } | |
142 AppendToPythonPath(pyproto_code_dir); | |
143 pyproto_code_dir = pyproto_code_dir.Append(FILE_PATH_LITERAL("google")); | |
144 AppendToPythonPath(pyproto_code_dir); | |
145 | |
146 FilePath python_runtime; | |
147 EXPECT_TRUE(GetPythonRunTime(&python_runtime)); | |
148 CommandLine cmd_line(python_runtime); | |
149 // Make python stdout and stderr unbuffered, to prevent incomplete stderr on | |
150 // win bots, and also fix mixed up ordering of stdout and stderr. | |
151 cmd_line.AppendSwitch("-u"); | |
152 FilePath datafile = testserver_path.Append(datafile_); | |
153 cmd_line.AppendArgPath(testserver); | |
154 cmd_line.AppendArg(base::StringPrintf("--port=%d", kPort_)); | |
155 cmd_line.AppendArgNative(FILE_PATH_LITERAL("--datafile=") + | |
156 datafile.value()); | |
157 | |
158 base::LaunchOptions options; | |
159 #if defined(OS_WIN) | |
160 options.start_hidden = true; | |
161 #endif | |
162 if (!base::LaunchProcess(cmd_line, options, &server_handle_)) { | |
163 LOG(ERROR) << "Failed to launch server: " | |
164 << cmd_line.GetCommandLineString(); | |
165 return false; | |
166 } | |
167 return true; | |
168 } | |
169 | |
170 // Stop the python server test suite. | |
171 bool Stop() { | |
172 if (server_handle_ == base::kNullProcessHandle) | |
173 return true; | |
174 | |
175 // First check if the process has already terminated. | |
176 if (!base::WaitForSingleProcess(server_handle_, 0) && | |
177 !base::KillProcess(server_handle_, 1, true)) { | |
178 VLOG(1) << "Kill failed?"; | |
179 return false; | |
180 } | |
181 | |
182 base::CloseProcessHandle(server_handle_); | |
183 server_handle_ = base::kNullProcessHandle; | |
184 VLOG(1) << "Stopped."; | |
185 return true; | |
186 } | |
187 | |
188 static const char* Host() { | |
189 return kHost_; | |
190 } | |
191 | |
192 static int Port() { | |
193 return kPort_; | |
194 } | |
195 | |
196 private: | |
197 static const char kHost_[]; | |
198 static const int kPort_; | |
199 FilePath datafile_; | |
200 base::ProcessHandle server_handle_; | |
201 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingTestServer); | |
202 }; | |
203 | |
204 const char SafeBrowsingTestServer::kHost_[] = "localhost"; | |
205 const int SafeBrowsingTestServer::kPort_ = 40102; | |
206 | |
207 // This starts the browser and keeps status of states related to SafeBrowsing. | 110 // This starts the browser and keeps status of states related to SafeBrowsing. |
208 class SafeBrowsingServiceTest : public InProcessBrowserTest { | 111 class SafeBrowsingServiceTest : public InProcessBrowserTest { |
209 public: | 112 public: |
210 SafeBrowsingServiceTest() | 113 SafeBrowsingServiceTest() |
211 : safe_browsing_service_(NULL), | 114 : safe_browsing_service_(NULL), |
212 is_database_ready_(true), | 115 is_database_ready_(true), |
213 is_update_scheduled_(false), | 116 is_update_scheduled_(false), |
214 is_checked_url_in_db_(false), | 117 is_checked_url_in_db_(false), |
215 is_checked_url_safe_(false) { | 118 is_checked_url_safe_(false) { |
216 } | 119 } |
217 | 120 |
218 virtual ~SafeBrowsingServiceTest() { | 121 virtual ~SafeBrowsingServiceTest() { |
219 } | 122 } |
220 | 123 |
124 virtual void SetUp() OVERRIDE { | |
125 FilePath datafile_path = FilePath(FILE_PATH_LITERAL("third_party")) | |
126 .Append(FILE_PATH_LITERAL("safe_browsing")) | |
127 .Append(FILE_PATH_LITERAL("testing")) | |
128 .Append(kDataFile); | |
129 test_server_.reset(new net::TestServer(net::TestServer::TYPE_SAFEBROWSING, | |
130 net::TestServer::kLocalhost, | |
131 datafile_path)); | |
132 ASSERT_TRUE(test_server_->Start()); | |
133 | |
134 server_host_ = test_server_->host_port_pair().host(); | |
135 server_port_ = test_server_->host_port_pair().port(); | |
136 LOG(INFO) << "server is " << server_host_ << ":" << server_port_; | |
137 InProcessBrowserTest::SetUp(); | |
138 } | |
139 | |
140 virtual void TearDown() OVERRIDE { | |
141 InProcessBrowserTest::TearDown(); | |
142 test_server_->Stop(); | |
143 } | |
144 | |
221 void UpdateSafeBrowsingStatus() { | 145 void UpdateSafeBrowsingStatus() { |
222 ASSERT_TRUE(safe_browsing_service_); | 146 ASSERT_TRUE(safe_browsing_service_); |
223 base::AutoLock lock(update_status_mutex_); | 147 base::AutoLock lock(update_status_mutex_); |
224 last_update_ = safe_browsing_service_->protocol_manager_->last_update(); | 148 last_update_ = safe_browsing_service_->protocol_manager_->last_update(); |
225 is_update_scheduled_ = | 149 is_update_scheduled_ = |
226 safe_browsing_service_->protocol_manager_->update_timer_.IsRunning(); | 150 safe_browsing_service_->protocol_manager_->update_timer_.IsRunning(); |
227 } | 151 } |
228 | 152 |
229 void ForceUpdate() { | 153 void ForceUpdate() { |
230 ASSERT_TRUE(safe_browsing_service_); | 154 ASSERT_TRUE(safe_browsing_service_); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 | 202 |
279 bool is_update_scheduled() { | 203 bool is_update_scheduled() { |
280 base::AutoLock l(update_status_mutex_); | 204 base::AutoLock l(update_status_mutex_); |
281 return is_update_scheduled_; | 205 return is_update_scheduled_; |
282 } | 206 } |
283 | 207 |
284 MessageLoop* SafeBrowsingMessageLoop() { | 208 MessageLoop* SafeBrowsingMessageLoop() { |
285 return safe_browsing_service_->safe_browsing_thread_->message_loop(); | 209 return safe_browsing_service_->safe_browsing_thread_->message_loop(); |
286 } | 210 } |
287 | 211 |
212 const std::string& server_host() const { | |
213 return server_host_; | |
Paweł Hajdan Jr.
2012/04/17 06:38:05
nit: Why don't you just propagate things from test
mattm
2012/04/18 00:20:00
Done.
| |
214 } | |
215 | |
216 int server_port() const { | |
217 return server_port_; | |
218 } | |
219 | |
288 protected: | 220 protected: |
289 bool InitSafeBrowsingService() { | 221 bool InitSafeBrowsingService() { |
290 safe_browsing_service_ = g_browser_process->safe_browsing_service(); | 222 safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
291 return safe_browsing_service_ != NULL; | 223 return safe_browsing_service_ != NULL; |
292 } | 224 } |
293 | 225 |
294 virtual void SetUpCommandLine(CommandLine* command_line) { | 226 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
295 // Makes sure the auto update is not triggered. This test will force the | 227 // Makes sure the auto update is not triggered. This test will force the |
296 // update when needed. | 228 // update when needed. |
297 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); | 229 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); |
298 | 230 |
299 // This test uses loopback. No need to use IPv6 especially it makes | 231 // This test uses loopback. No need to use IPv6 especially it makes |
300 // local requests slow on Windows trybot when ipv6 local address [::1] | 232 // local requests slow on Windows trybot when ipv6 local address [::1] |
301 // is not setup. | 233 // is not setup. |
302 command_line->AppendSwitch(switches::kDisableIPv6); | 234 command_line->AppendSwitch(switches::kDisableIPv6); |
303 | 235 |
304 // TODO(lzheng): The test server does not understand download related | 236 // TODO(lzheng): The test server does not understand download related |
305 // requests. We need to fix the server. | 237 // requests. We need to fix the server. |
306 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); | 238 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); |
307 | 239 |
308 // TODO(gcasto): Generate new testing data that includes the | 240 // TODO(gcasto): Generate new testing data that includes the |
309 // client-side phishing whitelist. | 241 // client-side phishing whitelist. |
310 command_line->AppendSwitch( | 242 command_line->AppendSwitch( |
311 switches::kDisableClientSidePhishingDetection); | 243 switches::kDisableClientSidePhishingDetection); |
312 | 244 |
313 // Point to the testing server for all SafeBrowsing requests. | 245 // Point to the testing server for all SafeBrowsing requests. |
314 std::string url_prefix = | 246 std::string url_prefix = |
315 base::StringPrintf("http://%s:%d/safebrowsing", | 247 base::StringPrintf("http://%s:%d/safebrowsing", |
316 SafeBrowsingTestServer::Host(), | 248 server_host_.c_str(), |
317 SafeBrowsingTestServer::Port()); | 249 server_port_); |
318 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); | 250 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); |
319 } | 251 } |
320 | 252 |
321 void SetTestStep(int step) { | 253 void SetTestStep(int step) { |
322 std::string test_step = base::StringPrintf("test_step=%d", step); | 254 std::string test_step = base::StringPrintf("test_step=%d", step); |
323 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); | 255 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); |
324 } | 256 } |
325 | 257 |
326 private: | 258 private: |
327 SafeBrowsingService* safe_browsing_service_; | 259 SafeBrowsingService* safe_browsing_service_; |
328 | 260 |
261 scoped_ptr<net::TestServer> test_server_; | |
262 std::string server_host_; | |
263 int server_port_; | |
264 | |
329 // Protects all variables below since they are read on UI thread | 265 // Protects all variables below since they are read on UI thread |
330 // but updated on IO thread or safebrowsing thread. | 266 // but updated on IO thread or safebrowsing thread. |
331 base::Lock update_status_mutex_; | 267 base::Lock update_status_mutex_; |
332 | 268 |
333 // States associated with safebrowsing service updates. | 269 // States associated with safebrowsing service updates. |
334 bool is_database_ready_; | 270 bool is_database_ready_; |
335 base::Time last_update_; | 271 base::Time last_update_; |
336 bool is_update_scheduled_; | 272 bool is_update_scheduled_; |
337 // 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 |
338 // database (thus potentially it is a phishing URL). | 274 // database (thus potentially it is a phishing URL). |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 BrowserThread::PostDelayedTask( | 384 BrowserThread::PostDelayedTask( |
449 BrowserThread::IO, | 385 BrowserThread::IO, |
450 FROM_HERE, | 386 FROM_HERE, |
451 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, | 387 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, |
452 this), | 388 this), |
453 base::TimeDelta::FromMilliseconds(wait_time_msec)); | 389 base::TimeDelta::FromMilliseconds(wait_time_msec)); |
454 // Will continue after OnWaitForStatusUpdateDone(). | 390 // Will continue after OnWaitForStatusUpdateDone(). |
455 ui_test_utils::RunMessageLoop(); | 391 ui_test_utils::RunMessageLoop(); |
456 } | 392 } |
457 | 393 |
458 void WaitTillServerReady(const char* host, int port) { | |
459 response_status_ = net::URLRequestStatus::FAILED; | |
460 GURL url(base::StringPrintf("http://%s:%d%s?test_step=0", | |
461 host, port, kDBResetPath)); | |
462 // TODO(lzheng): We should have a way to reliably tell when a server is | |
463 // ready so we could get rid of the Sleep and retry loop. | |
464 while (true) { | |
465 if (FetchUrl(url) == net::URLRequestStatus::SUCCESS) | |
466 break; | |
467 // Wait and try again if last fetch was failed. The loop will hit the | |
468 // timeout in OutOfProcTestRunner if the fetch can not get success | |
469 // response. | |
470 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | |
471 } | |
472 } | |
473 | |
474 // Calls test server to fetch database for verification. | 394 // Calls test server to fetch database for verification. |
475 net::URLRequestStatus::Status FetchDBToVerify(const char* host, int port, | 395 net::URLRequestStatus::Status FetchDBToVerify( |
476 int test_step) { | 396 const std::string& host, int port, int test_step) { |
477 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. | 397 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. |
478 GURL url(base::StringPrintf( | 398 GURL url(base::StringPrintf( |
479 "http://%s:%d%s?" | 399 "http://%s:%d%s?" |
480 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" | 400 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" |
481 "chunk_type=add", | 401 "chunk_type=add", |
482 host, port, kDBVerifyPath, test_step)); | 402 host.c_str(), port, kDBVerifyPath, test_step)); |
483 return FetchUrl(url); | 403 return FetchUrl(url); |
484 } | 404 } |
485 | 405 |
486 // Calls test server to fetch URLs for verification. | 406 // Calls test server to fetch URLs for verification. |
487 net::URLRequestStatus::Status FetchUrlsToVerify(const char* host, int port, | 407 net::URLRequestStatus::Status FetchUrlsToVerify( |
488 int test_step) { | 408 const std::string& host, int port, int test_step) { |
489 GURL url(base::StringPrintf( | 409 GURL url(base::StringPrintf( |
490 "http://%s:%d%s?" | 410 "http://%s:%d%s?" |
491 "client=chromium&appver=1.0&pver=2.2&test_step=%d", | 411 "client=chromium&appver=1.0&pver=2.2&test_step=%d", |
492 host, port, kUrlVerifyPath, test_step)); | 412 host.c_str(), port, kUrlVerifyPath, test_step)); |
493 return FetchUrl(url); | 413 return FetchUrl(url); |
494 } | 414 } |
495 | 415 |
496 // Calls test server to check if test data is done. E.g.: if there is a | 416 // Calls test server to check if test data is done. E.g.: if there is a |
497 // bad URL that server expects test to fetch full hash but the test didn't, | 417 // bad URL that server expects test to fetch full hash but the test didn't, |
498 // this verification will fail. | 418 // this verification will fail. |
499 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port, | 419 net::URLRequestStatus::Status VerifyTestComplete( |
500 int test_step) { | 420 const std::string& host, int port, int test_step) { |
501 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", | 421 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", |
502 host, port, kTestCompletePath, test_step)); | 422 host.c_str(), port, kTestCompletePath, test_step)); |
503 return FetchUrl(url); | 423 return FetchUrl(url); |
504 } | 424 } |
505 | 425 |
506 // Callback for URLFetcher. | 426 // Callback for URLFetcher. |
507 virtual void OnURLFetchComplete(const content::URLFetcher* source) { | 427 virtual void OnURLFetchComplete(const content::URLFetcher* source) { |
508 source->GetResponseAsString(&response_data_); | 428 source->GetResponseAsString(&response_data_); |
509 response_status_ = source->GetStatus().status(); | 429 response_status_ = source->GetStatus().status(); |
510 StopUILoop(); | 430 StopUILoop(); |
511 } | 431 } |
512 | 432 |
(...skipping 26 matching lines...) Expand all Loading... | |
539 scoped_ptr<content::URLFetcher> url_fetcher_; | 459 scoped_ptr<content::URLFetcher> url_fetcher_; |
540 std::string response_data_; | 460 std::string response_data_; |
541 net::URLRequestStatus::Status response_status_; | 461 net::URLRequestStatus::Status response_status_; |
542 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); | 462 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); |
543 }; | 463 }; |
544 | 464 |
545 // See http://crbug.com/96459 | 465 // See http://crbug.com/96459 |
546 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, | 466 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
547 DISABLED_SafeBrowsingSystemTest) { | 467 DISABLED_SafeBrowsingSystemTest) { |
548 LOG(INFO) << "Start test"; | 468 LOG(INFO) << "Start test"; |
549 const char* server_host = SafeBrowsingTestServer::Host(); | |
550 int server_port = SafeBrowsingTestServer::Port(); | |
551 ASSERT_TRUE(InitSafeBrowsingService()); | 469 ASSERT_TRUE(InitSafeBrowsingService()); |
552 | 470 |
553 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( | 471 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( |
554 new SafeBrowsingServiceTestHelper(this)); | 472 new SafeBrowsingServiceTestHelper(this)); |
555 int last_step = 0; | 473 int last_step = 0; |
556 FilePath datafile_path = FilePath(kDataFile); | |
557 SafeBrowsingTestServer test_server(datafile_path); | |
558 ASSERT_TRUE(test_server.Start()); | |
559 | |
560 // Make sure the server is running. | |
561 safe_browsing_helper->WaitTillServerReady(server_host, server_port); | |
562 | 474 |
563 // Waits and makes sure safebrowsing update is not happening. | 475 // Waits and makes sure safebrowsing update is not happening. |
564 // The wait will stop once OnWaitForStatusUpdateDone in | 476 // The wait will stop once OnWaitForStatusUpdateDone in |
565 // safe_browsing_helper is called and status from safe_browsing_service_ | 477 // safe_browsing_helper is called and status from safe_browsing_service_ |
566 // is checked. | 478 // is checked. |
567 safe_browsing_helper->WaitForStatusUpdate(0); | 479 safe_browsing_helper->WaitForStatusUpdate(0); |
568 EXPECT_TRUE(is_database_ready()); | 480 EXPECT_TRUE(is_database_ready()); |
569 EXPECT_FALSE(is_update_scheduled()); | 481 EXPECT_FALSE(is_update_scheduled()); |
570 EXPECT_TRUE(last_update().is_null()); | 482 EXPECT_TRUE(last_update().is_null()); |
571 // Starts updates. After each update, the test will fetch a list of URLs with | 483 // Starts updates. After each update, the test will fetch a list of URLs with |
(...skipping 20 matching lines...) Expand all Loading... | |
592 } while (is_update_scheduled() || !is_database_ready()); | 504 } while (is_update_scheduled() || !is_database_ready()); |
593 | 505 |
594 | 506 |
595 if (last_update() < now) { | 507 if (last_update() < now) { |
596 // This means no data available anymore. | 508 // This means no data available anymore. |
597 break; | 509 break; |
598 } | 510 } |
599 | 511 |
600 // Fetches URLs to verify and waits till server responses with data. | 512 // Fetches URLs to verify and waits till server responses with data. |
601 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 513 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
602 safe_browsing_helper->FetchUrlsToVerify(server_host, | 514 safe_browsing_helper->FetchUrlsToVerify(server_host(), |
603 server_port, | 515 server_port(), |
604 step)); | 516 step)); |
605 | 517 |
606 std::vector<PhishingUrl> phishing_urls; | 518 std::vector<PhishingUrl> phishing_urls; |
607 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), | 519 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), |
608 &phishing_urls)); | 520 &phishing_urls)); |
609 EXPECT_GT(phishing_urls.size(), 0U); | 521 EXPECT_GT(phishing_urls.size(), 0U); |
610 for (size_t j = 0; j < phishing_urls.size(); ++j) { | 522 for (size_t j = 0; j < phishing_urls.size(); ++j) { |
611 // Verifes with server if a URL is a phishing URL and waits till server | 523 // Verifes with server if a URL is a phishing URL and waits till server |
612 // responses. | 524 // responses. |
613 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); | 525 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); |
614 if (phishing_urls[j].is_phishing) { | 526 if (phishing_urls[j].is_phishing) { |
615 EXPECT_TRUE(is_checked_url_in_db()) | 527 EXPECT_TRUE(is_checked_url_in_db()) |
616 << phishing_urls[j].url | 528 << phishing_urls[j].url |
617 << " is_phishing: " << phishing_urls[j].is_phishing | 529 << " is_phishing: " << phishing_urls[j].is_phishing |
618 << " test step: " << step; | 530 << " test step: " << step; |
619 EXPECT_FALSE(is_checked_url_safe()) | 531 EXPECT_FALSE(is_checked_url_safe()) |
620 << phishing_urls[j].url | 532 << phishing_urls[j].url |
621 << " is_phishing: " << phishing_urls[j].is_phishing | 533 << " is_phishing: " << phishing_urls[j].is_phishing |
622 << " test step: " << step; | 534 << " test step: " << step; |
623 } else { | 535 } else { |
624 EXPECT_TRUE(is_checked_url_safe()) | 536 EXPECT_TRUE(is_checked_url_safe()) |
625 << phishing_urls[j].url | 537 << phishing_urls[j].url |
626 << " is_phishing: " << phishing_urls[j].is_phishing | 538 << " is_phishing: " << phishing_urls[j].is_phishing |
627 << " test step: " << step; | 539 << " test step: " << step; |
628 } | 540 } |
629 } | 541 } |
630 // TODO(lzheng): We should verify the fetched database with local | 542 // TODO(lzheng): We should verify the fetched database with local |
631 // database to make sure they match. | 543 // database to make sure they match. |
632 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 544 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
633 safe_browsing_helper->FetchDBToVerify(server_host, | 545 safe_browsing_helper->FetchDBToVerify(server_host(), |
634 server_port, | 546 server_port(), |
635 step)); | 547 step)); |
636 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); | 548 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); |
637 last_step = step; | 549 last_step = step; |
638 } | 550 } |
639 | 551 |
640 // Verifies with server if test is done and waits till server responses. | 552 // Verifies with server if test is done and waits till server responses. |
641 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 553 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
642 safe_browsing_helper->VerifyTestComplete(server_host, | 554 safe_browsing_helper->VerifyTestComplete(server_host(), |
643 server_port, | 555 server_port(), |
644 last_step)); | 556 last_step)); |
645 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 557 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
646 test_server.Stop(); | |
647 } | 558 } |
OLD | NEW |