Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_test.cc

Issue 7016011: iwyu: Include stringprintf.h where appropriate, part 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win fix. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/environment.h" 20 #include "base/environment.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/process_util.h" 22 #include "base/process_util.h"
23 #include "base/stringprintf.h"
23 #include "base/string_number_conversions.h" 24 #include "base/string_number_conversions.h"
24 #include "base/string_split.h" 25 #include "base/string_split.h"
25 #include "base/string_util.h"
26 #include "base/synchronization/lock.h" 26 #include "base/synchronization/lock.h"
27 #include "base/test/test_timeouts.h" 27 #include "base/test/test_timeouts.h"
28 #include "base/threading/platform_thread.h" 28 #include "base/threading/platform_thread.h"
29 #include "base/time.h" 29 #include "base/time.h"
30 #include "base/utf_string_conversions.h" 30 #include "base/utf_string_conversions.h"
31 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
32 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/safe_browsing/protocol_manager.h" 33 #include "chrome/browser/safe_browsing/protocol_manager.h"
34 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 34 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
35 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 134 }
135 AppendToPythonPath(pyproto_code_dir); 135 AppendToPythonPath(pyproto_code_dir);
136 pyproto_code_dir = pyproto_code_dir.Append(FILE_PATH_LITERAL("google")); 136 pyproto_code_dir = pyproto_code_dir.Append(FILE_PATH_LITERAL("google"));
137 AppendToPythonPath(pyproto_code_dir); 137 AppendToPythonPath(pyproto_code_dir);
138 138
139 FilePath python_runtime; 139 FilePath python_runtime;
140 EXPECT_TRUE(GetPythonRunTime(&python_runtime)); 140 EXPECT_TRUE(GetPythonRunTime(&python_runtime));
141 CommandLine cmd_line(python_runtime); 141 CommandLine cmd_line(python_runtime);
142 FilePath datafile = testserver_path.Append(datafile_); 142 FilePath datafile = testserver_path.Append(datafile_);
143 cmd_line.AppendArgPath(testserver); 143 cmd_line.AppendArgPath(testserver);
144 cmd_line.AppendSwitchASCII("port", StringPrintf("%d", kPort_)); 144 cmd_line.AppendSwitchASCII("port", base::StringPrintf("%d", kPort_));
145 cmd_line.AppendSwitchPath("datafile", datafile); 145 cmd_line.AppendSwitchPath("datafile", datafile);
146 146
147 if (!base::LaunchApp(cmd_line, false, true, &server_handle_)) { 147 if (!base::LaunchApp(cmd_line, false, true, &server_handle_)) {
148 LOG(ERROR) << "Failed to launch server: " 148 LOG(ERROR) << "Failed to launch server: "
149 << cmd_line.command_line_string(); 149 << cmd_line.command_line_string();
150 return false; 150 return false;
151 } 151 }
152 return true; 152 return true;
153 } 153 }
154 154
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 command_line->AppendSwitch(switches::kDisableIPv6); 296 command_line->AppendSwitch(switches::kDisableIPv6);
297 297
298 // TODO(lzheng): The test server does not understand download related 298 // TODO(lzheng): The test server does not understand download related
299 // requests. We need to fix the server. 299 // requests. We need to fix the server.
300 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); 300 command_line->AppendSwitch(switches::kSbDisableDownloadProtection);
301 301
302 // In this test, we fetch SafeBrowsing data and Mac key from the same 302 // In this test, we fetch SafeBrowsing data and Mac key from the same
303 // server. Although in real production, they are served from different 303 // server. Although in real production, they are served from different
304 // servers. 304 // servers.
305 std::string url_prefix = 305 std::string url_prefix =
306 StringPrintf("http://%s:%d/safebrowsing", 306 base::StringPrintf("http://%s:%d/safebrowsing",
307 SafeBrowsingTestServer::Host(), 307 SafeBrowsingTestServer::Host(),
308 SafeBrowsingTestServer::Port()); 308 SafeBrowsingTestServer::Port());
309 command_line->AppendSwitchASCII(switches::kSbInfoURLPrefix, url_prefix); 309 command_line->AppendSwitchASCII(switches::kSbInfoURLPrefix, url_prefix);
310 command_line->AppendSwitchASCII(switches::kSbMacKeyURLPrefix, url_prefix); 310 command_line->AppendSwitchASCII(switches::kSbMacKeyURLPrefix, url_prefix);
311 } 311 }
312 312
313 void SetTestStep(int step) { 313 void SetTestStep(int step) {
314 std::string test_step = StringPrintf("test_step=%d", step); 314 std::string test_step = base::StringPrintf("test_step=%d", step);
315 safe_browsing_service_->protocol_manager_->set_additional_query(test_step); 315 safe_browsing_service_->protocol_manager_->set_additional_query(test_step);
316 } 316 }
317 317
318 private: 318 private:
319 SafeBrowsingService* safe_browsing_service_; 319 SafeBrowsingService* safe_browsing_service_;
320 320
321 // Protects all variables below since they are read on UI thread 321 // Protects all variables below since they are read on UI thread
322 // but updated on IO thread or safebrowsing thread. 322 // but updated on IO thread or safebrowsing thread.
323 base::Lock update_status_mutex_; 323 base::Lock update_status_mutex_;
324 324
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 FROM_HERE, 441 FROM_HERE,
442 NewRunnableMethod(this, 442 NewRunnableMethod(this,
443 &SafeBrowsingServiceTestHelper::CheckStatusOnIOThread), 443 &SafeBrowsingServiceTestHelper::CheckStatusOnIOThread),
444 wait_time_msec); 444 wait_time_msec);
445 // Will continue after OnWaitForStatusUpdateDone(). 445 // Will continue after OnWaitForStatusUpdateDone().
446 ui_test_utils::RunMessageLoop(); 446 ui_test_utils::RunMessageLoop();
447 } 447 }
448 448
449 void WaitTillServerReady(const char* host, int port) { 449 void WaitTillServerReady(const char* host, int port) {
450 response_status_ = net::URLRequestStatus::FAILED; 450 response_status_ = net::URLRequestStatus::FAILED;
451 GURL url(StringPrintf("http://%s:%d%s?test_step=0", 451 GURL url(base::StringPrintf("http://%s:%d%s?test_step=0",
452 host, port, kDBResetPath)); 452 host, port, kDBResetPath));
453 // TODO(lzheng): We should have a way to reliably tell when a server is 453 // TODO(lzheng): We should have a way to reliably tell when a server is
454 // ready so we could get rid of the Sleep and retry loop. 454 // ready so we could get rid of the Sleep and retry loop.
455 while (true) { 455 while (true) {
456 if (FetchUrl(url) == net::URLRequestStatus::SUCCESS) 456 if (FetchUrl(url) == net::URLRequestStatus::SUCCESS)
457 break; 457 break;
458 // Wait and try again if last fetch was failed. The loop will hit the 458 // Wait and try again if last fetch was failed. The loop will hit the
459 // timeout in OutOfProcTestRunner if the fetch can not get success 459 // timeout in OutOfProcTestRunner if the fetch can not get success
460 // response. 460 // response.
461 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); 461 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
462 } 462 }
463 } 463 }
464 464
465 // Calls test server to fetch database for verification. 465 // Calls test server to fetch database for verification.
466 net::URLRequestStatus::Status FetchDBToVerify(const char* host, int port, 466 net::URLRequestStatus::Status FetchDBToVerify(const char* host, int port,
467 int test_step) { 467 int test_step) {
468 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server. 468 // TODO(lzheng): Remove chunk_type=add once it is not needed by the server.
469 GURL url(StringPrintf("http://%s:%d%s?" 469 GURL url(base::StringPrintf(
470 "client=chromium&appver=1.0&pver=2.2&test_step=%d&" 470 "http://%s:%d%s?"
471 "chunk_type=add", 471 "client=chromium&appver=1.0&pver=2.2&test_step=%d&"
472 host, port, kDBVerifyPath, test_step)); 472 "chunk_type=add",
473 host, port, kDBVerifyPath, test_step));
473 return FetchUrl(url); 474 return FetchUrl(url);
474 } 475 }
475 476
476 // Calls test server to fetch URLs for verification. 477 // Calls test server to fetch URLs for verification.
477 net::URLRequestStatus::Status FetchUrlsToVerify(const char* host, int port, 478 net::URLRequestStatus::Status FetchUrlsToVerify(const char* host, int port,
478 int test_step) { 479 int test_step) {
479 GURL url(StringPrintf("http://%s:%d%s?" 480 GURL url(base::StringPrintf(
480 "client=chromium&appver=1.0&pver=2.2&test_step=%d", 481 "http://%s:%d%s?"
481 host, port, kUrlVerifyPath, test_step)); 482 "client=chromium&appver=1.0&pver=2.2&test_step=%d",
483 host, port, kUrlVerifyPath, test_step));
482 return FetchUrl(url); 484 return FetchUrl(url);
483 } 485 }
484 486
485 // Calls test server to check if test data is done. E.g.: if there is a 487 // Calls test server to check if test data is done. E.g.: if there is a
486 // bad URL that server expects test to fetch full hash but the test didn't, 488 // bad URL that server expects test to fetch full hash but the test didn't,
487 // this verification will fail. 489 // this verification will fail.
488 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port, 490 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port,
489 int test_step) { 491 int test_step) {
490 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", 492 GURL url(StringPrintf("http://%s:%d%s?test_step=%d",
491 host, port, kTestCompletePath, test_step)); 493 host, port, kTestCompletePath, test_step));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 EXPECT_TRUE(is_database_ready()); 560 EXPECT_TRUE(is_database_ready());
559 EXPECT_TRUE(is_initial_request()); 561 EXPECT_TRUE(is_initial_request());
560 EXPECT_FALSE(is_update_scheduled()); 562 EXPECT_FALSE(is_update_scheduled());
561 EXPECT_TRUE(last_update().is_null()); 563 EXPECT_TRUE(last_update().is_null());
562 // Starts updates. After each update, the test will fetch a list of URLs with 564 // Starts updates. After each update, the test will fetch a list of URLs with
563 // expected results to verify with safebrowsing service. If there is no error, 565 // expected results to verify with safebrowsing service. If there is no error,
564 // the test moves on to the next step to get more update chunks. 566 // the test moves on to the next step to get more update chunks.
565 // This repeats till there is no update data. 567 // This repeats till there is no update data.
566 for (int step = 1;; step++) { 568 for (int step = 1;; step++) {
567 // Every step should be a fresh start. 569 // Every step should be a fresh start.
568 SCOPED_TRACE(StringPrintf("step=%d", step)); 570 SCOPED_TRACE(base::StringPrintf("step=%d", step));
569 EXPECT_TRUE(is_database_ready()); 571 EXPECT_TRUE(is_database_ready());
570 EXPECT_FALSE(is_update_scheduled()); 572 EXPECT_FALSE(is_update_scheduled());
571 573
572 // Starts safebrowsing update on IO thread. Waits till scheduled 574 // Starts safebrowsing update on IO thread. Waits till scheduled
573 // update finishes. Stops waiting after kMaxWaitSecPerStep if the update 575 // update finishes. Stops waiting after kMaxWaitSecPerStep if the update
574 // could not finish. 576 // could not finish.
575 base::Time now = base::Time::Now(); 577 base::Time now = base::Time::Now();
576 SetTestStep(step); 578 SetTestStep(step);
577 safe_browsing_helper->ForceUpdate(); 579 safe_browsing_helper->ForceUpdate();
578 580
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 } 632 }
631 633
632 // Verifies with server if test is done and waits till server responses. 634 // Verifies with server if test is done and waits till server responses.
633 EXPECT_EQ(net::URLRequestStatus::SUCCESS, 635 EXPECT_EQ(net::URLRequestStatus::SUCCESS,
634 safe_browsing_helper->VerifyTestComplete(server_host, 636 safe_browsing_helper->VerifyTestComplete(server_host,
635 server_port, 637 server_port,
636 last_step)); 638 last_step));
637 EXPECT_EQ("yes", safe_browsing_helper->response_data()); 639 EXPECT_EQ("yes", safe_browsing_helper->response_data());
638 test_server.Stop(); 640 test_server.Stop();
639 } 641 }
OLDNEW
« no previous file with comments | « chrome/browser/process_singleton_linux_uitest.cc ('k') | chrome/browser/sync/engine/apply_updates_command_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698