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 "base/command_line.h" |
| 34 #include "base/memory/discardable_memory_allocator.h" |
| 35 #include "base/metrics/statistics_recorder.h" |
| 36 #include "base/test/icu_test_util.h" |
| 37 #include "base/test/test_discardable_memory_allocator.h" |
| 38 #include "cc/blink/web_compositor_support_impl.h" |
| 39 #include "platform/EventTracer.h" |
| 40 #include "platform/HTTPNames.h" |
| 41 #include "platform/heap/Heap.h" |
| 42 #include "wtf/CryptographicallyRandomNumber.h" |
| 43 #include "wtf/CurrentTime.h" |
33 #include "wtf/PtrUtil.h" | 44 #include "wtf/PtrUtil.h" |
| 45 #include "wtf/WTF.h" |
| 46 #include "wtf/allocator/Partitions.h" |
34 #include <memory> | 47 #include <memory> |
35 | 48 |
36 namespace blink { | 49 namespace blink { |
37 | 50 |
| 51 namespace { |
| 52 |
| 53 double dummyCurrentTime() |
| 54 { |
| 55 return 0.0; |
| 56 } |
| 57 |
| 58 class DummyThread final : public blink::WebThread { |
| 59 public: |
| 60 bool isCurrentThread() const override { return true; } |
| 61 blink::WebScheduler* scheduler() const override { return nullptr; } |
| 62 }; |
| 63 |
| 64 } // namespace |
| 65 |
38 TestingPlatformSupport::TestingPlatformSupport() | 66 TestingPlatformSupport::TestingPlatformSupport() |
39 : TestingPlatformSupport(TestingPlatformSupport::Config()) | 67 : TestingPlatformSupport(TestingPlatformSupport::Config()) |
40 { | 68 { |
41 } | 69 } |
42 | 70 |
43 TestingPlatformSupport::TestingPlatformSupport(const Config& config) | 71 TestingPlatformSupport::TestingPlatformSupport(const Config& config) |
44 : m_config(config) | 72 : m_config(config) |
45 , m_oldPlatform(Platform::current()) | 73 , m_oldPlatform(Platform::current()) |
46 { | 74 { |
47 ASSERT(m_oldPlatform); | 75 ASSERT(m_oldPlatform); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() | 214 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() |
187 { | 215 { |
188 return m_mockWebThread.get(); | 216 return m_mockWebThread.get(); |
189 } | 217 } |
190 | 218 |
191 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc
heduler() | 219 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc
heduler() |
192 { | 220 { |
193 return m_mockWebThread->mockWebScheduler(); | 221 return m_mockWebThread->mockWebScheduler(); |
194 } | 222 } |
195 | 223 |
| 224 class ScopedUnittestsEnvironmentSetup::DummyPlatform final : public blink::Platf
orm { |
| 225 public: |
| 226 DummyPlatform() { } |
| 227 |
| 228 blink::WebThread* currentThread() override |
| 229 { |
| 230 static DummyThread dummyThread; |
| 231 return &dummyThread; |
| 232 }; |
| 233 }; |
| 234 |
| 235 ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup(int argc, char*
* argv) |
| 236 { |
| 237 base::CommandLine::Init(argc, argv); |
| 238 |
| 239 base::test::InitializeICUForTesting(); |
| 240 |
| 241 m_discardableMemoryAllocator = wrapUnique(new base::TestDiscardableMemoryAll
ocator); |
| 242 base::DiscardableMemoryAllocator::SetInstance(m_discardableMemoryAllocator.g
et()); |
| 243 base::StatisticsRecorder::Initialize(); |
| 244 |
| 245 m_platform = wrapUnique(new DummyPlatform); |
| 246 Platform::setCurrentPlatformForTesting(m_platform.get()); |
| 247 |
| 248 WTF::Partitions::initialize(nullptr); |
| 249 WTF::setTimeFunctionsForTesting(dummyCurrentTime); |
| 250 WTF::initialize(nullptr); |
| 251 |
| 252 m_compositorSupport = wrapUnique(new cc_blink::WebCompositorSupportImpl); |
| 253 m_testingPlatformConfig.compositorSupport = m_compositorSupport.get(); |
| 254 m_testingPlatformSupport = wrapUnique(new TestingPlatformSupport(m_testingPl
atformConfig)); |
| 255 |
| 256 ProcessHeap::init(); |
| 257 ThreadState::attachMainThread(); |
| 258 ThreadState::current()->registerTraceDOMWrappers(nullptr, nullptr, nullptr); |
| 259 EventTracer::initialize(); |
| 260 HTTPNames::init(); |
| 261 } |
| 262 |
| 263 ScopedUnittestsEnvironmentSetup::~ScopedUnittestsEnvironmentSetup() |
| 264 { |
| 265 blink::ThreadState::detachMainThread(); |
| 266 blink::ProcessHeap::shutdown(); |
| 267 |
| 268 // Destroy test platform objects before shutting down WTF layer. |
| 269 m_testingPlatformSupport.reset(); |
| 270 m_compositorSupport.reset(); |
| 271 |
| 272 WTF::shutdown(); |
| 273 WTF::Partitions::shutdown(); |
| 274 |
| 275 // Now - implicitly destroy m_platform and m_discardableMemoryAllocator. |
| 276 } |
| 277 |
196 } // namespace blink | 278 } // namespace blink |
OLD | NEW |