| OLD | NEW |
| 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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_METHOD5(create, PassRefPtr<ThreadableLoader>(ExecutionContext&, Threada
bleLoaderClient*, const ResourceRequest&, const ThreadableLoaderOptions&, const
ResourceLoaderOptions&)); | 54 MOCK_METHOD4(create, PassRefPtr<ThreadableLoader>(ExecutionContext&, Threada
bleLoaderClient*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&))
; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 PassRefPtr<BlobDataHandle> createBlobDataHandle(const char* s) | 57 PassRefPtr<BlobDataHandle> createBlobDataHandle(const char* s) |
| 58 { | 58 { |
| 59 OwnPtr<BlobData> data = BlobData::create(); | 59 OwnPtr<BlobData> data = BlobData::create(); |
| 60 data->appendText(s, false); | 60 data->appendText(s, false); |
| 61 auto size = data->length(); | 61 auto size = data->length(); |
| 62 return BlobDataHandle::create(data.release(), size); | 62 return BlobDataHandle::create(data.release(), size); |
| 63 } | 63 } |
| 64 | 64 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 90 Checkpoint checkpoint; | 90 Checkpoint checkpoint; |
| 91 | 91 |
| 92 ResourceRequest request; | 92 ResourceRequest request; |
| 93 ThreadableLoaderOptions options; | 93 ThreadableLoaderOptions options; |
| 94 ResourceLoaderOptions resourceLoaderOptions; | 94 ResourceLoaderOptions resourceLoaderOptions; |
| 95 | 95 |
| 96 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); | 96 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); |
| 97 | 97 |
| 98 InSequence s; | 98 InSequence s; |
| 99 EXPECT_CALL(checkpoint, Call(1)); | 99 EXPECT_CALL(checkpoint, Call(1)); |
| 100 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll( | 100 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll( |
| 101 SaveArg<2>(&request), | 101 SaveArg<2>(&options), |
| 102 SaveArg<3>(&options), | 102 SaveArg<3>(&resourceLoaderOptions), |
| 103 SaveArg<4>(&resourceLoaderOptions), | |
| 104 Return(loader.get()))); | 103 Return(loader.get()))); |
| 104 EXPECT_CALL(*loader, start(_)).WillOnce(SaveArg<0>(&request)); |
| 105 EXPECT_CALL(checkpoint, Call(2)); | 105 EXPECT_CALL(checkpoint, Call(2)); |
| 106 EXPECT_CALL(*loader, cancel()); | 106 EXPECT_CALL(*loader, cancel()); |
| 107 | 107 |
| 108 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 108 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 109 OwnPtr<WebDataConsumerHandle> handle | 109 OwnPtr<WebDataConsumerHandle> handle |
| 110 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 110 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 111 testing::runPendingTasks(); | 111 testing::runPendingTasks(); |
| 112 | 112 |
| 113 size_t size = 0; | 113 size_t size = 0; |
| 114 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); | 114 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 134 | 134 |
| 135 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenStopped) | 135 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenStopped) |
| 136 { | 136 { |
| 137 auto factory = new StrictMock<MockLoaderFactory>; | 137 auto factory = new StrictMock<MockLoaderFactory>; |
| 138 Checkpoint checkpoint; | 138 Checkpoint checkpoint; |
| 139 | 139 |
| 140 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); | 140 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); |
| 141 | 141 |
| 142 InSequence s; | 142 InSequence s; |
| 143 EXPECT_CALL(checkpoint, Call(1)); | 143 EXPECT_CALL(checkpoint, Call(1)); |
| 144 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(Return(l
oader.get())); | 144 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(Return(load
er.get())); |
| 145 EXPECT_CALL(*loader, start(_)); |
| 145 EXPECT_CALL(checkpoint, Call(2)); | 146 EXPECT_CALL(checkpoint, Call(2)); |
| 146 EXPECT_CALL(*loader, cancel()); | 147 EXPECT_CALL(*loader, cancel()); |
| 147 EXPECT_CALL(checkpoint, Call(3)); | 148 EXPECT_CALL(checkpoint, Call(3)); |
| 148 | 149 |
| 149 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 150 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 150 OwnPtr<WebDataConsumerHandle> handle | 151 OwnPtr<WebDataConsumerHandle> handle |
| 151 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 152 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 152 testing::runPendingTasks(); | 153 testing::runPendingTasks(); |
| 153 | 154 |
| 154 size_t size = 0; | 155 size_t size = 0; |
| 155 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); | 156 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); |
| 156 checkpoint.Call(1); | 157 checkpoint.Call(1); |
| 157 testing::runPendingTasks(); | 158 testing::runPendingTasks(); |
| 158 checkpoint.Call(2); | 159 checkpoint.Call(2); |
| 159 document().stopActiveDOMObjects(); | 160 document().stopActiveDOMObjects(); |
| 160 checkpoint.Call(3); | 161 checkpoint.Call(3); |
| 161 } | 162 } |
| 162 | 163 |
| 163 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenDestinationDetached) | 164 TEST_F(FetchBlobDataConsumerHandleTest, CancelLoaderWhenDestinationDetached) |
| 164 { | 165 { |
| 165 auto factory = new StrictMock<MockLoaderFactory>; | 166 auto factory = new StrictMock<MockLoaderFactory>; |
| 166 Checkpoint checkpoint; | 167 Checkpoint checkpoint; |
| 167 | 168 |
| 168 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); | 169 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); |
| 169 | 170 |
| 170 InSequence s; | 171 InSequence s; |
| 171 EXPECT_CALL(checkpoint, Call(1)); | 172 EXPECT_CALL(checkpoint, Call(1)); |
| 172 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(Return(l
oader.get())); | 173 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(Return(load
er.get())); |
| 174 EXPECT_CALL(*loader, start(_)); |
| 173 EXPECT_CALL(checkpoint, Call(2)); | 175 EXPECT_CALL(checkpoint, Call(2)); |
| 174 EXPECT_CALL(checkpoint, Call(3)); | 176 EXPECT_CALL(checkpoint, Call(3)); |
| 175 EXPECT_CALL(*loader, cancel()); | 177 EXPECT_CALL(*loader, cancel()); |
| 176 EXPECT_CALL(checkpoint, Call(4)); | 178 EXPECT_CALL(checkpoint, Call(4)); |
| 177 | 179 |
| 178 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 180 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 179 OwnPtr<WebDataConsumerHandle> handle | 181 OwnPtr<WebDataConsumerHandle> handle |
| 180 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 182 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 181 OwnPtr<WebDataConsumerHandle::Reader> reader = handle->obtainReader(nullptr)
; | 183 OwnPtr<WebDataConsumerHandle::Reader> reader = handle->obtainReader(nullptr)
; |
| 182 testing::runPendingTasks(); | 184 testing::runPendingTasks(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 196 TEST_F(FetchBlobDataConsumerHandleTest, ReadTest) | 198 TEST_F(FetchBlobDataConsumerHandleTest, ReadTest) |
| 197 { | 199 { |
| 198 auto factory = new StrictMock<MockLoaderFactory>; | 200 auto factory = new StrictMock<MockLoaderFactory>; |
| 199 Checkpoint checkpoint; | 201 Checkpoint checkpoint; |
| 200 | 202 |
| 201 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); | 203 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); |
| 202 ThreadableLoaderClient* client = nullptr; | 204 ThreadableLoaderClient* client = nullptr; |
| 203 | 205 |
| 204 InSequence s; | 206 InSequence s; |
| 205 EXPECT_CALL(checkpoint, Call(1)); | 207 EXPECT_CALL(checkpoint, Call(1)); |
| 206 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll(Sa
veArg<1>(&client), Return(loader.get()))); | 208 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA
rg<1>(&client), Return(loader.get()))); |
| 209 EXPECT_CALL(*loader, start(_)); |
| 207 EXPECT_CALL(checkpoint, Call(2)); | 210 EXPECT_CALL(checkpoint, Call(2)); |
| 208 EXPECT_CALL(*loader, cancel()); | 211 EXPECT_CALL(*loader, cancel()); |
| 209 | 212 |
| 210 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 213 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 211 OwnPtr<WebDataConsumerHandle> handle | 214 OwnPtr<WebDataConsumerHandle> handle |
| 212 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 215 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 213 | 216 |
| 214 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); | 217 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); |
| 215 src->add(Command(Command::Wait)); | 218 src->add(Command(Command::Wait)); |
| 216 src->add(Command(Command::Data, "hello, ")); | 219 src->add(Command(Command::Data, "hello, ")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 233 TEST_F(FetchBlobDataConsumerHandleTest, TwoPhaseReadTest) | 236 TEST_F(FetchBlobDataConsumerHandleTest, TwoPhaseReadTest) |
| 234 { | 237 { |
| 235 auto factory = new StrictMock<MockLoaderFactory>; | 238 auto factory = new StrictMock<MockLoaderFactory>; |
| 236 Checkpoint checkpoint; | 239 Checkpoint checkpoint; |
| 237 | 240 |
| 238 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); | 241 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); |
| 239 ThreadableLoaderClient* client = nullptr; | 242 ThreadableLoaderClient* client = nullptr; |
| 240 | 243 |
| 241 InSequence s; | 244 InSequence s; |
| 242 EXPECT_CALL(checkpoint, Call(1)); | 245 EXPECT_CALL(checkpoint, Call(1)); |
| 243 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll(Sa
veArg<1>(&client), Return(loader.get()))); | 246 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA
rg<1>(&client), Return(loader.get()))); |
| 247 EXPECT_CALL(*loader, start(_)); |
| 244 EXPECT_CALL(checkpoint, Call(2)); | 248 EXPECT_CALL(checkpoint, Call(2)); |
| 245 EXPECT_CALL(*loader, cancel()); | 249 EXPECT_CALL(*loader, cancel()); |
| 246 | 250 |
| 247 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 251 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 248 OwnPtr<WebDataConsumerHandle> handle | 252 OwnPtr<WebDataConsumerHandle> handle |
| 249 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 253 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 250 | 254 |
| 251 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); | 255 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); |
| 252 src->add(Command(Command::Wait)); | 256 src->add(Command(Command::Wait)); |
| 253 src->add(Command(Command::Data, "hello, ")); | 257 src->add(Command(Command::Data, "hello, ")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 270 TEST_F(FetchBlobDataConsumerHandleTest, LoadErrorTest) | 274 TEST_F(FetchBlobDataConsumerHandleTest, LoadErrorTest) |
| 271 { | 275 { |
| 272 auto factory = new StrictMock<MockLoaderFactory>; | 276 auto factory = new StrictMock<MockLoaderFactory>; |
| 273 Checkpoint checkpoint; | 277 Checkpoint checkpoint; |
| 274 | 278 |
| 275 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); | 279 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); |
| 276 ThreadableLoaderClient* client = nullptr; | 280 ThreadableLoaderClient* client = nullptr; |
| 277 | 281 |
| 278 InSequence s; | 282 InSequence s; |
| 279 EXPECT_CALL(checkpoint, Call(1)); | 283 EXPECT_CALL(checkpoint, Call(1)); |
| 280 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll(Sa
veArg<1>(&client), Return(loader.get()))); | 284 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA
rg<1>(&client), Return(loader.get()))); |
| 285 EXPECT_CALL(*loader, start(_)); |
| 281 EXPECT_CALL(checkpoint, Call(2)); | 286 EXPECT_CALL(checkpoint, Call(2)); |
| 282 | 287 |
| 283 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 288 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 284 OwnPtr<WebDataConsumerHandle> handle | 289 OwnPtr<WebDataConsumerHandle> handle |
| 285 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 290 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 286 | 291 |
| 287 size_t size = 0; | 292 size_t size = 0; |
| 288 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); | 293 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); |
| 289 checkpoint.Call(1); | 294 checkpoint.Call(1); |
| 290 testing::runPendingTasks(); | 295 testing::runPendingTasks(); |
| 291 checkpoint.Call(2); | 296 checkpoint.Call(2); |
| 292 client->didFail(ResourceError()); | 297 client->didFail(ResourceError()); |
| 293 HandleReaderRunner<HandleReader> runner(handle.release()); | 298 HandleReaderRunner<HandleReader> runner(handle.release()); |
| 294 OwnPtr<HandleReadResult> r = runner.wait(); | 299 OwnPtr<HandleReadResult> r = runner.wait(); |
| 295 EXPECT_EQ(kUnexpectedError, r->result()); | 300 EXPECT_EQ(kUnexpectedError, r->result()); |
| 296 } | 301 } |
| 297 | 302 |
| 298 TEST_F(FetchBlobDataConsumerHandleTest, BodyLoadErrorTest) | 303 TEST_F(FetchBlobDataConsumerHandleTest, BodyLoadErrorTest) |
| 299 { | 304 { |
| 300 auto factory = new StrictMock<MockLoaderFactory>; | 305 auto factory = new StrictMock<MockLoaderFactory>; |
| 301 Checkpoint checkpoint; | 306 Checkpoint checkpoint; |
| 302 | 307 |
| 303 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); | 308 RefPtr<MockThreadableLoader> loader = MockThreadableLoader::create(); |
| 304 ThreadableLoaderClient* client = nullptr; | 309 ThreadableLoaderClient* client = nullptr; |
| 305 | 310 |
| 306 InSequence s; | 311 InSequence s; |
| 307 EXPECT_CALL(checkpoint, Call(1)); | 312 EXPECT_CALL(checkpoint, Call(1)); |
| 308 EXPECT_CALL(*factory, create(Ref(document()), _, _, _, _)).WillOnce(DoAll(Sa
veArg<1>(&client), Return(loader.get()))); | 313 EXPECT_CALL(*factory, create(Ref(document()), _, _, _)).WillOnce(DoAll(SaveA
rg<1>(&client), Return(loader.get()))); |
| 314 EXPECT_CALL(*loader, start(_)); |
| 309 EXPECT_CALL(checkpoint, Call(2)); | 315 EXPECT_CALL(checkpoint, Call(2)); |
| 310 EXPECT_CALL(*loader, cancel()); | 316 EXPECT_CALL(*loader, cancel()); |
| 311 | 317 |
| 312 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 318 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 313 OwnPtr<WebDataConsumerHandle> handle | 319 OwnPtr<WebDataConsumerHandle> handle |
| 314 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 320 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 315 | 321 |
| 316 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); | 322 OwnPtr<ReplayingHandle> src = ReplayingHandle::create(); |
| 317 src->add(Command(Command::Wait)); | 323 src->add(Command(Command::Wait)); |
| 318 src->add(Command(Command::Data, "hello, ")); | 324 src->add(Command(Command::Data, "hello, ")); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(nullpt
r); | 410 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(nullpt
r); |
| 405 | 411 |
| 406 const void* buffer; | 412 const void* buffer; |
| 407 size_t available; | 413 size_t available; |
| 408 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 414 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 409 EXPECT_FALSE(reader->drainAsBlobDataHandle()); | 415 EXPECT_FALSE(reader->drainAsBlobDataHandle()); |
| 410 } | 416 } |
| 411 | 417 |
| 412 } // namespace | 418 } // namespace |
| 413 } // namespace blink | 419 } // namespace blink |
| OLD | NEW |