Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 38 #include "chrome/test/base/in_process_browser_test.h" | 38 #include "chrome/test/base/in_process_browser_test.h" |
| 39 #include "chrome/test/base/ui_test_utils.h" | 39 #include "chrome/test/base/ui_test_utils.h" |
| 40 #include "content/public/browser/browser_context.h" | 40 #include "content/public/browser/browser_context.h" |
| 41 #include "content/public/test/test_browser_thread.h" | 41 #include "content/public/test/test_browser_thread.h" |
| 42 #include "net/base/host_resolver.h" | 42 #include "net/base/host_resolver.h" |
| 43 #include "net/base/load_flags.h" | 43 #include "net/base/load_flags.h" |
| 44 #include "net/base/net_log.h" | 44 #include "net/base/net_log.h" |
| 45 #include "net/test/python_utils.h" | 45 #include "net/test/python_utils.h" |
| 46 #include "chrome/browser/safe_browsing/local_safebrowsing_test_server.h" | |
| 46 #include "net/url_request/url_fetcher.h" | 47 #include "net/url_request/url_fetcher.h" |
| 47 #include "net/url_request/url_fetcher_delegate.h" | 48 #include "net/url_request/url_fetcher_delegate.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_, base::TimeDelta()) && | |
| 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; | |
| 126 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &datafile_path)); | |
| 127 | |
| 128 datafile_path = datafile_path.Append(FILE_PATH_LITERAL("third_party")) | |
| 129 .Append(FILE_PATH_LITERAL("safe_browsing")) | |
| 130 .Append(FILE_PATH_LITERAL("testing")) | |
| 131 .Append(kDataFile); | |
| 132 test_server_.reset(new LocalSafeBrowsingTestServer(datafile_path)); | |
| 133 ASSERT_TRUE(test_server_->Start()); | |
| 134 | |
| 135 LOG(INFO) << "server is " << server_host() << ":" << server_port(); | |
| 136 InProcessBrowserTest::SetUp(); | |
|
Ryan Sleevi
2012/08/08 06:15:40
Running InProcBrowsertest::SetUp() after, rather t
mattm
2012/08/30 21:50:47
It can't do in the constructor, since you can't AS
| |
| 137 } | |
| 138 | |
| 139 virtual void TearDown() OVERRIDE { | |
| 140 InProcessBrowserTest::TearDown(); | |
| 141 test_server_->Stop(); | |
| 142 } | |
| 143 | |
| 221 void UpdateSafeBrowsingStatus() { | 144 void UpdateSafeBrowsingStatus() { |
| 222 ASSERT_TRUE(safe_browsing_service_); | 145 ASSERT_TRUE(safe_browsing_service_); |
| 223 base::AutoLock lock(update_status_mutex_); | 146 base::AutoLock lock(update_status_mutex_); |
| 224 last_update_ = safe_browsing_service_->protocol_manager_->last_update(); | 147 last_update_ = safe_browsing_service_->protocol_manager_->last_update(); |
| 225 is_update_scheduled_ = | 148 is_update_scheduled_ = |
| 226 safe_browsing_service_->protocol_manager_->update_timer_.IsRunning(); | 149 safe_browsing_service_->protocol_manager_->update_timer_.IsRunning(); |
| 227 } | 150 } |
| 228 | 151 |
| 229 void ForceUpdate() { | 152 void ForceUpdate() { |
| 230 ASSERT_TRUE(safe_browsing_service_); | 153 ASSERT_TRUE(safe_browsing_service_); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 | 201 |
| 279 bool is_update_scheduled() { | 202 bool is_update_scheduled() { |
| 280 base::AutoLock l(update_status_mutex_); | 203 base::AutoLock l(update_status_mutex_); |
| 281 return is_update_scheduled_; | 204 return is_update_scheduled_; |
| 282 } | 205 } |
| 283 | 206 |
| 284 MessageLoop* SafeBrowsingMessageLoop() { | 207 MessageLoop* SafeBrowsingMessageLoop() { |
| 285 return safe_browsing_service_->safe_browsing_thread_->message_loop(); | 208 return safe_browsing_service_->safe_browsing_thread_->message_loop(); |
| 286 } | 209 } |
| 287 | 210 |
| 211 const std::string& server_host() const { | |
| 212 return test_server_->host_port_pair().host(); | |
| 213 } | |
| 214 | |
| 215 int server_port() const { | |
| 216 return test_server_->host_port_pair().port(); | |
| 217 } | |
| 218 | |
| 288 protected: | 219 protected: |
| 289 bool InitSafeBrowsingService() { | 220 bool InitSafeBrowsingService() { |
| 290 safe_browsing_service_ = g_browser_process->safe_browsing_service(); | 221 safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
| 291 return safe_browsing_service_ != NULL; | 222 return safe_browsing_service_ != NULL; |
| 292 } | 223 } |
| 293 | 224 |
| 294 virtual void SetUpCommandLine(CommandLine* command_line) { | 225 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 295 // Makes sure the auto update is not triggered. This test will force the | 226 // Makes sure the auto update is not triggered. This test will force the |
| 296 // update when needed. | 227 // update when needed. |
| 297 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); | 228 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); |
| 298 | 229 |
| 299 // This test uses loopback. No need to use IPv6 especially it makes | 230 // This test uses loopback. No need to use IPv6 especially it makes |
| 300 // local requests slow on Windows trybot when ipv6 local address [::1] | 231 // local requests slow on Windows trybot when ipv6 local address [::1] |
| 301 // is not setup. | 232 // is not setup. |
| 302 command_line->AppendSwitch(switches::kDisableIPv6); | 233 command_line->AppendSwitch(switches::kDisableIPv6); |
| 303 | 234 |
| 304 // TODO(lzheng): The test server does not understand download related | 235 // TODO(lzheng): The test server does not understand download related |
| 305 // requests. We need to fix the server. | 236 // requests. We need to fix the server. |
| 306 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); | 237 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); |
| 307 | 238 |
| 308 // TODO(gcasto): Generate new testing data that includes the | 239 // TODO(gcasto): Generate new testing data that includes the |
| 309 // client-side phishing whitelist. | 240 // client-side phishing whitelist. |
| 310 command_line->AppendSwitch( | 241 command_line->AppendSwitch( |
| 311 switches::kDisableClientSidePhishingDetection); | 242 switches::kDisableClientSidePhishingDetection); |
| 312 | 243 |
| 313 // Point to the testing server for all SafeBrowsing requests. | 244 // Point to the testing server for all SafeBrowsing requests. |
| 314 std::string url_prefix = | 245 std::string url_prefix = |
| 315 base::StringPrintf("http://%s:%d/safebrowsing", | 246 base::StringPrintf("http://%s:%d/safebrowsing", |
| 316 SafeBrowsingTestServer::Host(), | 247 server_host().c_str(), |
| 317 SafeBrowsingTestServer::Port()); | 248 server_port()); |
| 318 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); | 249 command_line->AppendSwitchASCII(switches::kSbURLPrefix, url_prefix); |
| 319 } | 250 } |
| 320 | 251 |
| 321 void SetTestStep(int step) { | 252 void SetTestStep(int step) { |
| 322 std::string test_step = base::StringPrintf("test_step=%d", step); | 253 std::string test_step = base::StringPrintf("test_step=%d", step); |
| 323 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); | 254 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); |
| 324 } | 255 } |
| 325 | 256 |
| 326 private: | 257 private: |
| 327 SafeBrowsingService* safe_browsing_service_; | 258 SafeBrowsingService* safe_browsing_service_; |
| 328 | 259 |
| 260 scoped_ptr<net::TestServer> test_server_; | |
| 261 | |
| 329 // Protects all variables below since they are read on UI thread | 262 // Protects all variables below since they are read on UI thread |
| 330 // but updated on IO thread or safebrowsing thread. | 263 // but updated on IO thread or safebrowsing thread. |
| 331 base::Lock update_status_mutex_; | 264 base::Lock update_status_mutex_; |
| 332 | 265 |
| 333 // States associated with safebrowsing service updates. | 266 // States associated with safebrowsing service updates. |
| 334 bool is_database_ready_; | 267 bool is_database_ready_; |
| 335 base::Time last_update_; | 268 base::Time last_update_; |
| 336 bool is_update_scheduled_; | 269 bool is_update_scheduled_; |
| 337 // Indicates if there is a match between a URL's prefix and safebrowsing | 270 // Indicates if there is a match between a URL's prefix and safebrowsing |
| 338 // database (thus potentially it is a phishing URL). | 271 // database (thus potentially it is a phishing URL). |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 BrowserThread::PostDelayedTask( | 382 BrowserThread::PostDelayedTask( |
| 450 BrowserThread::IO, | 383 BrowserThread::IO, |
| 451 FROM_HERE, | 384 FROM_HERE, |
| 452 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, | 385 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, |
| 453 this), | 386 this), |
| 454 wait_time); | 387 wait_time); |
| 455 // Will continue after OnWaitForStatusUpdateDone(). | 388 // Will continue after OnWaitForStatusUpdateDone(). |
| 456 content::RunMessageLoop(); | 389 content::RunMessageLoop(); |
| 457 } | 390 } |
| 458 | 391 |
| 459 void WaitTillServerReady(const char* host, int port) { | |
| 460 response_status_ = net::URLRequestStatus::FAILED; | |
| 461 GURL url(base::StringPrintf("http://%s:%d%s?test_step=0", | |
| 462 host, port, kDBResetPath)); | |
| 463 // TODO(lzheng): We should have a way to reliably tell when a server is | |
| 464 // ready so we could get rid of the Sleep and retry loop. | |
| 465 while (true) { | |
| 466 if (FetchUrl(url) == net::URLRequestStatus::SUCCESS) | |
| 467 break; | |
| 468 // Wait and try again if last fetch was failed. The loop will hit the | |
| 469 // timeout in OutOfProcTestRunner if the fetch can not get success | |
| 470 // response. | |
| 471 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | |
| 472 } | |
| 473 } | |
| 474 | |
| 475 // Calls test server to fetch database for verification. | 392 // Calls test server to fetch database for verification. |
| 476 net::URLRequestStatus::Status FetchDBToVerify(const char* host, int port, | 393 net::URLRequestStatus::Status FetchDBToVerify( |
| 477 int test_step) { | 394 const std::string& host, int port, int test_step) { |
| 478 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. | 395 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. |
| 479 GURL url(base::StringPrintf( | 396 GURL url(base::StringPrintf( |
| 480 "http://%s:%d%s?" | 397 "http://%s:%d%s?" |
| 481 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" | 398 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" |
| 482 "chunk_type=add", | 399 "chunk_type=add", |
| 483 host, port, kDBVerifyPath, test_step)); | 400 host.c_str(), port, kDBVerifyPath, test_step)); |
| 484 return FetchUrl(url); | 401 return FetchUrl(url); |
| 485 } | 402 } |
| 486 | 403 |
| 487 // Calls test server to fetch URLs for verification. | 404 // Calls test server to fetch URLs for verification. |
| 488 net::URLRequestStatus::Status FetchUrlsToVerify(const char* host, int port, | 405 net::URLRequestStatus::Status FetchUrlsToVerify( |
| 489 int test_step) { | 406 const std::string& host, int port, int test_step) { |
| 490 GURL url(base::StringPrintf( | 407 GURL url(base::StringPrintf( |
| 491 "http://%s:%d%s?" | 408 "http://%s:%d%s?" |
| 492 "client=chromium&appver=1.0&pver=2.2&test_step=%d", | 409 "client=chromium&appver=1.0&pver=2.2&test_step=%d", |
| 493 host, port, kUrlVerifyPath, test_step)); | 410 host.c_str(), port, kUrlVerifyPath, test_step)); |
| 494 return FetchUrl(url); | 411 return FetchUrl(url); |
| 495 } | 412 } |
| 496 | 413 |
| 497 // Calls test server to check if test data is done. E.g.: if there is a | 414 // Calls test server to check if test data is done. E.g.: if there is a |
| 498 // bad URL that server expects test to fetch full hash but the test didn't, | 415 // bad URL that server expects test to fetch full hash but the test didn't, |
| 499 // this verification will fail. | 416 // this verification will fail. |
| 500 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port, | 417 net::URLRequestStatus::Status VerifyTestComplete( |
| 501 int test_step) { | 418 const std::string& host, int port, int test_step) { |
| 502 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", | 419 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", |
| 503 host, port, kTestCompletePath, test_step)); | 420 host.c_str(), port, kTestCompletePath, test_step)); |
| 504 return FetchUrl(url); | 421 return FetchUrl(url); |
| 505 } | 422 } |
| 506 | 423 |
| 507 // Callback for URLFetcher. | 424 // Callback for URLFetcher. |
| 508 virtual void OnURLFetchComplete(const net::URLFetcher* source) { | 425 virtual void OnURLFetchComplete(const net::URLFetcher* source) { |
| 509 source->GetResponseAsString(&response_data_); | 426 source->GetResponseAsString(&response_data_); |
| 510 response_status_ = source->GetStatus().status(); | 427 response_status_ = source->GetStatus().status(); |
| 511 StopUILoop(); | 428 StopUILoop(); |
| 512 } | 429 } |
| 513 | 430 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 541 SafeBrowsingServiceTest* safe_browsing_test_; | 458 SafeBrowsingServiceTest* safe_browsing_test_; |
| 542 scoped_ptr<net::URLFetcher> url_fetcher_; | 459 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 543 std::string response_data_; | 460 std::string response_data_; |
| 544 net::URLRequestStatus::Status response_status_; | 461 net::URLRequestStatus::Status response_status_; |
| 545 net::URLRequestContextGetter* request_context_; | 462 net::URLRequestContextGetter* request_context_; |
| 546 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); | 463 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); |
| 547 }; | 464 }; |
| 548 | 465 |
| 549 // See http://crbug.com/96459 | 466 // See http://crbug.com/96459 |
| 550 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, | 467 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
| 551 DISABLED_SafeBrowsingSystemTest) { | 468 SafeBrowsingSystemTest) { |
| 552 LOG(INFO) << "Start test"; | 469 LOG(INFO) << "Start test"; |
| 553 const char* server_host = SafeBrowsingTestServer::Host(); | |
| 554 int server_port = SafeBrowsingTestServer::Port(); | |
| 555 ASSERT_TRUE(InitSafeBrowsingService()); | 470 ASSERT_TRUE(InitSafeBrowsingService()); |
| 556 | 471 |
| 557 net::URLRequestContextGetter* request_context = | 472 net::URLRequestContextGetter* request_context = |
| 558 GetBrowserContext()->GetRequestContext(); | 473 GetBrowserContext()->GetRequestContext(); |
| 559 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( | 474 scoped_refptr<SafeBrowsingServiceTestHelper> safe_browsing_helper( |
| 560 new SafeBrowsingServiceTestHelper(this, request_context)); | 475 new SafeBrowsingServiceTestHelper(this, request_context)); |
| 561 int last_step = 0; | 476 int last_step = 0; |
| 562 FilePath datafile_path = FilePath(kDataFile); | |
| 563 SafeBrowsingTestServer test_server(datafile_path); | |
| 564 ASSERT_TRUE(test_server.Start()); | |
| 565 | |
| 566 // Make sure the server is running. | |
| 567 safe_browsing_helper->WaitTillServerReady(server_host, server_port); | |
| 568 | 477 |
| 569 // Waits and makes sure safebrowsing update is not happening. | 478 // Waits and makes sure safebrowsing update is not happening. |
| 570 // The wait will stop once OnWaitForStatusUpdateDone in | 479 // The wait will stop once OnWaitForStatusUpdateDone in |
| 571 // safe_browsing_helper is called and status from safe_browsing_service_ | 480 // safe_browsing_helper is called and status from safe_browsing_service_ |
| 572 // is checked. | 481 // is checked. |
| 573 safe_browsing_helper->WaitForStatusUpdate(base::TimeDelta()); | 482 safe_browsing_helper->WaitForStatusUpdate(base::TimeDelta()); |
| 574 EXPECT_TRUE(is_database_ready()); | 483 EXPECT_TRUE(is_database_ready()); |
| 575 EXPECT_FALSE(is_update_scheduled()); | 484 EXPECT_FALSE(is_update_scheduled()); |
| 576 EXPECT_TRUE(last_update().is_null()); | 485 EXPECT_TRUE(last_update().is_null()); |
| 577 // Starts updates. After each update, the test will fetch a list of URLs with | 486 // Starts updates. After each update, the test will fetch a list of URLs with |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 599 } while (is_update_scheduled() || !is_database_ready()); | 508 } while (is_update_scheduled() || !is_database_ready()); |
| 600 | 509 |
| 601 | 510 |
| 602 if (last_update() < now) { | 511 if (last_update() < now) { |
| 603 // This means no data available anymore. | 512 // This means no data available anymore. |
| 604 break; | 513 break; |
| 605 } | 514 } |
| 606 | 515 |
| 607 // Fetches URLs to verify and waits till server responses with data. | 516 // Fetches URLs to verify and waits till server responses with data. |
| 608 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 517 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
| 609 safe_browsing_helper->FetchUrlsToVerify(server_host, | 518 safe_browsing_helper->FetchUrlsToVerify(server_host(), |
| 610 server_port, | 519 server_port(), |
| 611 step)); | 520 step)); |
| 612 | 521 |
| 613 std::vector<PhishingUrl> phishing_urls; | 522 std::vector<PhishingUrl> phishing_urls; |
| 614 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), | 523 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), |
| 615 &phishing_urls)); | 524 &phishing_urls)); |
| 616 EXPECT_GT(phishing_urls.size(), 0U); | 525 EXPECT_GT(phishing_urls.size(), 0U); |
| 617 for (size_t j = 0; j < phishing_urls.size(); ++j) { | 526 for (size_t j = 0; j < phishing_urls.size(); ++j) { |
| 618 // Verifes with server if a URL is a phishing URL and waits till server | 527 // Verifes with server if a URL is a phishing URL and waits till server |
| 619 // responses. | 528 // responses. |
| 620 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); | 529 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); |
| 621 if (phishing_urls[j].is_phishing) { | 530 if (phishing_urls[j].is_phishing) { |
| 622 EXPECT_TRUE(is_checked_url_in_db()) | 531 EXPECT_TRUE(is_checked_url_in_db()) |
| 623 << phishing_urls[j].url | 532 << phishing_urls[j].url |
| 624 << " is_phishing: " << phishing_urls[j].is_phishing | 533 << " is_phishing: " << phishing_urls[j].is_phishing |
| 625 << " test step: " << step; | 534 << " test step: " << step; |
| 626 EXPECT_FALSE(is_checked_url_safe()) | 535 EXPECT_FALSE(is_checked_url_safe()) |
| 627 << phishing_urls[j].url | 536 << phishing_urls[j].url |
| 628 << " is_phishing: " << phishing_urls[j].is_phishing | 537 << " is_phishing: " << phishing_urls[j].is_phishing |
| 629 << " test step: " << step; | 538 << " test step: " << step; |
| 630 } else { | 539 } else { |
| 631 EXPECT_TRUE(is_checked_url_safe()) | 540 EXPECT_TRUE(is_checked_url_safe()) |
| 632 << phishing_urls[j].url | 541 << phishing_urls[j].url |
| 633 << " is_phishing: " << phishing_urls[j].is_phishing | 542 << " is_phishing: " << phishing_urls[j].is_phishing |
| 634 << " test step: " << step; | 543 << " test step: " << step; |
| 635 } | 544 } |
| 636 } | 545 } |
| 637 // TODO(lzheng): We should verify the fetched database with local | 546 // TODO(lzheng): We should verify the fetched database with local |
| 638 // database to make sure they match. | 547 // database to make sure they match. |
| 639 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 548 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
| 640 safe_browsing_helper->FetchDBToVerify(server_host, | 549 safe_browsing_helper->FetchDBToVerify(server_host(), |
| 641 server_port, | 550 server_port(), |
| 642 step)); | 551 step)); |
| 643 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); | 552 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); |
| 644 last_step = step; | 553 last_step = step; |
| 645 } | 554 } |
| 646 | 555 |
| 647 // Verifies with server if test is done and waits till server responses. | 556 // Verifies with server if test is done and waits till server responses. |
| 648 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 557 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
| 649 safe_browsing_helper->VerifyTestComplete(server_host, | 558 safe_browsing_helper->VerifyTestComplete(server_host(), |
| 650 server_port, | 559 server_port(), |
| 651 last_step)); | 560 last_step)); |
| 652 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 561 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
| 653 test_server.Stop(); | |
| 654 } | 562 } |
| OLD | NEW |