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/i18n/icu_util.h" | |
35 #include "base/memory/discardable_memory_allocator.h" | |
36 #include "base/metrics/statistics_recorder.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 class DummyPlatform final : public blink::Platform { | |
65 public: | |
66 DummyPlatform() { } | |
67 | |
68 blink::WebThread* currentThread() override | |
69 { | |
70 static DummyThread dummyThread; | |
71 return &dummyThread; | |
72 }; | |
73 }; | |
74 | |
75 } // namespace | |
76 | |
38 TestingPlatformSupport::TestingPlatformSupport() | 77 TestingPlatformSupport::TestingPlatformSupport() |
39 : TestingPlatformSupport(TestingPlatformSupport::Config()) | 78 : TestingPlatformSupport(TestingPlatformSupport::Config()) |
40 { | 79 { |
41 } | 80 } |
42 | 81 |
43 TestingPlatformSupport::TestingPlatformSupport(const Config& config) | 82 TestingPlatformSupport::TestingPlatformSupport(const Config& config) |
44 : m_config(config) | 83 : m_config(config) |
45 , m_oldPlatform(Platform::current()) | 84 , m_oldPlatform(Platform::current()) |
46 { | 85 { |
47 ASSERT(m_oldPlatform); | 86 ASSERT(m_oldPlatform); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() | 225 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() |
187 { | 226 { |
188 return m_mockWebThread.get(); | 227 return m_mockWebThread.get(); |
189 } | 228 } |
190 | 229 |
191 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc heduler() | 230 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc heduler() |
192 { | 231 { |
193 return m_mockWebThread->mockWebScheduler(); | 232 return m_mockWebThread->mockWebScheduler(); |
194 } | 233 } |
195 | 234 |
235 class ScopedUnittestsEnvironmentSetup::Impl { | |
236 public: | |
237 Impl(int argc, char** argv, TestType); | |
238 ~Impl(); | |
239 private: | |
240 base::TestDiscardableMemoryAllocator m_discardableMemoryAllocator; | |
241 std::unique_ptr<DummyPlatform> m_platform; | |
242 | |
243 cc_blink::WebCompositorSupportImpl m_compositorSupport; | |
244 TestingPlatformSupport::Config m_testingPlatformConfig; | |
245 std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; | |
246 }; | |
247 | |
248 ScopedUnittestsEnvironmentSetup::Impl::Impl( | |
249 int argc, char** argv, TestType testType) | |
250 { | |
251 base::CommandLine::Init(argc, argv); | |
252 | |
253 // Make sure we don't initialize twice in case of unit tests - | |
254 // base::TestSuite::Initialize already calls base::i18n::InitializeICU. | |
255 if (testType == TestType::LibFuzzer) | |
esprehn
2016/08/04 04:37:53
This doesn't feel right, why is the fuzzer running
Łukasz Anforowicz
2016/08/04 17:37:30
Good catch / call.
It turns out that test code sh
| |
256 base::i18n::InitializeICU(); | |
257 | |
258 base::DiscardableMemoryAllocator::SetInstance(&m_discardableMemoryAllocator) ; | |
259 base::StatisticsRecorder::Initialize(); | |
260 | |
261 m_platform = wrapUnique(new DummyPlatform); | |
262 Platform::setCurrentPlatformForTesting(m_platform.get()); | |
263 | |
264 WTF::Partitions::initialize(nullptr); | |
265 WTF::setTimeFunctionsForTesting(dummyCurrentTime); | |
266 WTF::initialize(nullptr); | |
267 | |
268 m_testingPlatformConfig.compositorSupport = &m_compositorSupport; | |
269 m_testingPlatformSupport = wrapUnique(new TestingPlatformSupport(m_testingPl atformConfig)); | |
270 | |
271 ProcessHeap::init(); | |
272 ThreadState::attachMainThread(); | |
273 ThreadState::current()->registerTraceDOMWrappers(nullptr, nullptr, nullptr); | |
274 EventTracer::initialize(); | |
275 HTTPNames::init(); | |
276 } | |
277 | |
278 ScopedUnittestsEnvironmentSetup::Impl::~Impl() | |
279 { | |
280 blink::ThreadState::detachMainThread(); | |
281 blink::ProcessHeap::shutdown(); | |
282 m_testingPlatformSupport.reset(); | |
283 | |
284 WTF::shutdown(); | |
285 WTF::Partitions::shutdown(); | |
286 } | |
287 | |
288 ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup( | |
289 int argc, char** argv, TestType testType) | |
290 { | |
291 m_impl = wrapUnique(new Impl(argc, argv, testType)); | |
292 } | |
293 | |
294 ScopedUnittestsEnvironmentSetup::~ScopedUnittestsEnvironmentSetup() | |
295 { | |
296 m_impl.reset(); | |
297 } | |
298 | |
196 } // namespace blink | 299 } // namespace blink |
OLD | NEW |