Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Side by Side Diff: gpu/command_buffer/service/valuebuffer_manager_unittest.cc

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/valuebuffer_manager.h" 5 #include "gpu/command_buffer/service/valuebuffer_manager.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "gpu/command_buffer/common/gles2_cmd_format.h" 10 #include "gpu/command_buffer/common/gles2_cmd_format.h"
11 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 11 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
12 #include "gpu/command_buffer/common/value_state.h" 12 #include "gpu/command_buffer/common/value_state.h"
13 #include "gpu/command_buffer/service/common_decoder.h" 13 #include "gpu/command_buffer/service/common_decoder.h"
14 #include "gpu/command_buffer/service/feature_info.h" 14 #include "gpu/command_buffer/service/feature_info.h"
15 #include "gpu/command_buffer/service/gpu_service_test.h" 15 #include "gpu/command_buffer/service/gpu_service_test.h"
16 #include "gpu/command_buffer/service/mocks.h" 16 #include "gpu/command_buffer/service/mocks.h"
17 #include "gpu/command_buffer/service/test_helper.h" 17 #include "gpu/command_buffer/service/test_helper.h"
18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gl/gl_bindings.h" 20 #include "ui/gl/gl_bindings.h"
20 #include "ui/gl/gl_mock.h" 21 #include "ui/gl/gl_mock.h"
21 22
22 namespace gpu { 23 namespace gpu {
23 namespace gles2 { 24 namespace gles2 {
24 25
26 class MockSubscriptionRefSetObserver : public SubscriptionRefSet::Observer {
27 public:
28 MOCK_METHOD1(OnAddSubscription, void(unsigned int target));
29 MOCK_METHOD1(OnRemoveSubscription, void(unsigned int target));
30 };
31
25 class ValuebufferManagerTest : public GpuServiceTest { 32 class ValuebufferManagerTest : public GpuServiceTest {
26 public: 33 public:
27 ValuebufferManagerTest() {} 34 ValuebufferManagerTest() {}
28 ~ValuebufferManagerTest() {} 35 ~ValuebufferManagerTest() {}
29 36
30 void SetUp() override { 37 void SetUp() override {
31 GpuServiceTest::SetUp(); 38 GpuServiceTest::SetUp();
39 subscription_ref_set_ = new SubscriptionRefSet();
32 pending_state_map_ = new ValueStateMap(); 40 pending_state_map_ = new ValueStateMap();
33 manager_.reset(new ValuebufferManager(pending_state_map_.get())); 41 subscription_ref_set_->AddObserver(&mock_observer_);
42 manager_.reset(new ValuebufferManager(subscription_ref_set_.get(),
43 pending_state_map_.get()));
34 } 44 }
35 45
36 void TearDown() override { 46 void TearDown() override {
37 manager_->Destroy(); 47 manager_->Destroy();
48 subscription_ref_set_->RemoveObserver(&mock_observer_);
38 GpuServiceTest::TearDown(); 49 GpuServiceTest::TearDown();
39 } 50 }
40 51
41 protected: 52 protected:
53 MockSubscriptionRefSetObserver mock_observer_;
54
55 scoped_refptr<SubscriptionRefSet> subscription_ref_set_;
42 scoped_refptr<ValueStateMap> pending_state_map_; 56 scoped_refptr<ValueStateMap> pending_state_map_;
43 scoped_ptr<ValuebufferManager> manager_; 57 scoped_ptr<ValuebufferManager> manager_;
44 }; 58 };
45 59
46 TEST_F(ValuebufferManagerTest, Basic) { 60 TEST_F(ValuebufferManagerTest, Basic) {
47 const GLuint kClient1Id = 1; 61 const GLuint kClient1Id = 1;
48 const GLuint kClient2Id = 2; 62 const GLuint kClient2Id = 2;
49 // Check we can create a Valuebuffer 63 // Check we can create a Valuebuffer
50 manager_->CreateValuebuffer(kClient1Id); 64 manager_->CreateValuebuffer(kClient1Id);
51 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id); 65 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 ASSERT_TRUE(new_state1->int_value[0] == 111); 116 ASSERT_TRUE(new_state1->int_value[0] == 111);
103 // Ensure state changes 117 // Ensure state changes
104 pending_state_map_->UpdateState(GL_MOUSE_POSITION_CHROMIUM, valuestate2); 118 pending_state_map_->UpdateState(GL_MOUSE_POSITION_CHROMIUM, valuestate2);
105 manager_->UpdateValuebufferState(valuebuffer0); 119 manager_->UpdateValuebufferState(valuebuffer0);
106 const ValueState* new_state2 = 120 const ValueState* new_state2 =
107 valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM); 121 valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM);
108 ASSERT_TRUE(new_state2 != NULL); 122 ASSERT_TRUE(new_state2 != NULL);
109 ASSERT_TRUE(new_state2->int_value[0] == 222); 123 ASSERT_TRUE(new_state2->int_value[0] == 222);
110 } 124 }
111 125
126 TEST_F(ValuebufferManagerTest, NotifySubscriptionRefs) {
127 const GLuint kClientId1 = 1;
128 const GLuint kClientId2 = 2;
129 manager_->CreateValuebuffer(kClientId1);
130 Valuebuffer* valuebuffer1 = manager_->GetValuebuffer(kClientId1);
131 ASSERT_TRUE(valuebuffer1 != NULL);
132 manager_->CreateValuebuffer(kClientId2);
133 Valuebuffer* valuebuffer2 = manager_->GetValuebuffer(kClientId2);
134 ASSERT_TRUE(valuebuffer2 != NULL);
135 EXPECT_CALL(mock_observer_, OnAddSubscription(GL_MOUSE_POSITION_CHROMIUM))
136 .Times(1);
137 valuebuffer1->AddSubscription(GL_MOUSE_POSITION_CHROMIUM);
138 EXPECT_CALL(mock_observer_, OnAddSubscription(GL_MOUSE_POSITION_CHROMIUM))
139 .Times(0);
140 valuebuffer2->AddSubscription(GL_MOUSE_POSITION_CHROMIUM);
141 EXPECT_CALL(mock_observer_, OnRemoveSubscription(GL_MOUSE_POSITION_CHROMIUM))
142 .Times(0);
143 valuebuffer1->RemoveSubscription(GL_MOUSE_POSITION_CHROMIUM);
144 // Ensure the manager still thinks a buffer has a reference to the
145 // subscription target.
146 EXPECT_CALL(mock_observer_, OnRemoveSubscription(GL_MOUSE_POSITION_CHROMIUM))
147 .Times(1);
148 valuebuffer2->RemoveSubscription(GL_MOUSE_POSITION_CHROMIUM);
149 }
150
112 } // namespace gles2 151 } // namespace gles2
113 } // namespace gpu 152 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/valuebuffer_manager.cc ('k') | gpu/command_buffer/tests/gl_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698