1 // Copyright (c) 2013 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.
5 #include "base/command_line.h"
6 #include "base/path_service.h"
7 #include "content/browser/gpu/gpu_process_host.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/common/content_paths.h"
10 #include "content/public/common/content_switches.h"
11 #include "content/public/common/url_constants.h"
12 #include "content/public/test/browser_test_utils.h"
13 #include "content/shell/shell.h"
14 #include "content/test/content_browser_test.h"
15 #include "content/test/content_browser_test_utils.h"
20 void VerifyGPUProcessLaunch(bool* result
) {
21 GpuProcessHost
* host
=
22 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED
,
23 content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH
);
28 class GpuFunctionalTest
: public ContentBrowserTest
{
30 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
31 base::FilePath test_dir
;
32 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA
, &test_dir
));
33 gpu_test_dir_
= test_dir
.AppendASCII("gpu");
36 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
37 command_line
->AppendSwitch(switches::kDisableGpuProcessPrelaunch
);
40 void VerifyHardwareAccelerated(const std::string
& feature
) {
41 NavigateToURL(shell(),
42 GURL(std::string(chrome::kChromeUIScheme
).
44 append(kChromeUIGpuHost
)));
47 // Verify that the given feature is hardware accelerated..
48 std::string javascript
=
49 "function VerifyHardwareAccelerated(feature) {"
50 " var list = document.querySelector(\".feature-status-list\");"
51 " for (var i=0; i < list.childElementCount; i++) {"
52 " var span_list = list.children[i].getElementsByTagName('span');"
53 " var feature_str = span_list[0].textContent;"
54 " var value_str = span_list[1].textContent;"
55 " if ((feature_str == feature) &&"
56 " (value_str == 'Hardware accelerated')) {"
57 " domAutomationController.send(\"success\");"
61 javascript
.append("VerifyHardwareAccelerated(\"");
62 javascript
.append(feature
);
63 javascript
.append("\");");
65 EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(),
68 EXPECT_EQ(result
, "success");
72 void VerifyGPUProcessOnPage(std::string filename
, bool wait
) {
74 ASSERT_TRUE(test_server()->Start());
75 DOMMessageQueue message_queue
;
77 std::string
url("files/gpu/");
78 GURL full_url
= test_server()->GetURL(url
.append(filename
));
79 NavigateToURL(shell(), full_url
);
82 std::string result_string
;
83 ASSERT_TRUE(message_queue
.WaitForMessage(&result_string
));
87 BrowserThread::PostTaskAndReply(
90 base::Bind(&VerifyGPUProcessLaunch
, &result
),
91 base::MessageLoop::QuitClosure());
92 base::MessageLoop::current()->Run();
96 base::FilePath gpu_test_dir_
;
99 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest
,
100 MANUAL_TestFeatureHardwareAccelerated
) {
101 VerifyHardwareAccelerated("WebGL: ");
102 VerifyHardwareAccelerated("Canvas: ");
103 VerifyHardwareAccelerated("3D CSS: ");
106 // Verify that gpu process is spawned in webgl example.
107 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest
, MANUAL_TestWebGL
) {
108 VerifyGPUProcessOnPage("functional_webgl.html", false);
111 // Verify that gpu process is spawned when viewing a 2D canvas.
112 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest
, MANUAL_Test2dCanvas
) {
113 VerifyGPUProcessOnPage("functional_canvas_demo.html", false);
116 // Verify that gpu process is spawned when viewing a 3D CSS page.
117 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest
, MANUAL_Test3dCss
) {
118 VerifyGPUProcessOnPage("functional_3d_css.html", false);
121 // Verify that gpu process is started when viewing video.
122 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest
, MANUAL_TestGpuWithVideo
) {
123 VerifyGPUProcessOnPage("functional_video.html", true);
126 } // namespace content