Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 10 matching lines...) Expand all Loading... | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 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 "base/memory/discardable_memory_allocator.h" | |
| 32 #include "base/test/test_discardable_memory_allocator.h" | |
| 33 #include "base/test/test_io_thread.h" | 31 #include "base/test/test_io_thread.h" |
| 34 #include "mojo/edk/embedder/embedder.h" | 32 #include "mojo/edk/embedder/embedder.h" |
| 35 #include "mojo/edk/test/scoped_ipc_support.h" | 33 #include "mojo/edk/test/scoped_ipc_support.h" |
| 36 #include "platform/EventTracer.h" | |
| 37 #include "platform/HTTPNames.h" | |
| 38 #include "platform/heap/Heap.h" | 34 #include "platform/heap/Heap.h" |
| 39 #include "platform/testing/TestingPlatformSupport.h" | 35 #include "platform/testing/TestingPlatformSupport.h" |
| 40 #include "public/platform/Platform.h" | |
| 41 #include "wtf/CryptographicallyRandomNumber.h" | |
| 42 #include "wtf/CurrentTime.h" | |
| 43 #include "wtf/PtrUtil.h" | |
| 44 #include "wtf/WTF.h" | |
| 45 #include "wtf/allocator/Partitions.h" | |
| 46 #include <base/bind.h> | 36 #include <base/bind.h> |
| 47 #include <base/bind_helpers.h> | 37 #include <base/bind_helpers.h> |
| 48 #include <base/command_line.h> | 38 #include <base/command_line.h> |
| 49 #include <base/metrics/statistics_recorder.h> | |
| 50 #include <base/test/launcher/unit_test_launcher.h> | 39 #include <base/test/launcher/unit_test_launcher.h> |
| 51 #include <base/test/test_suite.h> | 40 #include <base/test/test_suite.h> |
| 52 #include <cc/blink/web_compositor_support_impl.h> | |
| 53 #include <memory> | 41 #include <memory> |
| 54 | 42 |
| 55 namespace { | 43 namespace { |
| 56 | 44 |
| 57 double dummyCurrentTime() | |
| 58 { | |
| 59 return 0.0; | |
| 60 } | |
| 61 | |
| 62 int runTestSuite(base::TestSuite* testSuite) | 45 int runTestSuite(base::TestSuite* testSuite) |
| 63 { | 46 { |
| 64 int result = testSuite->Run(); | 47 int result = testSuite->Run(); |
| 65 blink::ThreadHeap::collectAllGarbage(); | 48 blink::ThreadHeap::collectAllGarbage(); |
| 66 return result; | 49 return result; |
| 67 } | 50 } |
| 68 | 51 |
| 69 class DummyPlatform final : public blink::Platform { | |
| 70 public: | |
| 71 DummyPlatform() { } | |
| 72 }; | |
| 73 | |
| 74 } // namespace | 52 } // namespace |
| 75 | 53 |
| 76 int main(int argc, char** argv) | 54 int main(int argc, char** argv) |
| 77 { | 55 { |
| 78 base::CommandLine::Init(argc, argv); | 56 base::CommandLine::Init(argc, argv); |
| 79 | 57 |
| 80 base::TestDiscardableMemoryAllocator discardableMemoryAllocator; | 58 blink::ScopedUnittestsEnvironmentSetup testEnvironmentSetup; |
| 81 base::DiscardableMemoryAllocator::SetInstance(&discardableMemoryAllocator); | |
| 82 | |
| 83 base::StatisticsRecorder::Initialize(); | |
| 84 | |
| 85 std::unique_ptr<DummyPlatform> platform = wrapUnique(new DummyPlatform); | |
| 86 blink::Platform::setCurrentPlatformForTesting(platform.get()); | |
| 87 | |
| 88 WTF::Partitions::initialize(nullptr); | |
| 89 WTF::setTimeFunctionsForTesting(dummyCurrentTime); | |
| 90 WTF::initialize(nullptr); | |
| 91 int result = 0; | 59 int result = 0; |
| 92 { | 60 { |
| 93 blink::TestingPlatformSupport::Config platformConfig; | |
| 94 cc_blink::WebCompositorSupportImpl compositorSupport; | |
| 95 platformConfig.compositorSupport = &compositorSupport; | |
| 96 blink::TestingPlatformSupport platform(platformConfig); | |
| 97 | |
| 98 blink::ProcessHeap::init(); | |
| 99 blink::ThreadState::attachMainThread(); | |
| 100 blink::ThreadState::current()->registerTraceDOMWrappers(nullptr, nullptr , nullptr); | |
| 101 blink::EventTracer::initialize(); | |
| 102 blink::HTTPNames::init(); | |
|
Łukasz Anforowicz
2016/07/29 23:43:58
Initialization of unit tests has been consolidated
| |
| 103 | |
| 104 base::TestSuite testSuite(argc, argv); | 61 base::TestSuite testSuite(argc, argv); |
| 105 | 62 |
| 106 mojo::edk::Init(); | 63 mojo::edk::Init(); |
| 107 base::TestIOThread testIoThread(base::TestIOThread::kAutoStart); | 64 base::TestIOThread testIoThread(base::TestIOThread::kAutoStart); |
| 108 std::unique_ptr<mojo::edk::test::ScopedIPCSupport> ipcSupport(wrapUnique (new mojo::edk::test::ScopedIPCSupport(testIoThread.task_runner()))); | 65 std::unique_ptr<mojo::edk::test::ScopedIPCSupport> ipcSupport(wrapUnique (new mojo::edk::test::ScopedIPCSupport(testIoThread.task_runner()))); |
| 109 result = base::LaunchUnitTests(argc, argv, base::Bind(runTestSuite, base ::Unretained(&testSuite))); | 66 result = base::LaunchUnitTests(argc, argv, base::Bind(runTestSuite, base ::Unretained(&testSuite))); |
| 110 | |
| 111 blink::ThreadState::detachMainThread(); | |
| 112 blink::ProcessHeap::shutdown(); | |
| 113 } | 67 } |
| 114 WTF::shutdown(); | |
| 115 WTF::Partitions::shutdown(); | |
| 116 return result; | 68 return result; |
| 117 } | 69 } |
| OLD | NEW |