Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1849)

Unified Diff: Source/web/tests/WebFrameTest.cpp

Issue 1302333003: Adds test coverage for 521663 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/web/tests/FrameTestHelpers.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « Source/web/tests/FrameTestHelpers.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698