| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <map> | 5 #include <map> |
| 6 | 6 |
| 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_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.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/javascript_test_util.h" |
| 16 #include "chrome/test/ui/ui_perf_test.h" | 16 #include "chrome/test/ui/ui_perf_test.h" |
| 17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 18 #include "ui/gfx/gl/gl_switches.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class FrameRateTest : public UIPerfTest { | 22 enum FrameRateTestFlags { |
| 23 kMakeBodyComposited = 1 << 0, |
| 24 kDisableVsync = 1 << 1, |
| 25 kDisableGpu = 1 << 2, |
| 26 kUseReferenceBuild = 1 << 3, |
| 27 }; |
| 28 |
| 29 std::string GetSuffixForTestFlags(int flags) { |
| 30 std::string suffix; |
| 31 if (flags & kMakeBodyComposited) |
| 32 suffix += "_comp"; |
| 33 if (flags & kDisableVsync) |
| 34 suffix += "_novsync"; |
| 35 if (flags & kDisableGpu) |
| 36 suffix += "_nogpu"; |
| 37 if (flags & kUseReferenceBuild) |
| 38 suffix += "_ref"; |
| 39 return suffix; |
| 40 } |
| 41 |
| 42 class FrameRateTest |
| 43 : public UIPerfTest |
| 44 , public ::testing::WithParamInterface<int> { |
| 22 public: | 45 public: |
| 23 FrameRateTest() { | 46 FrameRateTest() { |
| 24 show_window_ = true; | 47 show_window_ = true; |
| 25 dom_automation_enabled_ = true; | 48 dom_automation_enabled_ = true; |
| 26 // Since this is a performance test, try to use the host machine's GPU | 49 // Since this is a performance test, try to use the host machine's GPU |
| 27 // instead of falling back to software-rendering. | 50 // instead of falling back to software-rendering. |
| 28 force_use_osmesa_ = false; | 51 force_use_osmesa_ = false; |
| 29 disable_accelerated_compositing_ = false; | 52 disable_accelerated_compositing_ = false; |
| 30 } | 53 } |
| 31 | 54 |
| 32 virtual FilePath GetDataPath(const std::string& name) { | 55 virtual FilePath GetDataPath(const std::string& name) { |
| 33 // Make sure the test data is checked out. | 56 // Make sure the test data is checked out. |
| 34 FilePath test_path; | 57 FilePath test_path; |
| 35 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 58 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 36 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); | 59 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); |
| 37 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); | 60 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); |
| 38 test_path = test_path.Append(FILE_PATH_LITERAL("content")); | 61 test_path = test_path.Append(FILE_PATH_LITERAL("content")); |
| 39 test_path = test_path.AppendASCII(name); | 62 test_path = test_path.AppendASCII(name); |
| 40 return test_path; | 63 return test_path; |
| 41 } | 64 } |
| 42 | 65 |
| 43 virtual void SetUp() { | 66 virtual void SetUp() { |
| 44 // UI tests boot up render views starting from about:blank. This causes the | 67 if (GetParam() & kUseReferenceBuild) { |
| 45 // renderer to start up thinking it cannot use the GPU. To work around that, | 68 UseReferenceBuild(); |
| 46 // and allow the frame rate test to use the GPU, we must pass | 69 } |
| 47 // kAllowWebUICompositing. | 70 |
| 71 // UI tests boot up render views starting from about:blank. This causes |
| 72 // the renderer to start up thinking it cannot use the GPU. To work |
| 73 // around that, and allow the frame rate test to use the GPU, we must |
| 74 // pass kAllowWebUICompositing. |
| 48 launch_arguments_.AppendSwitch(switches::kAllowWebUICompositing); | 75 launch_arguments_.AppendSwitch(switches::kAllowWebUICompositing); |
| 49 | 76 |
| 77 if (GetParam() & kDisableGpu) { |
| 78 launch_arguments_.AppendSwitch(switches::kDisableAcceleratedCompositing); |
| 79 launch_arguments_.AppendSwitch(switches::kDisableExperimentalWebGL); |
| 80 } |
| 81 |
| 82 if (GetParam() & kDisableVsync) { |
| 83 launch_arguments_.AppendSwitch(switches::kDisableGpuVsync); |
| 84 } |
| 85 |
| 50 UIPerfTest::SetUp(); | 86 UIPerfTest::SetUp(); |
| 51 } | 87 } |
| 52 | 88 |
| 53 void RunTest(const std::string& name, | 89 void RunTest(const std::string& name) { |
| 54 const std::string& suffix, | |
| 55 bool make_body_composited) { | |
| 56 FilePath test_path = GetDataPath(name); | 90 FilePath test_path = GetDataPath(name); |
| 57 ASSERT_TRUE(file_util::DirectoryExists(test_path)) | 91 ASSERT_TRUE(file_util::DirectoryExists(test_path)) |
| 58 << "Missing test directory: " << test_path.value(); | 92 << "Missing test directory: " << test_path.value(); |
| 59 | 93 |
| 60 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); | 94 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); |
| 61 | 95 |
| 62 scoped_refptr<TabProxy> tab(GetActiveTab()); | 96 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 63 ASSERT_TRUE(tab.get()); | 97 ASSERT_TRUE(tab.get()); |
| 64 | 98 |
| 65 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 99 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 66 tab->NavigateToURL(net::FilePathToFileURL(test_path))); | 100 tab->NavigateToURL(net::FilePathToFileURL(test_path))); |
| 67 | 101 |
| 68 if (make_body_composited) { | 102 if (GetParam() & kMakeBodyComposited) { |
| 69 ASSERT_TRUE(tab->NavigateToURLAsync( | 103 ASSERT_TRUE(tab->NavigateToURLAsync( |
| 70 GURL("javascript:__make_body_composited();"))); | 104 GURL("javascript:__make_body_composited();"))); |
| 71 } | 105 } |
| 72 | 106 |
| 107 // Block until initialization completes. |
| 108 ASSERT_TRUE(WaitUntilJavaScriptCondition( |
| 109 tab, L"", L"window.domAutomationController.send(__initialized);", |
| 110 TestTimeouts::large_test_timeout_ms())); |
| 111 |
| 73 // Start the tests. | 112 // Start the tests. |
| 74 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start_all();"))); | 113 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start_all();"))); |
| 75 | 114 |
| 76 // Block until the tests completes. | 115 // Block until the tests completes. |
| 77 ASSERT_TRUE(WaitUntilJavaScriptCondition( | 116 ASSERT_TRUE(WaitUntilJavaScriptCondition( |
| 78 tab, L"", L"window.domAutomationController.send(!__running_all);", | 117 tab, L"", L"window.domAutomationController.send(!__running_all);", |
| 79 TestTimeouts::large_test_timeout_ms())); | 118 TestTimeouts::large_test_timeout_ms())); |
| 80 | 119 |
| 81 // Read out the results. | 120 // Read out the results. |
| 82 std::wstring json; | 121 std::wstring json; |
| 83 ASSERT_TRUE(tab->ExecuteAndExtractString( | 122 ASSERT_TRUE(tab->ExecuteAndExtractString( |
| 84 L"", | 123 L"", |
| 85 L"window.domAutomationController.send(" | 124 L"window.domAutomationController.send(" |
| 86 L"JSON.stringify(__calc_results_total()));", | 125 L"JSON.stringify(__calc_results_total()));", |
| 87 &json)); | 126 &json)); |
| 88 | 127 |
| 89 std::map<std::string, std::string> results; | 128 std::map<std::string, std::string> results; |
| 90 ASSERT_TRUE(JsonDictionaryToMap(WideToUTF8(json), &results)); | 129 ASSERT_TRUE(JsonDictionaryToMap(WideToUTF8(json), &results)); |
| 91 | 130 |
| 92 ASSERT_TRUE(results.find("mean") != results.end()); | 131 ASSERT_TRUE(results.find("mean") != results.end()); |
| 93 ASSERT_TRUE(results.find("sigma") != results.end()); | 132 ASSERT_TRUE(results.find("sigma") != results.end()); |
| 94 ASSERT_TRUE(results.find("gestures") != results.end()); | 133 ASSERT_TRUE(results.find("gestures") != results.end()); |
| 95 ASSERT_TRUE(results.find("means") != results.end()); | 134 ASSERT_TRUE(results.find("means") != results.end()); |
| 96 ASSERT_TRUE(results.find("sigmas") != results.end()); | 135 ASSERT_TRUE(results.find("sigmas") != results.end()); |
| 97 | 136 |
| 98 std::string trace_name = "fps" + suffix; | 137 std::string trace_name = "fps"; |
| 138 trace_name += GetSuffixForTestFlags(GetParam()); |
| 99 printf("GESTURES %s: %s= [%s] [%s] [%s]\n", name.c_str(), | 139 printf("GESTURES %s: %s= [%s] [%s] [%s]\n", name.c_str(), |
| 100 trace_name.c_str(), | 140 trace_name.c_str(), |
| 101 results["gestures"].c_str(), | 141 results["gestures"].c_str(), |
| 102 results["means"].c_str(), | 142 results["means"].c_str(), |
| 103 results["sigmas"].c_str()); | 143 results["sigmas"].c_str()); |
| 104 | 144 |
| 105 std::string mean_and_error = results["mean"] + "," + results["sigma"]; | 145 std::string mean_and_error = results["mean"] + "," + results["sigma"]; |
| 106 PrintResultMeanAndError(name, "", trace_name, mean_and_error, | 146 PrintResultMeanAndError(name, "", trace_name, mean_and_error, |
| 107 "frames-per-second", true); | 147 "frames-per-second", true); |
| 108 } | 148 } |
| 109 }; | 149 }; |
| 110 | 150 |
| 111 class FrameRateTest_Reference : public FrameRateTest { | 151 int kTestVariant_Plain(0); |
| 112 public: | 152 int kTestVariant_Comp(kMakeBodyComposited); |
| 113 void SetUp() { | 153 int kTestVariant_Reference(kUseReferenceBuild); |
| 114 UseReferenceBuild(); | 154 int kTestVariant_Comp_Reference(kMakeBodyComposited | kUseReferenceBuild); |
| 115 FrameRateTest::SetUp(); | 155 int kTestVariant_NoVsync(kDisableVsync); |
| 116 } | 156 int kTestVariant_NoGpu(kDisableGpu); |
| 117 }; | 157 int kTestVariant_NoVsync_Reference(kDisableVsync | kUseReferenceBuild); |
| 118 | 158 |
| 119 #define FRAME_RATE_TEST(content) \ | 159 // Must use a different class name to avoid test instantiation conflicts |
| 120 TEST_F(FrameRateTest, content) { \ | 160 // with FrameRateTest (used above). An alias is good enough. |
| 121 RunTest(#content, "", false); \ | 161 typedef FrameRateTest FrameRateCompositingTest; |
| 122 } \ | |
| 123 TEST_F(FrameRateTest_Reference, content) { \ | |
| 124 RunTest(#content, "_ref", false); \ | |
| 125 } | |
| 126 | |
| 127 | 162 |
| 128 // Tests that trigger compositing with a -webkit-translateZ(0) | 163 // Tests that trigger compositing with a -webkit-translateZ(0) |
| 129 #define FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(content) \ | 164 #define FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(content) \ |
| 130 TEST_F(FrameRateTest, content) { \ | 165 TEST_P(FrameRateCompositingTest, content) { \ |
| 131 RunTest(#content, "", false); \ | 166 RunTest(#content); \ |
| 132 } \ | |
| 133 TEST_F(FrameRateTest, content ## _comp) { \ | |
| 134 RunTest(#content, "_comp", true); \ | |
| 135 } \ | |
| 136 TEST_F(FrameRateTest_Reference, content) { \ | |
| 137 RunTest(#content, "_ref", false); \ | |
| 138 } \ | |
| 139 TEST_F(FrameRateTest_Reference, content ## _comp) { \ | |
| 140 RunTest(#content, "_comp_ref", true); \ | |
| 141 } | 167 } |
| 142 | 168 |
| 169 INSTANTIATE_TEST_CASE_P(, FrameRateCompositingTest, ::testing::Values( |
| 170 kTestVariant_Plain, |
| 171 kTestVariant_Comp, |
| 172 kTestVariant_Reference, |
| 173 kTestVariant_Comp_Reference)); |
| 174 |
| 143 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); | 175 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); |
| 144 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); | 176 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); |
| 145 | 177 |
| 178 // Must use a different class name to avoid test instantiation conflicts |
| 179 // with FrameRateTest (used above). An alias is good enough. |
| 180 typedef FrameRateTest FrameRateCanvasTest; |
| 181 |
| 182 // Tests for animated 2D canvas content |
| 183 #define FRAME_RATE_TEST_CANVAS(content) \ |
| 184 TEST_P(FrameRateCanvasTest, content) { \ |
| 185 RunTest(#content); \ |
| 186 } \ |
| 187 |
| 188 INSTANTIATE_TEST_CASE_P(, FrameRateCanvasTest, ::testing::Values( |
| 189 kTestVariant_Plain, |
| 190 kTestVariant_NoGpu, |
| 191 kTestVariant_Reference)); |
| 192 |
| 193 typedef FrameRateTest FrameRateNoVsyncCanvasTest; |
| 194 |
| 195 // Tests for animated 2D canvas content with and without disabling vsync |
| 196 #define FRAME_RATE_TEST_CANVAS_WITH_AND_WITHOUT_NOVSYNC(content) \ |
| 197 TEST_P(FrameRateNoVsyncCanvasTest, content) { \ |
| 198 RunTest(#content); \ |
| 199 } \ |
| 200 |
| 201 INSTANTIATE_TEST_CASE_P(, FrameRateNoVsyncCanvasTest, ::testing::Values( |
| 202 kTestVariant_Plain, |
| 203 kTestVariant_NoVsync, |
| 204 kTestVariant_NoGpu, |
| 205 kTestVariant_Reference, |
| 206 kTestVariant_NoVsync_Reference)); |
| 207 |
| 146 } // namespace | 208 } // namespace |
| OLD | NEW |