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 "wtf/PtrUtil.h" |
| 34 #include <memory> |
| 35 |
33 namespace blink { | 36 namespace blink { |
34 | 37 |
35 TestingPlatformSupport::TestingPlatformSupport() | 38 TestingPlatformSupport::TestingPlatformSupport() |
36 : TestingPlatformSupport(TestingPlatformSupport::Config()) | 39 : TestingPlatformSupport(TestingPlatformSupport::Config()) |
37 { | 40 { |
38 } | 41 } |
39 | 42 |
40 TestingPlatformSupport::TestingPlatformSupport(const Config& config) | 43 TestingPlatformSupport::TestingPlatformSupport(const Config& config) |
41 : m_config(config) | 44 : m_config(config) |
42 , m_oldPlatform(Platform::current()) | 45 , m_oldPlatform(Platform::current()) |
(...skipping 18 matching lines...) Expand all Loading... |
61 } | 64 } |
62 | 65 |
63 WebThread* TestingPlatformSupport::currentThread() | 66 WebThread* TestingPlatformSupport::currentThread() |
64 { | 67 { |
65 return m_oldPlatform ? m_oldPlatform->currentThread() : nullptr; | 68 return m_oldPlatform ? m_oldPlatform->currentThread() : nullptr; |
66 } | 69 } |
67 | 70 |
68 class TestingPlatformMockWebTaskRunner : public WebTaskRunner { | 71 class TestingPlatformMockWebTaskRunner : public WebTaskRunner { |
69 WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebTaskRunner); | 72 WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebTaskRunner); |
70 public: | 73 public: |
71 explicit TestingPlatformMockWebTaskRunner(Deque<OwnPtr<WebTaskRunner::Task>>
* tasks) : m_tasks(tasks) { } | 74 explicit TestingPlatformMockWebTaskRunner(Deque<std::unique_ptr<WebTaskRunne
r::Task>>* tasks) : m_tasks(tasks) { } |
72 ~TestingPlatformMockWebTaskRunner() override { } | 75 ~TestingPlatformMockWebTaskRunner() override { } |
73 | 76 |
74 void postTask(const WebTraceLocation&, Task* task) override | 77 void postTask(const WebTraceLocation&, Task* task) override |
75 { | 78 { |
76 m_tasks->append(adoptPtr(task)); | 79 m_tasks->append(wrapUnique(task)); |
77 } | 80 } |
78 | 81 |
79 void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) overrid
e | 82 void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) overrid
e |
80 { | 83 { |
81 ASSERT_NOT_REACHED(); | 84 ASSERT_NOT_REACHED(); |
82 } | 85 } |
83 | 86 |
84 WebTaskRunner* clone() override | 87 WebTaskRunner* clone() override |
85 { | 88 { |
86 return new TestingPlatformMockWebTaskRunner(m_tasks); | 89 return new TestingPlatformMockWebTaskRunner(m_tasks); |
87 } | 90 } |
88 | 91 |
89 double virtualTimeSeconds() const override | 92 double virtualTimeSeconds() const override |
90 { | 93 { |
91 ASSERT_NOT_REACHED(); | 94 ASSERT_NOT_REACHED(); |
92 return 0.0; | 95 return 0.0; |
93 } | 96 } |
94 | 97 |
95 double monotonicallyIncreasingVirtualTimeSeconds() const override | 98 double monotonicallyIncreasingVirtualTimeSeconds() const override |
96 { | 99 { |
97 ASSERT_NOT_REACHED(); | 100 ASSERT_NOT_REACHED(); |
98 return 0.0; | 101 return 0.0; |
99 } | 102 } |
100 | 103 |
101 private: | 104 private: |
102 Deque<OwnPtr<WebTaskRunner::Task>>* m_tasks; // NOT OWNED | 105 Deque<std::unique_ptr<WebTaskRunner::Task>>* m_tasks; // NOT OWNED |
103 }; | 106 }; |
104 | 107 |
105 // TestingPlatformMockScheduler definition: | 108 // TestingPlatformMockScheduler definition: |
106 | 109 |
107 TestingPlatformMockScheduler::TestingPlatformMockScheduler() | 110 TestingPlatformMockScheduler::TestingPlatformMockScheduler() |
108 : m_mockWebTaskRunner(adoptPtr(new TestingPlatformMockWebTaskRunner(&m_tasks
))) { } | 111 : m_mockWebTaskRunner(wrapUnique(new TestingPlatformMockWebTaskRunner(&m_tas
ks))) { } |
109 | 112 |
110 TestingPlatformMockScheduler::~TestingPlatformMockScheduler() { } | 113 TestingPlatformMockScheduler::~TestingPlatformMockScheduler() { } |
111 | 114 |
112 WebTaskRunner* TestingPlatformMockScheduler::loadingTaskRunner() | 115 WebTaskRunner* TestingPlatformMockScheduler::loadingTaskRunner() |
113 { | 116 { |
114 return m_mockWebTaskRunner.get(); | 117 return m_mockWebTaskRunner.get(); |
115 } | 118 } |
116 | 119 |
117 WebTaskRunner* TestingPlatformMockScheduler::timerTaskRunner() | 120 WebTaskRunner* TestingPlatformMockScheduler::timerTaskRunner() |
118 { | 121 { |
119 return m_mockWebTaskRunner.get(); | 122 return m_mockWebTaskRunner.get(); |
120 } | 123 } |
121 | 124 |
122 void TestingPlatformMockScheduler::runSingleTask() | 125 void TestingPlatformMockScheduler::runSingleTask() |
123 { | 126 { |
124 if (m_tasks.isEmpty()) | 127 if (m_tasks.isEmpty()) |
125 return; | 128 return; |
126 m_tasks.takeFirst()->run(); | 129 m_tasks.takeFirst()->run(); |
127 } | 130 } |
128 | 131 |
129 void TestingPlatformMockScheduler::runAllTasks() | 132 void TestingPlatformMockScheduler::runAllTasks() |
130 { | 133 { |
131 while (!m_tasks.isEmpty()) | 134 while (!m_tasks.isEmpty()) |
132 m_tasks.takeFirst()->run(); | 135 m_tasks.takeFirst()->run(); |
133 } | 136 } |
134 | 137 |
135 class TestingPlatformMockWebThread : public WebThread { | 138 class TestingPlatformMockWebThread : public WebThread { |
136 WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebThread); | 139 WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebThread); |
137 public: | 140 public: |
138 TestingPlatformMockWebThread() : m_mockWebScheduler(adoptPtr(new TestingPlat
formMockScheduler)) { } | 141 TestingPlatformMockWebThread() : m_mockWebScheduler(wrapUnique(new TestingPl
atformMockScheduler)) { } |
139 ~TestingPlatformMockWebThread() override { } | 142 ~TestingPlatformMockWebThread() override { } |
140 | 143 |
141 WebTaskRunner* getWebTaskRunner() override | 144 WebTaskRunner* getWebTaskRunner() override |
142 { | 145 { |
143 return m_mockWebScheduler->timerTaskRunner(); | 146 return m_mockWebScheduler->timerTaskRunner(); |
144 } | 147 } |
145 | 148 |
146 bool isCurrentThread() const override | 149 bool isCurrentThread() const override |
147 { | 150 { |
148 ASSERT_NOT_REACHED(); | 151 ASSERT_NOT_REACHED(); |
149 return true; | 152 return true; |
150 } | 153 } |
151 | 154 |
152 WebScheduler* scheduler() const override | 155 WebScheduler* scheduler() const override |
153 { | 156 { |
154 return m_mockWebScheduler.get(); | 157 return m_mockWebScheduler.get(); |
155 } | 158 } |
156 | 159 |
157 TestingPlatformMockScheduler* mockWebScheduler() | 160 TestingPlatformMockScheduler* mockWebScheduler() |
158 { | 161 { |
159 return m_mockWebScheduler.get(); | 162 return m_mockWebScheduler.get(); |
160 } | 163 } |
161 | 164 |
162 private: | 165 private: |
163 OwnPtr<TestingPlatformMockScheduler> m_mockWebScheduler; | 166 std::unique_ptr<TestingPlatformMockScheduler> m_mockWebScheduler; |
164 }; | 167 }; |
165 | 168 |
166 // TestingPlatformSupportWithMockScheduler definition: | 169 // TestingPlatformSupportWithMockScheduler definition: |
167 | 170 |
168 TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler
() | 171 TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler
() |
169 : m_mockWebThread(adoptPtr(new TestingPlatformMockWebThread())) { } | 172 : m_mockWebThread(wrapUnique(new TestingPlatformMockWebThread())) { } |
170 | 173 |
171 TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler
(const Config& config) | 174 TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler
(const Config& config) |
172 : TestingPlatformSupport(config) | 175 : TestingPlatformSupport(config) |
173 , m_mockWebThread(adoptPtr(new TestingPlatformMockWebThread())) { } | 176 , m_mockWebThread(wrapUnique(new TestingPlatformMockWebThread())) { } |
174 | 177 |
175 TestingPlatformSupportWithMockScheduler::~TestingPlatformSupportWithMockSchedule
r() { } | 178 TestingPlatformSupportWithMockScheduler::~TestingPlatformSupportWithMockSchedule
r() { } |
176 | 179 |
177 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() | 180 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() |
178 { | 181 { |
179 return m_mockWebThread.get(); | 182 return m_mockWebThread.get(); |
180 } | 183 } |
181 | 184 |
182 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc
heduler() | 185 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc
heduler() |
183 { | 186 { |
184 return m_mockWebThread->mockWebScheduler(); | 187 return m_mockWebThread->mockWebScheduler(); |
185 } | 188 } |
186 | 189 |
187 } // namespace blink | 190 } // namespace blink |
OLD | NEW |