| 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 "base/file_util.h" | |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "base/path_service.h" | |
| 8 #include "base/test/trace_event_analyzer.h" | |
| 9 #include "base/version.h" | |
| 10 #include "chrome/browser/ui/browser.h" | |
| 11 #include "chrome/common/chrome_paths.h" | |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "chrome/test/base/tracing.h" | |
| 14 #include "chrome/test/base/ui_test_utils.h" | |
| 15 #include "content/browser/gpu/gpu_blacklist.h" | |
| 16 #include "content/browser/gpu/gpu_data_manager.h" | |
| 17 #include "net/base/net_util.h" | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class GpuFeatureTest : public InProcessBrowserTest { | |
| 22 public: | |
| 23 GpuFeatureTest() {} | |
| 24 | |
| 25 virtual void SetUpCommandLine(CommandLine* command_line) { | |
| 26 // This enables DOM automation for tab contents. | |
| 27 EnableDOMAutomation(); | |
| 28 } | |
| 29 | |
| 30 void SetupBlacklist(const std::string& json_blacklist) { | |
| 31 scoped_ptr<Version> os_version(Version::GetVersionFromString("1.0")); | |
| 32 GpuBlacklist* blacklist = new GpuBlacklist("1.0 unknown"); | |
| 33 | |
| 34 ASSERT_TRUE(blacklist->LoadGpuBlacklist( | |
| 35 json_blacklist, GpuBlacklist::kAllOs)); | |
| 36 GpuDataManager::GetInstance()->SetBuiltInGpuBlacklist(blacklist); | |
| 37 } | |
| 38 | |
| 39 void RunTest(const std::string& url, bool expect_gpu_process) { | |
| 40 using namespace trace_analyzer; | |
| 41 | |
| 42 FilePath test_path; | |
| 43 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | |
| 44 test_path = test_path.Append(FILE_PATH_LITERAL("gpu")); | |
| 45 test_path = test_path.Append(FILE_PATH_LITERAL(url)); | |
| 46 | |
| 47 ASSERT_TRUE(file_util::PathExists(test_path)) | |
| 48 << "Missing test file: " << test_path.value(); | |
| 49 | |
| 50 ASSERT_TRUE(tracing::BeginTracing("test_gpu")); | |
| 51 | |
| 52 ui_test_utils::DOMMessageQueue message_queue; | |
| 53 // Have to use a new tab for the blacklist to work. | |
| 54 ui_test_utils::NavigateToURLWithDisposition( | |
| 55 browser(), net::FilePathToFileURL(test_path), NEW_FOREGROUND_TAB, | |
| 56 ui_test_utils::BROWSER_TEST_NONE); | |
| 57 // Wait for message indicating the test has finished running. | |
| 58 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | |
| 59 | |
| 60 std::string json_events; | |
| 61 ASSERT_TRUE(tracing::EndTracing(&json_events)); | |
| 62 | |
| 63 scoped_ptr<TraceAnalyzer> analyzer(TraceAnalyzer::Create(json_events)); | |
| 64 EXPECT_EQ(expect_gpu_process, analyzer->FindOneEvent( | |
| 65 Query(EVENT_NAME) == Query::String("GpuProcessLaunched")) != NULL); | |
| 66 } | |
| 67 }; | |
| 68 | |
| 69 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, AcceleratedCompositingAllowed) { | |
| 70 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | |
| 71 EXPECT_EQ(flags.flags(), 0u); | |
| 72 | |
| 73 const bool expect_gpu_process = true; | |
| 74 RunTest("feature_compositing.html", expect_gpu_process); | |
| 75 } | |
| 76 | |
| 77 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, AcceleratedCompositingBlocked) { | |
| 78 const std::string json_blacklist = | |
| 79 "{\n" | |
| 80 " \"name\": \"gpu blacklist\",\n" | |
| 81 " \"version\": \"1.0\",\n" | |
| 82 " \"entries\": [\n" | |
| 83 " {\n" | |
| 84 " \"id\": 1,\n" | |
| 85 " \"blacklist\": [\n" | |
| 86 " \"accelerated_compositing\"\n" | |
| 87 " ]\n" | |
| 88 " }\n" | |
| 89 " ]\n" | |
| 90 "}"; | |
| 91 SetupBlacklist(json_blacklist); | |
| 92 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | |
| 93 EXPECT_EQ( | |
| 94 flags.flags(), | |
| 95 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)); | |
| 96 | |
| 97 const bool expect_gpu_process = false; | |
| 98 RunTest("feature_compositing.html", expect_gpu_process); | |
| 99 } | |
| 100 | |
| 101 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, WebGLAllowed) { | |
| 102 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | |
| 103 EXPECT_EQ(flags.flags(), 0u); | |
| 104 | |
| 105 const bool expect_gpu_process = true; | |
| 106 RunTest("feature_webgl.html", expect_gpu_process); | |
| 107 } | |
| 108 | |
| 109 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, WebGLBlocked) { | |
| 110 const std::string json_blacklist = | |
| 111 "{\n" | |
| 112 " \"name\": \"gpu blacklist\",\n" | |
| 113 " \"version\": \"1.0\",\n" | |
| 114 " \"entries\": [\n" | |
| 115 " {\n" | |
| 116 " \"id\": 1,\n" | |
| 117 " \"blacklist\": [\n" | |
| 118 " \"webgl\"\n" | |
| 119 " ]\n" | |
| 120 " }\n" | |
| 121 " ]\n" | |
| 122 "}"; | |
| 123 SetupBlacklist(json_blacklist); | |
| 124 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | |
| 125 EXPECT_EQ( | |
| 126 flags.flags(), | |
| 127 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureWebgl)); | |
| 128 | |
| 129 const bool expect_gpu_process = false; | |
| 130 RunTest("feature_webgl.html", expect_gpu_process); | |
| 131 } | |
| 132 | |
| 133 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, Canvas2DAllowed) { | |
| 134 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | |
| 135 EXPECT_EQ(flags.flags(), 0u); | |
| 136 | |
| 137 #if defined(OS_MACOSX) | |
| 138 // TODO(zmo): enabling Mac when skia backend is enabled. | |
| 139 const bool expect_gpu_process = false; | |
| 140 #else | |
| 141 const bool expect_gpu_process = true; | |
| 142 #endif | |
| 143 RunTest("feature_canvas2d.html", expect_gpu_process); | |
| 144 } | |
| 145 | |
| 146 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, Canvas2DBlocked) { | |
| 147 const std::string json_blacklist = | |
| 148 "{\n" | |
| 149 " \"name\": \"gpu blacklist\",\n" | |
| 150 " \"version\": \"1.0\",\n" | |
| 151 " \"entries\": [\n" | |
| 152 " {\n" | |
| 153 " \"id\": 1,\n" | |
| 154 " \"blacklist\": [\n" | |
| 155 " \"accelerated_2d_canvas\"\n" | |
| 156 " ]\n" | |
| 157 " }\n" | |
| 158 " ]\n" | |
| 159 "}"; | |
| 160 SetupBlacklist(json_blacklist); | |
| 161 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); | |
| 162 EXPECT_EQ( | |
| 163 flags.flags(), | |
| 164 static_cast<uint32>(GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)); | |
| 165 | |
| 166 const bool expect_gpu_process = false; | |
| 167 RunTest("feature_canvas2d.html", expect_gpu_process); | |
| 168 } | |
| 169 | |
| 170 } // namespace anonymous | |
| 171 | |
| OLD | NEW |