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

Side by Side Diff: content/renderer/gpu/queue_message_swap_promise_unittest.cc

Issue 2705073003: Remove ScopedVector from content/renderer/. (Closed)
Patch Set: Rebase only Created 3 years, 10 months 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
« no previous file with comments | « content/renderer/gpu/frame_swap_message_queue.h ('k') | content/renderer/history_entry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "content/renderer/gpu/queue_message_swap_promise.h" 5 #include "content/renderer/gpu/queue_message_swap_promise.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/memory/scoped_vector.h"
14 #include "cc/output/swap_promise.h" 14 #include "cc/output/swap_promise.h"
15 #include "content/renderer/gpu/frame_swap_message_queue.h" 15 #include "content/renderer/gpu/frame_swap_message_queue.h"
16 #include "content/renderer/gpu/render_widget_compositor.h" 16 #include "content/renderer/gpu/render_widget_compositor.h"
17 #include "content/renderer/render_widget.h" 17 #include "content/renderer/render_widget.h"
18 #include "content/test/mock_render_process.h" 18 #include "content/test/mock_render_process.h"
19 #include "ipc/ipc_message.h" 19 #include "ipc/ipc_message.h"
20 #include "ipc/ipc_sync_message_filter.h" 20 #include "ipc/ipc_sync_message_filter.h"
21 #include "ipc/ipc_test_sink.h" 21 #include "ipc/ipc_test_sink.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 bool NextSwapHasMessage(const IPC::Message& message) { 102 bool NextSwapHasMessage(const IPC::Message& message) {
103 return ContainsMessage(NextSwapMessages(), message); 103 return ContainsMessage(NextSwapMessages(), message);
104 } 104 }
105 105
106 void QueueMessages(QueueMessageData data[], size_t count) { 106 void QueueMessages(QueueMessageData data[], size_t count) {
107 for (size_t i = 0; i < count; ++i) { 107 for (size_t i = 0; i < count; ++i) {
108 messages_.push_back( 108 messages_.push_back(
109 IPC::Message(0, i + 1, IPC::Message::PRIORITY_NORMAL)); 109 IPC::Message(0, i + 1, IPC::Message::PRIORITY_NORMAL));
110 promises_.push_back( 110 promises_.push_back(QueueMessageImpl(new IPC::Message(messages_[i]),
111 QueueMessageImpl(new IPC::Message(messages_[i]), 111 data[i].policy,
112 data[i].policy, 112 data[i].source_frame_number));
113 data[i].source_frame_number).release());
114 } 113 }
115 } 114 }
116 115
117 void CleanupPromises() { 116 void CleanupPromises() {
118 for (ScopedVector<cc::SwapPromise>::iterator i = promises_.begin(); 117 for (const auto& promise : promises_) {
119 i != promises_.end(); 118 if (promise.get()) {
120 ++i) { 119 promise->DidActivate();
121 if (*i) { 120 promise->WillSwap(NULL);
122 (*i)->DidActivate(); 121 promise->DidSwap();
123 (*i)->WillSwap(NULL);
124 (*i)->DidSwap();
125 } 122 }
126 } 123 }
127 } 124 }
128 125
129 protected: 126 protected:
130 void VisualStateSwapPromiseDidNotSwap( 127 void VisualStateSwapPromiseDidNotSwap(
131 cc::SwapPromise::DidNotSwapReason reason); 128 cc::SwapPromise::DidNotSwapReason reason);
132 129
133 base::MessageLoop message_loop_; 130 base::MessageLoop message_loop_;
134 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_; 131 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_;
135 scoped_refptr<TestSyncMessageFilter> sync_message_filter_; 132 scoped_refptr<TestSyncMessageFilter> sync_message_filter_;
136 std::vector<IPC::Message> messages_; 133 std::vector<IPC::Message> messages_;
137 ScopedVector<cc::SwapPromise> promises_; 134 std::vector<std::unique_ptr<cc::SwapPromise>> promises_;
138 135
139 private: 136 private:
140 std::vector<std::unique_ptr<IPC::Message>> next_swap_messages_; 137 std::vector<std::unique_ptr<IPC::Message>> next_swap_messages_;
141 138
142 DISALLOW_COPY_AND_ASSIGN(QueueMessageSwapPromiseTest); 139 DISALLOW_COPY_AND_ASSIGN(QueueMessageSwapPromiseTest);
143 }; 140 };
144 141
145 TEST_F(QueueMessageSwapPromiseTest, NextSwapPolicySchedulesMessageForNextSwap) { 142 TEST_F(QueueMessageSwapPromiseTest, NextSwapPolicySchedulesMessageForNextSwap) {
146 QueueMessageData data[] = { 143 QueueMessageData data[] = {
147 /* { policy, source_frame_number } */ 144 /* { policy, source_frame_number } */
148 {MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP, 1}, 145 {MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP, 1},
149 }; 146 };
150 QueueMessages(data, arraysize(data)); 147 QueueMessages(data, arraysize(data));
151 148
152 ASSERT_TRUE(promises_[0]); 149 ASSERT_TRUE(promises_[0].get());
153 promises_[0]->DidActivate(); 150 promises_[0]->DidActivate();
154 promises_[0]->WillSwap(NULL); 151 promises_[0]->WillSwap(NULL);
155 promises_[0]->DidSwap(); 152 promises_[0]->DidSwap();
156 153
157 EXPECT_TRUE(DirectSendMessages().empty()); 154 EXPECT_TRUE(DirectSendMessages().empty());
158 EXPECT_FALSE(frame_swap_message_queue_->Empty()); 155 EXPECT_FALSE(frame_swap_message_queue_->Empty());
159 // frame_swap_message_queue_->WillSwap(1); 156 // frame_swap_message_queue_->WillSwap(1);
160 EXPECT_TRUE(NextSwapHasMessage(messages_[0])); 157 EXPECT_TRUE(NextSwapHasMessage(messages_[0]));
161 } 158 }
162 159
163 TEST_F(QueueMessageSwapPromiseTest, NextSwapPolicyNeedsAtMostOnePromise) { 160 TEST_F(QueueMessageSwapPromiseTest, NextSwapPolicyNeedsAtMostOnePromise) {
164 QueueMessageData data[] = { 161 QueueMessageData data[] = {
165 /* { policy, source_frame_number } */ 162 /* { policy, source_frame_number } */
166 {MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP, 1}, 163 {MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP, 1},
167 {MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP, 1}, 164 {MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP, 1},
168 }; 165 };
169 QueueMessages(data, arraysize(data)); 166 QueueMessages(data, arraysize(data));
170 167
171 ASSERT_TRUE(promises_[0]); 168 ASSERT_TRUE(promises_[0].get());
172 ASSERT_FALSE(promises_[1]); 169 ASSERT_FALSE(promises_[1].get());
173 170
174 CleanupPromises(); 171 CleanupPromises();
175 } 172 }
176 173
177 TEST_F(QueueMessageSwapPromiseTest, NextSwapPolicySendsMessageOnNoUpdate) { 174 TEST_F(QueueMessageSwapPromiseTest, NextSwapPolicySendsMessageOnNoUpdate) {
178 QueueMessageData data[] = { 175 QueueMessageData data[] = {
179 /* { policy, source_frame_number } */ 176 /* { policy, source_frame_number } */
180 {MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP, 1}, 177 {MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP, 1},
181 }; 178 };
182 QueueMessages(data, arraysize(data)); 179 QueueMessages(data, arraysize(data));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 212 }
216 213
217 TEST_F(QueueMessageSwapPromiseTest, 214 TEST_F(QueueMessageSwapPromiseTest,
218 VisualStateQueuesMessageWhenCommitRequested) { 215 VisualStateQueuesMessageWhenCommitRequested) {
219 QueueMessageData data[] = { 216 QueueMessageData data[] = {
220 /* { policy, source_frame_number } */ 217 /* { policy, source_frame_number } */
221 {MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE, 1}, 218 {MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE, 1},
222 }; 219 };
223 QueueMessages(data, arraysize(data)); 220 QueueMessages(data, arraysize(data));
224 221
225 ASSERT_TRUE(promises_[0]); 222 ASSERT_TRUE(promises_[0].get());
226 EXPECT_TRUE(DirectSendMessages().empty()); 223 EXPECT_TRUE(DirectSendMessages().empty());
227 EXPECT_FALSE(frame_swap_message_queue_->Empty()); 224 EXPECT_FALSE(frame_swap_message_queue_->Empty());
228 EXPECT_TRUE(NextSwapMessages().empty()); 225 EXPECT_TRUE(NextSwapMessages().empty());
229 226
230 CleanupPromises(); 227 CleanupPromises();
231 } 228 }
232 229
233 TEST_F(QueueMessageSwapPromiseTest, 230 TEST_F(QueueMessageSwapPromiseTest,
234 VisualStateQueuesMessageWhenOtherMessageAlreadyQueued) { 231 VisualStateQueuesMessageWhenOtherMessageAlreadyQueued) {
235 QueueMessageData data[] = { 232 QueueMessageData data[] = {
(...skipping 15 matching lines...) Expand all
251 /* { policy, source_frame_number } */ 248 /* { policy, source_frame_number } */
252 {MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE, 1}, 249 {MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE, 1},
253 {MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE, 1}, 250 {MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE, 1},
254 {MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE, 2}, 251 {MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE, 2},
255 }; 252 };
256 QueueMessages(data, arraysize(data)); 253 QueueMessages(data, arraysize(data));
257 254
258 promises_[0]->DidActivate(); 255 promises_[0]->DidActivate();
259 promises_[0]->WillSwap(NULL); 256 promises_[0]->WillSwap(NULL);
260 promises_[0]->DidSwap(); 257 promises_[0]->DidSwap();
261 ASSERT_FALSE(promises_[1]); 258 ASSERT_FALSE(promises_[1].get());
262 std::vector<std::unique_ptr<IPC::Message>> messages; 259 std::vector<std::unique_ptr<IPC::Message>> messages;
263 messages.swap(NextSwapMessages()); 260 messages.swap(NextSwapMessages());
264 EXPECT_EQ(2u, messages.size()); 261 EXPECT_EQ(2u, messages.size());
265 EXPECT_TRUE(ContainsMessage(messages, messages_[0])); 262 EXPECT_TRUE(ContainsMessage(messages, messages_[0]));
266 EXPECT_TRUE(ContainsMessage(messages, messages_[1])); 263 EXPECT_TRUE(ContainsMessage(messages, messages_[1]));
267 EXPECT_FALSE(ContainsMessage(messages, messages_[2])); 264 EXPECT_FALSE(ContainsMessage(messages, messages_[2]));
268 265
269 promises_[2]->DidActivate(); 266 promises_[2]->DidActivate();
270 promises_[2]->DidNotSwap(cc::SwapPromise::SWAP_FAILS); 267 promises_[2]->DidNotSwap(cc::SwapPromise::SWAP_FAILS);
271 messages.swap(NextSwapMessages()); 268 messages.swap(NextSwapMessages());
(...skipping 16 matching lines...) Expand all
288 }; 285 };
289 QueueMessages(data, arraysize(data)); 286 QueueMessages(data, arraysize(data));
290 287
291 // If we fail to swap with COMMIT_FAILS or ACTIVATE_FAILS, then 288 // If we fail to swap with COMMIT_FAILS or ACTIVATE_FAILS, then
292 // messages are delivered by the RenderFrameHostImpl destructor, 289 // messages are delivered by the RenderFrameHostImpl destructor,
293 // rather than directly by the swap promise. 290 // rather than directly by the swap promise.
294 bool msg_delivered = reason != cc::SwapPromise::COMMIT_FAILS && 291 bool msg_delivered = reason != cc::SwapPromise::COMMIT_FAILS &&
295 reason != cc::SwapPromise::ACTIVATION_FAILS; 292 reason != cc::SwapPromise::ACTIVATION_FAILS;
296 293
297 promises_[0]->DidNotSwap(reason); 294 promises_[0]->DidNotSwap(reason);
298 ASSERT_FALSE(promises_[1]); 295 ASSERT_FALSE(promises_[1].get());
299 EXPECT_TRUE(NextSwapMessages().empty()); 296 EXPECT_TRUE(NextSwapMessages().empty());
300 EXPECT_EQ(msg_delivered, ContainsMessage(DirectSendMessages(), messages_[0])); 297 EXPECT_EQ(msg_delivered, ContainsMessage(DirectSendMessages(), messages_[0]));
301 EXPECT_EQ(msg_delivered, ContainsMessage(DirectSendMessages(), messages_[1])); 298 EXPECT_EQ(msg_delivered, ContainsMessage(DirectSendMessages(), messages_[1]));
302 EXPECT_FALSE(ContainsMessage(DirectSendMessages(), messages_[2])); 299 EXPECT_FALSE(ContainsMessage(DirectSendMessages(), messages_[2]));
303 300
304 promises_[2]->DidNotSwap(reason); 301 promises_[2]->DidNotSwap(reason);
305 EXPECT_TRUE(NextSwapMessages().empty()); 302 EXPECT_TRUE(NextSwapMessages().empty());
306 EXPECT_EQ(msg_delivered, ContainsMessage(DirectSendMessages(), messages_[2])); 303 EXPECT_EQ(msg_delivered, ContainsMessage(DirectSendMessages(), messages_[2]));
307 304
308 EXPECT_TRUE(NextSwapMessages().empty()); 305 EXPECT_TRUE(NextSwapMessages().empty());
(...skipping 12 matching lines...) Expand all
321 TEST_F(QueueMessageSwapPromiseTest, VisualStateSwapPromiseDidNotSwapSwapFails) { 318 TEST_F(QueueMessageSwapPromiseTest, VisualStateSwapPromiseDidNotSwapSwapFails) {
322 VisualStateSwapPromiseDidNotSwap(cc::SwapPromise::SWAP_FAILS); 319 VisualStateSwapPromiseDidNotSwap(cc::SwapPromise::SWAP_FAILS);
323 } 320 }
324 321
325 TEST_F(QueueMessageSwapPromiseTest, 322 TEST_F(QueueMessageSwapPromiseTest,
326 VisualStateSwapPromiseDidNotSwapActivationFails) { 323 VisualStateSwapPromiseDidNotSwapActivationFails) {
327 VisualStateSwapPromiseDidNotSwap(cc::SwapPromise::ACTIVATION_FAILS); 324 VisualStateSwapPromiseDidNotSwap(cc::SwapPromise::ACTIVATION_FAILS);
328 } 325 }
329 326
330 } // namespace content 327 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gpu/frame_swap_message_queue.h ('k') | content/renderer/history_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698