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

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

Issue 2588403002: TestingPlatformSupport: register Platform instance correctly (Closed)
Patch Set: review #16 and merge master Created 3 years, 11 months 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..035091aea01ad1fd890fe06d15b8d8a42690f9a8 100644
--- a/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h
+++ b/third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h
@@ -37,6 +37,7 @@
#include "public/platform/WebCompositorSupport.h"
#include "public/platform/WebScheduler.h"
#include "public/platform/WebThread.h"
+#include "wtf/Assertions.h"
#include "wtf/Vector.h"
#include <memory>
@@ -188,6 +189,34 @@ class TestingPlatformSupportWithMockScheduler : public TestingPlatformSupport {
std::unique_ptr<WebThread> m_thread;
};
+template <class T>
+class ScopedTestingPlatformSupport {
haraken 2017/01/11 08:58:08 Add a comment and explain how this class should be
haraken 2017/01/11 08:58:08 Add STACK_ALLOCATED.
Takashi Toyoshima 2017/01/11 12:46:54 Actually, this can not be a STACK_ALLOCATED class
Takashi Toyoshima 2017/01/11 12:46:54 comments including usage were added.
+ public:
+ ScopedTestingPlatformSupport() : m_originalPlatform(Platform::current()) {}
haraken 2017/01/11 08:58:08 Do we need this constructor?
Takashi Toyoshima 2017/01/11 12:46:54 I noticed there was a potential problem here. Plat
Takashi Toyoshima 2017/01/11 12:46:54 Yes. Here is one example that requires this const
+ explicit ScopedTestingPlatformSupport(
+ std::unique_ptr<T> testingPlatformSupport)
+ : m_originalPlatform(Platform::current()) {
+ reset(std::move(testingPlatformSupport));
+ }
+ void reset(std::unique_ptr<T> testingPlatformSupport) {
+ DCHECK_NE(m_testingPlatformSupport.get(), testingPlatformSupport.get());
+ if (testingPlatformSupport.get())
haraken 2017/01/11 08:58:08 If testingPlatformSupport is null, don't we want t
Takashi Toyoshima 2017/01/11 12:46:54 Good point. To restore a valid platform instance a
+ Platform::setCurrentPlatformForTesting(testingPlatformSupport.get());
+ m_testingPlatformSupport = std::move(testingPlatformSupport);
+ }
+ ~ScopedTestingPlatformSupport() {
+ m_testingPlatformSupport.reset();
+ if (m_originalPlatform)
+ Platform::setCurrentPlatformForTesting(m_originalPlatform);
haraken 2017/01/11 08:58:08 If you apply the change I proposed above, you can
Takashi Toyoshima 2017/01/11 12:46:54 Done.
+ }
+ 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 +231,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