Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / gl / glx_api_unittest.cc
blob5792bba17ba9eea70842ef38dce57b96e7700f3d
1 // Copyright 2015 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/memory/scoped_ptr.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gl/gl_glx_api_implementation.h"
9 #include "ui/gl/gl_implementation.h"
11 namespace gfx {
13 class GLXApiTest : public testing::Test {
14 public:
15 void SetUp() override {
16 fake_extension_string_ = "";
18 g_driver_glx.ClearBindings();
19 g_driver_glx.fn.glXQueryExtensionsStringFn = &FakeQueryExtensionsString;
20 SetGLImplementation(kGLImplementationMockGL);
21 SetGLGetProcAddressProc(
22 static_cast<GLGetProcAddressProc>(&FakeGLGetProcAddress));
25 void TearDown() override {
26 g_current_glx_context = nullptr;
27 api_.reset(nullptr);
28 g_driver_glx.ClearBindings();
30 fake_extension_string_ = "";
33 void InitializeAPI(base::CommandLine* command_line) {
34 api_.reset(new RealGLXApi());
35 g_current_glx_context = api_.get();
36 if (command_line)
37 api_->InitializeWithCommandLine(&g_driver_glx, command_line);
38 else
39 api_->Initialize(&g_driver_glx);
40 g_driver_glx.InitializeExtensionBindings();
43 void SetFakeExtensionString(const char* fake_string) {
44 fake_extension_string_ = fake_string;
47 const char* GetExtensions() {
48 return api_->glXQueryExtensionsStringFn(reinterpret_cast<Display*>(0x1), 0);
51 static GLXContext FakeCreateContextAttribsARB(Display* dpy,
52 GLXFBConfig config,
53 GLXContext share_context,
54 int direct,
55 const int* attrib_list) {
56 return static_cast<GLXContext>(nullptr);
59 static void* GL_BINDING_CALL FakeGLGetProcAddress(const char *proc) {
60 if (!strcmp("glXCreateContextAttribsARB", proc)) {
61 return reinterpret_cast<void *>(&FakeCreateContextAttribsARB);
63 return NULL;
66 static const char* GL_BINDING_CALL FakeQueryExtensionsString(Display* dpy,
67 int screen) {
68 return fake_extension_string_;
71 protected:
72 static const char* fake_extension_string_;
74 scoped_ptr<RealGLXApi> api_;
77 const char* GLXApiTest::fake_extension_string_ = "";
79 TEST_F(GLXApiTest, DisabledExtensionBitTest) {
80 static const char* kFakeExtensions = "GLX_ARB_create_context";
81 static const char* kFakeDisabledExtensions = "GLX_ARB_create_context";
83 SetFakeExtensionString(kFakeExtensions);
84 InitializeAPI(nullptr);
86 EXPECT_TRUE(g_driver_glx.ext.b_GLX_ARB_create_context);
88 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
89 command_line.AppendSwitchASCII(switches::kDisableGLExtensions,
90 kFakeDisabledExtensions);
91 InitializeAPI(&command_line);
93 EXPECT_FALSE(g_driver_glx.ext.b_GLX_ARB_create_context);
96 TEST_F(GLXApiTest, DisabledExtensionStringTest) {
97 static const char* kFakeExtensions = "EGL_EXT_1 EGL_EXT_2"
98 " EGL_EXT_3 EGL_EXT_4";
99 static const char* kFakeDisabledExtensions =
100 "EGL_EXT_1,EGL_EXT_2,EGL_FAKE";
101 static const char* kFilteredExtensions = "EGL_EXT_3 EGL_EXT_4";
103 SetFakeExtensionString(kFakeExtensions);
104 InitializeAPI(nullptr);
106 EXPECT_STREQ(kFakeExtensions, GetExtensions());
108 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
109 command_line.AppendSwitchASCII(switches::kDisableGLExtensions,
110 kFakeDisabledExtensions);
111 InitializeAPI(&command_line);
113 EXPECT_STREQ(kFilteredExtensions, GetExtensions());
116 } // namespace gfx