diff options
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/test/data/gpu/feature_canvas2d.html | 35 | ||||
-rw-r--r-- | chrome/test/data/gpu/feature_compositing.html | 21 | ||||
-rw-r--r-- | chrome/test/data/gpu/feature_webgl.html | 33 | ||||
-rw-r--r-- | chrome/test/gpu/gpu_feature_browsertest.cc | 171 | ||||
-rw-r--r-- | content/browser/gpu/gpu_process_host.cc | 2 |
6 files changed, 263 insertions, 0 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index b6c52df..4ebff16 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2669,6 +2669,7 @@ 'test/data/webui/certificate_viewer_ui_test-inl.h', 'test/data/webui/ntp4.js', 'test/data/webui/print_preview.js', + 'test/gpu/gpu_feature_browsertest.cc', # TODO(craig): Rename this and run from base_unittests when the test # is safe to run there. See http://crbug.com/78722 for details. '../base/files/file_path_watcher_browsertest.cc', diff --git a/chrome/test/data/gpu/feature_canvas2d.html b/chrome/test/data/gpu/feature_canvas2d.html new file mode 100644 index 0000000..eb07a6a --- /dev/null +++ b/chrome/test/data/gpu/feature_canvas2d.html @@ -0,0 +1,35 @@ +<!DOCTYPE HTML> +<html> +<head> +<meta charset="utf-8"> +<title>GPU Feature Testing: Canvas2D</title> +<script> +function init() { + var canvas = document.createElement("canvas"); + if (!canvas) + return null; + // Make sure canvas is large enough to trigger gpu acceleration. + canvas.width = 500; + canvas.height = 500; + var context = null; + try { + context = canvas.getContext("2d"); + } catch(e) {} + return context; +} + +function runTest() { + var c2d = init(); + if (c2d) { + // Initialization was triggered lazily on the first draw. + c2d.fillRect(0, 0, 1, 1); + } + domAutomationController.setAutomationId(1); + domAutomationController.send("FINISHED"); +} +</script> +</head> +<body onload="runTest()"> +Canvas2D should trigger GPU process launch if accelerated-2d-canvas is allowed. +</body> +</html> diff --git a/chrome/test/data/gpu/feature_compositing.html b/chrome/test/data/gpu/feature_compositing.html new file mode 100644 index 0000000..2ffed5e --- /dev/null +++ b/chrome/test/data/gpu/feature_compositing.html @@ -0,0 +1,21 @@ +<!DOCTYPE HTML> +<html> +<head> +<meta charset="utf-8"> +<title>GPU Feature Testing: Accelerated Compositing</title> +<style> +body { + -webkit-transform: translateZ(0); +} +</style> +<script> +function runTest() { + domAutomationController.setAutomationId(1); + domAutomationController.send("FINISHED"); +} +</script> +</head> +<body onload="runTest()"> +This page should trigger accelerated-compositing, i.e., gpu process should launch, if accelerated-compositing is allowed. +</body> +</html> diff --git a/chrome/test/data/gpu/feature_webgl.html b/chrome/test/data/gpu/feature_webgl.html new file mode 100644 index 0000000..cd6566d --- /dev/null +++ b/chrome/test/data/gpu/feature_webgl.html @@ -0,0 +1,33 @@ +<!DOCTYPE HTML> +<html> +<head> +<meta charset="utf-8"> +<title>GPU Feature Testing: WebGL</title> +<script> +function init() { + var canvas = document.createElement("canvas"); + if (!canvas) + return null; + var context = null; + try { + context = canvas.getContext("webgl"); + } catch(e) {} + if (!context) { + try { + context = canvas.getContext("experimental-webgl"); + } catch(e) {} + } + return context; +} + +function runTest() { + var gl = init(); + domAutomationController.setAutomationId(1); + domAutomationController.send("FINISHED"); +} +</script> +</head> +<body onload="runTest()"> +WebGL should trigger GPU process launch if it is allowed. +</body> +</html> diff --git a/chrome/test/gpu/gpu_feature_browsertest.cc b/chrome/test/gpu/gpu_feature_browsertest.cc new file mode 100644 index 0000000..dc4827c --- /dev/null +++ b/chrome/test/gpu/gpu_feature_browsertest.cc @@ -0,0 +1,171 @@ +// Copyright (c) 2011 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/file_util.h" +#include "base/memory/scoped_ptr.h" +#include "base/path_service.h" +#include "base/test/trace_event_analyzer.h" +#include "base/version.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/tracing.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/browser/gpu/gpu_blacklist.h" +#include "content/browser/gpu/gpu_data_manager.h" +#include "net/base/net_util.h" + +namespace { + +class GpuFeatureTest : public InProcessBrowserTest { + public: + GpuFeatureTest() {} + + virtual void SetUpCommandLine(CommandLine* command_line) { + // This enables DOM automation for tab contents. + EnableDOMAutomation(); + } + + void SetupBlacklist(const std::string& json_blacklist) { + scoped_ptr<Version> os_version(Version::GetVersionFromString("1.0")); + GpuBlacklist* blacklist = new GpuBlacklist("1.0 unknown"); + + ASSERT_TRUE(blacklist->LoadGpuBlacklist( + json_blacklist, GpuBlacklist::kAllOs)); + GpuDataManager::GetInstance()->SetBuiltInGpuBlacklist(blacklist); + } + + void RunTest(const std::string& url, bool expect_gpu_process) { + using namespace trace_analyzer; + + FilePath test_path; + PathService::Get(chrome::DIR_TEST_DATA, &test_path); + test_path = test_path.Append(FILE_PATH_LITERAL("gpu")); + test_path = test_path.Append(FILE_PATH_LITERAL(url)); + + ASSERT_TRUE(file_util::PathExists(test_path)) + << "Missing test file: " << test_path.value(); + + ASSERT_TRUE(tracing::BeginTracing("test_gpu")); + + ui_test_utils::DOMMessageQueue message_queue; + // Have to use a new tab for the blacklist to work. + ui_test_utils::NavigateToURLWithDisposition( + browser(), net::FilePathToFileURL(test_path), NEW_FOREGROUND_TAB, + ui_test_utils::BROWSER_TEST_NONE); + // Wait for message indicating the test has finished running. + ASSERT_TRUE(message_queue.WaitForMessage(NULL)); + + std::string json_events; + ASSERT_TRUE(tracing::EndTracing(&json_events)); + + scoped_ptr<TraceAnalyzer> analyzer(TraceAnalyzer::Create(json_events)); + EXPECT_EQ(expect_gpu_process, analyzer->FindOneEvent( + Query(EVENT_NAME) == Query::String("GpuProcessLaunched")) != NULL); + } +}; + +IN_PROC_BROWSER_TEST_F(GpuFeatureTest, AcceleratedCompositingAllowed) { + GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); + EXPECT_EQ(flags.flags(), 0u); + + const bool expect_gpu_process = true; + RunTest("feature_compositing.html", expect_gpu_process); +} + +IN_PROC_BROWSER_TEST_F(GpuFeatureTest, AcceleratedCompositingBlocked) { + const std::string json_blacklist = + "{\n" + " \"name\": \"gpu blacklist\",\n" + " \"version\": \"1.0\",\n" + " \"entries\": [\n" + " {\n" + " \"id\": 1,\n" + " \"blacklist\": [\n" + " \"accelerated_compositing\"\n" + " ]\n" + " }\n" + " ]\n" + "}"; + SetupBlacklist(json_blacklist); + GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); + EXPECT_EQ( + flags.flags(), + static_cast<uint32>(GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)); + + const bool expect_gpu_process = false; + RunTest("feature_compositing.html", expect_gpu_process); +} + +IN_PROC_BROWSER_TEST_F(GpuFeatureTest, WebGLAllowed) { + GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); + EXPECT_EQ(flags.flags(), 0u); + + const bool expect_gpu_process = true; + RunTest("feature_webgl.html", expect_gpu_process); +} + +IN_PROC_BROWSER_TEST_F(GpuFeatureTest, WebGLBlocked) { + const std::string json_blacklist = + "{\n" + " \"name\": \"gpu blacklist\",\n" + " \"version\": \"1.0\",\n" + " \"entries\": [\n" + " {\n" + " \"id\": 1,\n" + " \"blacklist\": [\n" + " \"webgl\"\n" + " ]\n" + " }\n" + " ]\n" + "}"; + SetupBlacklist(json_blacklist); + GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); + EXPECT_EQ( + flags.flags(), + static_cast<uint32>(GpuFeatureFlags::kGpuFeatureWebgl)); + + const bool expect_gpu_process = false; + RunTest("feature_webgl.html", expect_gpu_process); +} + +IN_PROC_BROWSER_TEST_F(GpuFeatureTest, Canvas2DAllowed) { + GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); + EXPECT_EQ(flags.flags(), 0u); + +#if defined(OS_MACOSX) + // TODO(zmo): enabling Mac when skia backend is enabled. + const bool expect_gpu_process = false; +#else + const bool expect_gpu_process = true; +#endif + RunTest("feature_canvas2d.html", expect_gpu_process); +} + +IN_PROC_BROWSER_TEST_F(GpuFeatureTest, Canvas2DBlocked) { + const std::string json_blacklist = + "{\n" + " \"name\": \"gpu blacklist\",\n" + " \"version\": \"1.0\",\n" + " \"entries\": [\n" + " {\n" + " \"id\": 1,\n" + " \"blacklist\": [\n" + " \"accelerated_2d_canvas\"\n" + " ]\n" + " }\n" + " ]\n" + "}"; + SetupBlacklist(json_blacklist); + GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags(); + EXPECT_EQ( + flags.flags(), + static_cast<uint32>(GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)); + + const bool expect_gpu_process = false; + RunTest("feature_canvas2d.html", expect_gpu_process); +} + +} // namespace anonymous + diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc index 0612fca..fade001a 100644 --- a/content/browser/gpu/gpu_process_host.cc +++ b/content/browser/gpu/gpu_process_host.cc @@ -467,6 +467,8 @@ void GpuProcessHost::OnProcessLaunched() { // respond to any requests to establish a GPU channel. The response // to such requests require that the GPU process handle be known. + TRACE_EVENT0("test_gpu", "GpuProcessLaunched"); + base::ProcessHandle child_handle = in_process_ ? base::GetCurrentProcessHandle() : handle(); |