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

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

Issue 25269006: Initial iframe loads shouldn't add session history items. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rewriting the fix in a different way and adding a test. Created 7 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/core/loader/FrameLoader.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 894474ce7f9157f36ccaeca05c2f1cce17953c77..c9758d209848d5b07b636e1fc8b3fce6dd371634 100644
--- a/Source/web/tests/WebFrameTest.cpp
+++ b/Source/web/tests/WebFrameTest.cpp
@@ -4065,4 +4065,85 @@ TEST_F(WebFrameTest, PushStateStartsAndStops)
EXPECT_EQ(client.stopLoadingCount(), 2);
}
+class TestHistoryWebFrameClient : public WebFrameClient {
+public:
+ TestHistoryWebFrameClient()
+ {
+ m_replacesCurrentHistoryItem = false;
+ m_frame = 0;
+ }
+ void didStartProvisionalLoad(WebFrame* frame)
+ {
+ WebDataSource* ds = frame->provisionalDataSource();
+ m_replacesCurrentHistoryItem = ds->replacesCurrentHistoryItem();
+ m_frame = frame;
+ }
+
+ bool replacesCurrentHistoryItem() { return m_replacesCurrentHistoryItem; }
+ WebFrame* frame() { return m_frame; }
+
+private:
+ bool m_replacesCurrentHistoryItem;
+ WebFrame* m_frame;
+};
+
+// Test which ensures that the first navigation in a subframe will always
+// result in history entry being replaced and not a new one added.
+TEST_F(WebFrameTest, FirstFrameNavigationReplacesHistory)
+{
+ registerMockedHttpURLLoad("history.html");
+ registerMockedHttpURLLoad("find.html");
+
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ TestHistoryWebFrameClient client;
+ webViewHelper.initializeAndLoad("about:blank", true, &client);
+ runPendingTasks();
+ EXPECT_TRUE(client.replacesCurrentHistoryItem());
+
+ WebFrame* frame = webViewHelper.webView()->mainFrame();
+
+ FrameTestHelpers::loadFrame(frame,
+ "javascript:document.body.appendChild(document.createElement('iframe'))");
+ // Need to call runPendingTasks in order for the JavaScript above to be
+ // evaluated and executed.
+ runPendingTasks();
+ WebFrame* iframe = frame->firstChild();
+ EXPECT_EQ(client.frame(), iframe);
+ EXPECT_TRUE(client.replacesCurrentHistoryItem());
+
+ FrameTestHelpers::loadFrame(frame,
+ "javascript:window.frames[0].location.assign('" + m_baseURL + "history.html')");
+ runPendingTasks();
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ EXPECT_EQ(client.frame(), iframe);
+ EXPECT_TRUE(client.replacesCurrentHistoryItem());
+
+ FrameTestHelpers::loadFrame(frame,
+ "javascript:window.frames[0].location.assign('" + m_baseURL + "find.html')");
+ runPendingTasks();
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ EXPECT_EQ(client.frame(), iframe);
+ EXPECT_FALSE(client.replacesCurrentHistoryItem());
+
+ // Repeat the test, but start out the iframe with initial URL, which is not
+ // "about:blank".
+ FrameTestHelpers::loadFrame(frame,
+ "javascript:var f = document.createElement('iframe'); "
+ "f.src = '" + m_baseURL + "history.html';"
+ "document.body.appendChild(f)");
+ runPendingTasks();
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+
+ iframe = frame->firstChild()->nextSibling();
+ EXPECT_EQ(client.frame(), iframe);
+ EXPECT_TRUE(client.replacesCurrentHistoryItem());
+
+ FrameTestHelpers::loadFrame(frame,
+ "javascript:window.frames[1].location.assign('" + m_baseURL + "find.html')");
+ runPendingTasks();
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ EXPECT_EQ(client.frame(), iframe);
+ EXPECT_FALSE(client.replacesCurrentHistoryItem());
+}
+
} // namespace
« no previous file with comments | « Source/core/loader/FrameLoader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698