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

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

Issue 544443002: Detach all subframes before swapping a frame. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Put a real document in subframe. Created 6 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
Index: Source/web/tests/WebFrameTest.cpp
diff --git a/Source/web/tests/WebFrameTest.cpp b/Source/web/tests/WebFrameTest.cpp
index 629eec70fd68d5de57cecfe4a7073e72187ea154..71f2fe182fe6f7e1cd011813a488aee848f6ec80 100644
--- a/Source/web/tests/WebFrameTest.cpp
+++ b/Source/web/tests/WebFrameTest.cpp
@@ -6075,6 +6075,49 @@ TEST_F(WebFrameSwapTest, SwapLastChild)
remoteFrame->close();
}
+void swapAndVerifySubframeConsistency(const char* const message, WebFrame* oldFrame, WebFrame* newFrame)
+{
+ SCOPED_TRACE(message);
+
+ EXPECT_TRUE(oldFrame->firstChild());
+ oldFrame->swap(newFrame);
+
+ EXPECT_FALSE(newFrame->firstChild());
+ EXPECT_FALSE(newFrame->lastChild());
+}
+
+TEST_F(WebFrameSwapTest, SwapParentShouldDetachChildren)
+{
+ WebRemoteFrame* remoteFrame = WebRemoteFrame::create(0);
+ WebFrame* targetFrame = mainFrame()->firstChild()->nextSibling();
+ EXPECT_TRUE(targetFrame);
+ swapAndVerifySubframeConsistency("local->remote", targetFrame, remoteFrame);
+
+ targetFrame = mainFrame()->firstChild()->nextSibling();
+ EXPECT_TRUE(targetFrame);
+
+ // Create child frames in the target frame before testing the swap.
+ FrameTestHelpers::TestWebFrameClient remoteFrameClient;
+ remoteFrame->createRemoteChild("", &remoteFrameClient);
+
+ FrameTestHelpers::TestWebFrameClient client;
+ WebFrame* localFrame = WebLocalFrame::create(&client);
+ swapAndVerifySubframeConsistency("remote->local", targetFrame, localFrame);
+
+ // FIXME: This almost certainly fires more load events on the iframe element
+ // than it should.
+ // Finally, make sure an embedder triggered load in the local frame swapped
+ // back in works.
+ FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html");
+ std::string content = localFrame->contentAsText(1024).utf8();
+ EXPECT_EQ("hello", content);
+
+ // Manually reset to break WebViewHelper's dependency on the stack allocated
+ // TestWebFrameClient.
+ reset();
+ remoteFrame->close();
+}
+
class MockDocumentThreadableLoaderClient : public blink::DocumentThreadableLoaderClient {
public:
MockDocumentThreadableLoaderClient() : m_failed(false) { }

Powered by Google App Engine
This is Rietveld 408576698