summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-14 03:32:07 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-14 03:32:07 +0000
commit0ff4ddd286f1d42e7f53eab4df21e4b955f7d02a (patch)
tree346f29b146496855f37927387719bd936937748c /chrome
parent19783666440e33def6a060a558a661be245d8144 (diff)
downloadchromium_src-0ff4ddd286f1d42e7f53eab4df21e4b955f7d02a.zip
chromium_src-0ff4ddd286f1d42e7f53eab4df21e4b955f7d02a.tar.gz
chromium_src-0ff4ddd286f1d42e7f53eab4df21e4b955f7d02a.tar.bz2
Adding in file I forgot to include in last commit
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28943 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/test/ui/dromaeo_benchmark_uitest.cc156
1 files changed, 156 insertions, 0 deletions
diff --git a/chrome/test/ui/dromaeo_benchmark_uitest.cc b/chrome/test/ui/dromaeo_benchmark_uitest.cc
new file mode 100644
index 0000000..74d8535
--- /dev/null
+++ b/chrome/test/ui/dromaeo_benchmark_uitest.cc
@@ -0,0 +1,156 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/string_util.h"
+#include "base/values.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/json_value_serializer.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/ui/javascript_test_util.h"
+#include "chrome/test/ui/ui_test.h"
+#include "googleurl/src/gurl.h"
+#include "net/base/net_util.h"
+
+namespace {
+
+static const FilePath::CharType kStartFile[] =
+ FILE_PATH_LITERAL("index.html?dom|jslib&automated");
+
+const wchar_t kRunDromaeo[] = L"run-dromaeo-benchmark";
+
+class DromaeoTest : public UITest {
+ public:
+ typedef std::map<std::string, std::string> ResultsMap;
+
+ DromaeoTest() : reference_(false) {
+ dom_automation_enabled_ = true;
+ show_window_ = true;
+ }
+
+ void RunTest() {
+ FilePath::StringType start_file(kStartFile);
+ FilePath test_path = GetDromaeoDir();
+ test_path = test_path.Append(start_file);
+ GURL test_url(net::FilePathToFileURL(test_path));
+
+ scoped_refptr<TabProxy> tab(GetActiveTab());
+ tab->NavigateToURL(test_url);
+
+ // Wait for the test to finish.
+ ASSERT_TRUE(WaitUntilTestCompletes(tab.get(), test_url));
+
+ PrintResults(tab.get());
+ }
+
+ protected:
+ bool reference_; // True if this is a reference build.
+
+ private:
+ // Return the path to the dromaeo benchmark directory on the local filesystem.
+ FilePath GetDromaeoDir() {
+ FilePath test_dir;
+ PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
+ return test_dir.AppendASCII("dromaeo");
+ }
+
+ bool WaitUntilTestCompletes(TabProxy* tab, const GURL& test_url) {
+ return WaitUntilCookieValue(tab, test_url, "__done", 1000,
+ UITest::test_timeout_ms(), "1");
+ }
+
+ bool GetScore(TabProxy* tab, std::string* score) {
+ std::wstring score_wide;
+ bool succeeded = tab->ExecuteAndExtractString(L"",
+ L"window.domAutomationController.send(automation.GetScore());",
+ &score_wide);
+
+ // Note that we don't use ASSERT_TRUE here (and in some other places) as it
+ // doesn't work inside a function with a return type other than void.
+ EXPECT_TRUE(succeeded);
+ if (!succeeded)
+ return false;
+
+ score->assign(WideToUTF8(score_wide));
+ return true;
+ }
+
+ bool GetResults(TabProxy* tab, ResultsMap* results) {
+ std::wstring json_wide;
+ bool succeeded = tab->ExecuteAndExtractString(L"",
+ L"window.domAutomationController.send("
+ L" JSON.stringify(automation.GetResults()));",
+ &json_wide);
+
+ EXPECT_TRUE(succeeded);
+ if (!succeeded)
+ return false;
+
+ std::string json = WideToUTF8(json_wide);
+ return JsonDictionaryToMap(json, results);
+ }
+
+ void PrintResults(TabProxy* tab) {
+ std::string score;
+ ASSERT_TRUE(GetScore(tab, &score));
+
+ ResultsMap results;
+ ASSERT_TRUE(GetResults(tab, &results));
+
+ std::string trace_name = reference_ ? "score_ref" : "score";
+ std::string unit_name = "runs/s";
+
+ PrintResult("score", "", trace_name, score, unit_name, true);
+
+ ResultsMap::const_iterator it = results.begin();
+ for (; it != results.end(); ++it)
+ PrintResult(it->first, "", trace_name, it->second, unit_name, false);
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(DromaeoTest);
+};
+
+class DromaeoReferenceTest : public DromaeoTest {
+ public:
+ DromaeoReferenceTest() : DromaeoTest() {
+ reference_ = true;
+ }
+
+ // Override the browser directory that is used by UITest::SetUp to cause it
+ // to use the reference build instead.
+ void SetUp() {
+ FilePath dir;
+ PathService::Get(chrome::DIR_TEST_TOOLS, &dir);
+ dir = dir.AppendASCII("reference_build");
+#if defined(OS_WIN)
+ dir = dir.AppendASCII("chrome");
+#elif defined(OS_LINUX)
+ dir = dir.AppendASCII("chrome_linux");
+#elif defined(OS_MACOSX)
+ dir = dir.AppendASCII("chrome_mac");
+#endif
+ browser_directory_ = dir;
+ UITest::SetUp();
+ }
+};
+
+TEST_F(DromaeoTest, Perf) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunDromaeo))
+ return;
+
+ RunTest();
+}
+
+TEST_F(DromaeoReferenceTest, Perf) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunDromaeo))
+ return;
+
+ RunTest();
+}
+
+} // namespace