Convert Google Now's Authentication Manager to use Promises
[chromium-blink-merge.git] / gpu / command_buffer / tests / gl_virtual_contexts_unittest.cc
blob1776ff12faad668182e89e8b63592dc77aed3834
1 // Copyright 2014 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 <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h>
8 #include "gpu/command_buffer/tests/gl_manager.h"
9 #include "gpu/command_buffer/tests/gl_test_utils.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
14 #define SHADER(Src) #Src
16 namespace gpu {
18 class GLVirtualContextsTest : public testing::Test {
19 protected:
20 static const int kSize0 = 4;
21 static const int kSize1 = 8;
22 static const int kSize2 = 16;
24 virtual void SetUp() {
25 GLManager::Options options;
26 options.size = gfx::Size(kSize0, kSize0);
27 gl_real_.Initialize(options);
28 gl_real_shared_.Initialize(options);
29 options.virtual_manager = &gl_real_shared_;
30 options.size = gfx::Size(kSize1, kSize1);
31 gl1_.Initialize(options);
32 options.size = gfx::Size(kSize2, kSize2);
33 gl2_.Initialize(options);
36 virtual void TearDown() {
37 gl1_.Destroy();
38 gl2_.Destroy();
39 gl_real_shared_.Destroy();
40 gl_real_.Destroy();
43 GLManager gl_real_;
44 GLManager gl_real_shared_;
45 GLManager gl1_;
46 GLManager gl2_;
49 namespace {
51 #if !defined(OS_ANDROID)
52 void SetupSimpleShader(const uint8* color) {
53 static const char* v_shader_str = SHADER(
54 attribute vec4 a_Position;
55 void main()
57 gl_Position = a_Position;
61 static const char* f_shader_str = SHADER(
62 precision mediump float;
63 uniform vec4 u_color;
64 void main()
66 gl_FragColor = u_color;
70 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str);
71 glUseProgram(program);
73 GLuint position_loc = glGetAttribLocation(program, "a_Position");
75 GLTestHelper::SetupUnitQuad(position_loc);
77 GLuint color_loc = glGetUniformLocation(program, "u_color");
78 glUniform4f(
79 color_loc,
80 color[0] / 255.0f,
81 color[1] / 255.0f,
82 color[2] / 255.0f,
83 color[3] / 255.0f);
86 void TestDraw(int size) {
87 uint8 expected_clear[] = { 127, 0, 255, 0, };
88 glClearColor(0.5f, 0.0f, 1.0f, 0.0f);
89 glClear(GL_COLOR_BUFFER_BIT);
90 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, size, size, 1, expected_clear));
91 glDrawArrays(GL_TRIANGLES, 0, 6);
94 #endif // !defined(OS_ANDROID)
96 } // anonymous namespace
98 // http://crbug.com/281565
99 #if !defined(OS_ANDROID)
100 TEST_F(GLVirtualContextsTest, Basic) {
101 struct TestInfo {
102 int size;
103 uint8 color[4];
104 GLManager* manager;
106 const int kNumTests = 3;
107 TestInfo tests[] = {
108 { kSize0, { 255, 0, 0, 0, }, &gl_real_, },
109 { kSize1, { 0, 255, 0, 0, }, &gl1_, },
110 { kSize2, { 0, 0, 255, 0, }, &gl2_, },
113 for (int ii = 0; ii < kNumTests; ++ii) {
114 const TestInfo& test = tests[ii];
115 GLManager* gl_manager = test.manager;
116 gl_manager->MakeCurrent();
117 SetupSimpleShader(test.color);
120 for (int ii = 0; ii < kNumTests; ++ii) {
121 const TestInfo& test = tests[ii];
122 GLManager* gl_manager = test.manager;
123 gl_manager->MakeCurrent();
124 TestDraw(test.size);
127 for (int ii = 0; ii < kNumTests; ++ii) {
128 const TestInfo& test = tests[ii];
129 GLManager* gl_manager = test.manager;
130 gl_manager->MakeCurrent();
131 EXPECT_TRUE(GLTestHelper::CheckPixels(
132 0, 0, test.size, test.size, 0, test.color));
135 for (int ii = 0; ii < kNumTests; ++ii) {
136 const TestInfo& test = tests[ii];
137 GLManager* gl_manager = test.manager;
138 gl_manager->MakeCurrent();
139 GLTestHelper::CheckGLError("no errors", __LINE__);
142 #endif
144 } // namespace gpu