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

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

Issue 2416523002: Expose the initiating origin/URL of a navigation in the Blink public API (Closed)
Patch Set: rebase Created 4 years, 1 month 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 | « third_party/WebKit/Source/web/WebDataSourceImpl.cpp ('k') | third_party/WebKit/public/web/WebDataSource.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/web/tests/WebFrameTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
index 7c47cbb2ab29a84247805c761fed7652484b8024..b95dd80d03a9e8603b73a4886e436dc0f3774ef6 100644
--- a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
+++ b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
@@ -10747,4 +10747,65 @@ TEST_F(WebFrameTest, NoLoadingCompletionCallbacksInDetach) {
webViewHelper.reset();
}
+TEST_F(WebFrameTest, RequestorURL) {
+ registerMockedHttpURLLoad("single_iframe.html");
+ registerMockedHttpURLLoad("visible_iframe.html");
+
+ class RequestorURLTrackingClient
+ : public FrameTestHelpers::TestWebFrameClient {
+ public:
+ // WebFrameClient overrides:
+ void didCommitProvisionalLoad(WebLocalFrame* frame,
+ const WebHistoryItem&,
+ WebHistoryCommitType) override {
+ m_trackedFrames.set(frame, frame->dataSource()->requestorURL());
+ }
+
+ WebURL requestorURLForFrame(WebLocalFrame* frame) {
+ return m_trackedFrames.get(frame);
+ }
+
+ private:
+ HashMap<WebLocalFrame*, WebURL> m_trackedFrames;
+ };
+
+ RequestorURLTrackingClient trackingClient;
+
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ webViewHelper.initializeAndLoad(m_baseURL + "single_iframe.html", true,
+ &trackingClient);
+
+ WebLocalFrameImpl* const mainFrame = webViewHelper.webView()->mainFrameImpl();
+ const WebURL mainFrameURL = mainFrame->frame()->document()->url();
+ WebLocalFrameImpl* const subFrame =
+ toWebLocalFrameImpl(mainFrame->firstChild());
+ const WebURL subFrameURL = subFrame->frame()->document()->url();
+
+ // The main frame should have no requestor URL.
+ EXPECT_EQ(WebURL(), trackingClient.requestorURLForFrame(mainFrame));
+ // The sub frame should have the main frame's URL as the requestor URL.
+ EXPECT_EQ(mainFrameURL, trackingClient.requestorURLForFrame(subFrame));
+
+ // Once the load has committed, the requestor URL should no longer be
+ // accessible, to avoid keeping potentially unreachable Documents alive.
+ EXPECT_EQ(WebURL(), subFrame->dataSource()->requestorURL());
+
+ // Now have the child frame navigate the top-level frame.
+ registerMockedHttpURLLoad("foo.html");
+ v8::HandleScope scope(v8::Isolate::GetCurrent());
+ ScriptExecutionCallbackHelper callbackHelper(
+ subFrame->mainWorldScriptContext());
+ subFrame->requestExecuteScriptAndReturnValue(
+ WebScriptSource("window.top.location = 'foo.html'"), false,
+ &callbackHelper);
+ FrameTestHelpers::pumpPendingRequestsForFrameToLoad(subFrame);
+ EXPECT_TRUE(callbackHelper.didComplete());
+
+ // The main frame's requestor URL should be the (former) subframe document's
+ // URL.
+ EXPECT_EQ(subFrameURL, trackingClient.requestorURLForFrame(mainFrame));
+
+ webViewHelper.reset();
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/web/WebDataSourceImpl.cpp ('k') | third_party/WebKit/public/web/WebDataSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698