| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // |
| 11 // This test launches safebrowsing test server and issues several update | 11 // This test launches safebrowsing test server and issues several update |
| 12 // requests against that server. Each update would get different data and after | 12 // requests against that server. Each update would get different data and after |
| 13 // each update, the test will get a list of URLs from the test server to verify | 13 // each update, the test will get a list of URLs from the test server to verify |
| 14 // its repository. The test will succeed only if all updates are performed and | 14 // its repository. The test will succeed only if all updates are performed and |
| 15 // URLs match what the server expected. | 15 // URLs match what the server expected. |
| 16 | 16 |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "base/condition_variable.h" | 20 #include "base/condition_variable.h" |
| 21 #include "base/environment.h" | 21 #include "base/environment.h" |
| 22 #include "base/lock.h" | 22 #include "base/lock.h" |
| 23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 24 #include "base/process_util.h" | 24 #include "base/process_util.h" |
| 25 #include "base/string_number_conversions.h" | 25 #include "base/string_number_conversions.h" |
| 26 #include "base/string_util.h" | 26 #include "base/string_util.h" |
| 27 #include "base/string_split.h" | 27 #include "base/string_split.h" |
| 28 #include "base/threading/platform_thread.h" |
| 28 #include "base/time.h" | 29 #include "base/time.h" |
| 29 #include "base/utf_string_conversions.h" | 30 #include "base/utf_string_conversions.h" |
| 30 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
| 31 #include "chrome/browser/browser_thread.h" | 32 #include "chrome/browser/browser_thread.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 34 #include "chrome/browser/renderer_host/resource_dispatcher_host.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_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 GURL url(StringPrintf("http://%s:%d%s?test_step=0", | 446 GURL url(StringPrintf("http://%s:%d%s?test_step=0", |
| 446 host, port, kDBResetPath)); | 447 host, port, kDBResetPath)); |
| 447 // TODO(lzheng): We should have a way to reliably tell when a server is | 448 // TODO(lzheng): We should have a way to reliably tell when a server is |
| 448 // ready so we could get rid of the Sleep and retry loop. | 449 // ready so we could get rid of the Sleep and retry loop. |
| 449 while (true) { | 450 while (true) { |
| 450 if (FetchUrl(url) == URLRequestStatus::SUCCESS) | 451 if (FetchUrl(url) == URLRequestStatus::SUCCESS) |
| 451 break; | 452 break; |
| 452 // Wait and try again if last fetch was failed. The loop will hit the | 453 // Wait and try again if last fetch was failed. The loop will hit the |
| 453 // timeout in OutOfProcTestRunner if the fetch can not get success | 454 // timeout in OutOfProcTestRunner if the fetch can not get success |
| 454 // response. | 455 // response. |
| 455 PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); | 456 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); |
| 456 } | 457 } |
| 457 } | 458 } |
| 458 | 459 |
| 459 // Calls test server to fetch database for verification. | 460 // Calls test server to fetch database for verification. |
| 460 URLRequestStatus::Status FetchDBToVerify(const char* host, int port, | 461 URLRequestStatus::Status FetchDBToVerify(const char* host, int port, |
| 461 int test_step) { | 462 int test_step) { |
| 462 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. | 463 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. |
| 463 GURL url(StringPrintf("http://%s:%d%s?" | 464 GURL url(StringPrintf("http://%s:%d%s?" |
| 464 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" | 465 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" |
| 465 "chunk_type=add", | 466 "chunk_type=add", |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 } | 625 } |
| 625 | 626 |
| 626 // Verifies with server if test is done and waits till server responses. | 627 // Verifies with server if test is done and waits till server responses. |
| 627 EXPECT_EQ(URLRequestStatus::SUCCESS, | 628 EXPECT_EQ(URLRequestStatus::SUCCESS, |
| 628 safe_browsing_helper->VerifyTestComplete(server_host, | 629 safe_browsing_helper->VerifyTestComplete(server_host, |
| 629 server_port, | 630 server_port, |
| 630 last_step)); | 631 last_step)); |
| 631 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 632 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
| 632 test_server.Stop(); | 633 test_server.Stop(); |
| 633 } | 634 } |
| OLD | NEW |