Commit 27fff6ea authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Fix ImageResourceTest.CancelWithImageAndFinishObserver to pass

ImageResourceTest.CancelWithImageAndFinishObserver had two problems:

- ResourceFinishObserver::NotifyFinished was not getting called because blink::test::RunPendingTasks() doesn't run tasks in FakeTaskRunners.
- Test failure was treated as passing because EXPECT_CALL was checked in the MockImageObserver destructor which runs in a GC after the test.

This CL replaces RunPendingTasks() call with FakeTaskRunner::RunUntilIdle() to fix the first issue.
And adds an explicit GC in TearDown so EXPECT_CALL gets checked inside the test.


Bug: 1138819
Change-Id: Ic0d0c089cab5e728d65f3e947e0b9b36a066395f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2507314Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823922}
parent 23886755
......@@ -118,7 +118,14 @@ constexpr size_t kJpegImageSubrangeWithDimensionsLength =
constexpr size_t kJpegImageSubrangeWithoutDimensionsLength = 3;
class ImageResourceTest : public testing::Test,
private ScopedMockOverlayScrollbars {};
private ScopedMockOverlayScrollbars {
void TearDown() override {
// Trigger a GC so MockFinishObserver gets destroyed and EXPECT_CALL gets
// checked before the test ends.
ThreadState::Current()->CollectAllGarbageForTesting(
BlinkGC::kNoHeapPointersOnStack);
}
};
// Ensure that the image decoder can determine the dimensions of kJpegImage from
// just the first kJpegImageSubrangeWithDimensionsLength bytes. If this test
......@@ -398,6 +405,8 @@ TEST_F(ImageResourceTest, CancelWithImageAndFinishObserver) {
ScopedMockedURLLoad scoped_mocked_url_load(test_url, GetTestFilePath());
ResourceFetcher* fetcher = CreateFetcher();
scheduler::FakeTaskRunner* task_runner =
static_cast<scheduler::FakeTaskRunner*>(fetcher->GetTaskRunner().get());
// Emulate starting a real load.
ImageResource* image_resource = ImageResource::CreateForTest(test_url);
......@@ -427,7 +436,7 @@ TEST_F(ImageResourceTest, CancelWithImageAndFinishObserver) {
// ResourceFinishObserver is notified asynchronously.
EXPECT_CALL(*finish_observer, NotifyFinished());
blink::test::RunPendingTasks();
task_runner->RunUntilIdle();
}
TEST_F(ImageResourceTest, DecodedDataRemainsWhileHasClients) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment