| 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 "base/command_line.h" |
| 5 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 6 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 8 #include "base/test/trace_event_analyzer.h" | 9 #include "base/test/trace_event_analyzer.h" |
| 9 #include "base/version.h" | 10 #include "base/version.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/tracing.h" | 14 #include "chrome/test/base/tracing.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/browser/gpu/gpu_blacklist.h" | 16 #include "content/browser/gpu/gpu_blacklist.h" |
| 16 #include "content/browser/gpu/gpu_data_manager.h" | 17 #include "content/browser/gpu/gpu_data_manager.h" |
| 17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 #include "ui/gfx/gl/gl_switches.h" |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 23 typedef uint32 GpuResultFlags; |
| 24 #define EXPECT_NO_GPU_PROCESS GpuResultFlags(0) |
| 25 // Expect GPU process to be created. |
| 26 #define EXPECT_GPU_PROCESS GpuResultFlags(1<<0) |
| 27 // Expect num_contexts_ to be created (onscreen or offscreen). |
| 28 #define EXPECT_GPU_CONTEXTS GpuResultFlags(1<<1) |
| 29 // Expect a SwapBuffers to occur (see gles2_cmd_decoder.cc). |
| 30 #define EXPECT_GPU_SWAP_BUFFERS GpuResultFlags(1<<2) |
| 31 |
| 21 class GpuFeatureTest : public InProcessBrowserTest { | 32 class GpuFeatureTest : public InProcessBrowserTest { |
| 22 public: | 33 public: |
| 23 GpuFeatureTest() {} | 34 GpuFeatureTest() |
| 35 : num_contexts_(0), |
| 36 num_offscreen_contexts_(0) {} |
| 24 | 37 |
| 25 virtual void SetUpCommandLine(CommandLine* command_line) { | 38 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 26 // This enables DOM automation for tab contents. | 39 // This enables DOM automation for tab contents. |
| 27 EnableDOMAutomation(); | 40 EnableDOMAutomation(); |
| 41 #if !defined(OS_MACOSX) |
| 42 CHECK(!command_line->HasSwitch(switches::kUseGL)) << |
| 43 "kUseGL must not be set by test framework code!"; |
| 44 command_line->AppendSwitchASCII(switches::kUseGL, "osmesa"); |
| 45 #endif |
| 28 } | 46 } |
| 29 | 47 |
| 30 void SetupBlacklist(const std::string& json_blacklist) { | 48 void SetupBlacklist(const std::string& json_blacklist) { |
| 31 scoped_ptr<Version> os_version(Version::GetVersionFromString("1.0")); | 49 scoped_ptr<Version> os_version(Version::GetVersionFromString("1.0")); |
| 32 GpuBlacklist* blacklist = new GpuBlacklist("1.0"); | 50 GpuBlacklist* blacklist = new GpuBlacklist("1.0"); |
| 33 | 51 |
| 34 ASSERT_TRUE(blacklist->LoadGpuBlacklist( | 52 ASSERT_TRUE(blacklist->LoadGpuBlacklist( |
| 35 json_blacklist, GpuBlacklist::kAllOs)); | 53 json_blacklist, GpuBlacklist::kAllOs)); |
| 36 GpuDataManager::GetInstance()->SetBuiltInGpuBlacklist(blacklist); | 54 GpuDataManager::GetInstance()->SetBuiltInGpuBlacklist(blacklist); |
| 37 } | 55 } |
| 38 | 56 |
| 39 void RunTest(const FilePath& url, bool expect_gpu_process) { | 57 void RunTest(const FilePath& url, GpuResultFlags expectations) { |
| 40 using namespace trace_analyzer; | 58 using namespace trace_analyzer; |
| 41 | 59 |
| 42 FilePath test_path; | 60 FilePath test_path; |
| 43 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 61 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 44 test_path = test_path.Append(FILE_PATH_LITERAL("gpu")); | 62 test_path = test_path.Append(FILE_PATH_LITERAL("gpu")); |
| 45 test_path = test_path.Append(url); | 63 test_path = test_path.Append(url); |
| 46 | 64 |
| 47 ASSERT_TRUE(file_util::PathExists(test_path)) | 65 ASSERT_TRUE(file_util::PathExists(test_path)) |
| 48 << "Missing test file: " << test_path.value(); | 66 << "Missing test file: " << test_path.value(); |
| 49 | 67 |
| 50 ASSERT_TRUE(tracing::BeginTracing("test_gpu")); | 68 ASSERT_TRUE(tracing::BeginTracing("test_gpu")); |
| 51 | 69 |
| 52 ui_test_utils::DOMMessageQueue message_queue; | 70 ui_test_utils::DOMMessageQueue message_queue; |
| 53 // Have to use a new tab for the blacklist to work. | 71 // Have to use a new tab for the blacklist to work. |
| 54 ui_test_utils::NavigateToURLWithDisposition( | 72 ui_test_utils::NavigateToURLWithDisposition( |
| 55 browser(), net::FilePathToFileURL(test_path), NEW_FOREGROUND_TAB, | 73 browser(), net::FilePathToFileURL(test_path), NEW_FOREGROUND_TAB, |
| 56 ui_test_utils::BROWSER_TEST_NONE); | 74 ui_test_utils::BROWSER_TEST_NONE); |
| 57 // Wait for message indicating the test has finished running. | 75 // Wait for message indicating the test has finished running. |
| 58 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | 76 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); |
| 59 | 77 |
| 60 std::string json_events; | 78 std::string json_events; |
| 61 ASSERT_TRUE(tracing::EndTracing(&json_events)); | 79 ASSERT_TRUE(tracing::EndTracing(&json_events)); |
| 62 | 80 |
| 63 scoped_ptr<TraceAnalyzer> analyzer(TraceAnalyzer::Create(json_events)); | 81 scoped_ptr<TraceAnalyzer> analyzer(TraceAnalyzer::Create(json_events)); |
| 64 EXPECT_EQ(expect_gpu_process, analyzer->FindOneEvent( | 82 analyzer->AssociateBeginEndEvents(); |
| 65 Query(EVENT_NAME) == Query::String("GpuProcessLaunched")) != NULL); | 83 TraceAnalyzer::TraceEventVector events; |
| 84 |
| 85 size_t num_gpu_processes = (expectations & EXPECT_GPU_PROCESS) ? 1 : 0; |
| 86 analyzer->FindEvents(Query::MatchBeginName("OnGraphicsInfoCollected"), |
| 87 &events); |
| 88 EXPECT_EQ(num_gpu_processes, events.size()); |
| 89 |
| 90 // Check for context creation if expected: |
| 91 if (expectations & EXPECT_GPU_CONTEXTS) { |
| 92 analyzer->FindEvents( |
| 93 Query(EVENT_NAME) == Query::String("TryCreateGLContext"), |
| 94 &events); |
| 95 EXPECT_EQ(num_contexts_, events.size()); |
| 96 analyzer->FindEvents( |
| 97 Query(EVENT_NAME) == Query::String("CreateGLContextSuccess"), |
| 98 &events); |
| 99 EXPECT_EQ(num_contexts_, events.size()); |
| 100 } |
| 101 |
| 102 // Check for swap buffers if expected: |
| 103 if (expectations & EXPECT_GPU_SWAP_BUFFERS) { |
| 104 analyzer->FindEvents( |
| 105 Query(EVENT_NAME) == Query::String("SwapBuffers"), |
| 106 &events); |
| 107 EXPECT_GT(events.size(), size_t(0)); |
| 108 } |
| 66 } | 109 } |
| 110 |
| 111 protected: |
| 112 size_t num_contexts_; |
| 113 size_t num_offscreen_contexts_; |
| 67 }; | 114 }; |
| 68 | 115 |
| 69 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, AcceleratedCompositingAllowed) { | 116 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, AcceleratedCompositingAllowed) { |
| 70 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | 117 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); |
| 71 EXPECT_EQ(flags.flags(), 0u); | 118 EXPECT_EQ(flags.flags(), 0u); |
| 72 | 119 |
| 73 const bool expect_gpu_process = true; | 120 num_contexts_ = 1; |
| 74 const FilePath url(FILE_PATH_LITERAL("feature_compositing.html")); | 121 const FilePath url(FILE_PATH_LITERAL("feature_compositing.html")); |
| 75 RunTest(url, expect_gpu_process); | 122 RunTest(url, EXPECT_GPU_PROCESS | EXPECT_GPU_SWAP_BUFFERS | |
| 123 EXPECT_GPU_CONTEXTS); |
| 76 } | 124 } |
| 77 | 125 |
| 78 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, AcceleratedCompositingBlocked) { | 126 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, AcceleratedCompositingBlocked) { |
| 79 const std::string json_blacklist = | 127 const std::string json_blacklist = |
| 80 "{\n" | 128 "{\n" |
| 81 " \"name\": \"gpu blacklist\",\n" | 129 " \"name\": \"gpu blacklist\",\n" |
| 82 " \"version\": \"1.0\",\n" | 130 " \"version\": \"1.0\",\n" |
| 83 " \"entries\": [\n" | 131 " \"entries\": [\n" |
| 84 " {\n" | 132 " {\n" |
| 85 " \"id\": 1,\n" | 133 " \"id\": 1,\n" |
| 86 " \"blacklist\": [\n" | 134 " \"blacklist\": [\n" |
| 87 " \"accelerated_compositing\"\n" | 135 " \"accelerated_compositing\"\n" |
| 88 " ]\n" | 136 " ]\n" |
| 89 " }\n" | 137 " }\n" |
| 90 " ]\n" | 138 " ]\n" |
| 91 "}"; | 139 "}"; |
| 92 SetupBlacklist(json_blacklist); | 140 SetupBlacklist(json_blacklist); |
| 93 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | 141 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); |
| 94 EXPECT_EQ( | 142 EXPECT_EQ( |
| 95 flags.flags(), | 143 flags.flags(), |
| 96 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)); | 144 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)); |
| 97 | 145 |
| 98 const bool expect_gpu_process = false; | |
| 99 const FilePath url(FILE_PATH_LITERAL("feature_compositing.html")); | 146 const FilePath url(FILE_PATH_LITERAL("feature_compositing.html")); |
| 100 RunTest(url, expect_gpu_process); | 147 RunTest(url, EXPECT_NO_GPU_PROCESS); |
| 101 } | 148 } |
| 102 | 149 |
| 103 #if defined(OS_LINUX) | 150 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, FLAKY_WebGLAllowed) { |
| 104 // http://crbug.com/104142 | |
| 105 #define MAYBE_WebGLAllowed DISABLED_WebGLAllowed | |
| 106 #else | |
| 107 #define MAYBE_WebGLAllowed WebGLAllowed | |
| 108 #endif | |
| 109 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, MAYBE_WebGLAllowed) { | |
| 110 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | 151 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); |
| 111 EXPECT_EQ(flags.flags(), 0u); | 152 EXPECT_EQ(flags.flags(), 0u); |
| 112 | 153 |
| 113 const bool expect_gpu_process = true; | 154 num_contexts_ = 2; |
| 114 const FilePath url(FILE_PATH_LITERAL("feature_webgl.html")); | 155 const FilePath url(FILE_PATH_LITERAL("feature_webgl.html")); |
| 115 RunTest(url, expect_gpu_process); | 156 RunTest(url, EXPECT_GPU_PROCESS | EXPECT_GPU_SWAP_BUFFERS | |
| 157 EXPECT_GPU_CONTEXTS); |
| 116 } | 158 } |
| 117 | 159 |
| 118 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, WebGLBlocked) { | 160 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, WebGLBlocked) { |
| 119 const std::string json_blacklist = | 161 const std::string json_blacklist = |
| 120 "{\n" | 162 "{\n" |
| 121 " \"name\": \"gpu blacklist\",\n" | 163 " \"name\": \"gpu blacklist\",\n" |
| 122 " \"version\": \"1.0\",\n" | 164 " \"version\": \"1.0\",\n" |
| 123 " \"entries\": [\n" | 165 " \"entries\": [\n" |
| 124 " {\n" | 166 " {\n" |
| 125 " \"id\": 1,\n" | 167 " \"id\": 1,\n" |
| 126 " \"blacklist\": [\n" | 168 " \"blacklist\": [\n" |
| 127 " \"webgl\"\n" | 169 " \"webgl\"\n" |
| 128 " ]\n" | 170 " ]\n" |
| 129 " }\n" | 171 " }\n" |
| 130 " ]\n" | 172 " ]\n" |
| 131 "}"; | 173 "}"; |
| 132 SetupBlacklist(json_blacklist); | 174 SetupBlacklist(json_blacklist); |
| 133 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | 175 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); |
| 134 EXPECT_EQ( | 176 EXPECT_EQ( |
| 135 flags.flags(), | 177 flags.flags(), |
| 136 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureWebgl)); | 178 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureWebgl)); |
| 137 | 179 |
| 138 const bool expect_gpu_process = false; | |
| 139 const FilePath url(FILE_PATH_LITERAL("feature_webgl.html")); | 180 const FilePath url(FILE_PATH_LITERAL("feature_webgl.html")); |
| 140 RunTest(url, expect_gpu_process); | 181 RunTest(url, EXPECT_NO_GPU_PROCESS); |
| 141 } | 182 } |
| 142 | 183 |
| 143 #if defined(OS_LINUX) | 184 #if defined(OS_LINUX) |
| 144 // http://crbug.com/104142 | 185 // http://crbug.com/104142 |
| 145 #define Canvas2DAllowed FLAKY_Canvas2DAllowed | 186 #define Canvas2DAllowed FLAKY_Canvas2DAllowed |
| 146 #endif | 187 #endif |
| 147 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, Canvas2DAllowed) { | 188 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, Canvas2DAllowed) { |
| 148 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | 189 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); |
| 149 EXPECT_EQ(flags.flags(), 0u); | 190 EXPECT_EQ(flags.flags(), 0u); |
| 150 | 191 |
| 151 #if defined(OS_MACOSX) | 192 #if defined(OS_MACOSX) |
| 152 // TODO(zmo): enabling Mac when skia backend is enabled. | 193 // TODO(zmo): enabling Mac when skia backend is enabled. |
| 153 const bool expect_gpu_process = false; | 194 const GpuResultFlags expectations = EXPECT_NO_GPU_PROCESS; |
| 154 #else | 195 #else |
| 155 const bool expect_gpu_process = true; | 196 num_contexts_ = 2; |
| 197 const GpuResultFlags expectations = EXPECT_GPU_PROCESS | |
| 198 EXPECT_GPU_SWAP_BUFFERS | |
| 199 EXPECT_GPU_CONTEXTS; |
| 156 #endif | 200 #endif |
| 157 const FilePath url(FILE_PATH_LITERAL("feature_canvas2d.html")); | 201 const FilePath url(FILE_PATH_LITERAL("feature_canvas2d.html")); |
| 158 RunTest(url, expect_gpu_process); | 202 RunTest(url, expectations); |
| 159 } | 203 } |
| 160 | 204 |
| 161 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, Canvas2DBlocked) { | 205 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, Canvas2DBlocked) { |
| 162 const std::string json_blacklist = | 206 const std::string json_blacklist = |
| 163 "{\n" | 207 "{\n" |
| 164 " \"name\": \"gpu blacklist\",\n" | 208 " \"name\": \"gpu blacklist\",\n" |
| 165 " \"version\": \"1.0\",\n" | 209 " \"version\": \"1.0\",\n" |
| 166 " \"entries\": [\n" | 210 " \"entries\": [\n" |
| 167 " {\n" | 211 " {\n" |
| 168 " \"id\": 1,\n" | 212 " \"id\": 1,\n" |
| 169 " \"blacklist\": [\n" | 213 " \"blacklist\": [\n" |
| 170 " \"accelerated_2d_canvas\"\n" | 214 " \"accelerated_2d_canvas\"\n" |
| 171 " ]\n" | 215 " ]\n" |
| 172 " }\n" | 216 " }\n" |
| 173 " ]\n" | 217 " ]\n" |
| 174 "}"; | 218 "}"; |
| 175 SetupBlacklist(json_blacklist); | 219 SetupBlacklist(json_blacklist); |
| 176 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | 220 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); |
| 177 EXPECT_EQ( | 221 EXPECT_EQ( |
| 178 flags.flags(), | 222 flags.flags(), |
| 179 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)); | 223 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)); |
| 180 | 224 |
| 181 const bool expect_gpu_process = false; | |
| 182 const FilePath url(FILE_PATH_LITERAL("feature_canvas2d.html")); | 225 const FilePath url(FILE_PATH_LITERAL("feature_canvas2d.html")); |
| 183 RunTest(url, expect_gpu_process); | 226 RunTest(url, EXPECT_NO_GPU_PROCESS); |
| 184 } | 227 } |
| 185 | 228 |
| 186 } // namespace anonymous | 229 } // namespace anonymous |
| 187 | 230 |
| OLD | NEW |