OLD | NEW |
(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 <map> |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" |
| 9 #include "base/string_number_conversions.h" |
| 10 #include "base/test/test_timeouts.h" |
| 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/test/automation/tab_proxy.h" |
| 14 #include "chrome/test/ui/javascript_test_util.h" |
| 15 #include "chrome/test/ui/ui_perf_test.h" |
| 16 #include "net/base/net_util.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 class FrameRateTest : public UIPerfTest { |
| 21 public: |
| 22 FrameRateTest() { |
| 23 show_window_ = true; |
| 24 dom_automation_enabled_ = true; |
| 25 } |
| 26 |
| 27 virtual FilePath GetDataPath(const std::string& name) { |
| 28 // Make sure the test data is checked out. |
| 29 FilePath test_path; |
| 30 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 31 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); |
| 32 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); |
| 33 test_path = test_path.AppendASCII(name); |
| 34 return test_path; |
| 35 } |
| 36 |
| 37 void RunTest(const std::string& name, const std::string& suffix) { |
| 38 FilePath test_path = GetDataPath(name); |
| 39 ASSERT_TRUE(file_util::DirectoryExists(test_path)) |
| 40 << "Missing test directory: " << test_path.value(); |
| 41 |
| 42 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); |
| 43 |
| 44 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 45 ASSERT_TRUE(tab.get()); |
| 46 |
| 47 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 48 tab->NavigateToURL(net::FilePathToFileURL(test_path))); |
| 49 |
| 50 // Start the test. |
| 51 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start();"))); |
| 52 |
| 53 // Block until the test completes. |
| 54 ASSERT_TRUE(WaitUntilJavaScriptCondition( |
| 55 tab, L"", L"window.domAutomationController.send(!__running);", |
| 56 TestTimeouts::huge_test_timeout_ms())); |
| 57 |
| 58 // Read out the results. |
| 59 std::wstring json; |
| 60 ASSERT_TRUE(tab->ExecuteAndExtractString( |
| 61 L"", |
| 62 L"window.domAutomationController.send(" |
| 63 L"JSON.stringify(__calc_results()));", |
| 64 &json)); |
| 65 |
| 66 std::map<std::string, std::string> results; |
| 67 ASSERT_TRUE(JsonDictionaryToMap(WideToUTF8(json), &results)); |
| 68 |
| 69 ASSERT_TRUE(results.find("mean") != results.end()); |
| 70 ASSERT_TRUE(results.find("sigma") != results.end()); |
| 71 |
| 72 std::string mean_and_error = results["mean"] + "," + results["sigma"]; |
| 73 PrintResultMeanAndError("fps" + suffix, "", "", mean_and_error, |
| 74 "frames-per-second", false); |
| 75 } |
| 76 }; |
| 77 |
| 78 class FrameRateTest_Reference : public FrameRateTest { |
| 79 public: |
| 80 // Override the browser directory that is used by UITest::SetUp to cause it |
| 81 // to use the reference build instead. |
| 82 void SetUp() { |
| 83 FilePath dir; |
| 84 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); |
| 85 dir = dir.AppendASCII("reference_build"); |
| 86 #if defined(OS_WIN) |
| 87 dir = dir.AppendASCII("chrome"); |
| 88 #elif defined(OS_LINUX) |
| 89 dir = dir.AppendASCII("chrome_linux"); |
| 90 #elif defined(OS_MACOSX) |
| 91 dir = dir.AppendASCII("chrome_mac"); |
| 92 #endif |
| 93 browser_directory_ = dir; |
| 94 FrameRateTest::SetUp(); |
| 95 } |
| 96 }; |
| 97 |
| 98 TEST_F(FrameRateTest, Blank) { |
| 99 RunTest("blank", ""); |
| 100 } |
| 101 |
| 102 // TODO(darin): Need to update the reference build to a version that supports |
| 103 // the webkitRequestAnimationFrame API. |
| 104 #if 0 |
| 105 TEST_F(FrameRateTest_Reference, Blank) { |
| 106 RunTest("blank", "_ref"); |
| 107 } |
| 108 #endif |
| 109 |
| 110 } // namespace |
OLD | NEW |