1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/command_line.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/net/url_request_mock_util.h"
13 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
14 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/content_switches.h"
28 #include "content/public/test/browser_test_utils.h"
29 #include "net/test/url_request/url_request_mock_http_job.h"
30 #include "third_party/WebKit/public/web/WebInputEvent.h"
32 class ReferrerPolicyTest
: public InProcessBrowserTest
{
34 ReferrerPolicyTest() {}
35 ~ReferrerPolicyTest() override
{}
37 void SetUpOnMainThread() override
{
38 content::BrowserThread::PostTask(
39 content::BrowserThread::IO
, FROM_HERE
,
40 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled
, true));
44 enum ExpectedReferrer
{
45 EXPECT_EMPTY_REFERRER
,
47 EXPECT_ORIGIN_AS_REFERRER
50 // Returns the expected title for the tab with the given (full) referrer and
51 // the expected modification of it.
52 base::string16
GetExpectedTitle(const GURL
& url
,
53 ExpectedReferrer expected_referrer
) {
55 switch (expected_referrer
) {
56 case EXPECT_EMPTY_REFERRER
:
57 referrer
= "Referrer is empty";
59 case EXPECT_FULL_REFERRER
:
60 referrer
= "Referrer is " + url
.spec();
62 case EXPECT_ORIGIN_AS_REFERRER
:
63 referrer
= "Referrer is " + url
.GetWithEmptyPath().spec();
66 return base::ASCIIToUTF16(referrer
);
69 // Adds all possible titles to the TitleWatcher, so we don't time out
70 // waiting for the title if the test fails.
71 void AddAllPossibleTitles(const GURL
& url
,
72 content::TitleWatcher
* title_watcher
) {
73 title_watcher
->AlsoWaitForTitle(
74 GetExpectedTitle(url
, EXPECT_EMPTY_REFERRER
));
75 title_watcher
->AlsoWaitForTitle(
76 GetExpectedTitle(url
, EXPECT_FULL_REFERRER
));
77 title_watcher
->AlsoWaitForTitle(
78 GetExpectedTitle(url
, EXPECT_ORIGIN_AS_REFERRER
));
81 // Returns a string representation of a given |referrer_policy|.
82 std::string
ReferrerPolicyToString(blink::WebReferrerPolicy referrer_policy
) {
83 switch (referrer_policy
) {
84 case blink::WebReferrerPolicyDefault
:
86 case blink::WebReferrerPolicyNoReferrerWhenDowngrade
:
88 case blink::WebReferrerPolicyOrigin
:
90 case blink::WebReferrerPolicyOriginWhenCrossOrigin
:
91 return "origin-when-crossorigin";
92 case blink::WebReferrerPolicyAlways
:
94 case blink::WebReferrerPolicyNever
:
102 enum StartOnProtocol
{ START_ON_HTTP
, START_ON_HTTPS
, };
104 enum LinkType
{ REGULAR_LINK
, LINK_WITH_TARGET_BLANK
, };
108 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
,
109 SERVER_REDIRECT_FROM_HTTP_TO_HTTP
,
110 SERVER_REDIRECT_FROM_HTTP_TO_HTTPS
113 std::string
RedirectTypeToString(RedirectType redirect
) {
117 case SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
:
119 case SERVER_REDIRECT_FROM_HTTP_TO_HTTP
:
121 case SERVER_REDIRECT_FROM_HTTP_TO_HTTPS
:
128 // Navigates from a page with a given |referrer_policy| and checks that the
129 // reported referrer matches the expectation.
131 // referrer_policy: The referrer policy to test.
132 // start_protocol: The protocol the test should start on.
133 // link_type: The link type that is used to trigger the navigation.
134 // redirect: Whether the link target should redirect and how.
135 // disposition: The disposition for the navigation.
136 // button: If not WebMouseEvent::ButtonNone, click on the
137 // link with the specified mouse button.
138 // expected_referrer: The kind of referrer to expect.
141 // The URL of the first page navigated to.
142 GURL
RunReferrerTest(const blink::WebReferrerPolicy referrer_policy
,
143 StartOnProtocol start_protocol
,
145 RedirectType redirect
,
146 WindowOpenDisposition disposition
,
147 blink::WebMouseEvent::Button button
,
148 ExpectedReferrer expected_referrer
) {
149 std::string relative_url
=
150 std::string("referrer_policy/referrer-policy-start.html?") + "policy=" +
151 ReferrerPolicyToString(referrer_policy
) + "&redirect=" +
152 RedirectTypeToString(redirect
) + "&link=" +
153 (button
== blink::WebMouseEvent::ButtonNone
? "false" : "true") +
154 "&target=" + (link_type
== LINK_WITH_TARGET_BLANK
? "_blank" : "");
156 const GURL start_url
=
157 (start_protocol
== START_ON_HTTPS
)
158 ? net::URLRequestMockHTTPJob::GetMockHttpsUrl(relative_url
)
159 : net::URLRequestMockHTTPJob::GetMockUrl(relative_url
);
161 ui_test_utils::WindowedTabAddedNotificationObserver
tab_added_observer(
162 content::NotificationService::AllSources());
164 base::string16 expected_title
=
165 GetExpectedTitle(start_url
, expected_referrer
);
166 content::WebContents
* tab
=
167 browser()->tab_strip_model()->GetActiveWebContents();
168 content::TitleWatcher
title_watcher(tab
, expected_title
);
170 // Watch for all possible outcomes to avoid timeouts if something breaks.
171 AddAllPossibleTitles(start_url
, &title_watcher
);
173 ui_test_utils::NavigateToURL(browser(), start_url
);
175 if (button
!= blink::WebMouseEvent::ButtonNone
) {
176 blink::WebMouseEvent mouse_event
;
177 mouse_event
.type
= blink::WebInputEvent::MouseDown
;
178 mouse_event
.button
= button
;
181 mouse_event
.clickCount
= 1;
182 tab
->GetRenderViewHost()->ForwardMouseEvent(mouse_event
);
183 mouse_event
.type
= blink::WebInputEvent::MouseUp
;
184 tab
->GetRenderViewHost()->ForwardMouseEvent(mouse_event
);
187 if (disposition
== CURRENT_TAB
) {
188 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
190 tab_added_observer
.Wait();
191 tab
= tab_added_observer
.GetTab();
193 content::TitleWatcher
title_watcher2(tab
, expected_title
);
195 // Watch for all possible outcomes to avoid timeouts if something breaks.
196 AddAllPossibleTitles(start_url
, &title_watcher2
);
198 EXPECT_EQ(expected_title
, title_watcher2
.WaitAndGetTitle());
201 EXPECT_EQ(referrer_policy
,
202 tab
->GetController().GetActiveEntry()->GetReferrer().policy
);
208 // The basic behavior of referrer policies is covered by layout tests in
209 // http/tests/security/referrer-policy-*. These tests cover (hopefully) all
210 // code paths chrome uses to navigate. To keep the number of combinations down,
211 // we only test the "origin" policy here.
213 // Some tests are marked as FAILS, see http://crbug.com/124750
215 // Content initiated navigation, from HTTP to HTTP.
216 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, Origin
) {
217 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
222 blink::WebMouseEvent::ButtonNone
,
223 EXPECT_ORIGIN_AS_REFERRER
);
226 // Content initiated navigation, from HTTPS to HTTP.
227 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsDefault
) {
228 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
233 blink::WebMouseEvent::ButtonNone
,
234 EXPECT_ORIGIN_AS_REFERRER
);
237 // User initiated navigation, from HTTP to HTTP.
238 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, LeftClickOrigin
) {
239 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
244 blink::WebMouseEvent::ButtonLeft
,
245 EXPECT_ORIGIN_AS_REFERRER
);
248 // User initiated navigation, from HTTPS to HTTP.
249 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsLeftClickOrigin
) {
250 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
255 blink::WebMouseEvent::ButtonLeft
,
256 EXPECT_ORIGIN_AS_REFERRER
);
259 // User initiated navigation, middle click, from HTTP to HTTP.
260 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, MiddleClickOrigin
) {
261 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
266 blink::WebMouseEvent::ButtonMiddle
,
267 EXPECT_ORIGIN_AS_REFERRER
);
270 // User initiated navigation, middle click, from HTTPS to HTTP.
271 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsMiddleClickOrigin
) {
272 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
277 blink::WebMouseEvent::ButtonMiddle
,
278 EXPECT_ORIGIN_AS_REFERRER
);
281 // User initiated navigation, target blank, from HTTP to HTTP.
282 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, TargetBlankOrigin
) {
283 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
285 LINK_WITH_TARGET_BLANK
,
288 blink::WebMouseEvent::ButtonLeft
,
289 EXPECT_ORIGIN_AS_REFERRER
);
292 // User initiated navigation, target blank, from HTTPS to HTTP.
293 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsTargetBlankOrigin
) {
294 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
296 LINK_WITH_TARGET_BLANK
,
299 blink::WebMouseEvent::ButtonLeft
,
300 EXPECT_ORIGIN_AS_REFERRER
);
303 // User initiated navigation, middle click, target blank, from HTTP to HTTP.
304 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, MiddleClickTargetBlankOrigin
) {
305 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
307 LINK_WITH_TARGET_BLANK
,
310 blink::WebMouseEvent::ButtonMiddle
,
311 EXPECT_ORIGIN_AS_REFERRER
);
314 // User initiated navigation, middle click, target blank, from HTTPS to HTTP.
315 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsMiddleClickTargetBlankOrigin
) {
316 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
318 LINK_WITH_TARGET_BLANK
,
321 blink::WebMouseEvent::ButtonMiddle
,
322 EXPECT_ORIGIN_AS_REFERRER
);
325 // Context menu, from HTTP to HTTP.
326 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, ContextMenuOrigin
) {
327 ContextMenuNotificationObserver
context_menu_observer(
328 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB
);
329 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
334 blink::WebMouseEvent::ButtonRight
,
335 EXPECT_ORIGIN_AS_REFERRER
);
338 // Context menu, from HTTPS to HTTP.
339 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsContextMenuOrigin
) {
340 ContextMenuNotificationObserver
context_menu_observer(
341 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB
);
342 RunReferrerTest(blink::WebReferrerPolicyOrigin
,
347 blink::WebMouseEvent::ButtonRight
,
348 EXPECT_ORIGIN_AS_REFERRER
);
351 // Content initiated navigation, from HTTP to HTTP via server redirect.
352 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, Redirect
) {
353 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTP
, REGULAR_LINK
,
354 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, CURRENT_TAB
,
355 blink::WebMouseEvent::ButtonNone
, EXPECT_ORIGIN_AS_REFERRER
);
358 // Content initiated navigation, from HTTPS to HTTP via server redirect.
359 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsRedirect
) {
360 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTPS
, REGULAR_LINK
,
361 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, CURRENT_TAB
,
362 blink::WebMouseEvent::ButtonNone
, EXPECT_ORIGIN_AS_REFERRER
);
365 // User initiated navigation, from HTTP to HTTP via server redirect.
366 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, LeftClickRedirect
) {
367 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTP
, REGULAR_LINK
,
368 SERVER_REDIRECT_FROM_HTTP_TO_HTTP
, CURRENT_TAB
,
369 blink::WebMouseEvent::ButtonLeft
, EXPECT_ORIGIN_AS_REFERRER
);
372 // User initiated navigation, from HTTPS to HTTP via server redirect.
373 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsLeftClickRedirect
) {
374 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTPS
, REGULAR_LINK
,
375 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, CURRENT_TAB
,
376 blink::WebMouseEvent::ButtonLeft
, EXPECT_ORIGIN_AS_REFERRER
);
379 // User initiated navigation, middle click, from HTTP to HTTP via server
381 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, MiddleClickRedirect
) {
382 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTP
, REGULAR_LINK
,
383 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, NEW_BACKGROUND_TAB
,
384 blink::WebMouseEvent::ButtonMiddle
,
385 EXPECT_ORIGIN_AS_REFERRER
);
388 // User initiated navigation, middle click, from HTTPS to HTTP via server
390 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsMiddleClickRedirect
) {
391 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTPS
, REGULAR_LINK
,
392 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, NEW_BACKGROUND_TAB
,
393 blink::WebMouseEvent::ButtonMiddle
,
394 EXPECT_ORIGIN_AS_REFERRER
);
397 // User initiated navigation, target blank, from HTTP to HTTP via server
399 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, TargetBlankRedirect
) {
400 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTP
,
401 LINK_WITH_TARGET_BLANK
, SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
,
402 NEW_FOREGROUND_TAB
, blink::WebMouseEvent::ButtonLeft
,
403 EXPECT_ORIGIN_AS_REFERRER
);
406 // User initiated navigation, target blank, from HTTPS to HTTP via server
408 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsTargetBlankRedirect
) {
409 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTPS
,
410 LINK_WITH_TARGET_BLANK
, SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
,
411 NEW_FOREGROUND_TAB
, blink::WebMouseEvent::ButtonLeft
,
412 EXPECT_ORIGIN_AS_REFERRER
);
415 // User initiated navigation, middle click, target blank, from HTTP to HTTP via
417 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, MiddleClickTargetBlankRedirect
) {
418 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTP
,
419 LINK_WITH_TARGET_BLANK
, SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
,
420 NEW_FOREGROUND_TAB
, blink::WebMouseEvent::ButtonMiddle
,
421 EXPECT_ORIGIN_AS_REFERRER
);
424 // User initiated navigation, middle click, target blank, from HTTPS to HTTP
425 // via server redirect.
426 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
,
427 HttpsMiddleClickTargetBlankRedirect
) {
428 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTPS
,
429 LINK_WITH_TARGET_BLANK
, SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
,
430 NEW_FOREGROUND_TAB
, blink::WebMouseEvent::ButtonMiddle
,
431 EXPECT_ORIGIN_AS_REFERRER
);
434 // Context menu, from HTTP to HTTP via server redirect.
435 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, ContextMenuRedirect
) {
436 ContextMenuNotificationObserver
context_menu_observer(
437 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB
);
438 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTP
, REGULAR_LINK
,
439 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, NEW_FOREGROUND_TAB
,
440 blink::WebMouseEvent::ButtonRight
, EXPECT_ORIGIN_AS_REFERRER
);
443 // Context menu, from HTTPS to HTTP via server redirect.
444 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpsContextMenuRedirect
) {
445 ContextMenuNotificationObserver
context_menu_observer(
446 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB
);
447 RunReferrerTest(blink::WebReferrerPolicyOrigin
, START_ON_HTTPS
, REGULAR_LINK
,
448 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, NEW_FOREGROUND_TAB
,
449 blink::WebMouseEvent::ButtonRight
, EXPECT_ORIGIN_AS_REFERRER
);
452 // Tests history navigation actions: Navigate from A to B with a referrer
453 // policy, then navigate to C, back to B, and reload.
454 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, History
) {
455 // Navigate from A to B.
456 GURL start_url
= RunReferrerTest(
457 blink::WebReferrerPolicyOrigin
, START_ON_HTTPS
, REGULAR_LINK
,
458 SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, CURRENT_TAB
,
459 blink::WebMouseEvent::ButtonLeft
, EXPECT_ORIGIN_AS_REFERRER
);
462 ui_test_utils::NavigateToURL(
463 browser(), net::URLRequestMockHTTPJob::GetMockUrl(std::string()));
465 base::string16 expected_title
=
466 GetExpectedTitle(start_url
, EXPECT_ORIGIN_AS_REFERRER
);
467 content::WebContents
* tab
=
468 browser()->tab_strip_model()->GetActiveWebContents();
469 scoped_ptr
<content::TitleWatcher
> title_watcher(
470 new content::TitleWatcher(tab
, expected_title
));
472 // Watch for all possible outcomes to avoid timeouts if something breaks.
473 AddAllPossibleTitles(start_url
, title_watcher
.get());
476 chrome::GoBack(browser(), CURRENT_TAB
);
477 EXPECT_EQ(expected_title
, title_watcher
->WaitAndGetTitle());
479 title_watcher
.reset(new content::TitleWatcher(tab
, expected_title
));
480 AddAllPossibleTitles(start_url
, title_watcher
.get());
483 chrome::Reload(browser(), CURRENT_TAB
);
484 EXPECT_EQ(expected_title
, title_watcher
->WaitAndGetTitle());
486 title_watcher
.reset(new content::TitleWatcher(tab
, expected_title
));
487 AddAllPossibleTitles(start_url
, title_watcher
.get());
489 // Shift-reload to B.
490 chrome::ReloadIgnoringCache(browser(), CURRENT_TAB
);
491 EXPECT_EQ(expected_title
, title_watcher
->WaitAndGetTitle());
494 // Tests that reloading a site for "request tablet version" correctly clears
496 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, RequestTabletSite
) {
497 GURL start_url
= RunReferrerTest(
498 blink::WebReferrerPolicyOrigin
, START_ON_HTTPS
, REGULAR_LINK
,
499 SERVER_REDIRECT_FROM_HTTP_TO_HTTP
, CURRENT_TAB
,
500 blink::WebMouseEvent::ButtonLeft
, EXPECT_ORIGIN_AS_REFERRER
);
502 base::string16 expected_title
=
503 GetExpectedTitle(start_url
, EXPECT_EMPTY_REFERRER
);
504 content::WebContents
* tab
=
505 browser()->tab_strip_model()->GetActiveWebContents();
506 content::TitleWatcher
title_watcher(tab
, expected_title
);
508 // Watch for all possible outcomes to avoid timeouts if something breaks.
509 AddAllPossibleTitles(start_url
, &title_watcher
);
511 // Request tablet version.
512 chrome::ToggleRequestTabletSite(browser());
513 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
516 // Test that an iframes gets the parent frames referrer and referrer policy if
517 // the load was triggered by the parent, or from the iframe itself, if the
518 // navigations was started by the iframe.
519 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, IFrame
) {
520 browser()->profile()->GetPrefs()->SetBoolean(
521 prefs::kWebKitAllowRunningInsecureContent
, true);
522 content::WebContents
* tab
=
523 browser()->tab_strip_model()->GetActiveWebContents();
524 base::string16
expected_title(base::ASCIIToUTF16("loaded"));
525 scoped_ptr
<content::TitleWatcher
> title_watcher(
526 new content::TitleWatcher(tab
, expected_title
));
528 // Load a page that loads an iframe.
529 ui_test_utils::NavigateToURL(
530 browser(), net::URLRequestMockHTTPJob::GetMockHttpsUrl(std::string(
531 "referrer_policy/referrer-policy-iframe.html")));
532 EXPECT_EQ(expected_title
, title_watcher
->WaitAndGetTitle());
534 // Verify that the referrer policy was honored and the main page's origin was
536 content::RenderFrameHost
* frame
= content::FrameMatchingPredicate(
537 tab
, base::Bind(&content::FrameIsChildOfMainFrame
));
539 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
541 "window.domAutomationController.send(document.title)",
545 net::URLRequestMockHTTPJob::GetMockHttpsUrl(std::string()).spec(),
548 // Reload the iframe.
549 expected_title
= base::ASCIIToUTF16("reset");
550 title_watcher
.reset(new content::TitleWatcher(tab
, expected_title
));
551 EXPECT_TRUE(content::ExecuteScript(tab
, "document.title = 'reset'"));
552 EXPECT_EQ(expected_title
, title_watcher
->WaitAndGetTitle());
554 expected_title
= base::ASCIIToUTF16("loaded");
555 title_watcher
.reset(new content::TitleWatcher(tab
, expected_title
));
556 EXPECT_TRUE(content::ExecuteScript(frame
, "location.reload()"));
557 EXPECT_EQ(expected_title
, title_watcher
->WaitAndGetTitle());
559 // Verify that the full url of the iframe was used as referrer.
560 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
562 "window.domAutomationController.send(document.title)",
564 EXPECT_EQ("Referrer is " +
565 net::URLRequestMockHTTPJob::GetMockUrl(
566 "referrer_policy/referrer-policy-log.html").spec(),
570 // Origin When Cross-Origin
572 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
,
573 HttpLeftClickHTTPSRedirectToHTTPOriginWhenCrossOrigin
) {
574 RunReferrerTest(blink::WebReferrerPolicyOriginWhenCrossOrigin
, START_ON_HTTPS
,
575 REGULAR_LINK
, SERVER_REDIRECT_FROM_HTTPS_TO_HTTP
, CURRENT_TAB
,
576 blink::WebMouseEvent::ButtonLeft
, EXPECT_ORIGIN_AS_REFERRER
);
579 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
,
580 HttpLeftClickRedirectToHTTPSOriginWhenCrossOrigin
) {
581 RunReferrerTest(blink::WebReferrerPolicyOriginWhenCrossOrigin
, START_ON_HTTP
,
582 REGULAR_LINK
, SERVER_REDIRECT_FROM_HTTP_TO_HTTPS
, CURRENT_TAB
,
583 blink::WebMouseEvent::ButtonLeft
, EXPECT_ORIGIN_AS_REFERRER
);
586 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
,
587 HttpLeftClickRedirectToHTTPOriginWhenCrossOrigin
) {
588 RunReferrerTest(blink::WebReferrerPolicyOriginWhenCrossOrigin
, START_ON_HTTP
,
589 REGULAR_LINK
, SERVER_REDIRECT_FROM_HTTP_TO_HTTP
, CURRENT_TAB
,
590 blink::WebMouseEvent::ButtonLeft
, EXPECT_FULL_REFERRER
);
593 // Reduced 'referer' granularity flag tests.
595 // User initiated navigation, from HTTP to HTTPS via server redirect.
596 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpLeftClickRedirectDefaultNoFlag
) {
597 RunReferrerTest(blink::WebReferrerPolicyDefault
, START_ON_HTTP
, REGULAR_LINK
,
598 SERVER_REDIRECT_FROM_HTTP_TO_HTTPS
, CURRENT_TAB
,
599 blink::WebMouseEvent::ButtonLeft
, EXPECT_FULL_REFERRER
);
602 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest
, HttpLeftClickRedirectDefaultFlag
) {
603 base::CommandLine::ForCurrentProcess()->AppendSwitch(
604 switches::kReducedReferrerGranularity
);
605 RunReferrerTest(blink::WebReferrerPolicyDefault
, START_ON_HTTP
, REGULAR_LINK
,
606 SERVER_REDIRECT_FROM_HTTP_TO_HTTPS
, CURRENT_TAB
,
607 blink::WebMouseEvent::ButtonLeft
, EXPECT_ORIGIN_AS_REFERRER
);