Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / gpu / webgl_conformance_test.cc
blob1468b2d21671a2e70cd251c711857af6680c8cb3
1 // Copyright (c) 2012 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/file_util.h"
7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/common/content_paths.h"
11 #include "content/public/common/content_switches.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 #include "gpu/config/gpu_test_config.h"
17 #include "gpu/config/gpu_test_expectations_parser.h"
18 #include "net/base/net_util.h"
20 namespace content {
22 class WebGLConformanceTest : public ContentBrowserTest {
23 public:
24 WebGLConformanceTest() {}
26 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
27 // Allow privileged WebGL extensions.
28 command_line->AppendSwitch(switches::kEnablePrivilegedWebGLExtensions);
29 #if defined(OS_ANDROID)
30 command_line->AppendSwitch(switches::kEnableExperimentalWebGL);
31 command_line->AppendSwitch(
32 switches::kDisableGestureRequirementForMediaPlayback);
33 #endif
36 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
37 base::FilePath webgl_conformance_path;
38 PathService::Get(base::DIR_SOURCE_ROOT, &webgl_conformance_path);
39 webgl_conformance_path = webgl_conformance_path.Append(
40 FILE_PATH_LITERAL("third_party"));
41 webgl_conformance_path = webgl_conformance_path.Append(
42 FILE_PATH_LITERAL("webgl_conformance"));
43 ASSERT_TRUE(file_util::DirectoryExists(webgl_conformance_path))
44 << "Missing conformance tests: " << webgl_conformance_path.value();
46 PathService::Get(DIR_TEST_DATA, &test_path_);
47 test_path_ = test_path_.Append(FILE_PATH_LITERAL("gpu"));
48 test_path_ = test_path_.Append(FILE_PATH_LITERAL("webgl_conformance.html"));
50 ASSERT_TRUE(bot_config_.LoadCurrentConfig(NULL))
51 << "Fail to load bot configuration";
52 ASSERT_TRUE(bot_config_.IsValid())
53 << "Invalid bot configuration";
55 base::FilePath path;
56 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &path));
57 path = path.Append(FILE_PATH_LITERAL("gpu"))
58 .Append(FILE_PATH_LITERAL("webgl_conformance_test_expectations.txt"));
59 ASSERT_TRUE(file_util::PathExists(path));
60 ASSERT_TRUE(test_expectations_.LoadTestExpectations(path));
63 void RunTest(std::string url, std::string test_name) {
64 int32 expectation =
65 test_expectations_.GetTestExpectation(test_name, bot_config_);
66 if (expectation != gpu::GPUTestExpectationsParser::kGpuTestPass) {
67 LOG(WARNING) << "Test " << test_name << " is bypassed";
68 return;
71 DOMMessageQueue message_queue;
72 NavigateToURL(shell(), net::FilePathToFileURL(test_path_));
74 std::string message;
75 NavigateToURL(shell(), GURL("javascript:start('" + url + "');"));
76 ASSERT_TRUE(message_queue.WaitForMessage(&message));
78 EXPECT_STREQ("\"SUCCESS\"", message.c_str()) << message;
81 private:
82 base::FilePath test_path_;
83 gpu::GPUTestBotConfig bot_config_;
84 gpu::GPUTestExpectationsParser test_expectations_;
87 #define CONFORMANCE_TEST(name, url) \
88 IN_PROC_BROWSER_TEST_F(WebGLConformanceTest, MANUAL_##name) { \
89 RunTest(url, #name); \
92 // The test declarations are located in webgl_conformance_test_list_autogen.h,
93 // because the list is automatically generated by a script.
94 // See: generate_webgl_conformance_test_list.py
95 #include "webgl_conformance_test_list_autogen.h"
97 } // namespace content