Chromium Code Reviews| 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 159c0febae33681c850788625010da4a68eee369..49e60e5221568eb72a96605ca31bf8654e5b7ee7 100644 |
| --- a/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h |
| +++ b/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h |
| @@ -31,6 +31,7 @@ |
| #ifndef TestingPlatformSupport_h |
| #define TestingPlatformSupport_h |
| +#include "base/logging.h" |
|
Takashi Toyoshima
2017/01/11 08:35:19
removed
|
| #include "platform/PlatformExport.h" |
| #include "platform/WebTaskRunner.h" |
| #include "public/platform/Platform.h" |
| @@ -188,6 +189,33 @@ class TestingPlatformSupportWithMockScheduler : public TestingPlatformSupport { |
| std::unique_ptr<WebThread> m_thread; |
| }; |
| +template <class T> |
| +class ScopedTestingPlatformSupport { |
| + public: |
| + ScopedTestingPlatformSupport() : m_originalPlatform(Platform::current()) {} |
| + explicit ScopedTestingPlatformSupport(T* testingPlatformSupport) |
|
jbroman
2016/12/22 15:27:54
Taking ownership by raw pointer, here and below, i
Takashi Toyoshima
2017/01/11 08:35:19
Done.
|
| + : m_originalPlatform(Platform::current()) { |
| + reset(testingPlatformSupport); |
| + } |
| + void reset(T* testingPlatformSupport) { |
| + DCHECK_NE(m_testingPlatformSupport.get(), testingPlatformSupport); |
| + if (testingPlatformSupport) |
| + Platform::setCurrentPlatformForTesting(testingPlatformSupport); |
| + m_testingPlatformSupport.reset(testingPlatformSupport); |
| + } |
| + ~ScopedTestingPlatformSupport() { |
| + m_testingPlatformSupport.reset(); |
| + if (m_originalPlatform) |
| + Platform::setCurrentPlatformForTesting(m_originalPlatform); |
| + } |
| + const T* operator->() const { return m_testingPlatformSupport.get(); } |
| + T* operator->() { return m_testingPlatformSupport.get(); } |
| + |
| + private: |
| + Platform* m_originalPlatform; |
| + std::unique_ptr<T> m_testingPlatformSupport; |
| +}; |
| + |
| class ScopedUnittestsEnvironmentSetup { |
| WTF_MAKE_NONCOPYABLE(ScopedUnittestsEnvironmentSetup); |
| @@ -202,7 +230,7 @@ class ScopedUnittestsEnvironmentSetup { |
| std::unique_ptr<DummyPlatform> m_platform; |
| std::unique_ptr<cc_blink::WebCompositorSupportImpl> m_compositorSupport; |
| TestingPlatformSupport::Config m_testingPlatformConfig; |
| - std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; |
| + ScopedTestingPlatformSupport<TestingPlatformSupport> m_testingPlatformSupport; |
| }; |
| } // namespace blink |