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