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

Side by Side Diff: chrome/test/ui/v8_benchmark_uitest.cc

Issue 42628: - Add UI test for the V8 Benchmark Suite.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | « chrome/test/ui/ui_tests.vcproj ('k') | chrome/test/ui/v8_benchmark_uitest.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "base/file_path.h"
7 #include "base/file_util.h"
8 #include "base/path_service.h"
9 #include "base/string_util.h"
10 #include "base/values.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/json_value_serializer.h"
14 #include "chrome/test/automation/tab_proxy.h"
15 #include "chrome/test/ui/javascript_test_util.h"
16 #include "chrome/test/ui/ui_test.h"
17 #include "googleurl/src/gurl.h"
18 #include "net/base/net_util.h"
19
20 namespace {
21
22 static const FilePath::CharType kStartFile[] =
23 FILE_PATH_LITERAL("run.html");
24
25 const wchar_t kRunV8Benchmark[] = L"run-v8-benchmark";
26
27 class V8BenchmarkTest : public UITest {
28 public:
29 typedef std::map<std::string, std::string> ResultsMap;
30
31 V8BenchmarkTest() : reference_(false) {
32 dom_automation_enabled_ = true;
33 show_window_ = true;
34 }
35
36 void RunTest() {
37 FilePath::StringType start_file(kStartFile);
38 FilePath test_path = GetV8BenchmarkDir();
39 test_path = test_path.Append(start_file);
40 GURL test_url(net::FilePathToFileURL(test_path));
41
42 scoped_ptr<TabProxy> tab(GetActiveTab());
43 tab->NavigateToURL(test_url);
44
45 // Wait for the test to finish.
46 ASSERT_TRUE(WaitUntilTestCompletes(tab.get(), test_url));
47
48 PrintResults(tab.get());
49 }
50
51 protected:
52 bool reference_; // True if this is a reference build.
53
54 private:
55 // Return the path to the V8 benchmark directory on the local filesystem.
56 FilePath GetV8BenchmarkDir() {
57 FilePath test_dir;
58 PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
59 return test_dir.AppendASCII("v8_benchmark");
60 }
61
62 bool WaitUntilTestCompletes(TabProxy* tab, const GURL& test_url) {
63 return WaitUntilCookieValue(tab, test_url, "__done", 1000,
64 UITest::test_timeout_ms(), "1");
65 }
66
67 bool GetScore(TabProxy* tab, std::string* score) {
68 std::wstring score_wide;
69 bool succeeded = tab->ExecuteAndExtractString(L"",
70 L"window.domAutomationController.send(automation.GetScore());",
71 &score_wide);
72
73 // Note that we don't use ASSERT_TRUE here (and in some other places) as it
74 // doesn't work inside a function with a return type other than void.
75 EXPECT_TRUE(succeeded);
76 if (!succeeded)
77 return false;
78
79 score->assign(WideToUTF8(score_wide));
80 return true;
81 }
82
83 bool GetResults(TabProxy* tab, ResultsMap* results) {
84 std::wstring json_wide;
85 bool succeeded = tab->ExecuteAndExtractString(L"",
86 L"window.domAutomationController.send("
87 L" JSON.stringify(automation.GetResults()));",
88 &json_wide);
89
90 EXPECT_TRUE(succeeded);
91 if (!succeeded)
92 return false;
93
94 std::string json = WideToUTF8(json_wide);
95 return JsonDictionaryToMap(json, results);
96 }
97
98 void PrintResults(TabProxy* tab) {
99 std::string score;
100 ASSERT_TRUE(GetScore(tab, &score));
101
102 ResultsMap results;
103 ASSERT_TRUE(GetResults(tab, &results));
104
105 std::string trace_name = reference_ ? "score_ref" : "score";
106 std::string unit_name = "score (bigger is better)";
107
108 PrintResult("score", "", trace_name, score, unit_name, true);
109
110 ResultsMap::const_iterator it = results.begin();
111 for (; it != results.end(); ++it)
112 PrintResult(it->first, "", trace_name, it->second, unit_name, false);
113 }
114
115 DISALLOW_COPY_AND_ASSIGN(V8BenchmarkTest);
116 };
117
118 class V8BenchmarkReferenceTest : public V8BenchmarkTest {
119 public:
120 V8BenchmarkReferenceTest() : V8BenchmarkTest() {
121 reference_ = true;
122 }
123
124 // Override the browser directory that is used by UITest::SetUp to cause it
125 // to use the reference build instead.
126 void SetUp() {
127 FilePath dir;
128 PathService::Get(chrome::DIR_TEST_TOOLS, &dir);
129 dir = dir.AppendASCII("reference_build");
130 dir = dir.AppendASCII("chrome");
131 browser_directory_ = dir.ToWStringHack();
132 UITest::SetUp();
133 }
134 };
135
136 } // namespace
137
138 TEST_F(V8BenchmarkTest, Perf) {
139 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunV8Benchmark))
140 return;
141
142 RunTest();
143 }
144
145 TEST_F(V8BenchmarkReferenceTest, Perf) {
146 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunV8Benchmark))
147 return;
148
149 RunTest();
150 }
OLDNEW
« no previous file with comments | « chrome/test/ui/ui_tests.vcproj ('k') | chrome/test/ui/v8_benchmark_uitest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698