Chromium Code Reviews| Index: Source/web/tests/WebFrameTest.cpp |
| diff --git a/Source/web/tests/WebFrameTest.cpp b/Source/web/tests/WebFrameTest.cpp |
| index 4a3f112917626400b361734eda6193e2b88165a5..30f3668f7a5752e9ec62dca24fc04099afd148c6 100644 |
| --- a/Source/web/tests/WebFrameTest.cpp |
| +++ b/Source/web/tests/WebFrameTest.cpp |
| @@ -7022,6 +7022,80 @@ TEST_F(WebFrameSwapTest, SwapMainFrame) |
| remoteFrame->close(); |
| } |
| +namespace { |
| + |
| +class ServeAsyncRequestsTask : public WebThread::Task { |
| +public: |
| + ServeAsyncRequestsTask(FrameTestHelpers::TestWebFrameClient* client, bool* gotCommit) |
| + : m_client(client) |
| + , m_gotCommit(gotCommit) |
| + { |
| + } |
| + |
| + void run() override |
| + { |
| + Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
|
sky
2015/09/02 23:33:15
This triggers a presubmit hook that fails. I had t
|
| + if (!m_gotCommit) |
| + Platform::current()->currentThread()->postTask(FROM_HERE, new ServeAsyncRequestsTask(m_client, m_gotCommit)); |
| + else |
| + Platform::current()->unitTestSupport()->exitRunLoop(); |
| + } |
| + |
| +private: |
| + FrameTestHelpers::TestWebFrameClient* const m_client; |
| + bool* m_gotCommit; |
| +}; |
| + |
| +// Starts a load for frame. The call returns once gotCommit is set to true. |
| +void StartLoad(WebFrame* frame, const std::string& url, FrameTestHelpers::TestWebFrameClient* client, bool* gotCommit) |
| +{ |
| + WebURLRequest urlRequest; |
| + urlRequest.initialize(); |
| + urlRequest.setURL(URLTestHelpers::toKURL(url)); |
| + |
| + // Schedule a task to start the load, followed by a task that exits the run loop once gotCommit is set to true. |
| + Platform::current()->currentThread()->postTask(FROM_HERE, new FrameTestHelpers::LoadTask(frame, urlRequest)); |
| + Platform::current()->currentThread()->postTask(FROM_HERE, new ServeAsyncRequestsTask(client, gotCommit)); |
| + Platform::current()->unitTestSupport()->enterRunLoop(); |
| +} |
| + |
| +class SwapMainFrameWhileLoadingWebFrameClient : public FrameTestHelpers::TestWebFrameClient { |
| +public: |
| + SwapMainFrameWhileLoadingWebFrameClient(bool* gotCommit) : m_gotCommit(gotCommit) {} |
| + ~SwapMainFrameWhileLoadingWebFrameClient() override {} |
| + |
| + void didCommitProvisionalLoad(WebLocalFrame*, const WebHistoryItem&, WebHistoryCommitType) override |
| + { |
| + *m_gotCommit = true; |
| + } |
| + |
| +private: |
| + bool* m_gotCommit; |
| +}; |
| + |
| +} // anonymous namespace |
| + |
| +TEST_F(WebFrameTest, SwapMainFrameWhileLoading) |
| +{ |
| + bool gotCommit = false; |
| + SwapMainFrameWhileLoadingWebFrameClient frameClient(&gotCommit); |
| + |
| + FrameTestHelpers::WebViewHelper webViewHelper; |
| + registerMockedHttpURLLoad("frame-a-b-c.html"); |
| + registerMockedHttpURLLoad("subframe-a.html"); |
| + registerMockedHttpURLLoad("subframe-b.html"); |
| + registerMockedHttpURLLoad("subframe-c.html"); |
| + registerMockedHttpURLLoad("subframe-hello.html"); |
| + |
| + webViewHelper.initialize(true, &frameClient); |
| + |
| + WebFrame* mainFrame = webViewHelper.webView()->mainFrame(); |
| + StartLoad(mainFrame, m_baseURL + "frame-a-b-c.html", &frameClient, &gotCommit); |
|
Nate Chapin
2015/09/03 21:02:06
What does this (and above) do that webViewHelper.i
sky
2015/09/03 21:03:44
It pumps events until didCommitProvisionalLoad is
Nate Chapin
2015/09/03 21:52:38
Instead of pumping manually, could you just do the
|
| + |
| + WebRemoteFrame* remoteFrame = WebRemoteFrame::create(WebTreeScopeType::Document, nullptr); |
| + mainFrame->swap(remoteFrame); |
| +} |
| + |
| void swapAndVerifyFirstChildConsistency(const char* const message, WebFrame* parent, WebFrame* newChild) |
| { |
| SCOPED_TRACE(message); |