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