Commit 051bf03a authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

scheduler: Remove EmptyFrameScheduler

We aim to forbid V8 execution from the default task runner of the main
thread. As one of the steps, this CL removes EmptyFrameScheduler that
offers the default task runner instead of a per-frame task runner.

By removing this, some assumptions are changed: Before this CL, a Page
might not have a PageScheduler. After this CL, a Page always have a
PageScheduler.

This CL also moves |CSSAnimationsTest::platform_| and other similar
variables to their ancenstor |PageTestBase::platform_| in order to
assure that a scheduler owned by a platform is destroyed after a local
frame is destroyed. This was necessary to pass the tests.

Bug: 870606
Change-Id: I39bf80aea5d4ac01da125b47224620605fea16de
Reviewed-on: https://chromium-review.googlesource.com/1162083
Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581135}
parent 37317999
......@@ -9,33 +9,27 @@
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_delegate.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
namespace blink {
namespace {
class TestingPlatformSupportWithMockSchedulerAndThreadedAnimations
: public TestingPlatformSupportWithMockScheduler {
public:
bool IsThreadedAnimationEnabled() override { return true; }
};
} // namespace
class CSSAnimationsTest : public RenderingTest {
public:
CSSAnimationsTest() {
EnablePlatform();
platform()->SetThreadedAnimationEnabled(true);
}
void SetUp() override {
platform_->SetAutoAdvanceNowToPendingTasks(false);
platform()->SetAutoAdvanceNowToPendingTasks(false);
// Advance timer manually as RenderingTest expects the time to be non-zero.
platform_->AdvanceClockSeconds(1.);
platform()->AdvanceClockSeconds(1.);
RenderingTest::SetUp();
EnableCompositing();
}
void TearDown() override {
platform_->SetAutoAdvanceNowToPendingTasks(true);
platform_->RunUntilIdle();
platform()->SetAutoAdvanceNowToPendingTasks(true);
platform()->RunUntilIdle();
}
void StartAnimationOnCompositor(Animation* animation) {
......@@ -46,8 +40,8 @@ class CSSAnimationsTest : public RenderingTest {
}
void AdvanceClockSeconds(double seconds) {
platform_->AdvanceClockSeconds(seconds);
platform_->RunUntilIdle();
platform()->AdvanceClockSeconds(seconds);
platform()->RunUntilIdle();
}
double GetContrastFilterAmount(Element* element) {
......@@ -58,11 +52,6 @@ class CSSAnimationsTest : public RenderingTest {
return static_cast<const BasicComponentTransferFilterOperation*>(filter)
->Amount();
}
private:
ScopedTestingPlatformSupport<
TestingPlatformSupportWithMockSchedulerAndThreadedAnimations>
platform_;
};
// Verify that a composited animation is retargeted according to its composited
......
......@@ -145,55 +145,6 @@ bool ShouldUseClientLoFiForRequest(
return true;
}
class EmptyFrameScheduler final : public FrameScheduler {
public:
EmptyFrameScheduler() { DCHECK(IsMainThread()); }
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(
TaskType type) override {
return Platform::Current()->MainThread()->GetTaskRunner();
}
std::unique_ptr<scheduler::WebResourceLoadingTaskRunnerHandle>
CreateResourceLoadingTaskRunnerHandle() override {
return scheduler::WebResourceLoadingTaskRunnerHandle::CreateUnprioritized(
GetTaskRunner(TaskType::kNetworkingWithURLLoaderAnnotation));
}
void SetFrameVisible(bool) override {}
bool IsFrameVisible() const override { return false; }
bool IsPageVisible() const override { return false; }
void SetPaused(bool) override {}
void SetCrossOrigin(bool) override {}
bool IsCrossOrigin() const override { return false; }
void SetIsAdFrame() override {}
bool IsAdFrame() const override { return false; }
void TraceUrlChange(const String& override) override {}
FrameScheduler::FrameType GetFrameType() const override {
return FrameScheduler::FrameType::kSubframe;
}
PageScheduler* GetPageScheduler() const override { return nullptr; }
WebScopedVirtualTimePauser CreateWebScopedVirtualTimePauser(
const String&,
WebScopedVirtualTimePauser::VirtualTaskDuration) override {
return WebScopedVirtualTimePauser();
}
void DidStartProvisionalLoad(bool is_main_frame) override {}
void DidCommitProvisionalLoad(bool is_web_history_inert_commit,
bool is_reload,
bool is_main_frame) override {}
void OnFirstMeaningfulPaint() override {}
std::unique_ptr<ActiveConnectionHandle> OnActiveConnectionCreated() override {
return nullptr;
}
bool IsExemptFromBudgetBasedThrottling() const override { return false; }
std::unique_ptr<blink::mojom::blink::PauseSubresourceLoadingHandle>
GetPauseSubresourceLoadingHandle() override {
return nullptr;
}
ukm::SourceId GetUkmSourceId() override { return ukm::kInvalidSourceId; }
};
} // namespace
template class CORE_TEMPLATE_EXPORT Supplement<LocalFrame>;
......@@ -917,14 +868,11 @@ inline LocalFrame::LocalFrame(LocalFrameClient* client,
FrameOwner* owner,
InterfaceRegistry* interface_registry)
: Frame(client, page, owner, LocalWindowProxyManager::Create(*this)),
frame_scheduler_(page.GetPageScheduler()
? page.GetPageScheduler()->CreateFrameScheduler(
this,
client->GetFrameBlameContext(),
IsMainFrame()
? FrameScheduler::FrameType::kMainFrame
: FrameScheduler::FrameType::kSubframe)
: std::make_unique<EmptyFrameScheduler>()),
frame_scheduler_(page.GetPageScheduler()->CreateFrameScheduler(
this,
client->GetFrameBlameContext(),
IsMainFrame() ? FrameScheduler::FrameType::kMainFrame
: FrameScheduler::FrameType::kSubframe)),
loader_(this),
navigation_scheduler_(NavigationScheduler::Create(this)),
script_controller_(ScriptController::Create(
......
......@@ -1805,6 +1805,9 @@ TEST(ImageResourceTest,
}
TEST(ImageResourceTest, PeriodicFlushTest) {
ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
platform;
EmptyChromeClient* chrome_client = new EmptyChromeClient();
Page::PageClients clients;
FillWithEmptyClients(clients);
......@@ -1812,8 +1815,6 @@ TEST(ImageResourceTest, PeriodicFlushTest) {
std::unique_ptr<DummyPageHolder> page_holder = DummyPageHolder::Create(
IntSize(800, 600), &clients, EmptyLocalFrameClient::Create(), nullptr);
ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
platform;
KURL test_url(kTestURL);
ScopedMockedURLLoad scoped_mocked_url_load(test_url, GetTestFilePath());
......
......@@ -122,11 +122,16 @@ float DeviceScaleFactorDeprecated(LocalFrame* frame) {
return page->DeviceScaleFactorDeprecated();
}
Page* Page::CreateOrdinary(PageClients& page_clients, Page* opener) {
Page* page = Create(page_clients);
Page* Page::Create(PageClients& page_clients) {
Page* page = new Page(page_clients);
page->SetPageScheduler(
Platform::Current()->CurrentThread()->Scheduler()->CreatePageScheduler(
page));
return page;
}
Page* Page::CreateOrdinary(PageClients& page_clients, Page* opener) {
Page* page = Create(page_clients);
if (opener) {
// Before: ... -> opener -> next -> ...
......
......@@ -102,9 +102,7 @@ class CORE_EXPORT Page final : public GarbageCollectedFinalized<Page>,
DISALLOW_COPY_AND_ASSIGN(PageClients);
};
static Page* Create(PageClients& page_clients) {
return new Page(page_clients);
}
static Page* Create(PageClients& page_clients);
// An "ordinary" page is a fully-featured page owned by a web view.
static Page* CreateOrdinary(PageClients&, Page* opener);
......
......@@ -137,4 +137,10 @@ FocusController& PageTestBase::GetFocusController() const {
return GetDocument().GetPage()->GetFocusController();
}
void PageTestBase::EnablePlatform() {
DCHECK(!platform_);
platform_ = std::make_unique<
ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>>();
}
} // namespace blink
......@@ -7,6 +7,7 @@
#include <gtest/gtest.h>
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
namespace blink {
......@@ -53,8 +54,19 @@ class PageTestBase : public testing::Test {
protected:
void LoadAhem();
void EnablePlatform();
ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>&
platform() {
return *platform_;
}
private:
// The order is important: |platform_| must be destroyed after
// |dummy_page_holder_| is destroyed.
std::unique_ptr<
ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>>
platform_;
std::unique_ptr<DummyPageHolder> dummy_page_holder_;
};
......
......@@ -35,7 +35,6 @@
#include "third_party/blink/renderer/platform/graphics/test/fake_web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/platform/loader/fetch/memory_cache.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/skia/include/core/SkColorSpaceXform.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSurface.h"
......@@ -1108,25 +1107,17 @@ TEST_F(CanvasRenderingContext2DTest, ColorManagedPutImageDataOnP3Canvas) {
class CanvasRenderingContext2DTestWithTestingPlatform
: public CanvasRenderingContext2DTest {
protected:
CanvasRenderingContext2DTestWithTestingPlatform() {
EnablePlatform();
platform()->AdvanceClockSeconds(1.); // For non-zero DocumentParserTimings.
}
void SetUp() override {
platform_ = std::make_unique<ScopedTestingPlatformSupport<
TestingPlatformSupportWithMockScheduler>>();
(*platform_)
->AdvanceClockSeconds(1.); // For non-zero DocumentParserTimings.
CanvasRenderingContext2DTest::SetUp();
GetDocument().View()->UpdateLayout();
}
void TearDown() override {
platform_.reset();
CanvasRenderingContext2DTest::TearDown();
}
void RunUntilIdle() { (*platform_)->RunUntilIdle(); }
std::unique_ptr<
ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>>
platform_;
void RunUntilIdle() { platform()->RunUntilIdle(); }
};
// https://crbug.com/708445: When the Canvas2DLayerBridge hibernates or wakes up
......
......@@ -43,7 +43,6 @@
#include "third_party/blink/renderer/platform/testing/empty_web_media_player.h"
#include "third_party/blink/renderer/platform/testing/histogram_tester.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
// The MediaTimelineWidths histogram suffix expected to be encountered in these
......@@ -997,10 +996,13 @@ TEST_F(MediaControlsImplTest, TimeIsCorrectlyFormatted) {
namespace {
class MediaControlsImplTestWithMockScheduler : public MediaControlsImplTest {
public:
MediaControlsImplTestWithMockScheduler() { EnablePlatform(); }
protected:
void SetUp() override {
// DocumentParserTiming has DCHECKS to make sure time > 0.0.
platform_->AdvanceClockSeconds(1);
platform()->AdvanceClockSeconds(1);
MediaControlsImplTest::SetUp();
}
......@@ -1011,9 +1013,6 @@ class MediaControlsImplTestWithMockScheduler : public MediaControlsImplTest {
return false;
return style->GetPropertyValue(CSSPropertyCursor) == "none";
}
ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
platform_;
};
} // namespace
......@@ -1031,23 +1030,23 @@ TEST_F(MediaControlsImplTestWithMockScheduler,
EXPECT_TRUE(IsElementVisible(*panel));
// Tabbing between controls prevents controls from hiding.
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
MediaControls().DispatchEvent(Event::Create("focusin"));
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
EXPECT_TRUE(IsElementVisible(*panel));
// Seeking on the timeline or volume bar prevents controls from hiding.
MediaControls().DispatchEvent(Event::Create("input"));
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
EXPECT_TRUE(IsElementVisible(*panel));
// Pressing a key prevents controls from hiding.
MediaControls().PanelElement()->DispatchEvent(Event::Create("keypress"));
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
EXPECT_TRUE(IsElementVisible(*panel));
// Once user interaction stops, controls can hide.
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
SimulateTransitionEnd(*panel);
EXPECT_FALSE(IsElementVisible(*panel));
}
......@@ -1067,7 +1066,7 @@ TEST_F(MediaControlsImplTestWithMockScheduler, CursorHidesWhenControlsHide) {
EXPECT_FALSE(IsCursorHidden());
// Once the controls hide, the cursor is hidden.
platform_->RunForPeriodSeconds(4);
platform()->RunForPeriodSeconds(4);
EXPECT_TRUE(IsCursorHidden());
// If the mouse moves, the controls are shown and the cursor is no longer
......@@ -1076,7 +1075,7 @@ TEST_F(MediaControlsImplTestWithMockScheduler, CursorHidesWhenControlsHide) {
EXPECT_FALSE(IsCursorHidden());
// Once the controls hide again, the cursor is hidden again.
platform_->RunForPeriodSeconds(4);
platform()->RunForPeriodSeconds(4);
EXPECT_TRUE(IsCursorHidden());
}
......@@ -1088,18 +1087,18 @@ TEST_F(MediaControlsImplTestWithMockScheduler, AccessibleFocusShowsControls) {
MediaControls().MediaElement().SetSrc("http://example.com");
MediaControls().MediaElement().Play();
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
EXPECT_TRUE(IsElementVisible(*panel));
MediaControls().OnAccessibleFocus();
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
EXPECT_TRUE(IsElementVisible(*panel));
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
EXPECT_FALSE(IsElementVisible(*panel));
MediaControls().OnAccessibleFocus();
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
EXPECT_TRUE(IsElementVisible(*panel));
}
......@@ -1112,11 +1111,11 @@ TEST_F(MediaControlsImplTestWithMockScheduler,
MediaControls().MediaElement().SetSrc("http://example.com");
MediaControls().MediaElement().Play();
platform_->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
EXPECT_TRUE(IsElementVisible(*panel));
MediaControls().OnAccessibleFocus();
platform_->RunForPeriodSeconds(4);
platform()->RunForPeriodSeconds(4);
EXPECT_FALSE(IsElementVisible(*panel));
// Display is none but can't be checked via InlineStyle. Adding checks of this
......
......@@ -11,7 +11,6 @@
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/platform/loader/fetch/memory_cache.h"
#include "third_party/blink/renderer/platform/testing/histogram_tester.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
......@@ -40,11 +39,13 @@ class NotificationImageLoaderTest : public PageTestBase {
// use.
loader_(
new NotificationImageLoader(NotificationImageLoader::Type::kIcon)) {
EnablePlatform();
}
~NotificationImageLoaderTest() override {
loader_->Stop();
platform_->GetURLLoaderMockFactory()
platform()
->GetURLLoaderMockFactory()
->UnregisterAllURLsAndClearMemoryCache();
}
......@@ -80,7 +81,6 @@ class NotificationImageLoaderTest : public PageTestBase {
protected:
HistogramTester histogram_tester_;
ScopedTestingPlatformSupport<TestingPlatformSupport> platform_;
private:
Persistent<NotificationImageLoader> loader_;
......@@ -93,7 +93,7 @@ TEST_F(NotificationImageLoaderTest, SuccessTest) {
histogram_tester_.ExpectTotalCount("Notifications.LoadFinishTime.Icon", 0);
histogram_tester_.ExpectTotalCount("Notifications.LoadFileSize.Icon", 0);
histogram_tester_.ExpectTotalCount("Notifications.LoadFailTime.Icon", 0);
platform_->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
platform()->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
EXPECT_EQ(NotificationLoadState::kLoadSuccessful, Loaded());
histogram_tester_.ExpectTotalCount("Notifications.LoadFinishTime.Icon", 1);
histogram_tester_.ExpectUniqueSample("Notifications.LoadFileSize.Icon", 7439,
......@@ -102,9 +102,6 @@ TEST_F(NotificationImageLoaderTest, SuccessTest) {
}
TEST_F(NotificationImageLoaderTest, TimeoutTest) {
ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
platform;
// To test for a timeout, this needs to override the clock in the platform.
// Just creating the mock platform will do everything to set it up.
KURL url = RegisterMockedURL(kNotificationImageLoaderIcon500x500);
......@@ -112,14 +109,14 @@ TEST_F(NotificationImageLoaderTest, TimeoutTest) {
// Run the platform for kImageFetchTimeoutInMs-1 seconds. This should not
// result in a timeout.
platform->RunForPeriodSeconds(kImageFetchTimeoutInMs / 1000 - 1);
platform()->RunForPeriodSeconds(kImageFetchTimeoutInMs / 1000 - 1);
EXPECT_EQ(NotificationLoadState::kNotLoaded, Loaded());
histogram_tester_.ExpectTotalCount("Notifications.LoadFinishTime.Icon", 0);
histogram_tester_.ExpectTotalCount("Notifications.LoadFileSize.Icon", 0);
histogram_tester_.ExpectTotalCount("Notifications.LoadFailTime.Icon", 0);
// Now advance time until a timeout should be expected.
platform->RunForPeriodSeconds(2);
platform()->RunForPeriodSeconds(2);
// If the loader times out, it calls the callback and returns an empty bitmap.
EXPECT_EQ(NotificationLoadState::kLoadFailed, Loaded());
......
......@@ -135,7 +135,9 @@ void SchedulerHelper::OnExitNestedRunLoop() {
}
const base::TickClock* SchedulerHelper::GetClock() const {
return sequence_manager_->GetTickClock();
if (sequence_manager_)
return sequence_manager_->GetTickClock();
return nullptr;
}
base::TimeTicks SchedulerHelper::NowTicks() const {
......
......@@ -296,8 +296,14 @@ void FrameSchedulerImpl::RemoveThrottleableQueueFromBackgroundCPUTimeBudgetPool(
if (!time_budget_pool)
return;
time_budget_pool->RemoveQueue(
main_thread_scheduler_->tick_clock()->NowTicks(), task_queue);
// On tests, the scheduler helper might already be shut down and tick is not
// available.
base::TimeTicks now;
if (main_thread_scheduler_->tick_clock())
now = main_thread_scheduler_->tick_clock()->NowTicks();
else
now = base::TimeTicks::Now();
time_budget_pool->RemoveQueue(now, task_queue);
}
void FrameSchedulerImpl::SetFrameVisible(bool frame_visible) {
......
......@@ -150,6 +150,14 @@ void TestingPlatformSupport::RunUntilIdle() {
base::RunLoop().RunUntilIdle();
}
bool TestingPlatformSupport::IsThreadedAnimationEnabled() {
return is_threaded_animation_enabled_;
}
void TestingPlatformSupport::SetThreadedAnimationEnabled(bool enabled) {
is_threaded_animation_enabled_ = enabled;
}
class ScopedUnittestsEnvironmentSetup::DummyPlatform final
: public blink::Platform {
public:
......
......@@ -68,8 +68,10 @@ class TestingPlatformSupport : public Platform {
override;
WebData GetDataResource(const char* name) override;
InterfaceProvider* GetInterfaceProvider() override;
bool IsThreadedAnimationEnabled() override;
virtual void RunUntilIdle();
void SetThreadedAnimationEnabled(bool enabled);
// Overrides the handling of GetInterface on the platform's associated
// interface provider.
......@@ -91,6 +93,9 @@ class TestingPlatformSupport : public Platform {
Platform* const old_platform_;
std::unique_ptr<TestingInterfaceProvider> interface_provider_;
private:
bool is_threaded_animation_enabled_ = false;
DISALLOW_COPY_AND_ASSIGN(TestingPlatformSupport);
};
......
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