OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/testing/TestingPlatformSupport.h" | 31 #include "platform/testing/TestingPlatformSupport.h" |
32 | 32 |
| 33 #include "platform/EventTracer.h" |
| 34 #include "platform/HTTPNames.h" |
| 35 #include "platform/heap/Heap.h" |
| 36 #include "wtf/CryptographicallyRandomNumber.h" |
| 37 #include "wtf/CurrentTime.h" |
33 #include "wtf/PtrUtil.h" | 38 #include "wtf/PtrUtil.h" |
| 39 #include "wtf/WTF.h" |
| 40 #include "wtf/allocator/Partitions.h" |
| 41 #include <base/memory/discardable_memory_allocator.h> |
| 42 #include <base/metrics/statistics_recorder.h> |
| 43 #include <base/test/test_discardable_memory_allocator.h> |
| 44 #include <cc/blink/web_compositor_support_impl.h> |
34 #include <memory> | 45 #include <memory> |
35 | 46 |
36 namespace blink { | 47 namespace blink { |
37 | 48 |
| 49 namespace { |
| 50 |
| 51 double dummyCurrentTime() |
| 52 { |
| 53 return 0.0; |
| 54 } |
| 55 |
| 56 class DummyThread final : public blink::WebThread { |
| 57 public: |
| 58 bool isCurrentThread() const override { return true; } |
| 59 blink::WebScheduler* scheduler() const override { return nullptr; } |
| 60 }; |
| 61 |
| 62 class DummyPlatform final : public blink::Platform { |
| 63 public: |
| 64 DummyPlatform() { } |
| 65 |
| 66 blink::WebThread* currentThread() override |
| 67 { |
| 68 static DummyThread dummyThread; |
| 69 return &dummyThread; |
| 70 }; |
| 71 }; |
| 72 |
| 73 } // namespace |
| 74 |
38 TestingPlatformSupport::TestingPlatformSupport() | 75 TestingPlatformSupport::TestingPlatformSupport() |
39 : TestingPlatformSupport(TestingPlatformSupport::Config()) | 76 : TestingPlatformSupport(TestingPlatformSupport::Config()) |
40 { | 77 { |
41 } | 78 } |
42 | 79 |
43 TestingPlatformSupport::TestingPlatformSupport(const Config& config) | 80 TestingPlatformSupport::TestingPlatformSupport(const Config& config) |
44 : m_config(config) | 81 : m_config(config) |
45 , m_oldPlatform(Platform::current()) | 82 , m_oldPlatform(Platform::current()) |
46 { | 83 { |
47 ASSERT(m_oldPlatform); | 84 ASSERT(m_oldPlatform); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() | 223 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() |
187 { | 224 { |
188 return m_mockWebThread.get(); | 225 return m_mockWebThread.get(); |
189 } | 226 } |
190 | 227 |
191 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc
heduler() | 228 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc
heduler() |
192 { | 229 { |
193 return m_mockWebThread->mockWebScheduler(); | 230 return m_mockWebThread->mockWebScheduler(); |
194 } | 231 } |
195 | 232 |
| 233 class ScopedUnittestsEnvironmentSetup::Impl { |
| 234 public: |
| 235 Impl(); |
| 236 ~Impl(); |
| 237 private: |
| 238 base::TestDiscardableMemoryAllocator m_discardableMemoryAllocator; |
| 239 std::unique_ptr<DummyPlatform> m_platform; |
| 240 |
| 241 cc_blink::WebCompositorSupportImpl m_compositorSupport; |
| 242 TestingPlatformSupport::Config m_testingPlatformConfig; |
| 243 std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; |
| 244 }; |
| 245 |
| 246 ScopedUnittestsEnvironmentSetup::Impl::Impl() |
| 247 { |
| 248 base::DiscardableMemoryAllocator::SetInstance(&m_discardableMemoryAllocator)
; |
| 249 base::StatisticsRecorder::Initialize(); |
| 250 |
| 251 m_platform = wrapUnique(new DummyPlatform); |
| 252 Platform::setCurrentPlatformForTesting(m_platform.get()); |
| 253 |
| 254 WTF::Partitions::initialize(nullptr); |
| 255 WTF::setTimeFunctionsForTesting(dummyCurrentTime); |
| 256 WTF::initialize(nullptr); |
| 257 |
| 258 m_testingPlatformConfig.compositorSupport = &m_compositorSupport; |
| 259 m_testingPlatformSupport = wrapUnique(new TestingPlatformSupport(m_testingPl
atformConfig)); |
| 260 |
| 261 ProcessHeap::init(); |
| 262 ThreadState::attachMainThread(); |
| 263 ThreadState::current()->registerTraceDOMWrappers(nullptr, nullptr, nullptr); |
| 264 EventTracer::initialize(); |
| 265 HTTPNames::init(); |
| 266 } |
| 267 |
| 268 ScopedUnittestsEnvironmentSetup::Impl::~Impl() |
| 269 { |
| 270 blink::ThreadState::detachMainThread(); |
| 271 blink::ProcessHeap::shutdown(); |
| 272 m_testingPlatformSupport.reset(); |
| 273 |
| 274 WTF::shutdown(); |
| 275 WTF::Partitions::shutdown(); |
| 276 } |
| 277 |
| 278 ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup() |
| 279 { |
| 280 m_impl = wrapUnique(new Impl()); |
| 281 } |
| 282 |
| 283 ScopedUnittestsEnvironmentSetup::~ScopedUnittestsEnvironmentSetup() |
| 284 { |
| 285 m_impl.reset(); |
| 286 } |
| 287 |
196 } // namespace blink | 288 } // namespace blink |
OLD | NEW |