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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #ifndef TestingPlatformSupport_h 31 #ifndef TestingPlatformSupport_h
32 #define TestingPlatformSupport_h 32 #define TestingPlatformSupport_h
33 33
34 #include "platform/PlatformExport.h" 34 #include "platform/PlatformExport.h"
35 #include "platform/WebTaskRunner.h" 35 #include "platform/WebTaskRunner.h"
36 #include "public/platform/Platform.h" 36 #include "public/platform/Platform.h"
37 #include "public/platform/WebCompositorSupport.h" 37 #include "public/platform/WebCompositorSupport.h"
38 #include "public/platform/WebScheduler.h" 38 #include "public/platform/WebScheduler.h"
39 #include "public/platform/WebThread.h" 39 #include "public/platform/WebThread.h"
40 #include "wtf/Assertions.h"
40 #include "wtf/Vector.h" 41 #include "wtf/Vector.h"
41 #include <memory> 42 #include <memory>
42 43
43 namespace base { 44 namespace base {
44 class SimpleTestTickClock; 45 class SimpleTestTickClock;
45 class TestDiscardableMemoryAllocator; 46 class TestDiscardableMemoryAllocator;
46 } 47 }
47 48
48 namespace cc { 49 namespace cc {
49 class OrderedSimpleTaskRunner; 50 class OrderedSimpleTaskRunner;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 182
182 protected: 183 protected:
183 static double getTestTime(); 184 static double getTestTime();
184 185
185 std::unique_ptr<base::SimpleTestTickClock> m_clock; 186 std::unique_ptr<base::SimpleTestTickClock> m_clock;
186 scoped_refptr<cc::OrderedSimpleTaskRunner> m_mockTaskRunner; 187 scoped_refptr<cc::OrderedSimpleTaskRunner> m_mockTaskRunner;
187 std::unique_ptr<scheduler::RendererSchedulerImpl> m_scheduler; 188 std::unique_ptr<scheduler::RendererSchedulerImpl> m_scheduler;
188 std::unique_ptr<WebThread> m_thread; 189 std::unique_ptr<WebThread> m_thread;
189 }; 190 };
190 191
192 template <class T>
193 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.
194 public:
195 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
196 explicit ScopedTestingPlatformSupport(
197 std::unique_ptr<T> testingPlatformSupport)
198 : m_originalPlatform(Platform::current()) {
199 reset(std::move(testingPlatformSupport));
200 }
201 void reset(std::unique_ptr<T> testingPlatformSupport) {
202 DCHECK_NE(m_testingPlatformSupport.get(), testingPlatformSupport.get());
203 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
204 Platform::setCurrentPlatformForTesting(testingPlatformSupport.get());
205 m_testingPlatformSupport = std::move(testingPlatformSupport);
206 }
207 ~ScopedTestingPlatformSupport() {
208 m_testingPlatformSupport.reset();
209 if (m_originalPlatform)
210 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.
211 }
212 const T* operator->() const { return m_testingPlatformSupport.get(); }
213 T* operator->() { return m_testingPlatformSupport.get(); }
214
215 private:
216 Platform* m_originalPlatform;
217 std::unique_ptr<T> m_testingPlatformSupport;
218 };
219
191 class ScopedUnittestsEnvironmentSetup { 220 class ScopedUnittestsEnvironmentSetup {
192 WTF_MAKE_NONCOPYABLE(ScopedUnittestsEnvironmentSetup); 221 WTF_MAKE_NONCOPYABLE(ScopedUnittestsEnvironmentSetup);
193 222
194 public: 223 public:
195 ScopedUnittestsEnvironmentSetup(int argc, char** argv); 224 ScopedUnittestsEnvironmentSetup(int argc, char** argv);
196 ~ScopedUnittestsEnvironmentSetup(); 225 ~ScopedUnittestsEnvironmentSetup();
197 226
198 private: 227 private:
199 class DummyPlatform; 228 class DummyPlatform;
200 std::unique_ptr<base::TestDiscardableMemoryAllocator> 229 std::unique_ptr<base::TestDiscardableMemoryAllocator>
201 m_discardableMemoryAllocator; 230 m_discardableMemoryAllocator;
202 std::unique_ptr<DummyPlatform> m_platform; 231 std::unique_ptr<DummyPlatform> m_platform;
203 std::unique_ptr<cc_blink::WebCompositorSupportImpl> m_compositorSupport; 232 std::unique_ptr<cc_blink::WebCompositorSupportImpl> m_compositorSupport;
204 TestingPlatformSupport::Config m_testingPlatformConfig; 233 TestingPlatformSupport::Config m_testingPlatformConfig;
205 std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; 234 ScopedTestingPlatformSupport<TestingPlatformSupport> m_testingPlatformSupport;
206 }; 235 };
207 236
208 } // namespace blink 237 } // namespace blink
209 238
210 #endif // TestingPlatformSupport_h 239 #endif // TestingPlatformSupport_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698