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

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

Issue 42581: - Add UI test for SunSpider.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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/data/sunspider/sunspider-results.html ('k') | chrome/test/ui/ui_tests.scons » ('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/ui_test.h"
16 #include "googleurl/src/gurl.h"
17 #include "net/base/net_util.h"
18
19 namespace {
20
21 static const FilePath::CharType kStartFile[] =
22 FILE_PATH_LITERAL("sunspider-driver.html");
23
24 const wchar_t kRunSunSpiderTest[] = L"run-sunspider-test";
25
26 class SunSpiderTest : public UITest {
27 public:
28 typedef std::map<std::string, std::string> ResultsMap;
29
30 SunSpiderTest() : reference_(false) {
31 dom_automation_enabled_ = true;
32 show_window_ = true;
33 }
34
35 void RunTest() {
36 FilePath::StringType start_file(kStartFile);
37 FilePath test_path = GetSunSpiderDir();
38 test_path = test_path.Append(start_file);
39 GURL test_url(net::FilePathToFileURL(test_path));
40
41 scoped_ptr<TabProxy> tab(GetActiveTab());
42 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 SunSpider directory on the local filesystem.
55 FilePath GetSunSpiderDir() {
56 FilePath test_dir;
57 PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
58 return test_dir.AppendASCII("sunspider");
59 }
60
61 bool WaitUntilTestCompletes(TabProxy* tab, const GURL& test_url) {
62 return WaitUntilCookieValue(tab, test_url, "__done", 1000,
63 UITest::test_timeout_ms(), "1");
64 }
65
66 bool GetTotal(TabProxy* tab, std::string* total) {
67 std::wstring total_wide;
68 bool succeeded = tab->ExecuteAndExtractString(L"",
69 L"window.domAutomationController.send(automation.GetTotal());",
70 &total_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 total->assign(WideToUTF8(total_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 JSONStringValueSerializer deserializer(json);
95 scoped_ptr<Value> root(deserializer.Deserialize(NULL));
96
97 EXPECT_TRUE(root.get());
98 if (!root.get())
99 return false;
100
101 EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
102 if (!root->IsType(Value::TYPE_DICTIONARY))
103 return false;
104
105 DictionaryValue* dict = static_cast<DictionaryValue*>(root.get());
106
107 DictionaryValue::key_iterator it = dict->begin_keys();
108 for (; it != dict->end_keys(); ++it) {
109 Value* value = NULL;
110 succeeded = dict->Get(*it, &value);
111
112 EXPECT_TRUE(succeeded);
113 if (!succeeded)
114 continue;
115
116 EXPECT_TRUE(value->IsType(Value::TYPE_STRING));
117 if (value->IsType(Value::TYPE_STRING)) {
118 std::string key = WideToUTF8(*it);
119
120 std::string result;
121 succeeded = value->GetAsString(&result);
122 EXPECT_TRUE(succeeded);
123
124 if (succeeded)
125 results->insert(std::make_pair(key, result));
126 }
127 }
128
129 return true;
130 }
131
132 void PrintResults(TabProxy* tab) {
133 std::string total;
134 ASSERT_TRUE(GetTotal(tab, &total));
135
136 ResultsMap results;
137 ASSERT_TRUE(GetResults(tab, &results));
138
139 std::string trace_name = reference_ ? "t_ref" : "t";
140
141 PrintResultMeanAndError("total", "", trace_name, total, "ms", true);
142
143 ResultsMap::iterator it = results.begin();
144 for (; it != results.end(); ++it)
145 PrintResultList(it->first, "", trace_name, it->second, "ms", false);
146 }
147
148 DISALLOW_COPY_AND_ASSIGN(SunSpiderTest);
149 };
150
151 class SunSpiderReferenceTest : public SunSpiderTest {
152 public:
153 SunSpiderReferenceTest() : SunSpiderTest() {
154 reference_ = true;
155 }
156
157 // Override the browser directory that is used by UITest::SetUp to cause it
158 // to use the reference build instead.
159 void SetUp() {
160 FilePath dir;
161 PathService::Get(chrome::DIR_TEST_TOOLS, &dir);
162 dir = dir.AppendASCII("reference_build");
163 dir = dir.AppendASCII("chrome");
164 browser_directory_ = dir.ToWStringHack();
165 UITest::SetUp();
166 }
167 };
168
169 } // namespace
170
171 TEST_F(SunSpiderTest, Perf) {
172 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunSunSpiderTest))
173 return;
174
175 RunTest();
176 }
177
178 TEST_F(SunSpiderReferenceTest, Perf) {
179 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunSunSpiderTest))
180 return;
181
182 RunTest();
183 }
OLDNEW
« no previous file with comments | « chrome/test/data/sunspider/sunspider-results.html ('k') | chrome/test/ui/ui_tests.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698