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

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

Issue 7578004: Move more files from chrome/test to chrome/test/base, part #7 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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/dom_checker_uitest.cc ('k') | chrome/test/ui/sunspider_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
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/test/test_timeouts.h"
11 #include "base/utf_string_conversions.h"
12 #include "base/values.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/test/automation/tab_proxy.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "chrome/test/ui/javascript_test_util.h"
17 #include "chrome/test/ui/ui_perf_test.h"
18 #include "content/common/json_value_serializer.h"
19 #include "googleurl/src/gurl.h"
20 #include "net/base/net_util.h"
21
22 namespace {
23
24 const char kRunDromaeo[] = "run-dromaeo-benchmark";
25
26 class DromaeoTest : public UIPerfTest {
27 public:
28 typedef std::map<std::string, std::string> ResultsMap;
29
30 DromaeoTest() : reference_(false) {
31 dom_automation_enabled_ = true;
32 show_window_ = true;
33 }
34
35 void RunTest(const std::string& suite) {
36 FilePath test_path = GetDromaeoDir();
37 std::string query_string = suite + "&automated";
38 test_path = test_path.Append(FILE_PATH_LITERAL("index.html"));
39 GURL test_url(ui_test_utils::GetFileUrlWithQuery(test_path, query_string));
40
41 scoped_refptr<TabProxy> tab(GetActiveTab());
42 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url));
43
44 // Wait for the test to finish.
45 ASSERT_TRUE(WaitUntilTestCompletes(tab.get(), test_url));
46
47 PrintResults(tab.get());
48 }
49
50 protected:
51 bool reference_; // True if this is a reference build.
52
53 private:
54 // Return the path to the dromaeo benchmark directory on the local filesystem.
55 FilePath GetDromaeoDir() {
56 FilePath test_dir;
57 PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
58 return test_dir.AppendASCII("dromaeo");
59 }
60
61 bool WaitUntilTestCompletes(TabProxy* tab, const GURL& test_url) {
62 return WaitUntilCookieValue(tab, test_url, "__done",
63 TestTimeouts::huge_test_timeout_ms(), "1");
64 }
65
66 bool GetScore(TabProxy* tab, std::string* score) {
67 std::wstring score_wide;
68 bool succeeded = tab->ExecuteAndExtractString(L"",
69 L"window.domAutomationController.send(automation.GetScore());",
70 &score_wide);
71
72 // Note that we don't use ASSERT_TRUE here (and in some other places) as it
73 // doesn't work inside a function with a return type other than void.
74 EXPECT_TRUE(succeeded);
75 if (!succeeded)
76 return false;
77
78 score->assign(WideToUTF8(score_wide));
79 return true;
80 }
81
82 bool GetResults(TabProxy* tab, ResultsMap* results) {
83 std::wstring json_wide;
84 bool succeeded = tab->ExecuteAndExtractString(L"",
85 L"window.domAutomationController.send("
86 L" JSON.stringify(automation.GetResults()));",
87 &json_wide);
88
89 EXPECT_TRUE(succeeded);
90 if (!succeeded)
91 return false;
92
93 std::string json = WideToUTF8(json_wide);
94 return JsonDictionaryToMap(json, results);
95 }
96
97 void PrintResults(TabProxy* tab) {
98 std::string score;
99 ASSERT_TRUE(GetScore(tab, &score));
100
101 ResultsMap results;
102 ASSERT_TRUE(GetResults(tab, &results));
103
104 std::string trace_name = reference_ ? "score_ref" : "score";
105 std::string unit_name = "runs/s";
106
107 ResultsMap::const_iterator it = results.begin();
108 // First result is overall score and thus "important".
109 bool important = true;
110 for (; it != results.end(); ++it) {
111 std::string test_name = it->first;
112 for (size_t i = 0; i < test_name.length(); i++)
113 if (!isalnum(test_name[i]))
114 test_name[i] = '_';
115 PrintResult(test_name, "", trace_name, it->second, unit_name, important);
116 important = false; // All others are not overall scores.
117 }
118 }
119
120 DISALLOW_COPY_AND_ASSIGN(DromaeoTest);
121 };
122
123 class DromaeoReferenceTest : public DromaeoTest {
124 public:
125 DromaeoReferenceTest() : DromaeoTest() {
126 reference_ = true;
127 }
128
129 void SetUp() {
130 UseReferenceBuild();
131 DromaeoTest::SetUp();
132 }
133 };
134
135 TEST_F(DromaeoTest, DOMCorePerf) {
136 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunDromaeo))
137 return;
138
139 RunTest("dom");
140 }
141
142 TEST_F(DromaeoTest, JSLibPerf) {
143 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunDromaeo))
144 return;
145
146 RunTest("jslib");
147 }
148
149 TEST_F(DromaeoReferenceTest, DOMCorePerf) {
150 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunDromaeo))
151 return;
152
153 RunTest("dom");
154 }
155
156 TEST_F(DromaeoReferenceTest, JSLibPerf) {
157 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunDromaeo))
158 return;
159
160 RunTest("jslib");
161 }
162
163
164 } // namespace
OLDNEW
« no previous file with comments | « chrome/test/ui/dom_checker_uitest.cc ('k') | chrome/test/ui/sunspider_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698