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

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

Issue 2177243002: Use per-frame TaskRunner instead of thread's default in DataConsumerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_consumer_handle_unique_ptr
Patch Set: update Created 4 years, 4 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 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
21 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "mojo/public/cpp/system/data_pipe.h" 23 #include "mojo/public/cpp/system/data_pipe.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/WebKit/public/platform/WebTaskRunner.h"
25 26
26 namespace content { 27 namespace content {
27 28
28 namespace { 29 namespace {
29 30
30 using blink::WebDataConsumerHandle; 31 using blink::WebDataConsumerHandle;
31 32
32 class ReadDataOperationBase { 33 class ReadDataOperationBase {
33 public: 34 public:
34 virtual ~ReadDataOperationBase() {} 35 virtual ~ReadDataOperationBase() {}
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 73
73 void ReadMore() override { 74 void ReadMore() override {
74 // We may have drained the pipe while this task was waiting to run. 75 // We may have drained the pipe while this task was waiting to run.
75 if (reader_) 76 if (reader_)
76 ReadData(); 77 ReadData();
77 } 78 }
78 79
79 void ReadData() { 80 void ReadData() {
80 if (!client_) { 81 if (!client_) {
81 client_.reset(new ClientImpl(this)); 82 client_.reset(new ClientImpl(this));
82 reader_ = handle_->obtainReader(client_.get()); 83 reader_ = handle_->obtainReader(client_.get(), nullptr);
83 } 84 }
84 85
85 Result rv = kOk; 86 Result rv = kOk;
86 size_t readSize = 0; 87 size_t readSize = 0;
87 while (true) { 88 while (true) {
88 char buffer[16]; 89 char buffer[16];
89 rv = reader_->read(&buffer, sizeof(buffer), kNone, &readSize); 90 rv = reader_->read(&buffer, sizeof(buffer), kNone, &readSize);
90 if (rv != kOk) 91 if (rv != kOk)
91 break; 92 break;
92 result_.insert(result_.size(), &buffer[0], readSize); 93 result_.insert(result_.size(), &buffer[0], readSize);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 131
131 void ReadMore() override { 132 void ReadMore() override {
132 // We may have drained the pipe while this task was waiting to run. 133 // We may have drained the pipe while this task was waiting to run.
133 if (reader_) 134 if (reader_)
134 ReadData(); 135 ReadData();
135 } 136 }
136 137
137 void ReadData() { 138 void ReadData() {
138 if (!client_) { 139 if (!client_) {
139 client_.reset(new ClientImpl(this)); 140 client_.reset(new ClientImpl(this));
140 reader_ = handle_->obtainReader(client_.get()); 141 reader_ = handle_->obtainReader(client_.get(), nullptr);
141 } 142 }
142 143
143 Result rv; 144 Result rv;
144 while (true) { 145 while (true) {
145 const void* buffer = nullptr; 146 const void* buffer = nullptr;
146 size_t size; 147 size_t size;
147 rv = reader_->beginRead(&buffer, kNone, &size); 148 rv = reader_->beginRead(&buffer, kNone, &size);
148 if (rv != kOk) 149 if (rv != kOk)
149 break; 150 break;
150 // In order to verify endRead, we read at most one byte for each time. 151 // In order to verify endRead, we read at most one byte for each time.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 273
273 run_loop.Run(); 274 run_loop.Run();
274 t.Stop(); 275 t.Stop();
275 276
276 EXPECT_EQ(expected, operation->result()); 277 EXPECT_EQ(expected, operation->result());
277 } 278 }
278 279
279 } // namespace 280 } // namespace
280 281
281 } // namespace content 282 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698