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

Side by Side 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 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 10729 matching lines...) Expand 10 before | Expand all | Expand 10 after
10740 &mainFrameClient); 10740 &mainFrameClient);
10741 10741
10742 EXPECT_TRUE(mainFrameClient.childClient().didCallFrameDetached()); 10742 EXPECT_TRUE(mainFrameClient.childClient().didCallFrameDetached());
10743 EXPECT_TRUE(mainFrameClient.childClient().didCallDidStopLoading()); 10743 EXPECT_TRUE(mainFrameClient.childClient().didCallDidStopLoading());
10744 EXPECT_TRUE(mainFrameClient.childClient().didCallDidFinishDocumentLoad()); 10744 EXPECT_TRUE(mainFrameClient.childClient().didCallDidFinishDocumentLoad());
10745 EXPECT_TRUE(mainFrameClient.childClient().didCallDidHandleOnloadEvents()); 10745 EXPECT_TRUE(mainFrameClient.childClient().didCallDidHandleOnloadEvents());
10746 10746
10747 webViewHelper.reset(); 10747 webViewHelper.reset();
10748 } 10748 }
10749 10749
10750 TEST_F(WebFrameTest, RequestorURL) {
10751 registerMockedHttpURLLoad("single_iframe.html");
10752 registerMockedHttpURLLoad("visible_iframe.html");
10753
10754 class RequestorURLTrackingClient
10755 : public FrameTestHelpers::TestWebFrameClient {
10756 public:
10757 // WebFrameClient overrides:
10758 void didCommitProvisionalLoad(WebLocalFrame* frame,
10759 const WebHistoryItem&,
10760 WebHistoryCommitType) override {
10761 m_trackedFrames.set(frame, frame->dataSource()->requestorURL());
10762 }
10763
10764 WebURL requestorURLForFrame(WebLocalFrame* frame) {
10765 return m_trackedFrames.get(frame);
10766 }
10767
10768 private:
10769 HashMap<WebLocalFrame*, WebURL> m_trackedFrames;
10770 };
10771
10772 RequestorURLTrackingClient trackingClient;
10773
10774 FrameTestHelpers::WebViewHelper webViewHelper;
10775 webViewHelper.initializeAndLoad(m_baseURL + "single_iframe.html", true,
10776 &trackingClient);
10777
10778 WebLocalFrameImpl* const mainFrame = webViewHelper.webView()->mainFrameImpl();
10779 const WebURL mainFrameURL = mainFrame->frame()->document()->url();
10780 WebLocalFrameImpl* const subFrame =
10781 toWebLocalFrameImpl(mainFrame->firstChild());
10782 const WebURL subFrameURL = subFrame->frame()->document()->url();
10783
10784 // The main frame should have no requestor URL.
10785 EXPECT_EQ(WebURL(), trackingClient.requestorURLForFrame(mainFrame));
10786 // The sub frame should have the main frame's URL as the requestor URL.
10787 EXPECT_EQ(mainFrameURL, trackingClient.requestorURLForFrame(subFrame));
10788
10789 // Once the load has committed, the requestor URL should no longer be
10790 // accessible, to avoid keeping potentially unreachable Documents alive.
10791 EXPECT_EQ(WebURL(), subFrame->dataSource()->requestorURL());
10792
10793 // Now have the child frame navigate the top-level frame.
10794 registerMockedHttpURLLoad("foo.html");
10795 v8::HandleScope scope(v8::Isolate::GetCurrent());
10796 ScriptExecutionCallbackHelper callbackHelper(
10797 subFrame->mainWorldScriptContext());
10798 subFrame->requestExecuteScriptAndReturnValue(
10799 WebScriptSource("window.top.location = 'foo.html'"), false,
10800 &callbackHelper);
10801 FrameTestHelpers::pumpPendingRequestsForFrameToLoad(subFrame);
10802 EXPECT_TRUE(callbackHelper.didComplete());
10803
10804 // The main frame's requestor URL should be the (former) subframe document's
10805 // URL.
10806 EXPECT_EQ(subFrameURL, trackingClient.requestorURLForFrame(mainFrame));
10807
10808 webViewHelper.reset();
10809 }
10810
10750 } // namespace blink 10811 } // namespace blink
OLDNEW
« 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