Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / gpu / command_buffer / service / context_group_unittest.cc
blob7aa1301f445f7e2f5ac13b221f67ce5b2cc524c7
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/mailbox_manager.h"
11 #include "gpu/command_buffer/service/test_helper.h"
12 #include "gpu/command_buffer/service/texture_manager.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gl/gl_mock.h"
16 using ::testing::_;
17 using ::testing::DoAll;
18 using ::testing::HasSubstr;
19 using ::testing::InSequence;
20 using ::testing::MatcherCast;
21 using ::testing::Not;
22 using ::testing::Pointee;
23 using ::testing::Return;
24 using ::testing::SetArrayArgument;
25 using ::testing::SetArgumentPointee;
26 using ::testing::StrEq;
28 namespace gpu {
29 namespace gles2 {
31 class ContextGroupTest : public GpuServiceTest {
32 public:
33 static const bool kBindGeneratesResource = false;
35 ContextGroupTest() {}
37 protected:
38 virtual void SetUp() {
39 GpuServiceTest::SetUp();
40 decoder_.reset(new MockGLES2Decoder());
41 group_ = scoped_refptr<ContextGroup>(
42 new ContextGroup(NULL, NULL, NULL, NULL, kBindGeneratesResource));
45 scoped_ptr<MockGLES2Decoder> decoder_;
46 scoped_refptr<ContextGroup> group_;
49 TEST_F(ContextGroupTest, Basic) {
50 // Test it starts off uninitialized.
51 EXPECT_EQ(0u, group_->max_vertex_attribs());
52 EXPECT_EQ(0u, group_->max_texture_units());
53 EXPECT_EQ(0u, group_->max_texture_image_units());
54 EXPECT_EQ(0u, group_->max_vertex_texture_image_units());
55 EXPECT_EQ(0u, group_->max_fragment_uniform_vectors());
56 EXPECT_EQ(0u, group_->max_varying_vectors());
57 EXPECT_EQ(0u, group_->max_vertex_uniform_vectors());
58 EXPECT_TRUE(group_->buffer_manager() == NULL);
59 EXPECT_TRUE(group_->framebuffer_manager() == NULL);
60 EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
61 EXPECT_TRUE(group_->texture_manager() == NULL);
62 EXPECT_TRUE(group_->program_manager() == NULL);
63 EXPECT_TRUE(group_->shader_manager() == NULL);
66 TEST_F(ContextGroupTest, InitializeNoExtensions) {
67 TestHelper::SetupContextGroupInitExpectations(
68 gl_.get(), DisallowedFeatures(), "", "", kBindGeneratesResource);
69 group_->Initialize(decoder_.get(), DisallowedFeatures());
70 EXPECT_EQ(static_cast<uint32>(TestHelper::kNumVertexAttribs),
71 group_->max_vertex_attribs());
72 EXPECT_EQ(static_cast<uint32>(TestHelper::kNumTextureUnits),
73 group_->max_texture_units());
74 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxTextureImageUnits),
75 group_->max_texture_image_units());
76 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVertexTextureImageUnits),
77 group_->max_vertex_texture_image_units());
78 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxFragmentUniformVectors),
79 group_->max_fragment_uniform_vectors());
80 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVaryingVectors),
81 group_->max_varying_vectors());
82 EXPECT_EQ(static_cast<uint32>(TestHelper::kMaxVertexUniformVectors),
83 group_->max_vertex_uniform_vectors());
84 EXPECT_TRUE(group_->buffer_manager() != NULL);
85 EXPECT_TRUE(group_->framebuffer_manager() != NULL);
86 EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
87 EXPECT_TRUE(group_->texture_manager() != NULL);
88 EXPECT_TRUE(group_->program_manager() != NULL);
89 EXPECT_TRUE(group_->shader_manager() != NULL);
91 group_->Destroy(decoder_.get(), false);
92 EXPECT_TRUE(group_->buffer_manager() == NULL);
93 EXPECT_TRUE(group_->framebuffer_manager() == NULL);
94 EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
95 EXPECT_TRUE(group_->texture_manager() == NULL);
96 EXPECT_TRUE(group_->program_manager() == NULL);
97 EXPECT_TRUE(group_->shader_manager() == NULL);
100 TEST_F(ContextGroupTest, MultipleContexts) {
101 scoped_ptr<MockGLES2Decoder> decoder2_(new MockGLES2Decoder());
102 TestHelper::SetupContextGroupInitExpectations(
103 gl_.get(), DisallowedFeatures(), "", "", kBindGeneratesResource);
104 group_->Initialize(decoder_.get(), DisallowedFeatures());
105 group_->Initialize(decoder2_.get(), DisallowedFeatures());
107 EXPECT_TRUE(group_->buffer_manager() != NULL);
108 EXPECT_TRUE(group_->framebuffer_manager() != NULL);
109 EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
110 EXPECT_TRUE(group_->texture_manager() != NULL);
111 EXPECT_TRUE(group_->program_manager() != NULL);
112 EXPECT_TRUE(group_->shader_manager() != NULL);
114 group_->Destroy(decoder_.get(), false);
116 EXPECT_TRUE(group_->buffer_manager() != NULL);
117 EXPECT_TRUE(group_->framebuffer_manager() != NULL);
118 EXPECT_TRUE(group_->renderbuffer_manager() != NULL);
119 EXPECT_TRUE(group_->texture_manager() != NULL);
120 EXPECT_TRUE(group_->program_manager() != NULL);
121 EXPECT_TRUE(group_->shader_manager() != NULL);
123 group_->Destroy(decoder2_.get(), false);
125 EXPECT_TRUE(group_->buffer_manager() == NULL);
126 EXPECT_TRUE(group_->framebuffer_manager() == NULL);
127 EXPECT_TRUE(group_->renderbuffer_manager() == NULL);
128 EXPECT_TRUE(group_->texture_manager() == NULL);
129 EXPECT_TRUE(group_->program_manager() == NULL);
130 EXPECT_TRUE(group_->shader_manager() == NULL);
133 } // namespace gles2
134 } // namespace gpu