OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 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_egl_api_implementation.h" |
| 9 #include "ui/gl/gl_switches.h" |
| 10 |
| 11 namespace gfx { |
| 12 |
| 13 class EGLApiTest : public testing::Test { |
| 14 public: |
| 15 void SetUp() override { |
| 16 fake_extension_string_ = ""; |
| 17 |
| 18 // TODO(dyen): Add a way to bind mock drivers for testing. |
| 19 g_driver_egl.ClearBindings(); |
| 20 g_driver_egl.fn.eglInitializeFn = &FakeInitialize; |
| 21 g_driver_egl.fn.eglQueryStringFn = &FakeQueryString; |
| 22 g_driver_egl.fn.eglGetCurrentDisplayFn = &FakeGetCurrentDisplay; |
| 23 g_driver_egl.fn.eglGetDisplayFn = &FakeGetDisplay; |
| 24 g_driver_egl.fn.eglGetErrorFn = &FakeGetError; |
| 25 } |
| 26 |
| 27 void TearDown() override { |
| 28 g_current_egl_context = nullptr; |
| 29 api_.reset(nullptr); |
| 30 g_driver_egl.ClearBindings(); |
| 31 |
| 32 fake_extension_string_ = ""; |
| 33 } |
| 34 |
| 35 void InitializeAPI(base::CommandLine* command_line) { |
| 36 api_.reset(new RealEGLApi()); |
| 37 g_current_egl_context = api_.get(); |
| 38 if (command_line) |
| 39 api_->InitializeWithCommandLine(&g_driver_egl, command_line); |
| 40 else |
| 41 api_->Initialize(&g_driver_egl); |
| 42 api_->InitializeFilteredExtensions(); |
| 43 } |
| 44 |
| 45 void SetFakeExtensionString(const char* fake_string) { |
| 46 fake_extension_string_ = fake_string; |
| 47 } |
| 48 |
| 49 static EGLBoolean GL_BINDING_CALL FakeInitialize(EGLDisplay display, |
| 50 EGLint * major, |
| 51 EGLint * minor) { |
| 52 return EGL_TRUE; |
| 53 } |
| 54 |
| 55 static const char* GL_BINDING_CALL FakeQueryString(EGLDisplay dpy, |
| 56 EGLint name) { |
| 57 return fake_extension_string_; |
| 58 } |
| 59 |
| 60 static EGLDisplay GL_BINDING_CALL FakeGetCurrentDisplay() { |
| 61 return nullptr; |
| 62 } |
| 63 |
| 64 static EGLDisplay GL_BINDING_CALL FakeGetDisplay( |
| 65 EGLNativeDisplayType native_display) { |
| 66 return EGL_NO_DISPLAY; |
| 67 } |
| 68 |
| 69 static EGLint GL_BINDING_CALL FakeGetError() { |
| 70 return EGL_SUCCESS; |
| 71 } |
| 72 |
| 73 const char* GetExtensions() { |
| 74 EGLDisplay display = api_->eglGetCurrentDisplayFn(); |
| 75 return api_->eglQueryStringFn(display, EGL_EXTENSIONS); |
| 76 } |
| 77 |
| 78 protected: |
| 79 static const char* fake_extension_string_; |
| 80 |
| 81 scoped_ptr<RealEGLApi> api_; |
| 82 }; |
| 83 |
| 84 const char* EGLApiTest::fake_extension_string_ = ""; |
| 85 |
| 86 TEST_F(EGLApiTest, DisabledExtensionStringTest) { |
| 87 static const char* kFakeExtensions = "EGL_EXT_1 EGL_EXT_2" |
| 88 " EGL_EXT_3 EGL_EXT_4"; |
| 89 static const char* kFakeDisabledExtensions = "EGL_EXT_1,EGL_EXT_2,EGL_FAKE"; |
| 90 static const char* kFilteredExtensions = "EGL_EXT_3 EGL_EXT_4"; |
| 91 |
| 92 SetFakeExtensionString(kFakeExtensions); |
| 93 InitializeAPI(nullptr); |
| 94 |
| 95 EXPECT_STREQ(kFakeExtensions, GetExtensions()); |
| 96 |
| 97 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 98 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, |
| 99 kFakeDisabledExtensions); |
| 100 InitializeAPI(&command_line); |
| 101 |
| 102 EXPECT_STREQ(kFilteredExtensions, GetExtensions()); |
| 103 } |
| 104 |
| 105 } // namespace gfx |
OLD | NEW |