Chromium Code Reviews| 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 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); | |
| 238 ~Impl(); | |
| 239 private: | |
| 240 base::TestDiscardableMemoryAllocator m_discardableMemoryAllocator; | |
| 241 std::unique_ptr<DummyPlatform> m_platform; | |
| 242 | |
| 243 cc_blink::WebCompositorSupportImpl m_compositorSupport; | |
|
esprehn
2016/08/10 04:05:29
Just put all of this in the header, there's no nee
Łukasz Anforowicz
2016/08/10 19:31:17
Done.
I need to note that I've also wrapped more
| |
| 244 TestingPlatformSupport::Config m_testingPlatformConfig; | |
| 245 std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; | |
| 246 }; | |
| 247 | |
| 248 ScopedUnittestsEnvironmentSetup::Impl::Impl(int argc, char** argv) | |
| 249 { | |
| 250 base::CommandLine::Init(argc, argv); | |
| 251 | |
| 252 base::test::InitializeICUForTesting(); | |
| 253 | |
| 254 base::DiscardableMemoryAllocator::SetInstance(&m_discardableMemoryAllocator) ; | |
| 255 base::StatisticsRecorder::Initialize(); | |
| 256 | |
| 257 m_platform = wrapUnique(new DummyPlatform); | |
| 258 Platform::setCurrentPlatformForTesting(m_platform.get()); | |
| 259 | |
| 260 WTF::Partitions::initialize(nullptr); | |
| 261 WTF::setTimeFunctionsForTesting(dummyCurrentTime); | |
| 262 WTF::initialize(nullptr); | |
| 263 | |
| 264 m_testingPlatformConfig.compositorSupport = &m_compositorSupport; | |
| 265 m_testingPlatformSupport = wrapUnique(new TestingPlatformSupport(m_testingPl atformConfig)); | |
| 266 | |
| 267 ProcessHeap::init(); | |
| 268 ThreadState::attachMainThread(); | |
| 269 ThreadState::current()->registerTraceDOMWrappers(nullptr, nullptr, nullptr); | |
| 270 EventTracer::initialize(); | |
| 271 HTTPNames::init(); | |
| 272 } | |
| 273 | |
| 274 ScopedUnittestsEnvironmentSetup::Impl::~Impl() | |
| 275 { | |
| 276 blink::ThreadState::detachMainThread(); | |
| 277 blink::ProcessHeap::shutdown(); | |
| 278 m_testingPlatformSupport.reset(); | |
| 279 | |
| 280 WTF::shutdown(); | |
| 281 WTF::Partitions::shutdown(); | |
| 282 } | |
| 283 | |
| 284 ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup(int argc, char* * argv) | |
| 285 { | |
| 286 m_impl = wrapUnique(new Impl(argc, argv)); | |
| 287 } | |
| 288 | |
| 289 ScopedUnittestsEnvironmentSetup::~ScopedUnittestsEnvironmentSetup() | |
| 290 { | |
| 291 m_impl.reset(); | |
|
esprehn
2016/08/10 04:05:29
manually clearing a unique_ptr in the destructor i
Łukasz Anforowicz
2016/08/10 19:31:17
You're right - this needs at least an explicit com
| |
| 292 } | |
| 293 | |
| 196 } // namespace blink | 294 } // namespace blink |
| OLD | NEW |