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..e1e2ff4524fa56fe632476685a561095dc685202 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/i18n/icu_util.h" |
+#include "base/memory/discardable_memory_allocator.h" |
+#include "base/metrics/statistics_recorder.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,68 @@ TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc |
return m_mockWebThread->mockWebScheduler(); |
} |
+class ScopedUnittestsEnvironmentSetup::Impl { |
+public: |
+ Impl(int argc, char** argv, TestType); |
+ ~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( |
+ int argc, char** argv, TestType testType) |
+{ |
+ base::CommandLine::Init(argc, argv); |
+ |
+ // Make sure we don't initialize twice in case of unit tests - |
+ // base::TestSuite::Initialize already calls base::i18n::InitializeICU. |
+ if (testType == TestType::LibFuzzer) |
esprehn
2016/08/04 04:37:53
This doesn't feel right, why is the fuzzer running
Łukasz Anforowicz
2016/08/04 17:37:30
Good catch / call.
It turns out that test code sh
|
+ base::i18n::InitializeICU(); |
+ |
+ 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, TestType testType) |
+{ |
+ m_impl = wrapUnique(new Impl(argc, argv, testType)); |
+} |
+ |
+ScopedUnittestsEnvironmentSetup::~ScopedUnittestsEnvironmentSetup() |
+{ |
+ m_impl.reset(); |
+} |
+ |
} // namespace blink |