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..e6bf67d6c954c522046ba90add19ca30a49bb0d6 100644 |
--- a/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp |
+++ b/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp |
@@ -30,11 +30,50 @@ |
#include "platform/testing/TestingPlatformSupport.h" |
+#include "base/command_line.h" |
+#include "base/memory/discardable_memory_allocator.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 "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 <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 +232,63 @@ TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc |
return m_mockWebThread->mockWebScheduler(); |
} |
+class ScopedUnittestsEnvironmentSetup::Impl { |
+public: |
+ Impl(int argc, char** argv); |
+ ~Impl(); |
+private: |
+ base::TestDiscardableMemoryAllocator m_discardableMemoryAllocator; |
+ std::unique_ptr<DummyPlatform> m_platform; |
+ |
+ cc_blink::WebCompositorSupportImpl m_compositorSupport; |
esprehn
2016/08/10 04:05:29
Just put all of this in the header, there's no nee
Łukasz Anforowicz
2016/08/10 19:31:17
Done.
I need to note that I've also wrapped more
|
+ TestingPlatformSupport::Config m_testingPlatformConfig; |
+ std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; |
+}; |
+ |
+ScopedUnittestsEnvironmentSetup::Impl::Impl(int argc, char** argv) |
+{ |
+ base::CommandLine::Init(argc, argv); |
+ |
+ base::test::InitializeICUForTesting(); |
+ |
+ 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(int argc, char** argv) |
+{ |
+ m_impl = wrapUnique(new Impl(argc, argv)); |
+} |
+ |
+ScopedUnittestsEnvironmentSetup::~ScopedUnittestsEnvironmentSetup() |
+{ |
+ m_impl.reset(); |
esprehn
2016/08/10 04:05:29
manually clearing a unique_ptr in the destructor i
Łukasz Anforowicz
2016/08/10 19:31:17
You're right - this needs at least an explicit com
|
+} |
+ |
} // namespace blink |