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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/FetchBlobDataConsumerHandleTest.cpp

Issue 1274063003: [Loader] Make ThreadableLoader non-RefCounted and be managed by OwnPtr (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reflect comments. Created 4 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "modules/fetch/FetchBlobDataConsumerHandle.h" 5 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
6 6
7 #include "core/dom/ExecutionContext.h" 7 #include "core/dom/ExecutionContext.h"
8 #include "core/fetch/ResourceLoaderOptions.h" 8 #include "core/fetch/ResourceLoaderOptions.h"
9 #include "core/loader/MockThreadableLoader.h" 9 #include "core/loader/MockThreadableLoader.h"
10 #include "core/loader/ThreadableLoaderClient.h" 10 #include "core/loader/ThreadableLoaderClient.h"
11 #include "core/testing/DummyPageHolder.h" 11 #include "core/testing/DummyPageHolder.h"
12 #include "modules/fetch/DataConsumerHandleTestUtil.h" 12 #include "modules/fetch/DataConsumerHandleTestUtil.h"
13 #include "platform/blob/BlobData.h" 13 #include "platform/blob/BlobData.h"
14 #include "platform/blob/BlobURL.h" 14 #include "platform/blob/BlobURL.h"
15 #include "platform/network/ResourceError.h" 15 #include "platform/network/ResourceError.h"
16 #include "platform/network/ResourceRequest.h" 16 #include "platform/network/ResourceRequest.h"
17 #include "platform/network/ResourceResponse.h" 17 #include "platform/network/ResourceResponse.h"
18 #include "platform/testing/UnitTestHelpers.h" 18 #include "platform/testing/UnitTestHelpers.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "wtf/OwnPtr.h"
21 #include "wtf/PassRefPtr.h" 22 #include "wtf/PassRefPtr.h"
22 #include "wtf/RefPtr.h" 23 #include "wtf/RefPtr.h"
23 #include <string.h> 24 #include <string.h>
24 25
25 namespace blink { 26 namespace blink {
26 namespace { 27 namespace {
27 28
28 using Result = WebDataConsumerHandle::Result; 29 using Result = WebDataConsumerHandle::Result;
29 const Result kShouldWait = WebDataConsumerHandle::ShouldWait; 30 const Result kShouldWait = WebDataConsumerHandle::ShouldWait;
30 const Result kUnexpectedError = WebDataConsumerHandle::UnexpectedError; 31 const Result kUnexpectedError = WebDataConsumerHandle::UnexpectedError;
(...skipping 13 matching lines...) Expand all
44 using ::testing::DoAll; 45 using ::testing::DoAll;
45 using ::testing::InSequence; 46 using ::testing::InSequence;
46 using ::testing::Ref; 47 using ::testing::Ref;
47 using ::testing::Return; 48 using ::testing::Return;
48 using ::testing::SaveArg; 49 using ::testing::SaveArg;
49 using ::testing::StrictMock; 50 using ::testing::StrictMock;
50 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>; 51 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>;
51 52
52 class MockLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory { 53 class MockLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory {
53 public: 54 public:
54 MOCK_METHOD4(create, PassRefPtr<ThreadableLoader>(ExecutionContext&, Threada bleLoaderClient*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&)) ; 55 PassOwnPtr<ThreadableLoader> create(ExecutionContext& executionContext, Thre adableLoaderClient* client, const ThreadableLoaderOptions& threadableLoaderOptio ns, const ResourceLoaderOptions& resourceLoaderOptions) override
56 {
57 return adoptPtr(createInternal(executionContext, client, threadableLoade rOptions, resourceLoaderOptions));
58 }
59
60 MOCK_METHOD4(createInternal, ThreadableLoader*(ExecutionContext&, Threadable LoaderClient*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&));
55 }; 61 };
56 62
57 PassRefPtr<BlobDataHandle> createBlobDataHandle(const char* s) 63 PassRefPtr<BlobDataHandle> createBlobDataHandle(const char* s)
58 { 64 {
59 OwnPtr<BlobData> data = BlobData::create(); 65 OwnPtr<BlobData> data = BlobData::create();
60 data->appendText(s, false); 66 data->appendText(s, false);
61 auto size = data->length(); 67 auto size = data->length();
62 return BlobDataHandle::create(data.release(), size); 68 return BlobDataHandle::create(data.release(), size);
63 } 69 }
64 70
(...skipping 21 matching lines...) Expand all
86 92
87 TEST_F(FetchBlobDataConsumerHandleTest, CreateLoader) 93 TEST_F(FetchBlobDataConsumerHandleTest, CreateLoader)
88 { 94 {
89 auto factory = new StrictMock<MockLoaderFactory>; 95 auto factory = new StrictMock<MockLoaderFactory>;
90 Checkpoint checkpoint; 96 Checkpoint checkpoint;
91 97
92 ResourceRequest request; 98 ResourceRequest request;
93 ThreadableLoaderOptions options; 99 ThreadableLoaderOptions options;
94 ResourceLoaderOptions resourceLoaderOptions; 100 ResourceLoaderOptions resourceLoaderOptions;
95 101
96 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 102 OwnPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
103 MockThreadableLoader* loaderPtr = loader.get();
97 104
98 InSequence s; 105 InSequence s;
99 EXPECT_CALL(checkpoint, Call(1)); 106 EXPECT_CALL(checkpoint, Call(1));
100 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll( 107 EXPECT_CALL(*factory, createInternal(Ref(document()), _, _, _)).WillOnce(DoA ll(
101 SaveArg<2>(&options), 108 SaveArg<2>(&options),
102 SaveArg<3>(&resourceLoaderOptions), 109 SaveArg<3>(&resourceLoaderOptions),
103 Return(loader.get()))); 110 Return(loader.leakPtr())));
104 EXPECT_CALL(*loader, start(_)).WillOnce(SaveArg<0>(&request)); 111 EXPECT_CALL(*loaderPtr, start(_)).WillOnce(SaveArg<0>(&request));
105 EXPECT_CALL(checkpoint, Call(2)); 112 EXPECT_CALL(checkpoint, Call(2));
106 EXPECT_CALL(*loader, cancel()); 113 EXPECT_CALL(*loaderPtr, cancel());
107 114
108 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 115 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
109 OwnPtr<WebDataConsumerHandle> handle 116 OwnPtr<WebDataConsumerHandle> handle
110 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 117 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
111 testing::runPendingTasks(); 118 testing::runPendingTasks();
112 119
113 size_t size = 0; 120 size_t size = 0;
114 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 121 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
115 checkpoint.Call(1); 122 checkpoint.Call(1);
116 testing::runPendingTasks(); 123 testing::runPendingTasks();
(...skipping 13 matching lines...) Expand all
130 EXPECT_EQ(DocumentContext, resourceLoaderOptions.requestInitiatorContext); 137 EXPECT_EQ(DocumentContext, resourceLoaderOptions.requestInitiatorContext);
131 EXPECT_EQ(RequestAsynchronously, resourceLoaderOptions.synchronousPolicy); 138 EXPECT_EQ(RequestAsynchronously, resourceLoaderOptions.synchronousPolicy);
132 EXPECT_EQ(NotCORSEnabled, resourceLoaderOptions.corsEnabled); 139 EXPECT_EQ(NotCORSEnabled, resourceLoaderOptions.corsEnabled);
133 } 140 }
134 141
135 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenStopped) 142 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenStopped)
136 { 143 {
137 auto factory = new StrictMock<MockLoaderFactory>; 144 auto factory = new StrictMock<MockLoaderFactory>;
138 Checkpoint checkpoint; 145 Checkpoint checkpoint;
139 146
140 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 147 OwnPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
148 MockThreadableLoader* loaderPtr = loader.get();
141 149
142 InSequence s; 150 InSequence s;
143 EXPECT_CALL(checkpoint, Call(1)); 151 EXPECT_CALL(checkpoint, Call(1));
144 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(Return(load er.get())); 152 EXPECT_CALL(*factory, createInternal(Ref(document()), _, _, _)).WillOnce(Ret urn(loader.leakPtr()));
145 EXPECT_CALL(*loader, start(_)); 153 EXPECT_CALL(*loaderPtr, start(_));
146 EXPECT_CALL(checkpoint, Call(2)); 154 EXPECT_CALL(checkpoint, Call(2));
147 EXPECT_CALL(*loader, cancel()); 155 EXPECT_CALL(*loaderPtr, cancel());
148 EXPECT_CALL(checkpoint, Call(3)); 156 EXPECT_CALL(checkpoint, Call(3));
149 157
150 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 158 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
151 OwnPtr<WebDataConsumerHandle> handle 159 OwnPtr<WebDataConsumerHandle> handle
152 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 160 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
153 testing::runPendingTasks(); 161 testing::runPendingTasks();
154 162
155 size_t size = 0; 163 size_t size = 0;
156 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 164 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
157 checkpoint.Call(1); 165 checkpoint.Call(1);
158 testing::runPendingTasks(); 166 testing::runPendingTasks();
159 checkpoint.Call(2); 167 checkpoint.Call(2);
160 document().stopActiveDOMObjects(); 168 document().stopActiveDOMObjects();
161 checkpoint.Call(3); 169 checkpoint.Call(3);
162 } 170 }
163 171
164 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenDestinationDetached) 172 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenDestinationDetached)
165 { 173 {
166 auto factory = new StrictMock<MockLoaderFactory>; 174 auto factory = new StrictMock<MockLoaderFactory>;
167 Checkpoint checkpoint; 175 Checkpoint checkpoint;
168 176
169 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 177 OwnPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
178 MockThreadableLoader* loaderPtr = loader.get();
170 179
171 InSequence s; 180 InSequence s;
172 EXPECT_CALL(checkpoint, Call(1)); 181 EXPECT_CALL(checkpoint, Call(1));
173 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(Return(load er.get())); 182 EXPECT_CALL(*factory, createInternal(Ref(document()), _, _, _)).WillOnce(Ret urn(loader.leakPtr()));
174 EXPECT_CALL(*loader, start(_)); 183 EXPECT_CALL(*loaderPtr, start(_));
175 EXPECT_CALL(checkpoint, Call(2)); 184 EXPECT_CALL(checkpoint, Call(2));
176 EXPECT_CALL(checkpoint, Call(3)); 185 EXPECT_CALL(checkpoint, Call(3));
177 EXPECT_CALL(*loader, cancel()); 186 EXPECT_CALL(*loaderPtr, cancel());
178 EXPECT_CALL(checkpoint, Call(4)); 187 EXPECT_CALL(checkpoint, Call(4));
179 188
180 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 189 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
181 OwnPtr<WebDataConsumerHandle> handle 190 OwnPtr<WebDataConsumerHandle> handle
182 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 191 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
183 OwnPtr<WebDataConsumerHandle::Reader> reader = handle->obtainReader(nullptr) ; 192 OwnPtr<WebDataConsumerHandle::Reader> reader = handle->obtainReader(nullptr) ;
184 testing::runPendingTasks(); 193 testing::runPendingTasks();
185 194
186 size_t size = 0; 195 size_t size = 0;
187 reader->read(nullptr, 0, kNone, &size); 196 reader->read(nullptr, 0, kNone, &size);
188 checkpoint.Call(1); 197 checkpoint.Call(1);
189 testing::runPendingTasks(); 198 testing::runPendingTasks();
190 checkpoint.Call(2); 199 checkpoint.Call(2);
191 handle = nullptr; 200 handle = nullptr;
192 reader = nullptr; 201 reader = nullptr;
193 checkpoint.Call(3); 202 checkpoint.Call(3);
194 Heap::collectAllGarbage(); 203 Heap::collectAllGarbage();
195 checkpoint.Call(4); 204 checkpoint.Call(4);
196 } 205 }
197 206
198 TEST_F(FetchBlobDataConsumerHandleTest, ReadTest) 207 TEST_F(FetchBlobDataConsumerHandleTest, ReadTest)
199 { 208 {
200 auto factory = new StrictMock<MockLoaderFactory>; 209 auto factory = new StrictMock<MockLoaderFactory>;
201 Checkpoint checkpoint; 210 Checkpoint checkpoint;
202 211
203 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 212 OwnPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
213 MockThreadableLoader* loaderPtr = loader.get();
204 ThreadableLoaderClient* client = nullptr; 214 ThreadableLoaderClient* client = nullptr;
205 215
206 InSequence s; 216 InSequence s;
207 EXPECT_CALL(checkpoint, Call(1)); 217 EXPECT_CALL(checkpoint, Call(1));
208 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA rg<1>(&client), Return(loader.get()))); 218 EXPECT_CALL(*factory, createInternal(Ref(document()), _, _, _)).WillOnce(DoA ll(SaveArg<1>(&client), Return(loader.leakPtr())));
209 EXPECT_CALL(*loader, start(_)); 219 EXPECT_CALL(*loaderPtr, start(_));
210 EXPECT_CALL(checkpoint, Call(2)); 220 EXPECT_CALL(checkpoint, Call(2));
211 EXPECT_CALL(*loader, cancel()); 221 EXPECT_CALL(*loaderPtr, cancel());
212 222
213 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 223 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
214 OwnPtr<WebDataConsumerHandle> handle 224 OwnPtr<WebDataConsumerHandle> handle
215 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 225 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
216 226
217 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); 227 OwnPtr<ReplayingHandle> src = ReplayingHandle::create();
218 src->add(Command(Command::Wait)); 228 src->add(Command(Command::Wait));
219 src->add(Command(Command::Data, "hello, ")); 229 src->add(Command(Command::Data, "hello, "));
220 src->add(Command(Command::Data, "world")); 230 src->add(Command(Command::Data, "world"));
221 src->add(Command(Command::Wait)); 231 src->add(Command(Command::Wait));
222 src->add(Command(Command::Done)); 232 src->add(Command(Command::Done));
223 233
224 size_t size = 0; 234 size_t size = 0;
225 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 235 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
226 checkpoint.Call(1); 236 checkpoint.Call(1);
227 testing::runPendingTasks(); 237 testing::runPendingTasks();
228 checkpoint.Call(2); 238 checkpoint.Call(2);
229 client->didReceiveResponse(0, ResourceResponse(), src.release()); 239 client->didReceiveResponse(0, ResourceResponse(), src.release());
230 HandleReaderRunner<HandleReader> runner(handle.release()); 240 HandleReaderRunner<HandleReader> runner(handle.release());
231 OwnPtr<HandleReadResult> r = runner.wait(); 241 OwnPtr<HandleReadResult> r = runner.wait();
232 EXPECT_EQ(kDone, r->result()); 242 EXPECT_EQ(kDone, r->result());
233 EXPECT_EQ("hello, world", toString(r->data())); 243 EXPECT_EQ("hello, world", toString(r->data()));
234 } 244 }
235 245
236 TEST_F(FetchBlobDataConsumerHandleTest, TwoPhaseReadTest) 246 TEST_F(FetchBlobDataConsumerHandleTest, TwoPhaseReadTest)
237 { 247 {
238 auto factory = new StrictMock<MockLoaderFactory>; 248 auto factory = new StrictMock<MockLoaderFactory>;
239 Checkpoint checkpoint; 249 Checkpoint checkpoint;
240 250
241 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 251 OwnPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
252 MockThreadableLoader* loaderPtr = loader.get();
242 ThreadableLoaderClient* client = nullptr; 253 ThreadableLoaderClient* client = nullptr;
243 254
244 InSequence s; 255 InSequence s;
245 EXPECT_CALL(checkpoint, Call(1)); 256 EXPECT_CALL(checkpoint, Call(1));
246 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA rg<1>(&client), Return(loader.get()))); 257 EXPECT_CALL(*factory, createInternal(Ref(document()), _, _, _)).WillOnce(DoA ll(SaveArg<1>(&client), Return(loader.leakPtr())));
247 EXPECT_CALL(*loader, start(_)); 258 EXPECT_CALL(*loaderPtr, start(_));
248 EXPECT_CALL(checkpoint, Call(2)); 259 EXPECT_CALL(checkpoint, Call(2));
249 EXPECT_CALL(*loader, cancel()); 260 EXPECT_CALL(*loaderPtr, cancel());
250 261
251 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 262 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
252 OwnPtr<WebDataConsumerHandle> handle 263 OwnPtr<WebDataConsumerHandle> handle
253 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 264 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
254 265
255 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); 266 OwnPtr<ReplayingHandle> src = ReplayingHandle::create();
256 src->add(Command(Command::Wait)); 267 src->add(Command(Command::Wait));
257 src->add(Command(Command::Data, "hello, ")); 268 src->add(Command(Command::Data, "hello, "));
258 src->add(Command(Command::Data, "world")); 269 src->add(Command(Command::Data, "world"));
259 src->add(Command(Command::Wait)); 270 src->add(Command(Command::Wait));
260 src->add(Command(Command::Done)); 271 src->add(Command(Command::Done));
261 272
262 size_t size = 0; 273 size_t size = 0;
263 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 274 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
264 checkpoint.Call(1); 275 checkpoint.Call(1);
265 testing::runPendingTasks(); 276 testing::runPendingTasks();
266 checkpoint.Call(2); 277 checkpoint.Call(2);
267 client->didReceiveResponse(0, ResourceResponse(), src.release()); 278 client->didReceiveResponse(0, ResourceResponse(), src.release());
268 HandleReaderRunner<HandleTwoPhaseReader> runner(handle.release()); 279 HandleReaderRunner<HandleTwoPhaseReader> runner(handle.release());
269 OwnPtr<HandleReadResult> r = runner.wait(); 280 OwnPtr<HandleReadResult> r = runner.wait();
270 EXPECT_EQ(kDone, r->result()); 281 EXPECT_EQ(kDone, r->result());
271 EXPECT_EQ("hello, world", toString(r->data())); 282 EXPECT_EQ("hello, world", toString(r->data()));
272 } 283 }
273 284
274 TEST_F(FetchBlobDataConsumerHandleTest, LoadErrorTest) 285 TEST_F(FetchBlobDataConsumerHandleTest, LoadErrorTest)
275 { 286 {
276 auto factory = new StrictMock<MockLoaderFactory>; 287 auto factory = new StrictMock<MockLoaderFactory>;
277 Checkpoint checkpoint; 288 Checkpoint checkpoint;
278 289
279 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 290 OwnPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
291 MockThreadableLoader* loaderPtr = loader.get();
280 ThreadableLoaderClient* client = nullptr; 292 ThreadableLoaderClient* client = nullptr;
281 293
282 InSequence s; 294 InSequence s;
283 EXPECT_CALL(checkpoint, Call(1)); 295 EXPECT_CALL(checkpoint, Call(1));
284 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA rg<1>(&client), Return(loader.get()))); 296 EXPECT_CALL(*factory, createInternal(Ref(document()), _, _, _)).WillOnce(DoA ll(SaveArg<1>(&client), Return(loader.leakPtr())));
285 EXPECT_CALL(*loader, start(_)); 297 EXPECT_CALL(*loaderPtr, start(_));
286 EXPECT_CALL(checkpoint, Call(2)); 298 EXPECT_CALL(checkpoint, Call(2));
287 299
288 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 300 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
289 OwnPtr<WebDataConsumerHandle> handle 301 OwnPtr<WebDataConsumerHandle> handle
290 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 302 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
291 303
292 size_t size = 0; 304 size_t size = 0;
293 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 305 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
294 checkpoint.Call(1); 306 checkpoint.Call(1);
295 testing::runPendingTasks(); 307 testing::runPendingTasks();
296 checkpoint.Call(2); 308 checkpoint.Call(2);
297 client->didFail(ResourceError()); 309 client->didFail(ResourceError());
298 HandleReaderRunner<HandleReader> runner(handle.release()); 310 HandleReaderRunner<HandleReader> runner(handle.release());
299 OwnPtr<HandleReadResult> r = runner.wait(); 311 OwnPtr<HandleReadResult> r = runner.wait();
300 EXPECT_EQ(kUnexpectedError, r->result()); 312 EXPECT_EQ(kUnexpectedError, r->result());
301 } 313 }
302 314
303 TEST_F(FetchBlobDataConsumerHandleTest, BodyLoadErrorTest) 315 TEST_F(FetchBlobDataConsumerHandleTest, BodyLoadErrorTest)
304 { 316 {
305 auto factory = new StrictMock<MockLoaderFactory>; 317 auto factory = new StrictMock<MockLoaderFactory>;
306 Checkpoint checkpoint; 318 Checkpoint checkpoint;
307 319
308 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 320 OwnPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
321 MockThreadableLoader* loaderPtr = loader.get();
309 ThreadableLoaderClient* client = nullptr; 322 ThreadableLoaderClient* client = nullptr;
310 323
311 InSequence s; 324 InSequence s;
312 EXPECT_CALL(checkpoint, Call(1)); 325 EXPECT_CALL(checkpoint, Call(1));
313 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA rg<1>(&client), Return(loader.get()))); 326 EXPECT_CALL(*factory, createInternal(Ref(document()), _, _, _)).WillOnce(DoA ll(SaveArg<1>(&client), Return(loader.leakPtr())));
314 EXPECT_CALL(*loader, start(_)); 327 EXPECT_CALL(*loaderPtr, start(_));
315 EXPECT_CALL(checkpoint, Call(2)); 328 EXPECT_CALL(checkpoint, Call(2));
316 EXPECT_CALL(*loader, cancel()); 329 EXPECT_CALL(*loaderPtr, cancel());
317 330
318 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 331 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
319 OwnPtr<WebDataConsumerHandle> handle 332 OwnPtr<WebDataConsumerHandle> handle
320 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 333 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
321 334
322 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); 335 OwnPtr<ReplayingHandle> src = ReplayingHandle::create();
323 src->add(Command(Command::Wait)); 336 src->add(Command(Command::Wait));
324 src->add(Command(Command::Data, "hello, ")); 337 src->add(Command(Command::Data, "hello, "));
325 src->add(Command(Command::Error)); 338 src->add(Command(Command::Error));
326 339
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(nullpt r); 423 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(nullpt r);
411 424
412 const void* buffer; 425 const void* buffer;
413 size_t available; 426 size_t available;
414 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); 427 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available));
415 EXPECT_FALSE(reader->drainAsBlobDataHandle()); 428 EXPECT_FALSE(reader->drainAsBlobDataHandle());
416 } 429 }
417 430
418 } // namespace 431 } // namespace
419 } // namespace blink 432 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698