OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 14 matching lines...) Expand all Loading... |
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 "config.h" | 31 #include "config.h" |
32 #include "web/tests/FrameTestHelpers.h" | 32 #include "web/tests/FrameTestHelpers.h" |
33 | 33 |
34 #include "core/testing/URLTestHelpers.h" | 34 #include "core/testing/URLTestHelpers.h" |
| 35 #include "core/testing/UnitTestHelpers.h" |
35 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
36 #include "public/platform/WebData.h" | 37 #include "public/platform/WebData.h" |
37 #include "public/platform/WebString.h" | 38 #include "public/platform/WebString.h" |
38 #include "public/platform/WebThread.h" | 39 #include "public/platform/WebThread.h" |
39 #include "public/platform/WebURLRequest.h" | 40 #include "public/platform/WebURLRequest.h" |
40 #include "public/platform/WebURLResponse.h" | 41 #include "public/platform/WebURLResponse.h" |
41 #include "public/platform/WebUnitTestSupport.h" | 42 #include "public/platform/WebUnitTestSupport.h" |
42 #include "public/web/WebSettings.h" | 43 #include "public/web/WebSettings.h" |
43 #include "public/web/WebViewClient.h" | 44 #include "public/web/WebViewClient.h" |
44 #include "web/WebLocalFrameImpl.h" | 45 #include "web/WebLocalFrameImpl.h" |
(...skipping 17 matching lines...) Expand all Loading... |
62 // 5. While ServeAsyncRequestsTask observes TestWebFrameClient to still have | 63 // 5. While ServeAsyncRequestsTask observes TestWebFrameClient to still have |
63 // loads in progress, it posts itself back to the run loop. | 64 // loads in progress, it posts itself back to the run loop. |
64 // 6. When ServeAsyncRequestsTask notices there are no more loads in progress, | 65 // 6. When ServeAsyncRequestsTask notices there are no more loads in progress, |
65 // it exits the run loop. | 66 // it exits the run loop. |
66 // 7. At this point, all parsing, resource loads, and layout should be finished. | 67 // 7. At this point, all parsing, resource loads, and layout should be finished. |
67 TestWebFrameClient* testClientForFrame(WebFrame* frame) | 68 TestWebFrameClient* testClientForFrame(WebFrame* frame) |
68 { | 69 { |
69 return static_cast<TestWebFrameClient*>(toWebLocalFrameImpl(frame)->client()
); | 70 return static_cast<TestWebFrameClient*>(toWebLocalFrameImpl(frame)->client()
); |
70 } | 71 } |
71 | 72 |
72 class QuitTask : public WebThread::Task { | |
73 public: | |
74 void PostThis(Timer<QuitTask>*) | |
75 { | |
76 // We don't just quit here because the SharedTimer may be part-way | |
77 // through the current queue of tasks when runPendingTasks was called, | |
78 // and we can't miss the tasks that were behind it. | |
79 // Takes ownership of |this|. | |
80 Platform::current()->currentThread()->postTask(FROM_HERE, this); | |
81 } | |
82 | |
83 virtual void run() | |
84 { | |
85 Platform::current()->currentThread()->exitRunLoop(); | |
86 } | |
87 }; | |
88 | |
89 class ServeAsyncRequestsTask : public WebThread::Task { | 73 class ServeAsyncRequestsTask : public WebThread::Task { |
90 public: | 74 public: |
91 explicit ServeAsyncRequestsTask(TestWebFrameClient* client) | 75 explicit ServeAsyncRequestsTask(TestWebFrameClient* client) |
92 : m_client(client) | 76 : m_client(client) |
93 { | 77 { |
94 } | 78 } |
95 | 79 |
96 virtual void run() override | 80 virtual void run() override |
97 { | 81 { |
98 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(
); | 82 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(
); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 { | 220 { |
237 Platform::current()->currentThread()->postTask(FROM_HERE, new ReloadTask(fra
me, true)); | 221 Platform::current()->currentThread()->postTask(FROM_HERE, new ReloadTask(fra
me, true)); |
238 pumpPendingRequests(frame); | 222 pumpPendingRequests(frame); |
239 } | 223 } |
240 | 224 |
241 void pumpPendingRequestsDoNotUse(WebFrame* frame) | 225 void pumpPendingRequestsDoNotUse(WebFrame* frame) |
242 { | 226 { |
243 pumpPendingRequests(frame); | 227 pumpPendingRequests(frame); |
244 } | 228 } |
245 | 229 |
246 // FIXME: There's a duplicate implementation in UnitTestHelpers.cpp. Remove one. | |
247 void runPendingTasks() | |
248 { | |
249 // Pending tasks include Timers that have been scheduled. | |
250 Timer<QuitTask> quitOnTimeout(new QuitTask, &QuitTask::PostThis); | |
251 quitOnTimeout.startOneShot(0, FROM_HERE); | |
252 Platform::current()->currentThread()->enterRunLoop(); | |
253 } | |
254 | |
255 WebViewHelper::WebViewHelper() | 230 WebViewHelper::WebViewHelper() |
256 : m_webView(0) | 231 : m_webView(0) |
257 { | 232 { |
258 } | 233 } |
259 | 234 |
260 WebViewHelper::~WebViewHelper() | 235 WebViewHelper::~WebViewHelper() |
261 { | 236 { |
262 reset(); | 237 reset(); |
263 } | 238 } |
264 | 239 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 --m_loadsInProgress; | 305 --m_loadsInProgress; |
331 } | 306 } |
332 | 307 |
333 void TestWebFrameClient::waitForLoadToComplete() | 308 void TestWebFrameClient::waitForLoadToComplete() |
334 { | 309 { |
335 for (;;) { | 310 for (;;) { |
336 // We call runPendingTasks multiple times as single call of | 311 // We call runPendingTasks multiple times as single call of |
337 // runPendingTasks may not be enough. | 312 // runPendingTasks may not be enough. |
338 // runPendingTasks only ensures that main thread task queue is empty, | 313 // runPendingTasks only ensures that main thread task queue is empty, |
339 // and asynchronous parsing make use of off main thread HTML parser. | 314 // and asynchronous parsing make use of off main thread HTML parser. |
340 FrameTestHelpers::runPendingTasks(); | 315 testing::runPendingTasks(); |
341 if (!isLoading()) | 316 if (!isLoading()) |
342 break; | 317 break; |
343 | 318 |
344 Platform::current()->yieldCurrentThread(); | 319 Platform::current()->yieldCurrentThread(); |
345 } | 320 } |
346 } | 321 } |
347 | 322 |
348 void TestWebViewClient::initializeLayerTreeView() | 323 void TestWebViewClient::initializeLayerTreeView() |
349 { | 324 { |
350 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLay
erTreeViewForTesting()); | 325 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLay
erTreeViewForTesting()); |
351 ASSERT(m_layerTreeView); | 326 ASSERT(m_layerTreeView); |
352 } | 327 } |
353 | 328 |
354 } // namespace FrameTestHelpers | 329 } // namespace FrameTestHelpers |
355 } // namespace blink | 330 } // namespace blink |
OLD | NEW |