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

Unified Diff: third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h

Issue 2266443002: Optimize posting of WTF::Closure and improve scheduler test mocks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cut back to just the WTF::Closure fix plus the scheduler test mock refactor. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h
diff --git a/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h b/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h
index 0421cc0cc4c7d63ce7384e69d29c73a21650e9ed..78a32bf75162f75254b0e19635292ce72bf466ad 100644
--- a/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h
+++ b/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h
@@ -40,15 +40,23 @@
#include <memory>
namespace base {
+class SimpleTestTickClock;
class TestDiscardableMemoryAllocator;
-} // namespace base
+}
+
+namespace cc {
+class OrderedSimpleTaskRunner;
+}
namespace cc_blink {
class WebCompositorSupportImpl;
} // namespace cc_blink
namespace blink {
-
+namespace scheduler {
+class RendererScheduler;
+class RendererSchedulerImpl;
+}
class TestingPlatformMockWebTaskRunner;
class TestingPlatformMockWebThread;
class WebCompositorSupport;
@@ -57,36 +65,6 @@ class WebThread;
class TestingCompositorSupport : public WebCompositorSupport {
};
-class TestingPlatformMockScheduler : public WebScheduler {
- WTF_MAKE_NONCOPYABLE(TestingPlatformMockScheduler);
-public:
- TestingPlatformMockScheduler();
- ~TestingPlatformMockScheduler() override;
-
- void runSingleTask();
- void runAllTasks();
-
- // WebScheduler implementation:
- WebTaskRunner* loadingTaskRunner() override;
- WebTaskRunner* timerTaskRunner() override;
- void shutdown() override {}
- bool shouldYieldForHighPriorityWork() override { return false; }
- bool canExceedIdleDeadlineIfRequired() override { return false; }
- void postIdleTask(const WebTraceLocation&, WebThread::IdleTask*) override { }
- void postNonNestableIdleTask(const WebTraceLocation&, WebThread::IdleTask*) override { }
- void postIdleTaskAfterWakeup(const WebTraceLocation&, WebThread::IdleTask*) override { }
- std::unique_ptr<WebViewScheduler> createWebViewScheduler(InterventionReporter*) override { return nullptr; }
- void suspendTimerQueue() override { }
- void resumeTimerQueue() override { }
- void addPendingNavigation(WebScheduler::NavigatingFrameType) override { }
- void removePendingNavigation(WebScheduler::NavigatingFrameType) override { }
- void onNavigationStarted() override { }
-
-private:
- WTF::Deque<std::unique_ptr<WebTaskRunner::Task>> m_tasks;
- std::unique_ptr<TestingPlatformMockWebTaskRunner> m_mockWebTaskRunner;
-};
-
class TestingPlatformSupport : public Platform {
WTF_MAKE_NONCOPYABLE(TestingPlatformSupport);
public:
@@ -103,6 +81,16 @@ public:
WebString defaultLocale() override;
WebCompositorSupport* compositorSupport() override;
WebThread* currentThread() override;
+ WebBlobRegistry* blobRegistry() override;
+ WebClipboard* clipboard() override;
+ WebFileUtilities* fileUtilities() override;
+ WebIDBFactory* idbFactory() override;
+ WebMimeRegistry* mimeRegistry() override;
+ WebURLLoaderMockFactory* getURLLoaderMockFactory() override;
+ blink::WebURLLoader* createURLLoader() override;
+
+ WebData loadResource(const char* name) override;
+ WebURLError cancelledError(const WebURL&) const override;
protected:
const Config m_config;
@@ -118,10 +106,36 @@ public:
// Platform:
WebThread* currentThread() override;
- TestingPlatformMockScheduler* mockWebScheduler();
+
+ // Runs a single task.
+ void runSingleTask();
+
+ // Runs all currently queued immediate tasks and delayed tasks whose delay has expired
+ // plus any immediate tasks that are posted as a result of running those tasks.
+ //
+ // This function ignores future delayed tasks when deciding if the system is idle.
+ // If you need to ensure delayed tasks run, try runForPeriodSeconds() instead.
+ void runUntilIdle();
+
+ // Runs for |seconds|. Note we use a testing clock rather than the wall clock here.
+ void runForPeriodSeconds(double seconds);
+
+ // Advances |m_clock| by |seconds|.
+ void advanceClockSeconds(double seconds);
+
+ scheduler::RendererScheduler* rendererScheduler() const;
+
+ // Controls the behavior of |m_mockTaskRunner| if true, then |m_clock| will
+ // be advanced to the next timer when there's no more immediate work to do.
+ void setAutoAdvanceNowToPendingTasks(bool);
protected:
- std::unique_ptr<TestingPlatformMockWebThread> m_mockWebThread;
+ static double getTestTime();
+
+ std::unique_ptr<base::SimpleTestTickClock> m_clock;
+ scoped_refptr<cc::OrderedSimpleTaskRunner> m_mockTaskRunner;
+ std::unique_ptr<scheduler::RendererSchedulerImpl> m_scheduler;
+ std::unique_ptr<WebThread> m_thread;
};
class ScopedUnittestsEnvironmentSetup {

Powered by Google App Engine
This is Rietveld 408576698