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

Side by Side Diff: content/renderer/scheduler/resource_dispatch_throttler_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/render_thread_impl_discardable_memory_browsertest.cc ('k') | no next file » | 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/scheduler/resource_dispatch_throttler.h" 5 #include "content/renderer/scheduler/resource_dispatch_throttler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
11 #include <vector>
12
10 #include "base/macros.h" 13 #include "base/macros.h"
11 #include "base/memory/scoped_vector.h" 14 #include "base/memory/ptr_util.h"
12 #include "content/common/resource_messages.h" 15 #include "content/common/resource_messages.h"
13 #include "content/common/resource_request.h" 16 #include "content/common/resource_request.h"
14 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/scheduler/test/fake_renderer_schedu ler.h" 18 #include "third_party/WebKit/public/platform/scheduler/test/fake_renderer_schedu ler.h"
16 19
17 namespace content { 20 namespace content {
18 namespace { 21 namespace {
19 22
20 const uint32_t kRequestsPerFlush = 4; 23 const uint32_t kRequestsPerFlush = 4;
21 const double kFlushPeriodSeconds = 1.f / 60; 24 const double kFlushPeriodSeconds = 1.f / 60;
22 const int kRoutingId = 1; 25 const int kRoutingId = 1;
23 26
24 typedef ScopedVector<IPC::Message> ScopedMessages; 27 typedef std::vector<std::unique_ptr<IPC::Message>> ScopedMessages;
25 28
26 int GetRequestId(const IPC::Message& msg) { 29 int GetRequestId(const IPC::Message& msg) {
27 int request_id = -1; 30 int request_id = -1;
28 switch (msg.type()) { 31 switch (msg.type()) {
29 case ResourceHostMsg_RequestResource::ID: { 32 case ResourceHostMsg_RequestResource::ID: {
30 base::PickleIterator iter(msg); 33 base::PickleIterator iter(msg);
31 int routing_id = -1; 34 int routing_id = -1;
32 if (!iter.ReadInt(&routing_id) || !iter.ReadInt(&request_id)) 35 if (!iter.ReadInt(&routing_id) || !iter.ReadInt(&request_id))
33 NOTREACHED() << "Invalid id for resource request message."; 36 NOTREACHED() << "Invalid id for resource request message.";
34 } break; 37 } break;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 109
107 class ResourceDispatchThrottlerTest : public testing::Test, public IPC::Sender { 110 class ResourceDispatchThrottlerTest : public testing::Test, public IPC::Sender {
108 public: 111 public:
109 ResourceDispatchThrottlerTest() : last_request_id_(0) { 112 ResourceDispatchThrottlerTest() : last_request_id_(0) {
110 throttler_.reset(new ResourceDispatchThrottlerForTest(this, &scheduler_)); 113 throttler_.reset(new ResourceDispatchThrottlerForTest(this, &scheduler_));
111 } 114 }
112 ~ResourceDispatchThrottlerTest() override {} 115 ~ResourceDispatchThrottlerTest() override {}
113 116
114 // IPC::Sender implementation: 117 // IPC::Sender implementation:
115 bool Send(IPC::Message* msg) override { 118 bool Send(IPC::Message* msg) override {
116 sent_messages_.push_back(msg); 119 sent_messages_.push_back(base::WrapUnique(msg));
117 return true; 120 return true;
118 } 121 }
119 122
120 protected: 123 protected:
121 void SetHighPriorityWorkAnticipated(bool anticipated) { 124 void SetHighPriorityWorkAnticipated(bool anticipated) {
122 scheduler_.set_high_priority_work_anticipated(anticipated); 125 scheduler_.set_high_priority_work_anticipated(anticipated);
123 } 126 }
124 127
125 void Advance(base::TimeDelta delta) { throttler_->Advance(delta); } 128 void Advance(base::TimeDelta delta) { throttler_->Advance(delta); }
126 129
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return throttler_->Send(new ResourceHostMsg_CancelRequest(request_id)); 166 return throttler_->Send(new ResourceHostMsg_CancelRequest(request_id));
164 } 167 }
165 168
166 size_t GetAndResetSentMessageCount() { 169 size_t GetAndResetSentMessageCount() {
167 size_t sent_message_count = sent_messages_.size(); 170 size_t sent_message_count = sent_messages_.size();
168 sent_messages_.clear(); 171 sent_messages_.clear();
169 return sent_message_count; 172 return sent_message_count;
170 } 173 }
171 174
172 const IPC::Message* LastSentMessage() const { 175 const IPC::Message* LastSentMessage() const {
173 return sent_messages_.empty() ? nullptr : sent_messages_.back(); 176 return sent_messages_.empty() ? nullptr : sent_messages_.back().get();
174 } 177 }
175 178
176 int LastSentRequestId() const { 179 int LastSentRequestId() const {
177 const IPC::Message* msg = LastSentMessage(); 180 const IPC::Message* msg = LastSentMessage();
178 if (!msg) 181 if (!msg)
179 return -1; 182 return -1;
180 183
181 int routing_id = -1; 184 int routing_id = -1;
182 int request_id = -1; 185 int request_id = -1;
183 base::PickleIterator iter(*msg); 186 base::PickleIterator iter(*msg);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 EXPECT_EQ(priority_msg.type(), ResourceHostMsg_DidChangePriority::ID); 410 EXPECT_EQ(priority_msg.type(), ResourceHostMsg_DidChangePriority::ID);
408 EXPECT_EQ(cancel_msg.type(), ResourceHostMsg_CancelRequest::ID); 411 EXPECT_EQ(cancel_msg.type(), ResourceHostMsg_CancelRequest::ID);
409 412
410 EXPECT_EQ(GetRequestId(request_msg), GetRequestId(priority_msg)); 413 EXPECT_EQ(GetRequestId(request_msg), GetRequestId(priority_msg));
411 EXPECT_EQ(GetRequestId(request_msg) - 1, GetRequestId(cancel_msg)); 414 EXPECT_EQ(GetRequestId(request_msg) - 1, GetRequestId(cancel_msg));
412 } 415 }
413 EXPECT_FALSE(FlushScheduled()); 416 EXPECT_FALSE(FlushScheduled());
414 } 417 }
415 418
416 } // namespace content 419 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl_discardable_memory_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698