Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1279)

Unified Diff: third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h

Issue 2588403002: TestingPlatformSupport: register Platform instance correctly (Closed)
Patch Set: new plan Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698