| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/command_line.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/json_value_serializer.h" | 13 #include "chrome/common/json_value_serializer.h" |
| 14 #include "chrome/test/automation/tab_proxy.h" | 14 #include "chrome/test/automation/tab_proxy.h" |
| 15 #include "chrome/test/ui/javascript_test_util.h" |
| 15 #include "chrome/test/ui/ui_test.h" | 16 #include "chrome/test/ui/ui_test.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 static const FilePath::CharType kStartFile[] = | 22 static const FilePath::CharType kStartFile[] = |
| 22 FILE_PATH_LITERAL("sunspider-driver.html"); | 23 FILE_PATH_LITERAL("sunspider-driver.html"); |
| 23 | 24 |
| 24 const wchar_t kRunSunSpider[] = L"run-sunspider"; | 25 const wchar_t kRunSunSpider[] = L"run-sunspider"; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 bool succeeded = tab->ExecuteAndExtractString(L"", | 85 bool succeeded = tab->ExecuteAndExtractString(L"", |
| 85 L"window.domAutomationController.send(" | 86 L"window.domAutomationController.send(" |
| 86 L" JSON.stringify(automation.GetResults()));", | 87 L" JSON.stringify(automation.GetResults()));", |
| 87 &json_wide); | 88 &json_wide); |
| 88 | 89 |
| 89 EXPECT_TRUE(succeeded); | 90 EXPECT_TRUE(succeeded); |
| 90 if (!succeeded) | 91 if (!succeeded) |
| 91 return false; | 92 return false; |
| 92 | 93 |
| 93 std::string json = WideToUTF8(json_wide); | 94 std::string json = WideToUTF8(json_wide); |
| 94 JSONStringValueSerializer deserializer(json); | 95 return JsonDictionaryToMap(json, results); |
| 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 } | 96 } |
| 131 | 97 |
| 132 void PrintResults(TabProxy* tab) { | 98 void PrintResults(TabProxy* tab) { |
| 133 std::string total; | 99 std::string total; |
| 134 ASSERT_TRUE(GetTotal(tab, &total)); | 100 ASSERT_TRUE(GetTotal(tab, &total)); |
| 135 | 101 |
| 136 ResultsMap results; | 102 ResultsMap results; |
| 137 ASSERT_TRUE(GetResults(tab, &results)); | 103 ASSERT_TRUE(GetResults(tab, &results)); |
| 138 | 104 |
| 139 std::string trace_name = reference_ ? "t_ref" : "t"; | 105 std::string trace_name = reference_ ? "t_ref" : "t"; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 140 |
| 175 RunTest(); | 141 RunTest(); |
| 176 } | 142 } |
| 177 | 143 |
| 178 TEST_F(SunSpiderReferenceTest, Perf) { | 144 TEST_F(SunSpiderReferenceTest, Perf) { |
| 179 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunSunSpider)) | 145 if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunSunSpider)) |
| 180 return; | 146 return; |
| 181 | 147 |
| 182 RunTest(); | 148 RunTest(); |
| 183 } | 149 } |
| OLD | NEW |