NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / referrer_policy_browsertest.cc
blob852dfd6862a8321dd88fb28bb0de67fef20b8cc4
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.
5 #include "base/bind.h"
6 #include "base/prefs/pref_service.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/tab_contents/render_view_context_menu.h"
12 #include "chrome/browser/tab_contents/render_view_context_menu_browsertest_util.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/browser_test_utils.h"
25 #include "net/test/spawned_test_server/spawned_test_server.h"
26 #include "third_party/WebKit/public/web/WebInputEvent.h"
28 // GTK requires a X11-level mouse event to open a context menu correctly.
29 #if defined(TOOLKIT_GTK)
30 #define MAYBE_ContextMenuOrigin DISABLED_ContextMenuOrigin
31 #define MAYBE_HttpsContextMenuOrigin DISABLED_HttpsContextMenuOrigin
32 #define MAYBE_ContextMenuRedirect DISABLED_ContextMenuRedirect
33 #define MAYBE_HttpsContextMenuRedirect DISABLED_HttpsContextMenuRedirect
34 #else
35 #define MAYBE_ContextMenuOrigin ContextMenuOrigin
36 #define MAYBE_HttpsContextMenuOrigin HttpsContextMenuOrigin
37 #define MAYBE_ContextMenuRedirect ContextMenuRedirect
38 #define MAYBE_HttpsContextMenuRedirect HttpsContextMenuRedirect
39 #endif
41 namespace {
43 const base::FilePath::CharType kDocRoot[] =
44 FILE_PATH_LITERAL("chrome/test/data/referrer_policy");
46 } // namespace
48 class ReferrerPolicyTest : public InProcessBrowserTest {
49 public:
50 ReferrerPolicyTest() {}
51 virtual ~ReferrerPolicyTest() {}
53 virtual void SetUp() OVERRIDE {
54 test_server_.reset(new net::SpawnedTestServer(
55 net::SpawnedTestServer::TYPE_HTTP,
56 net::SpawnedTestServer::kLocalhost,
57 base::FilePath(kDocRoot)));
58 ASSERT_TRUE(test_server_->Start());
59 ssl_test_server_.reset(new net::SpawnedTestServer(
60 net::SpawnedTestServer::TYPE_HTTPS,
61 net::SpawnedTestServer::kLocalhost,
62 base::FilePath(kDocRoot)));
63 ASSERT_TRUE(ssl_test_server_->Start());
65 InProcessBrowserTest::SetUp();
68 protected:
69 enum ExpectedReferrer {
70 EXPECT_EMPTY_REFERRER,
71 EXPECT_FULL_REFERRER,
72 EXPECT_ORIGIN_AS_REFERRER
75 // Returns the expected title for the tab with the given (full) referrer and
76 // the expected modification of it.
77 base::string16 GetExpectedTitle(const GURL& url,
78 ExpectedReferrer expected_referrer) {
79 std::string referrer;
80 switch (expected_referrer) {
81 case EXPECT_EMPTY_REFERRER:
82 referrer = "Referrer is empty";
83 break;
84 case EXPECT_FULL_REFERRER:
85 referrer = "Referrer is " + url.spec();
86 break;
87 case EXPECT_ORIGIN_AS_REFERRER:
88 referrer = "Referrer is " + url.GetWithEmptyPath().spec();
89 break;
91 return base::ASCIIToUTF16(referrer);
94 // Adds all possible titles to the TitleWatcher, so we don't time out
95 // waiting for the title if the test fails.
96 void AddAllPossibleTitles(const GURL& url,
97 content::TitleWatcher* title_watcher) {
98 title_watcher->AlsoWaitForTitle(
99 GetExpectedTitle(url, EXPECT_EMPTY_REFERRER));
100 title_watcher->AlsoWaitForTitle(
101 GetExpectedTitle(url, EXPECT_FULL_REFERRER));
102 title_watcher->AlsoWaitForTitle(
103 GetExpectedTitle(url, EXPECT_ORIGIN_AS_REFERRER));
106 // Returns a string representation of a given |referrer_policy|.
107 std::string ReferrerPolicyToString(blink::WebReferrerPolicy referrer_policy) {
108 switch (referrer_policy) {
109 case blink::WebReferrerPolicyDefault:
110 return "default";
111 case blink::WebReferrerPolicyOrigin:
112 return "origin";
113 case blink::WebReferrerPolicyAlways:
114 return "always";
115 case blink::WebReferrerPolicyNever:
116 return "never";
117 default:
118 NOTREACHED();
119 return "";
123 enum StartOnProtocol { START_ON_HTTP, START_ON_HTTPS, };
125 enum LinkType { REGULAR_LINK, LINk_WITH_TARGET_BLANK, };
127 enum RedirectType { NO_REDIRECT, SERVER_REDIRECT, SERVER_REDIRECT_ON_HTTP, };
129 std::string RedirectTypeToString(RedirectType redirect) {
130 switch (redirect) {
131 case NO_REDIRECT:
132 return "none";
133 case SERVER_REDIRECT:
134 return "https";
135 case SERVER_REDIRECT_ON_HTTP:
136 return "http";
138 NOTREACHED();
139 return "";
142 // Navigates from a page with a given |referrer_policy| and checks that the
143 // reported referrer matches the expectation.
144 // Parameters:
145 // referrer_policy: The referrer policy to test.
146 // start_protocol: The protocol the test should start on.
147 // link_type: The link type that is used to trigger the navigation.
148 // redirect: Whether the link target should redirect and how.
149 // disposition: The disposition for the navigation.
150 // button: If not WebMouseEvent::ButtonNone, click on the
151 // link with the specified mouse button.
152 // expected_referrer: The kind of referrer to expect.
154 // Returns:
155 // The URL of the first page navigated to.
156 GURL RunReferrerTest(const blink::WebReferrerPolicy referrer_policy,
157 StartOnProtocol start_protocol,
158 LinkType link_type,
159 RedirectType redirect,
160 WindowOpenDisposition disposition,
161 blink::WebMouseEvent::Button button,
162 ExpectedReferrer expected_referrer) {
163 GURL start_url;
164 net::SpawnedTestServer* start_server = start_protocol == START_ON_HTTPS
165 ? ssl_test_server_.get()
166 : test_server_.get();
167 start_url = start_server->GetURL(
168 std::string("files/referrer-policy-start.html?") + "policy=" +
169 ReferrerPolicyToString(referrer_policy) + "&port=" +
170 base::IntToString(test_server_->host_port_pair().port()) +
171 "&ssl_port=" +
172 base::IntToString(ssl_test_server_->host_port_pair().port()) +
173 "&redirect=" + RedirectTypeToString(redirect) + "&link=" +
174 (button == blink::WebMouseEvent::ButtonNone ? "false" : "true") +
175 "&target=" + (link_type == LINk_WITH_TARGET_BLANK ? "_blank" : ""));
177 ui_test_utils::WindowedTabAddedNotificationObserver tab_added_observer(
178 content::NotificationService::AllSources());
180 base::string16 expected_title =
181 GetExpectedTitle(start_url, expected_referrer);
182 content::WebContents* tab =
183 browser()->tab_strip_model()->GetActiveWebContents();
184 content::TitleWatcher title_watcher(tab, expected_title);
186 // Watch for all possible outcomes to avoid timeouts if something breaks.
187 AddAllPossibleTitles(start_url, &title_watcher);
189 ui_test_utils::NavigateToURL(browser(), start_url);
191 if (button != blink::WebMouseEvent::ButtonNone) {
192 blink::WebMouseEvent mouse_event;
193 mouse_event.type = blink::WebInputEvent::MouseDown;
194 mouse_event.button = button;
195 mouse_event.x = 15;
196 mouse_event.y = 15;
197 mouse_event.clickCount = 1;
198 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
199 mouse_event.type = blink::WebInputEvent::MouseUp;
200 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
203 if (disposition == CURRENT_TAB) {
204 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
205 } else {
206 tab_added_observer.Wait();
207 tab = tab_added_observer.GetTab();
208 EXPECT_TRUE(tab);
209 content::WaitForLoadStop(tab);
210 EXPECT_EQ(expected_title, tab->GetTitle());
213 EXPECT_EQ(referrer_policy,
214 tab->GetController().GetActiveEntry()->GetReferrer().policy);
216 return start_url;
219 scoped_ptr<net::SpawnedTestServer> test_server_;
220 scoped_ptr<net::SpawnedTestServer> ssl_test_server_;
223 // The basic behavior of referrer policies is covered by layout tests in
224 // http/tests/security/referrer-policy-*. These tests cover (hopefully) all
225 // code paths chrome uses to navigate. To keep the number of combinations down,
226 // we only test the "origin" policy here.
228 // Some tests are marked as FAILS, see http://crbug.com/124750
230 // Content initiated navigation, from HTTP to HTTP.
231 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, Origin) {
232 RunReferrerTest(blink::WebReferrerPolicyOrigin,
233 START_ON_HTTP,
234 REGULAR_LINK,
235 NO_REDIRECT,
236 CURRENT_TAB,
237 blink::WebMouseEvent::ButtonNone,
238 EXPECT_ORIGIN_AS_REFERRER);
241 // Content initiated navigation, from HTTPS to HTTP.
242 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsDefault) {
243 RunReferrerTest(blink::WebReferrerPolicyOrigin,
244 START_ON_HTTPS,
245 REGULAR_LINK,
246 NO_REDIRECT,
247 CURRENT_TAB,
248 blink::WebMouseEvent::ButtonNone,
249 EXPECT_ORIGIN_AS_REFERRER);
252 // User initiated navigation, from HTTP to HTTP.
253 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, LeftClickOrigin) {
254 RunReferrerTest(blink::WebReferrerPolicyOrigin,
255 START_ON_HTTP,
256 REGULAR_LINK,
257 NO_REDIRECT,
258 CURRENT_TAB,
259 blink::WebMouseEvent::ButtonLeft,
260 EXPECT_ORIGIN_AS_REFERRER);
263 // User initiated navigation, from HTTPS to HTTP.
264 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsLeftClickOrigin) {
265 RunReferrerTest(blink::WebReferrerPolicyOrigin,
266 START_ON_HTTPS,
267 REGULAR_LINK,
268 NO_REDIRECT,
269 CURRENT_TAB,
270 blink::WebMouseEvent::ButtonLeft,
271 EXPECT_ORIGIN_AS_REFERRER);
274 // User initiated navigation, middle click, from HTTP to HTTP.
275 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MiddleClickOrigin) {
276 RunReferrerTest(blink::WebReferrerPolicyOrigin,
277 START_ON_HTTP,
278 REGULAR_LINK,
279 NO_REDIRECT,
280 NEW_BACKGROUND_TAB,
281 blink::WebMouseEvent::ButtonMiddle,
282 EXPECT_ORIGIN_AS_REFERRER);
285 // User initiated navigation, middle click, from HTTPS to HTTP.
286 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsMiddleClickOrigin) {
287 RunReferrerTest(blink::WebReferrerPolicyOrigin,
288 START_ON_HTTPS,
289 REGULAR_LINK,
290 NO_REDIRECT,
291 NEW_BACKGROUND_TAB,
292 blink::WebMouseEvent::ButtonMiddle,
293 EXPECT_ORIGIN_AS_REFERRER);
296 // User initiated navigation, target blank, from HTTP to HTTP.
297 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, TargetBlankOrigin) {
298 RunReferrerTest(blink::WebReferrerPolicyOrigin,
299 START_ON_HTTP,
300 LINk_WITH_TARGET_BLANK,
301 NO_REDIRECT,
302 NEW_FOREGROUND_TAB,
303 blink::WebMouseEvent::ButtonLeft,
304 EXPECT_ORIGIN_AS_REFERRER);
307 // User initiated navigation, target blank, from HTTPS to HTTP.
308 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsTargetBlankOrigin) {
309 RunReferrerTest(blink::WebReferrerPolicyOrigin,
310 START_ON_HTTPS,
311 LINk_WITH_TARGET_BLANK,
312 NO_REDIRECT,
313 NEW_FOREGROUND_TAB,
314 blink::WebMouseEvent::ButtonLeft,
315 EXPECT_ORIGIN_AS_REFERRER);
318 // User initiated navigation, middle click, target blank, from HTTP to HTTP.
319 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MiddleClickTargetBlankOrigin) {
320 RunReferrerTest(blink::WebReferrerPolicyOrigin,
321 START_ON_HTTP,
322 LINk_WITH_TARGET_BLANK,
323 NO_REDIRECT,
324 NEW_FOREGROUND_TAB,
325 blink::WebMouseEvent::ButtonMiddle,
326 EXPECT_ORIGIN_AS_REFERRER);
329 // User initiated navigation, middle click, target blank, from HTTPS to HTTP.
330 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsMiddleClickTargetBlankOrigin) {
331 RunReferrerTest(blink::WebReferrerPolicyOrigin,
332 START_ON_HTTPS,
333 LINk_WITH_TARGET_BLANK,
334 NO_REDIRECT,
335 NEW_FOREGROUND_TAB,
336 blink::WebMouseEvent::ButtonMiddle,
337 EXPECT_ORIGIN_AS_REFERRER);
340 // Context menu, from HTTP to HTTP.
341 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_ContextMenuOrigin) {
342 ContextMenuNotificationObserver context_menu_observer(
343 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
344 RunReferrerTest(blink::WebReferrerPolicyOrigin,
345 START_ON_HTTP,
346 REGULAR_LINK,
347 NO_REDIRECT,
348 NEW_FOREGROUND_TAB,
349 blink::WebMouseEvent::ButtonRight,
350 EXPECT_ORIGIN_AS_REFERRER);
353 // Context menu, from HTTPS to HTTP.
354 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_HttpsContextMenuOrigin) {
355 ContextMenuNotificationObserver context_menu_observer(
356 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
357 RunReferrerTest(blink::WebReferrerPolicyOrigin,
358 START_ON_HTTPS,
359 REGULAR_LINK,
360 NO_REDIRECT,
361 NEW_FOREGROUND_TAB,
362 blink::WebMouseEvent::ButtonRight,
363 EXPECT_ORIGIN_AS_REFERRER);
366 // Content initiated navigation, from HTTP to HTTP via server redirect.
367 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, Redirect) {
368 RunReferrerTest(blink::WebReferrerPolicyOrigin,
369 START_ON_HTTP,
370 REGULAR_LINK,
371 SERVER_REDIRECT,
372 CURRENT_TAB,
373 blink::WebMouseEvent::ButtonNone,
374 EXPECT_ORIGIN_AS_REFERRER);
377 // Content initiated navigation, from HTTPS to HTTP via server redirect.
378 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsRedirect) {
379 RunReferrerTest(blink::WebReferrerPolicyOrigin,
380 START_ON_HTTPS,
381 REGULAR_LINK,
382 SERVER_REDIRECT,
383 CURRENT_TAB,
384 blink::WebMouseEvent::ButtonNone,
385 EXPECT_ORIGIN_AS_REFERRER);
388 // User initiated navigation, from HTTP to HTTP via server redirect.
389 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, LeftClickRedirect) {
390 RunReferrerTest(blink::WebReferrerPolicyOrigin,
391 START_ON_HTTP,
392 REGULAR_LINK,
393 SERVER_REDIRECT,
394 CURRENT_TAB,
395 blink::WebMouseEvent::ButtonLeft,
396 EXPECT_ORIGIN_AS_REFERRER);
399 // User initiated navigation, from HTTPS to HTTP via server redirect.
400 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsLeftClickRedirect) {
401 RunReferrerTest(blink::WebReferrerPolicyOrigin,
402 START_ON_HTTPS,
403 REGULAR_LINK,
404 SERVER_REDIRECT,
405 CURRENT_TAB,
406 blink::WebMouseEvent::ButtonLeft,
407 EXPECT_ORIGIN_AS_REFERRER);
410 // User initiated navigation, middle click, from HTTP to HTTP via server
411 // redirect.
412 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MiddleClickRedirect) {
413 RunReferrerTest(blink::WebReferrerPolicyOrigin,
414 START_ON_HTTP,
415 REGULAR_LINK,
416 SERVER_REDIRECT,
417 NEW_BACKGROUND_TAB,
418 blink::WebMouseEvent::ButtonMiddle,
419 EXPECT_ORIGIN_AS_REFERRER);
422 // User initiated navigation, middle click, from HTTPS to HTTP via server
423 // redirect.
424 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsMiddleClickRedirect) {
425 RunReferrerTest(blink::WebReferrerPolicyOrigin,
426 START_ON_HTTPS,
427 REGULAR_LINK,
428 SERVER_REDIRECT,
429 NEW_BACKGROUND_TAB,
430 blink::WebMouseEvent::ButtonMiddle,
431 EXPECT_ORIGIN_AS_REFERRER);
434 // User initiated navigation, target blank, from HTTP to HTTP via server
435 // redirect.
436 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, TargetBlankRedirect) {
437 RunReferrerTest(blink::WebReferrerPolicyOrigin,
438 START_ON_HTTP,
439 LINk_WITH_TARGET_BLANK,
440 SERVER_REDIRECT,
441 NEW_FOREGROUND_TAB,
442 blink::WebMouseEvent::ButtonLeft,
443 EXPECT_ORIGIN_AS_REFERRER);
446 // User initiated navigation, target blank, from HTTPS to HTTP via server
447 // redirect.
448 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsTargetBlankRedirect) {
449 RunReferrerTest(blink::WebReferrerPolicyOrigin,
450 START_ON_HTTPS,
451 LINk_WITH_TARGET_BLANK,
452 SERVER_REDIRECT,
453 NEW_FOREGROUND_TAB,
454 blink::WebMouseEvent::ButtonLeft,
455 EXPECT_ORIGIN_AS_REFERRER);
458 // User initiated navigation, middle click, target blank, from HTTP to HTTP via
459 // server redirect.
460 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MiddleClickTargetBlankRedirect) {
461 RunReferrerTest(blink::WebReferrerPolicyOrigin,
462 START_ON_HTTP,
463 LINk_WITH_TARGET_BLANK,
464 SERVER_REDIRECT,
465 NEW_FOREGROUND_TAB,
466 blink::WebMouseEvent::ButtonMiddle,
467 EXPECT_ORIGIN_AS_REFERRER);
470 // User initiated navigation, middle click, target blank, from HTTPS to HTTP
471 // via server redirect.
472 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest,
473 HttpsMiddleClickTargetBlankRedirect) {
474 RunReferrerTest(blink::WebReferrerPolicyOrigin,
475 START_ON_HTTPS,
476 LINk_WITH_TARGET_BLANK,
477 SERVER_REDIRECT,
478 NEW_FOREGROUND_TAB,
479 blink::WebMouseEvent::ButtonMiddle,
480 EXPECT_ORIGIN_AS_REFERRER);
483 // Context menu, from HTTP to HTTP via server redirect.
484 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_ContextMenuRedirect) {
485 ContextMenuNotificationObserver context_menu_observer(
486 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
487 RunReferrerTest(blink::WebReferrerPolicyOrigin,
488 START_ON_HTTP,
489 REGULAR_LINK,
490 SERVER_REDIRECT,
491 NEW_FOREGROUND_TAB,
492 blink::WebMouseEvent::ButtonRight,
493 EXPECT_ORIGIN_AS_REFERRER);
496 // Context menu, from HTTPS to HTTP via server redirect.
497 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_HttpsContextMenuRedirect) {
498 ContextMenuNotificationObserver context_menu_observer(
499 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
500 RunReferrerTest(blink::WebReferrerPolicyOrigin,
501 START_ON_HTTPS,
502 REGULAR_LINK,
503 SERVER_REDIRECT,
504 NEW_FOREGROUND_TAB,
505 blink::WebMouseEvent::ButtonRight,
506 EXPECT_ORIGIN_AS_REFERRER);
509 // Tests history navigation actions: Navigate from A to B with a referrer
510 // policy, then navigate to C, back to B, and reload.
511 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, History) {
512 // Navigate from A to B.
513 GURL start_url = RunReferrerTest(blink::WebReferrerPolicyOrigin,
514 START_ON_HTTPS,
515 REGULAR_LINK,
516 SERVER_REDIRECT,
517 CURRENT_TAB,
518 blink::WebMouseEvent::ButtonLeft,
519 EXPECT_ORIGIN_AS_REFERRER);
521 // Navigate to C.
522 ui_test_utils::NavigateToURL(browser(), test_server_->GetURL(std::string()));
524 base::string16 expected_title =
525 GetExpectedTitle(start_url, EXPECT_ORIGIN_AS_REFERRER);
526 content::WebContents* tab =
527 browser()->tab_strip_model()->GetActiveWebContents();
528 scoped_ptr<content::TitleWatcher> title_watcher(
529 new content::TitleWatcher(tab, expected_title));
531 // Watch for all possible outcomes to avoid timeouts if something breaks.
532 AddAllPossibleTitles(start_url, title_watcher.get());
534 // Go back to B.
535 chrome::GoBack(browser(), CURRENT_TAB);
536 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
538 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
539 AddAllPossibleTitles(start_url, title_watcher.get());
541 // Reload to B.
542 chrome::Reload(browser(), CURRENT_TAB);
543 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
545 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
546 AddAllPossibleTitles(start_url, title_watcher.get());
548 // Shift-reload to B.
549 chrome::ReloadIgnoringCache(browser(), CURRENT_TAB);
550 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
553 // Tests that reloading a site for "request tablet version" correctly clears
554 // the referrer.
555 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, RequestTabletSite) {
556 GURL start_url = RunReferrerTest(blink::WebReferrerPolicyOrigin,
557 START_ON_HTTPS,
558 REGULAR_LINK,
559 SERVER_REDIRECT_ON_HTTP,
560 CURRENT_TAB,
561 blink::WebMouseEvent::ButtonLeft,
562 EXPECT_ORIGIN_AS_REFERRER);
564 base::string16 expected_title =
565 GetExpectedTitle(start_url, EXPECT_EMPTY_REFERRER);
566 content::WebContents* tab =
567 browser()->tab_strip_model()->GetActiveWebContents();
568 content::TitleWatcher title_watcher(tab, expected_title);
570 // Watch for all possible outcomes to avoid timeouts if something breaks.
571 AddAllPossibleTitles(start_url, &title_watcher);
573 // Request tablet version.
574 chrome::ToggleRequestTabletSite(browser());
575 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
578 // Test that an iframes gets the parent frames referrer and referrer policy if
579 // the load was triggered by the parent, or from the iframe itself, if the
580 // navigations was started by the iframe.
581 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, IFrame) {
582 browser()->profile()->GetPrefs()->SetBoolean(
583 prefs::kWebKitAllowRunningInsecureContent, true);
584 content::WebContents* tab =
585 browser()->tab_strip_model()->GetActiveWebContents();
586 base::string16 expected_title(base::ASCIIToUTF16("loaded"));
587 scoped_ptr<content::TitleWatcher> title_watcher(
588 new content::TitleWatcher(tab, expected_title));
590 // Load a page that loads an iframe.
591 ui_test_utils::NavigateToURL(
592 browser(),
593 ssl_test_server_->GetURL(
594 std::string("files/referrer-policy-iframe.html?") +
595 base::IntToString(test_server_->host_port_pair().port())));
596 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
598 // Verify that the referrer policy was honored and the main page's origin was
599 // send as referrer.
600 std::string title;
601 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString(
602 tab,
603 "//iframe",
604 "window.domAutomationController.send(document.title)",
605 &title));
606 EXPECT_EQ("Referrer is " + ssl_test_server_->GetURL(std::string()).spec(),
607 title);
609 // Reload the iframe.
610 expected_title = base::ASCIIToUTF16("reset");
611 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
612 EXPECT_TRUE(content::ExecuteScript(tab, "document.title = 'reset'"));
613 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
615 expected_title = base::ASCIIToUTF16("loaded");
616 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
617 EXPECT_TRUE(
618 content::ExecuteScriptInFrame(tab, "//iframe", "location.reload()"));
619 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
621 // Verify that the full url of the iframe was used as referrer.
622 EXPECT_TRUE(content::ExecuteScriptInFrameAndExtractString(
623 tab,
624 "//iframe",
625 "window.domAutomationController.send(document.title)",
626 &title));
627 EXPECT_EQ("Referrer is " +
628 test_server_->GetURL("files/referrer-policy-log.html").spec(),
629 title);