| 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
|
|
|