Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / context_group_unittest.cc
blobce47bd2cb4012467ae081df9dd2366dbce4fbaa1
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 "gpu/command_buffer/service/context_group.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
9 #include "gpu/command_buffer/service/gpu_service_test.h"
10 #include "gpu/command_buffer/service/test_helper.h"
11 #include "gpu/command_buffer/service/texture_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gl/gl_mock.h"
15 using ::testing::_;
16 using ::testing::DoAll;
17 using ::testing::HasSubstr;
18 using ::testing::InSequence;
19 using ::testing::MatcherCast;
20 using ::testing::Not;
21 using ::testing::Pointee;
22 using ::testing::Return;
23 using ::testing::SetArrayArgument;
24 using ::testing::SetArgumentPointee;
25 using ::testing::StrEq;
27 namespace gpu {
28 namespace gles2 {
30 class ContextGroupTest : public GpuServiceTest {
31 public:
32 static const bool kBindGeneratesResource = false;
34 ContextGroupTest() {}
36 protected:
37 virtual void SetUp() {
38 GpuServiceTest::SetUp();
39 decoder_.reset(new MockGLES2Decoder());
40 group_ = scoped_refptr<ContextGroup>(
41 new ContextGroup(NULL, NULL, NULL, NULL, kBindGeneratesResource));
44 scoped_ptr<MockGLES2Decoder> decoder_;
45 scoped_refptr<ContextGroup> group_;
48 TEST_F(ContextGroupTest, Basic) {
49 // Test it starts off uninitialized.
50 EXPECT_EQ(0u, group_->max_vertex_attribs());
51 EXPECT_EQ(0u, group_->max_texture_units());
52 EXPECT_EQ(0u, group_->max_texture_image_units());
53 EXPECT_EQ(0u, group_->max_vertex_texture_image_units());
54 EXPECT_EQ(0u, group_->max_fragment_uniform_vectors());
55 EXPECT_EQ(0u, group_->max_varying_vectors());
56 EXPECT_EQ(0u, group_->max_vertex_uniform_vectors());
57 EXPECT_TRUE(group_->buffer_manager() == NULL);
58 EXPECT_TRUE(group_->framebuffer_manager() == NULL);
59 EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
60 EXPECT_TRUE(group_->texture_manager() == NULL);
61 EXPECT_TRUE(group_->program_manager() == NULL);
62 EXPECT_TRUE(group_->shader_manager() == NULL);
65 TEST_F(ContextGroupTest, InitializeNoExtensions) {
66 TestHelper::SetupContextGroupInitExpectations(
67 gl_.get(), DisallowedFeatures(), "", "", kBindGeneratesResource);
68 group_->Initialize(decoder_.get(), DisallowedFeatures());
69 EXPECT_EQ(static_cast<uint32>(TestHelper::kNumVertexAttribs),
70 group_->max_vertex_attribs());
71 EXPECT_EQ(static_cast<uint32>(TestHelper::kNumTextureUnits),
72 group_->max_texture_units());
73 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxTextureImageUnits),
74 group_->max_texture_image_units());
75 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVertexTextureImageUnits),
76 group_->max_vertex_texture_image_units());
77 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxFragmentUniformVectors),
78 group_->max_fragment_uniform_vectors());
79 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVaryingVectors),
80 group_->max_varying_vectors());
81 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVertexUniformVectors),
82 group_->max_vertex_uniform_vectors());
83 EXPECT_TRUE(group_->buffer_manager() != NULL);
84 EXPECT_TRUE(group_->framebuffer_manager() != NULL);
85 EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
86 EXPECT_TRUE(group_->texture_manager() != NULL);
87 EXPECT_TRUE(group_->program_manager() != NULL);
88 EXPECT_TRUE(group_->shader_manager() != NULL);
90 group_->Destroy(decoder_.get(), false);
91 EXPECT_TRUE(group_->buffer_manager() == NULL);
92 EXPECT_TRUE(group_->framebuffer_manager() == NULL);
93 EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
94 EXPECT_TRUE(group_->texture_manager() == NULL);
95 EXPECT_TRUE(group_->program_manager() == NULL);
96 EXPECT_TRUE(group_->shader_manager() == NULL);
99 TEST_F(ContextGroupTest, MultipleContexts) {
100 scoped_ptr<MockGLES2Decoder> decoder2_(new MockGLES2Decoder());
101 TestHelper::SetupContextGroupInitExpectations(
102 gl_.get(), DisallowedFeatures(), "", "", kBindGeneratesResource);
103 group_->Initialize(decoder_.get(), DisallowedFeatures());
104 group_->Initialize(decoder2_.get(), DisallowedFeatures());
106 EXPECT_TRUE(group_->buffer_manager() != NULL);
107 EXPECT_TRUE(group_->framebuffer_manager() != NULL);
108 EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
109 EXPECT_TRUE(group_->texture_manager() != NULL);
110 EXPECT_TRUE(group_->program_manager() != NULL);
111 EXPECT_TRUE(group_->shader_manager() != NULL);
113 group_->Destroy(decoder_.get(), false);
115 EXPECT_TRUE(group_->buffer_manager() != NULL);
116 EXPECT_TRUE(group_->framebuffer_manager() != NULL);
117 EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
118 EXPECT_TRUE(group_->texture_manager() != NULL);
119 EXPECT_TRUE(group_->program_manager() != NULL);
120 EXPECT_TRUE(group_->shader_manager() != NULL);
122 group_->Destroy(decoder2_.get(), false);
124 EXPECT_TRUE(group_->buffer_manager() == NULL);
125 EXPECT_TRUE(group_->framebuffer_manager() == NULL);
126 EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
127 EXPECT_TRUE(group_->texture_manager() == NULL);
128 EXPECT_TRUE(group_->program_manager() == NULL);
129 EXPECT_TRUE(group_->shader_manager() == NULL);
132 } // namespace gles2
133 } // namespace gpu