| Index: third_party/WebKit/Source/web/tests/FrameTestHelpers.cpp
|
| diff --git a/third_party/WebKit/Source/web/tests/FrameTestHelpers.cpp b/third_party/WebKit/Source/web/tests/FrameTestHelpers.cpp
|
| index ead7d8151ea912b65c58c451629ae66b93422016..f568661e0593bbcc54a17cd8597df078f5f1b7a9 100644
|
| --- a/third_party/WebKit/Source/web/tests/FrameTestHelpers.cpp
|
| +++ b/third_party/WebKit/Source/web/tests/FrameTestHelpers.cpp
|
| @@ -45,6 +45,7 @@
|
| #include "public/web/WebViewClient.h"
|
| #include "web/WebLocalFrameImpl.h"
|
| #include "web/WebRemoteFrameImpl.h"
|
| +#include "wtf/Functional.h"
|
| #include "wtf/StdLibExtras.h"
|
|
|
| namespace blink {
|
| @@ -56,125 +57,42 @@ namespace {
|
| // dance. Since the parser is threaded, simply spinning the run loop once is not
|
| // enough to ensure completion of a load. Instead, the following pattern is
|
| // used to ensure that tests see the final state:
|
| -// 1. Post a task to trigger a load (LoadTask/LoadHTMLStringTask/ReloadTask).
|
| +// 1. Post a task to trigger a load (bind() with WebFrame::loadRequest/
|
| +// runLoadHTMLStringTask/WebFrame::reload).
|
| // 2. Enter the run loop.
|
| // 3. Posted task triggers the load, and starts pumping pending resource
|
| -// requests using ServeAsyncRequestsTask.
|
| +// requests using runServeAsyncRequestsTask().
|
| // 4. TestWebFrameClient watches for didStartLoading/didStopLoading calls,
|
| // keeping track of how many loads it thinks are in flight.
|
| -// 5. While ServeAsyncRequestsTask observes TestWebFrameClient to still have
|
| -// loads in progress, it posts itself back to the run loop.
|
| -// 6. When ServeAsyncRequestsTask notices there are no more loads in progress,
|
| -// it exits the run loop.
|
| +// 5. While runServeAsyncRequestsTask() observes TestWebFrameClient to still
|
| +// have loads in progress, it posts itself back to the run loop.
|
| +// 6. When runServeAsyncRequestsTask() notices there are no more loads in
|
| +// progress, it exits the run loop.
|
| // 7. At this point, all parsing, resource loads, and layout should be finished.
|
| TestWebFrameClient* testClientForFrame(WebFrame* frame)
|
| {
|
| return static_cast<TestWebFrameClient*>(toWebLocalFrameImpl(frame)->client());
|
| }
|
|
|
| -class ServeAsyncRequestsTask : public WebTaskRunner::Task {
|
| -public:
|
| - explicit ServeAsyncRequestsTask(TestWebFrameClient* client)
|
| - : m_client(client)
|
| - {
|
| - }
|
| -
|
| - void run() override
|
| - {
|
| - Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
|
| - if (m_client->isLoading())
|
| - Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new ServeAsyncRequestsTask(m_client));
|
| - else
|
| - testing::exitRunLoop();
|
| - }
|
| -
|
| -private:
|
| - TestWebFrameClient* const m_client;
|
| -};
|
| +void runServeAsyncRequestsTask(TestWebFrameClient* client)
|
| +{
|
| + Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
|
| + if (client->isLoading())
|
| + Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, bind(&runServeAsyncRequestsTask, client));
|
| + else
|
| + testing::exitRunLoop();
|
| +}
|
|
|
| void pumpPendingRequests(WebFrame* frame)
|
| {
|
| - Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new ServeAsyncRequestsTask(testClientForFrame(frame)));
|
| + Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, bind(&runServeAsyncRequestsTask, testClientForFrame(frame)));
|
| testing::enterRunLoop();
|
| }
|
|
|
| -class LoadTask : public WebTaskRunner::Task {
|
| -public:
|
| - LoadTask(WebFrame* frame, const WebURLRequest& request)
|
| - : m_frame(frame)
|
| - , m_request(request)
|
| - {
|
| - }
|
| -
|
| - void run() override
|
| - {
|
| - m_frame->loadRequest(m_request);
|
| - }
|
| -
|
| -private:
|
| - WebFrame* const m_frame;
|
| - const WebURLRequest m_request;
|
| -};
|
| -
|
| -class LoadHTMLStringTask : public WebTaskRunner::Task {
|
| -public:
|
| - LoadHTMLStringTask(WebFrame* frame, const std::string& html, const WebURL& baseURL)
|
| - : m_frame(frame)
|
| - , m_html(html)
|
| - , m_baseURL(baseURL)
|
| - {
|
| - }
|
| -
|
| - void run() override
|
| - {
|
| - m_frame->loadHTMLString(WebData(m_html.data(), m_html.size()), m_baseURL);
|
| - }
|
| -
|
| -private:
|
| - WebFrame* const m_frame;
|
| - const std::string m_html;
|
| - const WebURL m_baseURL;
|
| -};
|
| -
|
| -class LoadHistoryItemTask : public WebTaskRunner::Task {
|
| -public:
|
| - LoadHistoryItemTask(WebFrame* frame, const WebHistoryItem& item, WebHistoryLoadType loadType, WebURLRequest::CachePolicy cachePolicy)
|
| - : m_frame(frame)
|
| - , m_item(item)
|
| - , m_loadType(loadType)
|
| - , m_cachePolicy(cachePolicy)
|
| - {
|
| - }
|
| -
|
| - void run() override
|
| - {
|
| - m_frame->loadHistoryItem(m_item, m_loadType, m_cachePolicy);
|
| - }
|
| -
|
| -private:
|
| - WebFrame* const m_frame;
|
| - const WebHistoryItem m_item;
|
| - const WebHistoryLoadType m_loadType;
|
| - const WebURLRequest::CachePolicy m_cachePolicy;
|
| -};
|
| -
|
| -class ReloadTask : public WebTaskRunner::Task {
|
| -public:
|
| - ReloadTask(WebFrame* frame, bool ignoreCache)
|
| - : m_frame(frame)
|
| - , m_ignoreCache(ignoreCache)
|
| - {
|
| - }
|
| -
|
| - void run() override
|
| - {
|
| - m_frame->reload(m_ignoreCache);
|
| - }
|
| -
|
| -private:
|
| - WebFrame* const m_frame;
|
| - const bool m_ignoreCache;
|
| -};
|
| +void runLoadHTMLStringTask(WebFrame* frame, const std::string& html, const WebURL& baseURL)
|
| +{
|
| + frame->loadHTMLString(WebData(html.data(), html.size()), baseURL);
|
| +}
|
|
|
| TestWebFrameClient* defaultWebFrameClient()
|
| {
|
| @@ -196,31 +114,31 @@ void loadFrame(WebFrame* frame, const std::string& url)
|
| urlRequest.initialize();
|
| urlRequest.setURL(URLTestHelpers::toKURL(url));
|
|
|
| - Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new LoadTask(frame, urlRequest));
|
| + Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, bind(&WebFrame::loadRequest, frame, urlRequest));
|
| pumpPendingRequests(frame);
|
| }
|
|
|
| void loadHTMLString(WebFrame* frame, const std::string& html, const WebURL& baseURL)
|
| {
|
| - Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new LoadHTMLStringTask(frame, html, baseURL));
|
| + Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, WTF::bind(&runLoadHTMLStringTask, frame, html, baseURL));
|
| pumpPendingRequests(frame);
|
| }
|
|
|
| void loadHistoryItem(WebFrame* frame, const WebHistoryItem& item, WebHistoryLoadType loadType, WebURLRequest::CachePolicy cachePolicy)
|
| {
|
| - Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new LoadHistoryItemTask(frame, item, loadType, cachePolicy));
|
| + Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, bind(&WebFrame::loadHistoryItem, frame, item, loadType, cachePolicy));
|
| pumpPendingRequests(frame);
|
| }
|
|
|
| void reloadFrame(WebFrame* frame)
|
| {
|
| - Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new ReloadTask(frame, false));
|
| + Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, bind(&WebFrame::reload, frame, false));
|
| pumpPendingRequests(frame);
|
| }
|
|
|
| void reloadFrameIgnoringCache(WebFrame* frame)
|
| {
|
| - Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new ReloadTask(frame, true));
|
| + Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, bind(&WebFrame::reload, frame, true));
|
| pumpPendingRequests(frame);
|
| }
|
|
|
|
|