Commit 070f3cf6 authored by Minggang Wang's avatar Minggang Wang Committed by Commit Bot

Running delayed tasks immediately in ServiceWorkerRegistrationTest

This patch uses TimeSource::MOCK_TIME trait to construct ScopedTaskEnvironment,
which will enable the delayed tasks to be handled when reaching idle.

By doing so, we can get rid of the usage of RunUntilActivated().

Bug: 988930
Change-Id: I6c3ea276e7ce300eb525c886404c1e54a312a0c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1747858Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Minggang Wang <minggang.wang@intel.com>
Cr-Commit-Position: refs/heads/master@{#686739}
parent 3c913e18
......@@ -173,7 +173,8 @@ class MockServiceWorkerRegistrationObject
class ServiceWorkerRegistrationTest : public testing::Test {
public:
ServiceWorkerRegistrationTest()
: thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
: thread_bundle_(base::test::ScopedTaskEnvironment::TimeSource::MOCK_TIME,
TestBrowserThreadBundle::IO_MAINLOOP) {}
void SetUp() override {
helper_ = std::make_unique<EmbeddedWorkerTestHelper>(base::FilePath());
......@@ -570,8 +571,6 @@ TEST_P(ServiceWorkerActivationTest, NoInflightRequest) {
scoped_refptr<ServiceWorkerRegistration> reg = registration();
scoped_refptr<ServiceWorkerVersion> version_1 = reg->active_version();
scoped_refptr<ServiceWorkerVersion> version_2 = reg->waiting_version();
auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>();
reg->SetTaskRunnerForTest(runner);
// Remove the controllee. Since there is an in-flight request,
// activation should not yet happen.
......@@ -588,7 +587,9 @@ TEST_P(ServiceWorkerActivationTest, NoInflightRequest) {
RequestTermination(&version_1_client()->host());
TestServiceWorkerObserver observer(helper_->context_wrapper());
observer.RunUntilActivated(version_2.get(), runner);
observer.RunUntilStatusChange(version_2.get(),
ServiceWorkerVersion::ACTIVATED);
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version_2->status());
EXPECT_EQ(version_2.get(), reg->active_version());
}
......
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