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

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

Issue 1264453002: Split the constructor of ThreadableLoader into two methods (ctor and start()) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 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 "config.h" 5 #include "config.h"
6 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 6 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
7 7
8 #include "core/dom/ExecutionContext.h" 8 #include "core/dom/ExecutionContext.h"
9 #include "core/fetch/ResourceLoaderOptions.h" 9 #include "core/fetch/ResourceLoaderOptions.h"
10 #include "core/loader/ThreadableLoader.h" 10 #include "core/loader/ThreadableLoader.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 using ::testing::DoAll; 45 using ::testing::DoAll;
46 using ::testing::InSequence; 46 using ::testing::InSequence;
47 using ::testing::Ref; 47 using ::testing::Ref;
48 using ::testing::Return; 48 using ::testing::Return;
49 using ::testing::SaveArg; 49 using ::testing::SaveArg;
50 using ::testing::StrictMock; 50 using ::testing::StrictMock;
51 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>; 51 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>;
52 52
53 class MockLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory { 53 class MockLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory {
54 public: 54 public:
55 MOCK_METHOD5(create, PassRefPtr<ThreadableLoader>(ExecutionContext&, Threada bleLoaderClient*, const ResourceRequest&, const ThreadableLoaderOptions&, const ResourceLoaderOptions&)); 55 MOCK_METHOD4(create, PassRefPtr<ThreadableLoader>(ExecutionContext&, Threada bleLoaderClient*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&)) ;
56 }; 56 };
57 57
58 class MockThreadableLoader : public ThreadableLoader { 58 class MockThreadableLoader : public ThreadableLoader {
59 public: 59 public:
60 static PassRefPtr<MockThreadableLoader> create() { return adoptRef(new Stric tMock<MockThreadableLoader>); } 60 static PassRefPtr<MockThreadableLoader> create() { return adoptRef(new Stric tMock<MockThreadableLoader>); }
61 61
62 MOCK_METHOD1(start, void(const ResourceRequest&));
62 MOCK_METHOD1(overrideTimeout, void(unsigned long)); 63 MOCK_METHOD1(overrideTimeout, void(unsigned long));
63 MOCK_METHOD0(cancel, void()); 64 MOCK_METHOD0(cancel, void());
64 65
65 protected: 66 protected:
66 MockThreadableLoader() = default; 67 MockThreadableLoader() = default;
67 }; 68 };
68 69
69 PassRefPtr<BlobDataHandle> createBlobDataHandle(const char* s) 70 PassRefPtr<BlobDataHandle> createBlobDataHandle(const char* s)
70 { 71 {
71 OwnPtr<BlobData> data = BlobData::create(); 72 OwnPtr<BlobData> data = BlobData::create();
(...skipping 30 matching lines...) Expand all
102 Checkpoint checkpoint; 103 Checkpoint checkpoint;
103 104
104 ResourceRequest request; 105 ResourceRequest request;
105 ThreadableLoaderOptions options; 106 ThreadableLoaderOptions options;
106 ResourceLoaderOptions resourceLoaderOptions; 107 ResourceLoaderOptions resourceLoaderOptions;
107 108
108 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 109 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
109 110
110 InSequence s; 111 InSequence s;
111 EXPECT_CALL(checkpoint, Call(1)); 112 EXPECT_CALL(checkpoint, Call(1));
112 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll( 113 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(
113 SaveArg<2>(&request), 114 SaveArg<2>(&options),
114 SaveArg<3>(&options), 115 SaveArg<3>(&resourceLoaderOptions),
115 SaveArg<4>(&resourceLoaderOptions),
116 Return(loader.get()))); 116 Return(loader.get())));
117 EXPECT_CALL(*loader, start(_));
hiroshige 2015/07/28 11:35:37 saveArg<1>(&request) might fix the unit test failu
tyoshino (SeeGerritForStatus) 2015/07/28 12:21:51 Done.
117 EXPECT_CALL(checkpoint, Call(2)); 118 EXPECT_CALL(checkpoint, Call(2));
118 EXPECT_CALL(*loader, cancel()); 119 EXPECT_CALL(*loader, cancel());
119 120
120 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 121 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
121 OwnPtr<WebDataConsumerHandle> handle 122 OwnPtr<WebDataConsumerHandle> handle
122 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 123 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
123 testing::runPendingTasks(); 124 testing::runPendingTasks();
124 125
125 size_t size = 0; 126 size_t size = 0;
126 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 127 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
(...skipping 19 matching lines...) Expand all
146 147
147 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenStopped) 148 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenStopped)
148 { 149 {
149 auto factory = new StrictMock<MockLoaderFactory>; 150 auto factory = new StrictMock<MockLoaderFactory>;
150 Checkpoint checkpoint; 151 Checkpoint checkpoint;
151 152
152 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 153 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
153 154
154 InSequence s; 155 InSequence s;
155 EXPECT_CALL(checkpoint, Call(1)); 156 EXPECT_CALL(checkpoint, Call(1));
156 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(Return(l oader.get())); 157 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(Return(load er.get()));
158 EXPECT_CALL(*loader, start(_));
157 EXPECT_CALL(checkpoint, Call(2)); 159 EXPECT_CALL(checkpoint, Call(2));
158 EXPECT_CALL(*loader, cancel()); 160 EXPECT_CALL(*loader, cancel());
159 EXPECT_CALL(checkpoint, Call(3)); 161 EXPECT_CALL(checkpoint, Call(3));
160 162
161 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 163 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
162 OwnPtr<WebDataConsumerHandle> handle 164 OwnPtr<WebDataConsumerHandle> handle
163 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 165 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
164 testing::runPendingTasks(); 166 testing::runPendingTasks();
165 167
166 size_t size = 0; 168 size_t size = 0;
167 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 169 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
168 checkpoint.Call(1); 170 checkpoint.Call(1);
169 testing::runPendingTasks(); 171 testing::runPendingTasks();
170 checkpoint.Call(2); 172 checkpoint.Call(2);
171 document().stopActiveDOMObjects(); 173 document().stopActiveDOMObjects();
172 checkpoint.Call(3); 174 checkpoint.Call(3);
173 } 175 }
174 176
175 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenDestinationDetached) 177 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenDestinationDetached)
176 { 178 {
177 auto factory = new StrictMock<MockLoaderFactory>; 179 auto factory = new StrictMock<MockLoaderFactory>;
178 Checkpoint checkpoint; 180 Checkpoint checkpoint;
179 181
180 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 182 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
181 183
182 InSequence s; 184 InSequence s;
183 EXPECT_CALL(checkpoint, Call(1)); 185 EXPECT_CALL(checkpoint, Call(1));
184 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(Return(l oader.get())); 186 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(Return(load er.get()));
187 EXPECT_CALL(*loader, start(_));
185 EXPECT_CALL(checkpoint, Call(2)); 188 EXPECT_CALL(checkpoint, Call(2));
186 EXPECT_CALL(checkpoint, Call(3)); 189 EXPECT_CALL(checkpoint, Call(3));
187 EXPECT_CALL(*loader, cancel()); 190 EXPECT_CALL(*loader, cancel());
188 EXPECT_CALL(checkpoint, Call(4)); 191 EXPECT_CALL(checkpoint, Call(4));
189 192
190 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 193 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
191 OwnPtr<WebDataConsumerHandle> handle 194 OwnPtr<WebDataConsumerHandle> handle
192 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 195 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
193 OwnPtr<WebDataConsumerHandle::Reader> reader = handle->obtainReader(nullptr) ; 196 OwnPtr<WebDataConsumerHandle::Reader> reader = handle->obtainReader(nullptr) ;
194 testing::runPendingTasks(); 197 testing::runPendingTasks();
(...skipping 13 matching lines...) Expand all
208 TEST_F(FetchBlobDataConsumerHandleTest, ReadTest) 211 TEST_F(FetchBlobDataConsumerHandleTest, ReadTest)
209 { 212 {
210 auto factory = new StrictMock<MockLoaderFactory>; 213 auto factory = new StrictMock<MockLoaderFactory>;
211 Checkpoint checkpoint; 214 Checkpoint checkpoint;
212 215
213 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 216 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
214 ThreadableLoaderClient* client = nullptr; 217 ThreadableLoaderClient* client = nullptr;
215 218
216 InSequence s; 219 InSequence s;
217 EXPECT_CALL(checkpoint, Call(1)); 220 EXPECT_CALL(checkpoint, Call(1));
218 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll(Sa veArg<1>(&client), Return(loader.get()))); 221 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA rg<1>(&client), Return(loader.get())));
222 EXPECT_CALL(*loader, start(_));
219 EXPECT_CALL(checkpoint, Call(2)); 223 EXPECT_CALL(checkpoint, Call(2));
220 EXPECT_CALL(*loader, cancel()); 224 EXPECT_CALL(*loader, cancel());
221 225
222 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 226 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
223 OwnPtr<WebDataConsumerHandle> handle 227 OwnPtr<WebDataConsumerHandle> handle
224 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 228 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
225 229
226 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); 230 OwnPtr<ReplayingHandle> src = ReplayingHandle::create();
227 src->add(Command(Command::Wait)); 231 src->add(Command(Command::Wait));
228 src->add(Command(Command::Data, "hello, ")); 232 src->add(Command(Command::Data, "hello, "));
(...skipping 16 matching lines...) Expand all
245 TEST_F(FetchBlobDataConsumerHandleTest, TwoPhaseReadTest) 249 TEST_F(FetchBlobDataConsumerHandleTest, TwoPhaseReadTest)
246 { 250 {
247 auto factory = new StrictMock<MockLoaderFactory>; 251 auto factory = new StrictMock<MockLoaderFactory>;
248 Checkpoint checkpoint; 252 Checkpoint checkpoint;
249 253
250 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 254 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
251 ThreadableLoaderClient* client = nullptr; 255 ThreadableLoaderClient* client = nullptr;
252 256
253 InSequence s; 257 InSequence s;
254 EXPECT_CALL(checkpoint, Call(1)); 258 EXPECT_CALL(checkpoint, Call(1));
255 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll(Sa veArg<1>(&client), Return(loader.get()))); 259 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA rg<1>(&client), Return(loader.get())));
260 EXPECT_CALL(*loader, start(_));
256 EXPECT_CALL(checkpoint, Call(2)); 261 EXPECT_CALL(checkpoint, Call(2));
257 EXPECT_CALL(*loader, cancel()); 262 EXPECT_CALL(*loader, cancel());
258 263
259 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 264 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
260 OwnPtr<WebDataConsumerHandle> handle 265 OwnPtr<WebDataConsumerHandle> handle
261 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 266 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
262 267
263 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); 268 OwnPtr<ReplayingHandle> src = ReplayingHandle::create();
264 src->add(Command(Command::Wait)); 269 src->add(Command(Command::Wait));
265 src->add(Command(Command::Data, "hello, ")); 270 src->add(Command(Command::Data, "hello, "));
(...skipping 16 matching lines...) Expand all
282 TEST_F(FetchBlobDataConsumerHandleTest, LoadErrorTest) 287 TEST_F(FetchBlobDataConsumerHandleTest, LoadErrorTest)
283 { 288 {
284 auto factory = new StrictMock<MockLoaderFactory>; 289 auto factory = new StrictMock<MockLoaderFactory>;
285 Checkpoint checkpoint; 290 Checkpoint checkpoint;
286 291
287 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 292 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
288 ThreadableLoaderClient* client = nullptr; 293 ThreadableLoaderClient* client = nullptr;
289 294
290 InSequence s; 295 InSequence s;
291 EXPECT_CALL(checkpoint, Call(1)); 296 EXPECT_CALL(checkpoint, Call(1));
292 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll(Sa veArg<1>(&client), Return(loader.get()))); 297 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA rg<1>(&client), Return(loader.get())));
298 EXPECT_CALL(*loader, start(_));
293 EXPECT_CALL(checkpoint, Call(2)); 299 EXPECT_CALL(checkpoint, Call(2));
294 300
295 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 301 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
296 OwnPtr<WebDataConsumerHandle> handle 302 OwnPtr<WebDataConsumerHandle> handle
297 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 303 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
298 304
299 size_t size = 0; 305 size_t size = 0;
300 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 306 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
301 checkpoint.Call(1); 307 checkpoint.Call(1);
302 testing::runPendingTasks(); 308 testing::runPendingTasks();
303 checkpoint.Call(2); 309 checkpoint.Call(2);
304 client->didFail(ResourceError()); 310 client->didFail(ResourceError());
305 HandleReaderRunner<HandleReader> runner(handle.release()); 311 HandleReaderRunner<HandleReader> runner(handle.release());
306 OwnPtr<HandleReadResult> r = runner.wait(); 312 OwnPtr<HandleReadResult> r = runner.wait();
307 EXPECT_EQ(kUnexpectedError, r->result()); 313 EXPECT_EQ(kUnexpectedError, r->result());
308 } 314 }
309 315
310 TEST_F(FetchBlobDataConsumerHandleTest, BodyLoadErrorTest) 316 TEST_F(FetchBlobDataConsumerHandleTest, BodyLoadErrorTest)
311 { 317 {
312 auto factory = new StrictMock<MockLoaderFactory>; 318 auto factory = new StrictMock<MockLoaderFactory>;
313 Checkpoint checkpoint; 319 Checkpoint checkpoint;
314 320
315 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); 321 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create();
316 ThreadableLoaderClient* client = nullptr; 322 ThreadableLoaderClient* client = nullptr;
317 323
318 InSequence s; 324 InSequence s;
319 EXPECT_CALL(checkpoint, Call(1)); 325 EXPECT_CALL(checkpoint, Call(1));
320 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll(Sa veArg<1>(&client), Return(loader.get()))); 326 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA rg<1>(&client), Return(loader.get())));
327 EXPECT_CALL(*loader, start(_));
321 EXPECT_CALL(checkpoint, Call(2)); 328 EXPECT_CALL(checkpoint, Call(2));
322 EXPECT_CALL(*loader, cancel()); 329 EXPECT_CALL(*loader, cancel());
323 330
324 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); 331 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me");
325 OwnPtr<WebDataConsumerHandle> handle 332 OwnPtr<WebDataConsumerHandle> handle
326 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); 333 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry);
327 334
328 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); 335 OwnPtr<ReplayingHandle> src = ReplayingHandle::create();
329 src->add(Command(Command::Wait)); 336 src->add(Command(Command::Wait));
330 src->add(Command(Command::Data, "hello, ")); 337 src->add(Command(Command::Data, "hello, "));
331 src->add(Command(Command::Error)); 338 src->add(Command(Command::Error));
332 339
333 size_t size = 0; 340 size_t size = 0;
334 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); 341 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size);
335 checkpoint.Call(1); 342 checkpoint.Call(1);
336 testing::runPendingTasks(); 343 testing::runPendingTasks();
337 checkpoint.Call(2); 344 checkpoint.Call(2);
338 client->didReceiveResponse(0, ResourceResponse(), src.release()); 345 client->didReceiveResponse(0, ResourceResponse(), src.release());
339 HandleReaderRunner<HandleReader> runner(handle.release()); 346 HandleReaderRunner<HandleReader> runner(handle.release());
340 OwnPtr<HandleReadResult> r = runner.wait(); 347 OwnPtr<HandleReadResult> r = runner.wait();
341 EXPECT_EQ(kUnexpectedError, r->result()); 348 EXPECT_EQ(kUnexpectedError, r->result());
342 } 349 }
343 350
344 } // namespace 351 } // namespace
345 } // namespace blink 352 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698