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 27 matching lines...) Expand all Loading... |
38 #include "public/platform/WebThread.h" | 38 #include "public/platform/WebThread.h" |
39 #include "public/platform/WebURLRequest.h" | 39 #include "public/platform/WebURLRequest.h" |
40 #include "public/platform/WebURLResponse.h" | 40 #include "public/platform/WebURLResponse.h" |
41 #include "public/platform/WebUnitTestSupport.h" | 41 #include "public/platform/WebUnitTestSupport.h" |
42 #include "public/web/WebFrameWidget.h" | 42 #include "public/web/WebFrameWidget.h" |
43 #include "public/web/WebSettings.h" | 43 #include "public/web/WebSettings.h" |
44 #include "public/web/WebTreeScopeType.h" | 44 #include "public/web/WebTreeScopeType.h" |
45 #include "public/web/WebViewClient.h" | 45 #include "public/web/WebViewClient.h" |
46 #include "web/WebLocalFrameImpl.h" | 46 #include "web/WebLocalFrameImpl.h" |
47 #include "web/WebRemoteFrameImpl.h" | 47 #include "web/WebRemoteFrameImpl.h" |
| 48 #include "wtf/Functional.h" |
48 #include "wtf/StdLibExtras.h" | 49 #include "wtf/StdLibExtras.h" |
49 | 50 |
50 namespace blink { | 51 namespace blink { |
51 namespace FrameTestHelpers { | 52 namespace FrameTestHelpers { |
52 | 53 |
53 namespace { | 54 namespace { |
54 | 55 |
55 // The frame test helpers coordinate frame loads in a carefully choreographed | 56 // The frame test helpers coordinate frame loads in a carefully choreographed |
56 // dance. Since the parser is threaded, simply spinning the run loop once is not | 57 // dance. Since the parser is threaded, simply spinning the run loop once is not |
57 // enough to ensure completion of a load. Instead, the following pattern is | 58 // enough to ensure completion of a load. Instead, the following pattern is |
58 // used to ensure that tests see the final state: | 59 // used to ensure that tests see the final state: |
59 // 1. Starts a load. | 60 // 1. Starts a load. |
60 // 2. Enter the run loop. | 61 // 2. Enter the run loop. |
61 // 3. Posted task triggers the load, and starts pumping pending resource | 62 // 3. Posted task triggers the load, and starts pumping pending resource |
62 // requests using ServeAsyncRequestsTask. | 63 // requests using runServeAsyncRequestsTask(). |
63 // 4. TestWebFrameClient watches for didStartLoading/didStopLoading calls, | 64 // 4. TestWebFrameClient watches for didStartLoading/didStopLoading calls, |
64 // keeping track of how many loads it thinks are in flight. | 65 // keeping track of how many loads it thinks are in flight. |
65 // 5. While ServeAsyncRequestsTask observes TestWebFrameClient to still have | 66 // 5. While runServeAsyncRequestsTask() observes TestWebFrameClient to still |
66 // loads in progress, it posts itself back to the run loop. | 67 // have loads in progress, it posts itself back to the run loop. |
67 // 6. When ServeAsyncRequestsTask notices there are no more loads in progress, | 68 // 6. When runServeAsyncRequestsTask() notices there are no more loads in |
68 // it exits the run loop. | 69 // progress, it exits the run loop. |
69 // 7. At this point, all parsing, resource loads, and layout should be finished. | 70 // 7. At this point, all parsing, resource loads, and layout should be finished. |
70 TestWebFrameClient* testClientForFrame(WebFrame* frame) | 71 TestWebFrameClient* testClientForFrame(WebFrame* frame) |
71 { | 72 { |
72 return static_cast<TestWebFrameClient*>(toWebLocalFrameImpl(frame)->client()
); | 73 return static_cast<TestWebFrameClient*>(toWebLocalFrameImpl(frame)->client()
); |
73 } | 74 } |
74 | 75 |
75 class ServeAsyncRequestsTask : public WebTaskRunner::Task { | 76 void runServeAsyncRequestsTask(TestWebFrameClient* client) |
76 public: | 77 { |
77 explicit ServeAsyncRequestsTask(TestWebFrameClient* client) | 78 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
78 : m_client(client) | 79 if (client->isLoading()) |
79 { | 80 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, bind(&runServeAsyncRequestsTask, client)); |
80 } | 81 else |
81 | 82 testing::exitRunLoop(); |
82 void run() override | 83 } |
83 { | |
84 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(
); | |
85 if (m_client->isLoading()) | |
86 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_F
ROM_HERE, new ServeAsyncRequestsTask(m_client)); | |
87 else | |
88 testing::exitRunLoop(); | |
89 } | |
90 | |
91 private: | |
92 TestWebFrameClient* const m_client; | |
93 }; | |
94 | 84 |
95 void pumpPendingRequests(WebFrame* frame) | 85 void pumpPendingRequests(WebFrame* frame) |
96 { | 86 { |
97 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE
, new ServeAsyncRequestsTask(testClientForFrame(frame))); | 87 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE
, bind(&runServeAsyncRequestsTask, testClientForFrame(frame))); |
98 testing::enterRunLoop(); | 88 testing::enterRunLoop(); |
99 } | 89 } |
100 | 90 |
101 TestWebFrameClient* defaultWebFrameClient() | 91 TestWebFrameClient* defaultWebFrameClient() |
102 { | 92 { |
103 DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ()); | 93 DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ()); |
104 return &client; | 94 return &client; |
105 } | 95 } |
106 | 96 |
107 TestWebViewClient* defaultWebViewClient() | 97 TestWebViewClient* defaultWebViewClient() |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 276 } |
287 | 277 |
288 void TestWebViewClient::initializeLayerTreeView() | 278 void TestWebViewClient::initializeLayerTreeView() |
289 { | 279 { |
290 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLay
erTreeViewForTesting()); | 280 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLay
erTreeViewForTesting()); |
291 ASSERT(m_layerTreeView); | 281 ASSERT(m_layerTreeView); |
292 } | 282 } |
293 | 283 |
294 } // namespace FrameTestHelpers | 284 } // namespace FrameTestHelpers |
295 } // namespace blink | 285 } // namespace blink |
OLD | NEW |