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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/DataConsumerTeeTest.cpp

Issue 2177243002: Use per-frame TaskRunner instead of thread's default in DataConsumerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_consumer_handle_unique_ptr
Patch Set: update Created 4 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 "modules/fetch/DataConsumerTee.h" 5 #include "modules/fetch/DataConsumerTee.h"
6 6
7 #include "core/testing/DummyPageHolder.h" 7 #include "core/testing/DummyPageHolder.h"
8 #include "core/testing/NullExecutionContext.h" 8 #include "core/testing/NullExecutionContext.h"
9 #include "modules/fetch/DataConsumerHandleTestUtil.h" 9 #include "modules/fetch/DataConsumerHandleTestUtil.h"
10 #include "platform/CrossThreadFunctional.h" 10 #include "platform/CrossThreadFunctional.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 { 331 {
332 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(); 332 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create();
333 std::unique_ptr<MockFetchDataConsumerHandle> src(MockFetchDataConsumerHandle ::create()); 333 std::unique_ptr<MockFetchDataConsumerHandle> src(MockFetchDataConsumerHandle ::create());
334 334
335 // |reader| will be adopted by |obtainFetchDataReader|. 335 // |reader| will be adopted by |obtainFetchDataReader|.
336 MockFetchDataConsumerReader* reader = MockFetchDataConsumerReader::create(). release(); 336 MockFetchDataConsumerReader* reader = MockFetchDataConsumerReader::create(). release();
337 337
338 Checkpoint checkpoint; 338 Checkpoint checkpoint;
339 InSequence s; 339 InSequence s;
340 EXPECT_CALL(checkpoint, Call(1)); 340 EXPECT_CALL(checkpoint, Call(1));
341 EXPECT_CALL(*src, obtainFetchDataReader(_)).WillOnce(Return(ByMove(WTF::wrap Unique(reader)))); 341 EXPECT_CALL(*src, obtainFetchDataReaderMock(_)).WillOnce(Return(ByMove(WTF:: wrapUnique(reader))));
342 EXPECT_CALL(*reader, drainAsBlobDataHandle(kAllowBlobWithInvalidSize)).WillO nce(Return(blobDataHandle)); 342 EXPECT_CALL(*reader, drainAsBlobDataHandle(kAllowBlobWithInvalidSize)).WillO nce(Return(blobDataHandle));
343 EXPECT_CALL(*reader, destruct()); 343 EXPECT_CALL(*reader, destruct());
344 EXPECT_CALL(checkpoint, Call(2)); 344 EXPECT_CALL(checkpoint, Call(2));
345 345
346 std::unique_ptr<FetchDataConsumerHandle> dest1, dest2; 346 std::unique_ptr<FetchDataConsumerHandle> dest1, dest2;
347 std::unique_ptr<TeeCreationThread<FetchDataConsumerHandle>> t = wrapUnique(n ew TeeCreationThread<FetchDataConsumerHandle>()); 347 std::unique_ptr<TeeCreationThread<FetchDataConsumerHandle>> t = wrapUnique(n ew TeeCreationThread<FetchDataConsumerHandle>());
348 348
349 checkpoint.Call(1); 349 checkpoint.Call(1);
350 t->run(std::move(src), &dest1, &dest2); 350 t->run(std::move(src), &dest1, &dest2);
351 checkpoint.Call(2); 351 checkpoint.Call(2);
352 352
353 ASSERT_TRUE(dest1); 353 ASSERT_TRUE(dest1);
354 ASSERT_TRUE(dest2); 354 ASSERT_TRUE(dest2);
355 EXPECT_EQ(blobDataHandle, dest1->obtainFetchDataReader(nullptr)->drainAsBlob DataHandle(kAllowBlobWithInvalidSize)); 355 EXPECT_EQ(blobDataHandle, dest1->obtainFetchDataReader(nullptr, getCurrentTa skRunner())->drainAsBlobDataHandle(kAllowBlobWithInvalidSize));
356 EXPECT_EQ(blobDataHandle, dest2->obtainFetchDataReader(nullptr)->drainAsBlob DataHandle(kAllowBlobWithInvalidSize)); 356 EXPECT_EQ(blobDataHandle, dest2->obtainFetchDataReader(nullptr, getCurrentTa skRunner())->drainAsBlobDataHandle(kAllowBlobWithInvalidSize));
357 } 357 }
358 358
359 TEST(FetchDataConsumerTeeTest, CreateFromBlobWithInvalidSize) 359 TEST(FetchDataConsumerTeeTest, CreateFromBlobWithInvalidSize)
360 { 360 {
361 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), -1); 361 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), -1);
362 std::unique_ptr<MockFetchDataConsumerHandle> src(MockFetchDataConsumerHandle ::create()); 362 std::unique_ptr<MockFetchDataConsumerHandle> src(MockFetchDataConsumerHandle ::create());
363 363
364 // |reader| is adopted by |obtainFetchDataReader|. 364 // |reader| is adopted by |obtainFetchDataReader|.
365 MockFetchDataConsumerReader* reader = MockFetchDataConsumerReader::create(). release(); 365 MockFetchDataConsumerReader* reader = MockFetchDataConsumerReader::create(). release();
366 366
367 Checkpoint checkpoint; 367 Checkpoint checkpoint;
368 InSequence s; 368 InSequence s;
369 EXPECT_CALL(checkpoint, Call(1)); 369 EXPECT_CALL(checkpoint, Call(1));
370 EXPECT_CALL(*src, obtainFetchDataReader(_)).WillOnce(Return(ByMove(WTF::wrap Unique(reader)))); 370 EXPECT_CALL(*src, obtainFetchDataReaderMock(_)).WillOnce(Return(ByMove(WTF:: wrapUnique(reader))));
371 EXPECT_CALL(*reader, drainAsBlobDataHandle(kAllowBlobWithInvalidSize)).WillO nce(Return(blobDataHandle)); 371 EXPECT_CALL(*reader, drainAsBlobDataHandle(kAllowBlobWithInvalidSize)).WillO nce(Return(blobDataHandle));
372 EXPECT_CALL(*reader, destruct()); 372 EXPECT_CALL(*reader, destruct());
373 EXPECT_CALL(checkpoint, Call(2)); 373 EXPECT_CALL(checkpoint, Call(2));
374 374
375 std::unique_ptr<FetchDataConsumerHandle> dest1, dest2; 375 std::unique_ptr<FetchDataConsumerHandle> dest1, dest2;
376 std::unique_ptr<TeeCreationThread<FetchDataConsumerHandle>> t = wrapUnique(n ew TeeCreationThread<FetchDataConsumerHandle>()); 376 std::unique_ptr<TeeCreationThread<FetchDataConsumerHandle>> t = wrapUnique(n ew TeeCreationThread<FetchDataConsumerHandle>());
377 377
378 checkpoint.Call(1); 378 checkpoint.Call(1);
379 t->run(std::move(src), &dest1, &dest2); 379 t->run(std::move(src), &dest1, &dest2);
380 checkpoint.Call(2); 380 checkpoint.Call(2);
381 381
382 ASSERT_TRUE(dest1); 382 ASSERT_TRUE(dest1);
383 ASSERT_TRUE(dest2); 383 ASSERT_TRUE(dest2);
384 EXPECT_FALSE(dest1->obtainFetchDataReader(nullptr)->drainAsBlobDataHandle(kD isallowBlobWithInvalidSize)); 384 EXPECT_FALSE(dest1->obtainFetchDataReader(nullptr, getCurrentTaskRunner())-> drainAsBlobDataHandle(kDisallowBlobWithInvalidSize));
385 EXPECT_EQ(blobDataHandle, dest1->obtainFetchDataReader(nullptr)->drainAsBlob DataHandle(kAllowBlobWithInvalidSize)); 385 EXPECT_EQ(blobDataHandle, dest1->obtainFetchDataReader(nullptr, getCurrentTa skRunner())->drainAsBlobDataHandle(kAllowBlobWithInvalidSize));
386 EXPECT_FALSE(dest2->obtainFetchDataReader(nullptr)->drainAsBlobDataHandle(kD isallowBlobWithInvalidSize)); 386 EXPECT_FALSE(dest2->obtainFetchDataReader(nullptr, getCurrentTaskRunner())-> drainAsBlobDataHandle(kDisallowBlobWithInvalidSize));
387 EXPECT_EQ(blobDataHandle, dest2->obtainFetchDataReader(nullptr)->drainAsBlob DataHandle(kAllowBlobWithInvalidSize)); 387 EXPECT_EQ(blobDataHandle, dest2->obtainFetchDataReader(nullptr, getCurrentTa skRunner())->drainAsBlobDataHandle(kAllowBlobWithInvalidSize));
388 } 388 }
389 389
390 TEST(FetchDataConsumerTeeTest, CreateDone) 390 TEST(FetchDataConsumerTeeTest, CreateDone)
391 { 391 {
392 std::unique_ptr<Handle> src(Handle::create()); 392 std::unique_ptr<Handle> src(Handle::create());
393 std::unique_ptr<FetchDataConsumerHandle> dest1, dest2; 393 std::unique_ptr<FetchDataConsumerHandle> dest1, dest2;
394 394
395 src->add(Command(Command::Done)); 395 src->add(Command(Command::Done));
396 396
397 std::unique_ptr<TeeCreationThread<FetchDataConsumerHandle>> t = wrapUnique(n ew TeeCreationThread<FetchDataConsumerHandle>()); 397 std::unique_ptr<TeeCreationThread<FetchDataConsumerHandle>> t = wrapUnique(n ew TeeCreationThread<FetchDataConsumerHandle>());
398 t->run(createFetchDataConsumerHandleFromWebHandle(std::move(src)), &dest1, & dest2); 398 t->run(createFetchDataConsumerHandleFromWebHandle(std::move(src)), &dest1, & dest2);
399 399
400 ASSERT_TRUE(dest1); 400 ASSERT_TRUE(dest1);
401 ASSERT_TRUE(dest2); 401 ASSERT_TRUE(dest2);
402 402
403 EXPECT_FALSE(dest1->obtainFetchDataReader(nullptr)->drainAsBlobDataHandle(kA llowBlobWithInvalidSize)); 403 EXPECT_FALSE(dest1->obtainFetchDataReader(nullptr, getCurrentTaskRunner())-> drainAsBlobDataHandle(kAllowBlobWithInvalidSize));
404 EXPECT_FALSE(dest2->obtainFetchDataReader(nullptr)->drainAsBlobDataHandle(kA llowBlobWithInvalidSize)); 404 EXPECT_FALSE(dest2->obtainFetchDataReader(nullptr, getCurrentTaskRunner())-> drainAsBlobDataHandle(kAllowBlobWithInvalidSize));
405 405
406 HandleReaderRunner<HandleReader> r1(std::move(dest1)), r2(std::move(dest2)); 406 HandleReaderRunner<HandleReader> r1(std::move(dest1)), r2(std::move(dest2));
407 407
408 std::unique_ptr<HandleReadResult> res1 = r1.wait(); 408 std::unique_ptr<HandleReadResult> res1 = r1.wait();
409 std::unique_ptr<HandleReadResult> res2 = r2.wait(); 409 std::unique_ptr<HandleReadResult> res2 = r2.wait();
410 410
411 EXPECT_EQ(kDone, res1->result()); 411 EXPECT_EQ(kDone, res1->result());
412 EXPECT_EQ(0u, res1->data().size()); 412 EXPECT_EQ(0u, res1->data().size());
413 EXPECT_EQ(kDone, res2->result()); 413 EXPECT_EQ(kDone, res2->result());
414 EXPECT_EQ(0u, res2->data().size()); 414 EXPECT_EQ(0u, res2->data().size());
415 } 415 }
416 416
417 } // namespace 417 } // namespace
418 } // namespace blink 418 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698