Chromium Code Reviews| Index: gpu/command_buffer/tests/gl_context_unittest.cc |
| diff --git a/gpu/command_buffer/tests/gl_context_unittest.cc b/gpu/command_buffer/tests/gl_context_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9aa0b7db9b1d92cf12dac0c9b4fefd45dd6d4cb1 |
| --- /dev/null |
| +++ b/gpu/command_buffer/tests/gl_context_unittest.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <vector> |
| + |
| +#include "base/command_line.h" |
| +#include "base/strings/string_split.h" |
| +#include "base/strings/string_util.h" |
| +#include "gpu/command_buffer/tests/gl_manager.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "ui/gl/gl_gl_api_implementation.h" |
| +#include "ui/gl/gl_surface.h" |
| +#include "ui/gl/gl_switches.h" |
| + |
| +namespace gpu { |
| + |
| +TEST(GLContextTests, DisabledExtensionsTest) { |
|
no sievers
2015/04/30 23:49:05
Maybe a better name for this file is gl_api_unitte
David Yen
2015/05/01 21:20:37
done and moved to gfx_unittests
|
| + static const char* kExtraDisabledExt = "GL_ExtraDisabledExt"; |
| + |
| + GLManager gl; |
| + gl.Initialize(GLManager::Options()); |
|
no sievers
2015/04/30 23:49:05
Uh I wouldn't use GLManager here. That's for setti
David Yen
2015/05/01 21:20:37
No longer relevant in the new unit test.
|
| + gfx::GLContext* gl_context = gl.context(); |
| + |
| + const std::string gl_extensions = gl_context->GetExtensions(); |
| + ASSERT_FALSE(gl_extensions.empty()); |
| + |
|
no sievers
2015/04/30 23:49:05
I think we can do something like this:
const GLu
David Yen
2015/05/01 21:20:37
Done, new unit test is more or less done this way.
|
| + std::vector<std::string> extensions; |
| + base::SplitString(gl_extensions, ' ', &extensions); |
| + ASSERT_LT(3u, gl_extensions.size()); |
| + |
| + EXPECT_TRUE(gl_context->HasExtension(extensions[0].c_str())); |
| + EXPECT_TRUE(gl_context->HasExtension(extensions[1].c_str())); |
| + EXPECT_TRUE(gl_context->HasExtension(extensions[2].c_str())); |
| + EXPECT_FALSE(gl_context->HasExtension(kExtraDisabledExt)); |
| + |
| + // Disable some extensions along with an extra one that does not exist. |
| + std::vector<std::string> disabled_extensions; |
| + disabled_extensions.push_back(extensions[0]); |
| + disabled_extensions.push_back(extensions[1]); |
| + disabled_extensions.push_back(kExtraDisabledExt); |
| + |
| + base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| + command_line.AppendSwitchASCII(switches::kDisableGLExtensions, |
| + JoinString(disabled_extensions, " ")); |
| + |
| + gfx::RealGLApi disabled_extension_api; |
| + disabled_extension_api.Initialize(&gfx::g_driver_gl, &command_line); |
| + gfx::ScopedSetGLToRealGLApi scoped_set_api(&disabled_extension_api); |
| + |
| + EXPECT_FALSE(gl_context->HasExtension(extensions[0].c_str())); |
| + EXPECT_FALSE(gl_context->HasExtension(extensions[1].c_str())); |
| + EXPECT_TRUE(gl_context->HasExtension(extensions[2].c_str())); |
| + EXPECT_FALSE(gl_context->HasExtension(kExtraDisabledExt)); |
| + |
| + gl.Destroy(); |
| +} |
| + |
| +} // namespace gpu |
| + |