OLD | NEW |
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/command_line.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | |
7 #include "base/path_service.h" | 6 #include "base/path_service.h" |
8 #include "base/string_util.h" | |
9 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
10 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | |
12 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
| 10 #include "chrome/common/automation_constants.h" |
13 #include "chrome/test/automation/tab_proxy.h" | 11 #include "chrome/test/automation/tab_proxy.h" |
14 #include "chrome/test/perf/perf_test.h" | 12 #include "chrome/test/perf/perf_test.h" |
15 #include "chrome/test/ui/javascript_test_util.h" | 13 #include "chrome/test/ui/javascript_test_util.h" |
16 #include "chrome/test/ui/ui_perf_test.h" | 14 #include "chrome/test/ui/ui_perf_test.h" |
17 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
18 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
19 | 17 |
20 namespace { | 18 namespace { |
21 | 19 |
22 static const FilePath::CharType kStartFile[] = | 20 static const FilePath::CharType kStartFile[] = |
23 FILE_PATH_LITERAL("sunspider-driver.html"); | 21 FILE_PATH_LITERAL("perf_test.html"); |
24 | 22 |
25 const char kRunSunSpider[] = "run-sunspider"; | 23 class IndexedDBTest : public UIPerfTest { |
26 | |
27 class SunSpiderTest : public UIPerfTest { | |
28 public: | 24 public: |
29 typedef std::map<std::string, std::string> ResultsMap; | 25 typedef std::map<std::string, std::string> ResultsMap; |
30 | 26 |
31 SunSpiderTest() : reference_(false) { | 27 IndexedDBTest() : reference_(false) { |
32 dom_automation_enabled_ = true; | 28 dom_automation_enabled_ = true; |
33 show_window_ = true; | 29 show_window_ = true; |
34 } | 30 } |
35 | 31 |
36 void RunTest() { | 32 void RunTest() { |
37 FilePath::StringType start_file(kStartFile); | 33 FilePath::StringType start_file(kStartFile); |
38 FilePath test_path = GetSunSpiderDir(); | 34 FilePath test_path = GetIndexedDBTestDir(); |
39 test_path = test_path.Append(start_file); | 35 test_path = test_path.Append(start_file); |
40 GURL test_url(net::FilePathToFileURL(test_path)); | 36 GURL test_url(net::FilePathToFileURL(test_path)); |
41 | 37 |
42 scoped_refptr<TabProxy> tab(GetActiveTab()); | 38 scoped_refptr<TabProxy> tab(GetActiveTab()); |
43 ASSERT_TRUE(tab.get()); | 39 ASSERT_TRUE(tab.get()); |
44 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url)); | 40 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url)); |
45 | 41 |
46 // Wait for the test to finish. | 42 // Wait for the test to finish. |
47 ASSERT_TRUE(WaitUntilTestCompletes(tab.get(), test_url)); | 43 ASSERT_TRUE(WaitUntilTestCompletes(tab.get(), test_url)); |
48 | 44 |
49 PrintResults(tab.get()); | 45 PrintResults(tab.get()); |
50 } | 46 } |
51 | 47 |
52 protected: | 48 protected: |
53 bool reference_; // True if this is a reference build. | 49 bool reference_; // True if this is a reference build. |
54 | 50 |
55 private: | 51 private: |
56 // Return the path to the SunSpider directory on the local filesystem. | 52 // Return the path to the IndexedDB test directory on the local filesystem. |
57 FilePath GetSunSpiderDir() { | 53 FilePath GetIndexedDBTestDir() { |
58 FilePath test_dir; | 54 FilePath test_dir; |
59 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); | 55 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); |
60 return test_dir.AppendASCII("sunspider"); | 56 return test_dir.AppendASCII("indexeddb"); |
61 } | 57 } |
62 | 58 |
63 bool WaitUntilTestCompletes(TabProxy* tab, const GURL& test_url) { | 59 bool WaitUntilTestCompletes(TabProxy* tab, const GURL& test_url) { |
64 return WaitUntilCookieValue(tab, test_url, "__done", | 60 return WaitUntilCookieValue(tab, test_url, "__done", |
65 TestTimeouts::large_test_timeout_ms(), "1"); | 61 TestTimeouts::large_test_timeout_ms(), "1"); |
66 } | 62 } |
67 | 63 |
68 bool GetTotal(TabProxy* tab, std::string* total) { | |
69 std::wstring total_wide; | |
70 bool succeeded = tab->ExecuteAndExtractString(L"", | |
71 L"window.domAutomationController.send(automation.GetTotal());", | |
72 &total_wide); | |
73 | |
74 // Note that we don't use ASSERT_TRUE here (and in some other places) as it | |
75 // doesn't work inside a function with a return type other than void. | |
76 EXPECT_TRUE(succeeded); | |
77 if (!succeeded) | |
78 return false; | |
79 | |
80 total->assign(WideToUTF8(total_wide)); | |
81 return true; | |
82 } | |
83 | |
84 bool GetResults(TabProxy* tab, ResultsMap* results) { | 64 bool GetResults(TabProxy* tab, ResultsMap* results) { |
85 std::wstring json_wide; | 65 std::wstring json_wide; |
86 bool succeeded = tab->ExecuteAndExtractString(L"", | 66 bool succeeded = tab->ExecuteAndExtractString(L"", |
87 L"window.domAutomationController.send(" | 67 L"window.domAutomationController.send(" |
88 L" JSON.stringify(automation.GetResults()));", | 68 L" JSON.stringify(automation.getResults()));", |
89 &json_wide); | 69 &json_wide); |
90 | 70 |
91 EXPECT_TRUE(succeeded); | 71 EXPECT_TRUE(succeeded); |
92 if (!succeeded) | 72 if (!succeeded) |
93 return false; | 73 return false; |
94 | 74 |
95 std::string json = WideToUTF8(json_wide); | 75 std::string json = WideToUTF8(json_wide); |
96 return JsonDictionaryToMap(json, results); | 76 return JsonDictionaryToMap(json, results); |
97 } | 77 } |
98 | 78 |
99 void PrintResults(TabProxy* tab) { | 79 void PrintResults(TabProxy* tab) { |
100 std::string total; | |
101 ASSERT_TRUE(GetTotal(tab, &total)); | |
102 | |
103 ResultsMap results; | 80 ResultsMap results; |
104 ASSERT_TRUE(GetResults(tab, &results)); | 81 ASSERT_TRUE(GetResults(tab, &results)); |
105 | 82 |
106 std::string trace_name = reference_ ? "t_ref" : "t"; | 83 std::string trace_name = reference_ ? "t_ref" : "t"; |
107 | 84 |
108 perf_test::PrintResultMeanAndError("total", "", trace_name, total, "ms", | |
109 true); | |
110 | |
111 ResultsMap::const_iterator it = results.begin(); | 85 ResultsMap::const_iterator it = results.begin(); |
112 for (; it != results.end(); ++it) | 86 for (; it != results.end(); ++it) |
113 perf_test::PrintResultList(it->first, "", trace_name, it->second, "ms", | 87 perf_test::PrintResultList(it->first, "", trace_name, it->second, "ms", |
114 false); | 88 false); |
115 } | 89 } |
116 | 90 |
117 DISALLOW_COPY_AND_ASSIGN(SunSpiderTest); | 91 DISALLOW_COPY_AND_ASSIGN(IndexedDBTest); |
118 }; | 92 }; |
119 | 93 |
120 class SunSpiderReferenceTest : public SunSpiderTest { | 94 class IndexedDBReferenceTest : public IndexedDBTest { |
121 public: | 95 public: |
122 SunSpiderReferenceTest() : SunSpiderTest() { | 96 IndexedDBReferenceTest() : IndexedDBTest() { |
123 reference_ = true; | 97 reference_ = true; |
124 } | 98 } |
125 | 99 |
126 void SetUp() { | 100 void SetUp() { |
127 UseReferenceBuild(); | 101 UseReferenceBuild(); |
128 SunSpiderTest::SetUp(); | 102 IndexedDBTest::SetUp(); |
129 } | 103 } |
130 }; | 104 }; |
131 | 105 |
132 TEST_F(SunSpiderTest, Perf) { | 106 TEST_F(IndexedDBTest, Perf) { |
133 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunSunSpider)) | |
134 return; | |
135 | 107 |
136 RunTest(); | 108 RunTest(); |
137 } | 109 } |
138 | 110 |
139 TEST_F(SunSpiderReferenceTest, Perf) { | 111 TEST_F(IndexedDBReferenceTest, Perf) { |
140 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunSunSpider)) | |
141 return; | |
142 | 112 |
143 RunTest(); | 113 RunTest(); |
144 } | 114 } |
145 | 115 |
146 } // namespace | 116 } // namespace |
OLD | NEW |