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

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

Powered by Google App Engine
This is Rietveld 408576698