Home | History | Annotate | Download | only in gpu
      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.
      4 
      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"
     16 
     17 namespace content {
     18 
     19 namespace {
     20   void VerifyGPUProcessLaunch(bool* result) {
     21     GpuProcessHost* host =
     22         GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
     23                             content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH);
     24     *result = !!host;
     25   }
     26 }
     27 
     28 class GpuFunctionalTest : public ContentBrowserTest {
     29  protected:
     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");
     34   }
     35 
     36   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     37     command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch);
     38   }
     39 
     40   void VerifyHardwareAccelerated(const std::string& feature) {
     41     NavigateToURL(shell(),
     42                   GURL(std::string(chrome::kChromeUIScheme).
     43                        append("://").
     44                        append(kChromeUIGpuHost)));
     45 
     46     {
     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\");"
     58           "    }"
     59           "  }"
     60           "};";
     61       javascript.append("VerifyHardwareAccelerated(\"");
     62       javascript.append(feature);
     63       javascript.append("\");");
     64       std::string result;
     65       EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(),
     66                                                 javascript,
     67                                                 &result));
     68       EXPECT_EQ(result, "success");
     69     }
     70   }
     71 
     72   void VerifyGPUProcessOnPage(std::string filename, bool wait) {
     73     Shell::Initialize();
     74     ASSERT_TRUE(test_server()->Start());
     75     DOMMessageQueue message_queue;
     76 
     77     std::string url("files/gpu/");
     78     GURL full_url = test_server()->GetURL(url.append(filename));
     79     NavigateToURL(shell(), full_url);
     80 
     81     if (wait) {
     82       std::string result_string;
     83       ASSERT_TRUE(message_queue.WaitForMessage(&result_string));
     84     }
     85 
     86     bool result = false;
     87     BrowserThread::PostTaskAndReply(
     88         BrowserThread::IO,
     89         FROM_HERE,
     90         base::Bind(&VerifyGPUProcessLaunch, &result),
     91         base::MessageLoop::QuitClosure());
     92     base::MessageLoop::current()->Run();
     93     EXPECT_TRUE(result);
     94   }
     95 
     96   base::FilePath gpu_test_dir_;
     97 };
     98 
     99 #if defined(OS_LINUX) && !defined(NDEBUG)
    100 // http://crbug.com/254724
    101 #define IF_NOT_DEBUG_LINUX(x) DISABLED_ ## x
    102 #else
    103 #define IF_NOT_DEBUG_LINUX(x) x
    104 #endif
    105 
    106 IN_PROC_BROWSER_TEST_F(
    107     GpuFunctionalTest,
    108     IF_NOT_DEBUG_LINUX(MANUAL_TestFeatureHardwareAccelerated)) {
    109   VerifyHardwareAccelerated("WebGL: ");
    110   VerifyHardwareAccelerated("Canvas: ");
    111   VerifyHardwareAccelerated("3D CSS: ");
    112 }
    113 
    114 // Verify that gpu process is spawned in webgl example.
    115 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest,
    116                        IF_NOT_DEBUG_LINUX(MANUAL_TestWebGL)) {
    117   VerifyGPUProcessOnPage("functional_webgl.html", false);
    118 }
    119 
    120 // Verify that gpu process is spawned when viewing a 2D canvas.
    121 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest,
    122                        IF_NOT_DEBUG_LINUX(MANUAL_Test2dCanvas)) {
    123   VerifyGPUProcessOnPage("functional_canvas_demo.html", false);
    124 }
    125 
    126 // Verify that gpu process is spawned when viewing a 3D CSS page.
    127 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest,
    128                        IF_NOT_DEBUG_LINUX(MANUAL_Test3dCss)) {
    129   VerifyGPUProcessOnPage("functional_3d_css.html", false);
    130 }
    131 
    132 #if defined(OS_LINUX)
    133 // crbug.com/257109
    134 #define MANUAL_TestGpuWithVideo DISABLED_TestGpuWithVideo
    135 #endif
    136 
    137 // Verify that gpu process is started when viewing video.
    138 IN_PROC_BROWSER_TEST_F(GpuFunctionalTest,
    139                        MANUAL_TestGpuWithVideo) {
    140   VerifyGPUProcessOnPage("functional_video.html", true);
    141 }
    142 
    143 } // namespace content
    144