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

Side by Side Diff: content/child/web_data_consumer_handle_impl_unittest.cc

Issue 1544293002: Convert Pass()→std::move() in //content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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/child/web_data_consumer_handle_impl.h" 5 #include "content/child/web_data_consumer_handle_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9
10 #include <algorithm> 9 #include <algorithm>
11 #include <string> 10 #include <string>
11 #include <utility>
12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
18 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
19 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
20 #include "mojo/public/cpp/system/data_pipe.h" 21 #include "mojo/public/cpp/system/data_pipe.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 private: 55 private:
55 ReadDataOperationBase* operation_; 56 ReadDataOperationBase* operation_;
56 }; 57 };
57 58
58 class ReadDataOperation : public ReadDataOperationBase { 59 class ReadDataOperation : public ReadDataOperationBase {
59 public: 60 public:
60 typedef WebDataConsumerHandle::Result Result; 61 typedef WebDataConsumerHandle::Result Result;
61 ReadDataOperation(mojo::ScopedDataPipeConsumerHandle handle, 62 ReadDataOperation(mojo::ScopedDataPipeConsumerHandle handle,
62 base::MessageLoop* main_message_loop, 63 base::MessageLoop* main_message_loop,
63 const base::Closure& on_done) 64 const base::Closure& on_done)
64 : handle_(new WebDataConsumerHandleImpl(handle.Pass())), 65 : handle_(new WebDataConsumerHandleImpl(std::move(handle))),
65 main_message_loop_(main_message_loop), 66 main_message_loop_(main_message_loop),
66 on_done_(on_done) {} 67 on_done_(on_done) {}
67 68
68 const std::string& result() const { return result_; } 69 const std::string& result() const { return result_; }
69 70
70 void ReadMore() override { ReadData(); } 71 void ReadMore() override { ReadData(); }
71 72
72 void ReadData() { 73 void ReadData() {
73 if (!client_) { 74 if (!client_) {
74 client_.reset(new ClientImpl(this)); 75 client_.reset(new ClientImpl(this));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 base::Closure on_done_; 110 base::Closure on_done_;
110 std::string result_; 111 std::string result_;
111 }; 112 };
112 113
113 class TwoPhaseReadDataOperation : public ReadDataOperationBase { 114 class TwoPhaseReadDataOperation : public ReadDataOperationBase {
114 public: 115 public:
115 typedef WebDataConsumerHandle::Result Result; 116 typedef WebDataConsumerHandle::Result Result;
116 TwoPhaseReadDataOperation(mojo::ScopedDataPipeConsumerHandle handle, 117 TwoPhaseReadDataOperation(mojo::ScopedDataPipeConsumerHandle handle,
117 base::MessageLoop* main_message_loop, 118 base::MessageLoop* main_message_loop,
118 const base::Closure& on_done) 119 const base::Closure& on_done)
119 : handle_(new WebDataConsumerHandleImpl(handle.Pass())), 120 : handle_(new WebDataConsumerHandleImpl(std::move(handle))),
120 main_message_loop_(main_message_loop), on_done_(on_done) {} 121 main_message_loop_(main_message_loop),
122 on_done_(on_done) {}
121 123
122 const std::string& result() const { return result_; } 124 const std::string& result() const { return result_; }
123 125
124 void ReadMore() override { 126 void ReadMore() override {
125 ReadData(); 127 ReadData();
126 } 128 }
127 129
128 void ReadData() { 130 void ReadData() {
129 if (!client_) { 131 if (!client_) {
130 client_.reset(new ClientImpl(this)); 132 client_.reset(new ClientImpl(this));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 223
222 base::MessageLoop message_loop_; 224 base::MessageLoop message_loop_;
223 225
224 mojo::ScopedDataPipeProducerHandle producer_; 226 mojo::ScopedDataPipeProducerHandle producer_;
225 mojo::ScopedDataPipeConsumerHandle consumer_; 227 mojo::ScopedDataPipeConsumerHandle consumer_;
226 }; 228 };
227 229
228 TEST_F(WebDataConsumerHandleImplTest, ReadData) { 230 TEST_F(WebDataConsumerHandleImplTest, ReadData) {
229 base::RunLoop run_loop; 231 base::RunLoop run_loop;
230 auto operation = make_scoped_ptr(new ReadDataOperation( 232 auto operation = make_scoped_ptr(new ReadDataOperation(
231 consumer_.Pass(), 233 std::move(consumer_), &message_loop_, run_loop.QuitClosure()));
232 &message_loop_,
233 run_loop.QuitClosure()));
234 234
235 base::Thread t("DataConsumerHandle test thread"); 235 base::Thread t("DataConsumerHandle test thread");
236 ASSERT_TRUE(t.Start()); 236 ASSERT_TRUE(t.Start());
237 237
238 t.task_runner()->PostTask(FROM_HERE, 238 t.task_runner()->PostTask(FROM_HERE,
239 base::Bind(&ReadDataOperation::ReadData, 239 base::Bind(&ReadDataOperation::ReadData,
240 base::Unretained(operation.get()))); 240 base::Unretained(operation.get())));
241 241
242 std::string expected = ProduceData(24 * 1024); 242 std::string expected = ProduceData(24 * 1024);
243 producer_.reset(); 243 producer_.reset();
244 244
245 run_loop.Run(); 245 run_loop.Run();
246 t.Stop(); 246 t.Stop();
247 247
248 EXPECT_EQ(expected, operation->result()); 248 EXPECT_EQ(expected, operation->result());
249 } 249 }
250 250
251 TEST_F(WebDataConsumerHandleImplTest, TwoPhaseReadData) { 251 TEST_F(WebDataConsumerHandleImplTest, TwoPhaseReadData) {
252 base::RunLoop run_loop; 252 base::RunLoop run_loop;
253 auto operation = make_scoped_ptr(new TwoPhaseReadDataOperation( 253 auto operation = make_scoped_ptr(new TwoPhaseReadDataOperation(
254 consumer_.Pass(), 254 std::move(consumer_), &message_loop_, run_loop.QuitClosure()));
255 &message_loop_,
256 run_loop.QuitClosure()));
257 255
258 base::Thread t("DataConsumerHandle test thread"); 256 base::Thread t("DataConsumerHandle test thread");
259 ASSERT_TRUE(t.Start()); 257 ASSERT_TRUE(t.Start());
260 258
261 t.task_runner()->PostTask(FROM_HERE, 259 t.task_runner()->PostTask(FROM_HERE,
262 base::Bind(&TwoPhaseReadDataOperation::ReadData, 260 base::Bind(&TwoPhaseReadDataOperation::ReadData,
263 base::Unretained(operation.get()))); 261 base::Unretained(operation.get())));
264 262
265 std::string expected = ProduceData(24 * 1024); 263 std::string expected = ProduceData(24 * 1024);
266 producer_.reset(); 264 producer_.reset();
267 265
268 run_loop.Run(); 266 run_loop.Run();
269 t.Stop(); 267 t.Stop();
270 268
271 EXPECT_EQ(expected, operation->result()); 269 EXPECT_EQ(expected, operation->result());
272 } 270 }
273 271
274 } // namespace 272 } // namespace
275 273
276 } // namespace content 274 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_data_consumer_handle_impl.cc ('k') | content/child/web_discardable_memory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698