Chromium Code Reviews| 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 528f9e3e4f33eaace6bf030d62239db4ede5bb3d..2c647ff0718b85524df830a0b0595333d5e988da 100644 |
| --- a/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp |
| +++ b/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp |
| @@ -30,11 +30,48 @@ |
| #include "platform/testing/TestingPlatformSupport.h" |
| +#include "platform/EventTracer.h" |
| +#include "platform/HTTPNames.h" |
| +#include "platform/heap/Heap.h" |
| +#include "wtf/CryptographicallyRandomNumber.h" |
| +#include "wtf/CurrentTime.h" |
| #include "wtf/PtrUtil.h" |
| +#include "wtf/WTF.h" |
| +#include "wtf/allocator/Partitions.h" |
| +#include <base/memory/discardable_memory_allocator.h> |
|
tkent
2016/08/02 23:00:45
I know you just move the code, but we should not a
Łukasz Anforowicz
2016/08/03 16:02:46
Thanks for pointing this out - I assumed that the
|
| +#include <base/metrics/statistics_recorder.h> |
| +#include <base/test/test_discardable_memory_allocator.h> |
| +#include <cc/blink/web_compositor_support_impl.h> |
| #include <memory> |
| namespace blink { |
| +namespace { |
| + |
| +double dummyCurrentTime() |
| +{ |
| + return 0.0; |
| +} |
| + |
| +class DummyThread final : public blink::WebThread { |
| +public: |
| + bool isCurrentThread() const override { return true; } |
| + blink::WebScheduler* scheduler() const override { return nullptr; } |
| +}; |
| + |
| +class DummyPlatform final : public blink::Platform { |
| +public: |
| + DummyPlatform() { } |
| + |
| + blink::WebThread* currentThread() override |
| + { |
| + static DummyThread dummyThread; |
| + return &dummyThread; |
| + }; |
| +}; |
| + |
| +} // namespace |
| + |
| TestingPlatformSupport::TestingPlatformSupport() |
| : TestingPlatformSupport(TestingPlatformSupport::Config()) |
| { |
| @@ -193,4 +230,59 @@ TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc |
| return m_mockWebThread->mockWebScheduler(); |
| } |
| +class ScopedUnittestsEnvironmentSetup::Impl { |
| +public: |
| + Impl(); |
| + ~Impl(); |
| +private: |
| + base::TestDiscardableMemoryAllocator m_discardableMemoryAllocator; |
| + std::unique_ptr<DummyPlatform> m_platform; |
| + |
| + cc_blink::WebCompositorSupportImpl m_compositorSupport; |
| + TestingPlatformSupport::Config m_testingPlatformConfig; |
| + std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; |
| +}; |
| + |
| +ScopedUnittestsEnvironmentSetup::Impl::Impl() |
| +{ |
| + base::DiscardableMemoryAllocator::SetInstance(&m_discardableMemoryAllocator); |
| + base::StatisticsRecorder::Initialize(); |
| + |
| + m_platform = wrapUnique(new DummyPlatform); |
| + Platform::setCurrentPlatformForTesting(m_platform.get()); |
| + |
| + WTF::Partitions::initialize(nullptr); |
| + WTF::setTimeFunctionsForTesting(dummyCurrentTime); |
| + WTF::initialize(nullptr); |
| + |
| + m_testingPlatformConfig.compositorSupport = &m_compositorSupport; |
| + m_testingPlatformSupport = wrapUnique(new TestingPlatformSupport(m_testingPlatformConfig)); |
| + |
| + ProcessHeap::init(); |
| + ThreadState::attachMainThread(); |
| + ThreadState::current()->registerTraceDOMWrappers(nullptr, nullptr, nullptr); |
| + EventTracer::initialize(); |
| + HTTPNames::init(); |
| +} |
| + |
| +ScopedUnittestsEnvironmentSetup::Impl::~Impl() |
| +{ |
| + blink::ThreadState::detachMainThread(); |
| + blink::ProcessHeap::shutdown(); |
| + m_testingPlatformSupport.reset(); |
| + |
| + WTF::shutdown(); |
| + WTF::Partitions::shutdown(); |
| +} |
| + |
| +ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup() |
| +{ |
| + m_impl = wrapUnique(new Impl()); |
| +} |
| + |
| +ScopedUnittestsEnvironmentSetup::~ScopedUnittestsEnvironmentSetup() |
| +{ |
| + m_impl.reset(); |
| +} |
| + |
| } // namespace blink |