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

Side by Side Diff: chrome/test/perf/page_cycler_test.cc

Issue 9956045: Add Web Page Replay test to page cycler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Windows compile error. Created 8 years, 8 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
« no previous file with comments | « no previous file | tools/page_cycler/common/head.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/test/base/chrome_process_util.h" 22 #include "chrome/test/base/chrome_process_util.h"
23 #include "chrome/test/base/test_switches.h" 23 #include "chrome/test/base/test_switches.h"
24 #include "chrome/test/perf/perf_test.h" 24 #include "chrome/test/perf/perf_test.h"
25 #include "chrome/test/ui/ui_perf_test.h" 25 #include "chrome/test/ui/ui_perf_test.h"
26 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
27 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
28 28
29 #ifndef NDEBUG 29 #ifndef NDEBUG
30 static const int kTestIterations = 2; 30 static const int kTestIterations = 2;
31 static const int kDatabaseTestIterations = 2; 31 static const int kDatabaseTestIterations = 2;
32 static const int kWebPageReplayIterations = 2;
32 #else 33 #else
33 static const int kTestIterations = 10; 34 static const int kTestIterations = 10;
34 // For some unknown reason, the DB perf tests are much much slower on the 35 // For some unknown reason, the DB perf tests are much much slower on the
35 // Vista perf bot, so we have to cut down the number of iterations to 5 36 // Vista perf bot, so we have to cut down the number of iterations to 5
36 // to make sure each test finishes in less than 10 minutes. 37 // to make sure each test finishes in less than 10 minutes.
37 static const int kDatabaseTestIterations = 5; 38 static const int kDatabaseTestIterations = 5;
39 static const int kWebPageReplayIterations = 5;
38 #endif 40 #endif
39 static const int kIDBTestIterations = 5; 41 static const int kIDBTestIterations = 5;
40 42
41 // URL at which data files may be found for HTTP tests. The document root of 43 // URL at which data files may be found for HTTP tests. The document root of
42 // this URL's server should point to data/page_cycler/. 44 // this URL's server should point to data/page_cycler/.
43 static const char kBaseUrl[] = "http://localhost:8000/"; 45 static const char kBaseUrl[] = "http://localhost:8000/";
44 46
47 // The following port numbers must match those in
48 // src/tools/python/google/webpagereplay_utils.py.
49 static const char kWebPageReplayHttpPort[] = "8080";
50 static const char kWebPageReplayHttpsPort[] = "8413";
51
45 namespace { 52 namespace {
46 53
47 void PopulateBufferCache(const FilePath& test_dir) { 54 void PopulateBufferCache(const FilePath& test_dir) {
48 // This will recursively walk the directory given and read all the 55 // This will recursively walk the directory given and read all the
49 // files it finds. This is done so the system file cache is likely 56 // files it finds. This is done so the system file cache is likely
50 // to have as much loaded as possible. Without this, the tests of 57 // to have as much loaded as possible. Without this, the tests of
51 // this build gets one set of timings and then the reference build 58 // this build gets one set of timings and then the reference build
52 // test, gets slightly faster ones (even if the reference build is 59 // test, gets slightly faster ones (even if the reference build is
53 // the same binary). The hope is by forcing all the possible data 60 // the same binary). The hope is by forcing all the possible data
54 // into the cache we equalize the tests for comparing timing data. 61 // into the cache we equalize the tests for comparing timing data.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 158 }
152 159
153 virtual bool HasErrors(const std::string /*timings*/) { 160 virtual bool HasErrors(const std::string /*timings*/) {
154 return false; 161 return false;
155 } 162 }
156 163
157 virtual int GetTestIterations() { 164 virtual int GetTestIterations() {
158 return num_test_iterations_; 165 return num_test_iterations_;
159 } 166 }
160 167
161 // For HTTP tests, the name must be safe for use in a URL without escaping. 168 virtual void GetTestUrl(const char* name, bool use_http, GURL *test_url) {
162 void RunPageCycler(const char* name, std::wstring* pages,
163 std::string* timings, bool use_http) {
164 FilePath test_path = GetDataPath(name); 169 FilePath test_path = GetDataPath(name);
165 ASSERT_TRUE(file_util::DirectoryExists(test_path)) 170 ASSERT_TRUE(file_util::DirectoryExists(test_path))
166 << "Missing test directory " << test_path.value(); 171 << "Missing test directory " << test_path.value();
167
168 PopulateBufferCache(test_path); 172 PopulateBufferCache(test_path);
169 173
170 GURL test_url;
171 if (use_http) { 174 if (use_http) {
172 test_url = GURL(std::string(kBaseUrl) + name + "/start.html"); 175 *test_url = GURL(std::string(kBaseUrl) + name + "/start.html");
173 } else { 176 } else {
174 test_path = test_path.Append(FILE_PATH_LITERAL("start.html")); 177 test_path = test_path.Append(FILE_PATH_LITERAL("start.html"));
175 test_url = net::FilePathToFileURL(test_path); 178 *test_url = net::FilePathToFileURL(test_path);
176 } 179 }
177 180
178 // run N iterations 181 // run N iterations
179 GURL::Replacements replacements; 182 GURL::Replacements replacements;
180 const std::string query_string = 183 const std::string query_string =
181 "iterations=" + base::IntToString(GetTestIterations()) + "&auto=1"; 184 "iterations=" + base::IntToString(GetTestIterations()) + "&auto=1";
182 replacements.SetQuery( 185 replacements.SetQuery(
183 query_string.c_str(), 186 query_string.c_str(),
184 url_parse::Component(0, query_string.length())); 187 url_parse::Component(0, query_string.length()));
185 test_url = test_url.ReplaceComponents(replacements); 188 *test_url = test_url->ReplaceComponents(replacements);
189 }
190
191 // For HTTP tests, the name must be safe for use in a URL without escaping.
192 void RunPageCycler(const char* name, std::wstring* pages,
193 std::string* timings, bool use_http) {
194 GURL test_url;
195 GetTestUrl(name, use_http, &test_url);
186 196
187 scoped_refptr<TabProxy> tab(GetActiveTab()); 197 scoped_refptr<TabProxy> tab(GetActiveTab());
188 ASSERT_TRUE(tab.get()); 198 ASSERT_TRUE(tab.get());
189 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url)); 199 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url));
190 200
191 // Wait for the test to finish. 201 // Wait for the test to finish.
192 ASSERT_TRUE(WaitUntilCookieValue( 202 ASSERT_TRUE(WaitUntilCookieValue(
193 tab.get(), test_url, "__pc_done", 203 tab.get(), test_url, "__pc_done",
194 TestTimeouts::large_test_timeout_ms(), "1")); 204 TestTimeouts::large_test_timeout_ms(), "1"));
195 205
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 446
437 virtual bool HasErrors(const std::string timings) { 447 virtual bool HasErrors(const std::string timings) {
438 return HasDatabaseErrors(timings); 448 return HasDatabaseErrors(timings);
439 } 449 }
440 450
441 virtual int GetTestIterations() { 451 virtual int GetTestIterations() {
442 return kIDBTestIterations; 452 return kIDBTestIterations;
443 } 453 }
444 }; 454 };
445 455
456 // Web Page Replay is a proxy server to record and serve pages
457 // with realistic network delays and bandwidth throttling.
458 // runtest.py launches replay.py to support these tests.
459 class PageCyclerWebPageReplayTest : public PageCyclerTest {
460 public:
461 PageCyclerWebPageReplayTest() {
462 // These Chrome command-line arguments need to be kept in sync
463 // with src/tools/python/google/webpagereplay_utils.py.
464 FilePath extension_path = GetPageCyclerWprPath("extension");
465 launch_arguments_.AppendSwitchPath(
466 switches::kLoadExtension, extension_path);
467 // TODO(slamm): Instead of kHostResolverRules, add a new switch,
468 // kTestingFixedDnsPort, and configure Web Page Replay to run
469 // a DNS proxy on that port to test Chrome's DNS code.
470 launch_arguments_.AppendSwitchASCII(
471 switches::kHostResolverRules, "MAP * 127.0.0.1");
472 launch_arguments_.AppendSwitchASCII(
473 switches::kTestingFixedHttpPort, kWebPageReplayHttpPort);
474 launch_arguments_.AppendSwitchASCII(
475 switches::kTestingFixedHttpsPort, kWebPageReplayHttpsPort);
476 launch_arguments_.AppendSwitch(switches::kEnableExperimentalExtensionApis);
477 launch_arguments_.AppendSwitch(switches::kEnableStatsTable);
478 launch_arguments_.AppendSwitch(switches::kEnableBenchmarking);
479 launch_arguments_.AppendSwitch(switches::kIgnoreCertificateErrors);
480 launch_arguments_.AppendSwitch(switches::kNoProxyServer);
481 }
482
483 FilePath GetPageCyclerWprPath(const char* name) {
484 FilePath wpr_path;
485 PathService::Get(base::DIR_SOURCE_ROOT, &wpr_path);
486 wpr_path = wpr_path.AppendASCII("tools");
487 wpr_path = wpr_path.AppendASCII("page_cycler");
488 wpr_path = wpr_path.AppendASCII("webpagereplay");
489 wpr_path = wpr_path.AppendASCII(name);
490 return wpr_path;
491 }
492
493 virtual int GetTestIterations() OVERRIDE {
494 return kWebPageReplayIterations;
495 }
496
497 virtual void GetTestUrl(const char* name, bool use_http,
498 GURL *test_url) OVERRIDE {
499 FilePath start_path = GetPageCyclerWprPath("start.html");
500
501 // Add query parameters for iterations and test name.
502 const std::string query_string =
503 "iterations=" + base::IntToString(GetTestIterations()) +
504 "&test=" + name +
505 "&auto=1";
506 GURL::Replacements replacements;
507 replacements.SetQuery(
508 query_string.c_str(),
509 url_parse::Component(0, query_string.length()));
510
511 *test_url = net::FilePathToFileURL(start_path);
512 *test_url = test_url->ReplaceComponents(replacements);
513 }
514
515 void RunTest(const char* graph, const char* name) {
516 FilePath test_path = GetPageCyclerWprPath("tests");
517 test_path = test_path.AppendASCII(name);
518 test_path = test_path.ReplaceExtension(FILE_PATH_LITERAL(".js"));
519 ASSERT_TRUE(file_util::PathExists(test_path))
520 << "Missing test file " << test_path.value();
521
522 const bool use_http = false; // always use a file
523 PageCyclerTest::RunTestWithSuffix(graph, name, use_http, "");
524 }
525 };
526
446 // This macro simplifies setting up regular and reference build tests. 527 // This macro simplifies setting up regular and reference build tests.
447 #define PAGE_CYCLER_TESTS(test, name, use_http) \ 528 #define PAGE_CYCLER_TESTS(test, name, use_http) \
448 TEST_F(PageCyclerTest, name) { \ 529 TEST_F(PageCyclerTest, name) { \
449 RunTest("times", test, use_http); \ 530 RunTest("times", test, use_http); \
450 } \ 531 } \
451 TEST_F(PageCyclerReferenceTest, name) { \ 532 TEST_F(PageCyclerReferenceTest, name) { \
452 RunTest("times", test, use_http); \ 533 RunTest("times", test, use_http); \
453 } 534 }
454 535
455 // This macro simplifies setting up regular and reference build tests 536 // This macro simplifies setting up regular and reference build tests
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 571 }
491 572
492 // This macro lets us define tests with an extension that listens to the 573 // This macro lets us define tests with an extension that listens to the
493 // webrequest.onBeforeRequest. It measures the effect that a blocking event 574 // webrequest.onBeforeRequest. It measures the effect that a blocking event
494 // for every request has on page cycle time. 575 // for every request has on page cycle time.
495 #define PAGE_CYCLER_EXTENSIONS_WEBREQUEST_FILE_TESTS(test, name) \ 576 #define PAGE_CYCLER_EXTENSIONS_WEBREQUEST_FILE_TESTS(test, name) \
496 TEST_F(PageCyclerExtensionWebRequestTest, name) { \ 577 TEST_F(PageCyclerExtensionWebRequestTest, name) { \
497 RunTest("times", "extension_webrequest", "_extwr", test, false); \ 578 RunTest("times", "extension_webrequest", "_extwr", test, false); \
498 } 579 }
499 580
581 #define PAGE_CYCLER_WEBPAGEREPLAY_TESTS(test, name) \
582 TEST_F(PageCyclerWebPageReplayTest, name) { \
583 RunTest("times", test); \
584 }
585
500 // file-URL tests 586 // file-URL tests
501 PAGE_CYCLER_FILE_TESTS("moz", MozFile); 587 PAGE_CYCLER_FILE_TESTS("moz", MozFile);
502 PAGE_CYCLER_EXTENSIONS_FILE_TESTS("moz", MozFile); 588 PAGE_CYCLER_EXTENSIONS_FILE_TESTS("moz", MozFile);
503 PAGE_CYCLER_EXTENSIONS_WEBREQUEST_FILE_TESTS("moz", MozFile) 589 PAGE_CYCLER_EXTENSIONS_WEBREQUEST_FILE_TESTS("moz", MozFile)
504 PAGE_CYCLER_FILE_TESTS("intl1", Intl1File); 590 PAGE_CYCLER_FILE_TESTS("intl1", Intl1File);
505 PAGE_CYCLER_FILE_TESTS("intl2", Intl2File); 591 PAGE_CYCLER_FILE_TESTS("intl2", Intl2File);
506 PAGE_CYCLER_EXTENSIONS_WEBREQUEST_FILE_TESTS("intl2", Intl2File); 592 PAGE_CYCLER_EXTENSIONS_WEBREQUEST_FILE_TESTS("intl2", Intl2File);
507 PAGE_CYCLER_FILE_TESTS("dom", DomFile); 593 PAGE_CYCLER_FILE_TESTS("dom", DomFile);
508 PAGE_CYCLER_FILE_TESTS("dhtml", DhtmlFile); 594 PAGE_CYCLER_FILE_TESTS("dhtml", DhtmlFile);
509 PAGE_CYCLER_FILE_TESTS("morejs", MorejsFile); 595 PAGE_CYCLER_FILE_TESTS("morejs", MorejsFile);
510 PAGE_CYCLER_EXTENSIONS_FILE_TESTS("morejs", MorejsFile); 596 PAGE_CYCLER_EXTENSIONS_FILE_TESTS("morejs", MorejsFile);
511 // added more tests here: 597 // added more tests here:
512 PAGE_CYCLER_FILE_TESTS("alexa_us", Alexa_usFile); 598 PAGE_CYCLER_FILE_TESTS("alexa_us", Alexa_usFile);
513 PAGE_CYCLER_FILE_TESTS("moz2", Moz2File); 599 PAGE_CYCLER_FILE_TESTS("moz2", Moz2File);
514 PAGE_CYCLER_FILE_TESTS("morejsnp", MorejsnpFile); 600 PAGE_CYCLER_FILE_TESTS("morejsnp", MorejsnpFile);
515 PAGE_CYCLER_FILE_TESTS("bloat", BloatFile); 601 PAGE_CYCLER_FILE_TESTS("bloat", BloatFile);
516 602
517 // http (localhost) tests 603 // http (localhost) tests
518 PAGE_CYCLER_HTTP_TESTS("moz", MozHttp); 604 PAGE_CYCLER_HTTP_TESTS("moz", MozHttp);
519 PAGE_CYCLER_HTTP_TESTS("intl1", Intl1Http); 605 PAGE_CYCLER_HTTP_TESTS("intl1", Intl1Http);
520 PAGE_CYCLER_HTTP_TESTS("intl2", Intl2Http); 606 PAGE_CYCLER_HTTP_TESTS("intl2", Intl2Http);
521 PAGE_CYCLER_HTTP_TESTS("dom", DomHttp); 607 PAGE_CYCLER_HTTP_TESTS("dom", DomHttp);
522 PAGE_CYCLER_HTTP_TESTS("bloat", BloatHttp); 608 PAGE_CYCLER_HTTP_TESTS("bloat", BloatHttp);
523 609
610 // Web Page Replay (simulated network) tests.
611 // Windows is unsupported because of issues with loopback adapter and
612 // dummynet is unavailable on Vista and above.
613 #if !defined(OS_WIN)
614 PAGE_CYCLER_WEBPAGEREPLAY_TESTS("2012Q2", 2012Q2);
615 #endif
616
524 // HTML5 database tests 617 // HTML5 database tests
525 // These tests are _really_ slow on XP/Vista. 618 // These tests are _really_ slow on XP/Vista.
526 #if !defined(OS_WIN) 619 #if !defined(OS_WIN)
527 PAGE_CYCLER_DATABASE_TESTS("select-transactions", 620 PAGE_CYCLER_DATABASE_TESTS("select-transactions",
528 SelectTransactions); 621 SelectTransactions);
529 PAGE_CYCLER_DATABASE_TESTS("select-readtransactions", 622 PAGE_CYCLER_DATABASE_TESTS("select-readtransactions",
530 SelectReadTransactions); 623 SelectReadTransactions);
531 PAGE_CYCLER_DATABASE_TESTS("select-readtransactions-read-results", 624 PAGE_CYCLER_DATABASE_TESTS("select-readtransactions-read-results",
532 SelectReadTransactionsReadResults); 625 SelectReadTransactionsReadResults);
533 PAGE_CYCLER_DATABASE_TESTS("insert-transactions", 626 PAGE_CYCLER_DATABASE_TESTS("insert-transactions",
534 InsertTransactions); 627 InsertTransactions);
535 PAGE_CYCLER_DATABASE_TESTS("update-transactions", 628 PAGE_CYCLER_DATABASE_TESTS("update-transactions",
536 UpdateTransactions); 629 UpdateTransactions);
537 PAGE_CYCLER_DATABASE_TESTS("delete-transactions", 630 PAGE_CYCLER_DATABASE_TESTS("delete-transactions",
538 DeleteTransactions); 631 DeleteTransactions);
539 PAGE_CYCLER_DATABASE_TESTS("pseudo-random-transactions", 632 PAGE_CYCLER_DATABASE_TESTS("pseudo-random-transactions",
540 PseudoRandomTransactions); 633 PseudoRandomTransactions);
541 #endif 634 #endif
542 635
543 // Indexed DB tests. 636 // Indexed DB tests.
544 PAGE_CYCLER_IDB_TESTS("basic_insert", BasicInsert); 637 PAGE_CYCLER_IDB_TESTS("basic_insert", BasicInsert);
545 638
546 } // namespace 639 } // namespace
OLDNEW
« no previous file with comments | « no previous file | tools/page_cycler/common/head.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698