| Index: third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp
|
| diff --git a/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp b/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp
|
| index 20eb5e342a807e2c9b4f0e50d4f42dd8309c4d1f..76ce2caec2833145fdfa28981cc829cd709f0953 100644
|
| --- a/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp
|
| +++ b/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp
|
| @@ -32,13 +32,18 @@
|
|
|
| #include "base/command_line.h"
|
| #include "base/memory/discardable_memory_allocator.h"
|
| +#include "base/memory/ptr_util.h"
|
| #include "base/metrics/statistics_recorder.h"
|
| #include "base/test/icu_test_util.h"
|
| #include "base/test/test_discardable_memory_allocator.h"
|
| #include "cc/blink/web_compositor_support_impl.h"
|
| +#include "cc/test/ordered_simple_task_runner.h"
|
| #include "platform/EventTracer.h"
|
| #include "platform/HTTPNames.h"
|
| #include "platform/heap/Heap.h"
|
| +#include "platform/scheduler/base/test_time_source.h"
|
| +#include "platform/scheduler/child/scheduler_tqm_delegate_for_test.h"
|
| +#include "platform/scheduler/renderer/renderer_scheduler_impl.h"
|
| #include "wtf/CryptographicallyRandomNumber.h"
|
| #include "wtf/CurrentTime.h"
|
| #include "wtf/PtrUtil.h"
|
| @@ -88,7 +93,10 @@ WebString TestingPlatformSupport::defaultLocale()
|
|
|
| WebCompositorSupport* TestingPlatformSupport::compositorSupport()
|
| {
|
| - return m_config.compositorSupport;
|
| + if (m_config.compositorSupport)
|
| + return m_config.compositorSupport;
|
| +
|
| + return m_oldPlatform ? m_oldPlatform->compositorSupport() : nullptr;
|
| }
|
|
|
| WebThread* TestingPlatformSupport::currentThread()
|
| @@ -96,135 +104,119 @@ WebThread* TestingPlatformSupport::currentThread()
|
| return m_oldPlatform ? m_oldPlatform->currentThread() : nullptr;
|
| }
|
|
|
| -class TestingPlatformMockWebTaskRunner : public WebTaskRunner {
|
| - WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebTaskRunner);
|
| -public:
|
| - explicit TestingPlatformMockWebTaskRunner(Deque<std::unique_ptr<WebTaskRunner::Task>>* tasks) : m_tasks(tasks) { }
|
| - ~TestingPlatformMockWebTaskRunner() override { }
|
| -
|
| - void postTask(const WebTraceLocation&, Task* task) override
|
| - {
|
| - m_tasks->append(wrapUnique(task));
|
| - }
|
| -
|
| - void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) override
|
| - {
|
| - NOTREACHED();
|
| - }
|
| -
|
| - bool runsTasksOnCurrentThread() override
|
| - {
|
| - NOTREACHED();
|
| - return true;
|
| - }
|
| -
|
| - std::unique_ptr<WebTaskRunner> clone() override
|
| - {
|
| - return WTF::wrapUnique(new TestingPlatformMockWebTaskRunner(m_tasks));
|
| - }
|
| -
|
| - double virtualTimeSeconds() const override
|
| - {
|
| - NOTREACHED();
|
| - return 0.0;
|
| - }
|
| -
|
| - double monotonicallyIncreasingVirtualTimeSeconds() const override
|
| - {
|
| - NOTREACHED();
|
| - return 0.0;
|
| - }
|
| -
|
| - base::SingleThreadTaskRunner* taskRunner() override
|
| - {
|
| - NOTREACHED();
|
| - return nullptr;
|
| - }
|
| +WebBlobRegistry* TestingPlatformSupport::blobRegistry()
|
| +{
|
| + return m_oldPlatform ? m_oldPlatform->blobRegistry() : nullptr;
|
| +}
|
|
|
| -private:
|
| - Deque<std::unique_ptr<WebTaskRunner::Task>>* m_tasks; // NOT OWNED
|
| -};
|
| +WebClipboard* TestingPlatformSupport::clipboard()
|
| +{
|
| + return m_oldPlatform ? m_oldPlatform->clipboard() : nullptr;
|
| +}
|
|
|
| -// TestingPlatformMockScheduler definition:
|
| +WebFileUtilities* TestingPlatformSupport::fileUtilities()
|
| +{
|
| + return m_oldPlatform ? m_oldPlatform->fileUtilities() : nullptr;
|
| +}
|
|
|
| -TestingPlatformMockScheduler::TestingPlatformMockScheduler()
|
| - : m_mockWebTaskRunner(wrapUnique(new TestingPlatformMockWebTaskRunner(&m_tasks))) { }
|
| +WebIDBFactory* TestingPlatformSupport::idbFactory()
|
| +{
|
| + return m_oldPlatform ? m_oldPlatform->idbFactory() : nullptr;
|
| +}
|
|
|
| -TestingPlatformMockScheduler::~TestingPlatformMockScheduler() { }
|
| +WebMimeRegistry* TestingPlatformSupport::mimeRegistry()
|
| +{
|
| + return m_oldPlatform ? m_oldPlatform->mimeRegistry() : nullptr;
|
| +}
|
|
|
| -WebTaskRunner* TestingPlatformMockScheduler::loadingTaskRunner()
|
| +WebURLLoaderMockFactory* TestingPlatformSupport::getURLLoaderMockFactory()
|
| {
|
| - return m_mockWebTaskRunner.get();
|
| + return m_oldPlatform ? m_oldPlatform->getURLLoaderMockFactory() : nullptr;
|
| }
|
|
|
| -WebTaskRunner* TestingPlatformMockScheduler::timerTaskRunner()
|
| +WebURLLoader* TestingPlatformSupport::createURLLoader()
|
| {
|
| - return m_mockWebTaskRunner.get();
|
| + return m_oldPlatform ? m_oldPlatform->createURLLoader() : nullptr;
|
| }
|
|
|
| -void TestingPlatformMockScheduler::runSingleTask()
|
| +WebData TestingPlatformSupport::loadResource(const char* name)
|
| {
|
| - if (m_tasks.isEmpty())
|
| - return;
|
| - m_tasks.takeFirst()->run();
|
| + return m_oldPlatform ? m_oldPlatform->loadResource(name) : WebData();
|
| }
|
|
|
| -void TestingPlatformMockScheduler::runAllTasks()
|
| +WebURLError TestingPlatformSupport::cancelledError(const WebURL& url) const
|
| {
|
| - while (!m_tasks.isEmpty())
|
| - m_tasks.takeFirst()->run();
|
| + return m_oldPlatform ? m_oldPlatform->cancelledError(url) : WebURLError();
|
| }
|
|
|
| -class TestingPlatformMockWebThread : public WebThread {
|
| - WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebThread);
|
| -public:
|
| - TestingPlatformMockWebThread() : m_mockWebScheduler(wrapUnique(new TestingPlatformMockScheduler)) { }
|
| - ~TestingPlatformMockWebThread() override { }
|
| +// TestingPlatformSupportWithMockScheduler definition:
|
|
|
| - WebTaskRunner* getWebTaskRunner() override
|
| - {
|
| - return m_mockWebScheduler->timerTaskRunner();
|
| - }
|
| +TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler()
|
| + : TestingPlatformSupportWithMockScheduler(TestingPlatformSupport::Config()) { }
|
|
|
| - bool isCurrentThread() const override
|
| - {
|
| - NOTREACHED();
|
| - return true;
|
| - }
|
| +TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler(const Config& config)
|
| + : TestingPlatformSupport(config)
|
| + , m_clock(new base::SimpleTestTickClock())
|
| + , m_mockTaskRunner(new cc::OrderedSimpleTaskRunner(m_clock.get(), true))
|
| + , m_scheduler(new scheduler::RendererSchedulerImpl(scheduler::SchedulerTqmDelegateForTest::Create(m_mockTaskRunner, base::WrapUnique(new scheduler::TestTimeSource(m_clock.get())))))
|
| + , m_thread(m_scheduler->CreateMainThread())
|
| +{
|
| + // Set the work batch size to one so RunPendingTasks behaves as expected.
|
| + m_scheduler->GetSchedulerHelperForTesting()->SetWorkBatchSizeForTesting(1);
|
|
|
| - WebScheduler* scheduler() const override
|
| - {
|
| - return m_mockWebScheduler.get();
|
| - }
|
| + WTF::setTimeFunctionsForTesting(getTestTime);
|
| +}
|
|
|
| - TestingPlatformMockScheduler* mockWebScheduler()
|
| - {
|
| - return m_mockWebScheduler.get();
|
| - }
|
| +TestingPlatformSupportWithMockScheduler::~TestingPlatformSupportWithMockScheduler()
|
| +{
|
| + WTF::setTimeFunctionsForTesting(nullptr);
|
| + m_scheduler->Shutdown();
|
| +}
|
|
|
| -private:
|
| - std::unique_ptr<TestingPlatformMockScheduler> m_mockWebScheduler;
|
| -};
|
| +WebThread* TestingPlatformSupportWithMockScheduler::currentThread()
|
| +{
|
| + if (m_thread->isCurrentThread())
|
| + return m_thread.get();
|
| + return TestingPlatformSupport::currentThread();
|
| +}
|
|
|
| -// TestingPlatformSupportWithMockScheduler definition:
|
| +void TestingPlatformSupportWithMockScheduler::runSingleTask()
|
| +{
|
| + m_mockTaskRunner->SetRunTaskLimit(1);
|
| + m_mockTaskRunner->RunPendingTasks();
|
| + m_mockTaskRunner->ClearRunTaskLimit();
|
| +}
|
|
|
| -TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler()
|
| - : m_mockWebThread(wrapUnique(new TestingPlatformMockWebThread())) { }
|
| +void TestingPlatformSupportWithMockScheduler::runUntilIdle()
|
| +{
|
| + m_mockTaskRunner->RunUntilIdle();
|
| +}
|
|
|
| -TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler(const Config& config)
|
| - : TestingPlatformSupport(config)
|
| - , m_mockWebThread(wrapUnique(new TestingPlatformMockWebThread())) { }
|
| +void TestingPlatformSupportWithMockScheduler::runForPeriodSeconds(double seconds)
|
| +{
|
| + m_mockTaskRunner->RunForPeriod(base::TimeDelta::FromSecondsD(seconds));
|
| +}
|
|
|
| -TestingPlatformSupportWithMockScheduler::~TestingPlatformSupportWithMockScheduler() { }
|
| +void TestingPlatformSupportWithMockScheduler::advanceClockSeconds(double seconds)
|
| +{
|
| + m_clock->Advance(base::TimeDelta::FromSecondsD(seconds));
|
| +}
|
|
|
| -WebThread* TestingPlatformSupportWithMockScheduler::currentThread()
|
| +void TestingPlatformSupportWithMockScheduler::setAutoAdvanceNowToPendingTasks(bool autoAdvance)
|
| +{
|
| + m_mockTaskRunner->SetAutoAdvanceNowToPendingTasks(autoAdvance);
|
| +}
|
| +
|
| +scheduler::RendererScheduler* TestingPlatformSupportWithMockScheduler::rendererScheduler() const
|
| {
|
| - return m_mockWebThread.get();
|
| + return m_scheduler.get();
|
| }
|
|
|
| -TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebScheduler()
|
| +// static
|
| +double TestingPlatformSupportWithMockScheduler::getTestTime()
|
| {
|
| - return m_mockWebThread->mockWebScheduler();
|
| + TestingPlatformSupportWithMockScheduler* platform = static_cast<TestingPlatformSupportWithMockScheduler*>(Platform::current());
|
| + return (platform->m_clock->NowTicks() - base::TimeTicks()).InSecondsF();
|
| }
|
|
|
| class ScopedUnittestsEnvironmentSetup::DummyPlatform final : public blink::Platform {
|
|
|