Introduce ProfilerMetricsProvider
[chromium-blink-merge.git] / chrome / browser / referrer_policy_browsertest.cc
blobab6a221bcbf6267f3f102089521b9ae45bdaee3e
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/renderer_context_menu/render_view_context_menu.h"
12 #include "chrome/browser/renderer_context_menu/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::TitleWatcher title_watcher2(tab, expected_title);
211 // Watch for all possible outcomes to avoid timeouts if something breaks.
212 AddAllPossibleTitles(start_url, &title_watcher2);
214 EXPECT_EQ(expected_title, title_watcher2.WaitAndGetTitle());
217 EXPECT_EQ(referrer_policy,
218 tab->GetController().GetActiveEntry()->GetReferrer().policy);
220 return start_url;
223 scoped_ptr<net::SpawnedTestServer> test_server_;
224 scoped_ptr<net::SpawnedTestServer> ssl_test_server_;
227 // The basic behavior of referrer policies is covered by layout tests in
228 // http/tests/security/referrer-policy-*. These tests cover (hopefully) all
229 // code paths chrome uses to navigate. To keep the number of combinations down,
230 // we only test the "origin" policy here.
232 // Some tests are marked as FAILS, see http://crbug.com/124750
234 // Content initiated navigation, from HTTP to HTTP.
235 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, Origin) {
236 RunReferrerTest(blink::WebReferrerPolicyOrigin,
237 START_ON_HTTP,
238 REGULAR_LINK,
239 NO_REDIRECT,
240 CURRENT_TAB,
241 blink::WebMouseEvent::ButtonNone,
242 EXPECT_ORIGIN_AS_REFERRER);
245 // Content initiated navigation, from HTTPS to HTTP.
246 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsDefault) {
247 RunReferrerTest(blink::WebReferrerPolicyOrigin,
248 START_ON_HTTPS,
249 REGULAR_LINK,
250 NO_REDIRECT,
251 CURRENT_TAB,
252 blink::WebMouseEvent::ButtonNone,
253 EXPECT_ORIGIN_AS_REFERRER);
256 // User initiated navigation, from HTTP to HTTP.
257 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, LeftClickOrigin) {
258 RunReferrerTest(blink::WebReferrerPolicyOrigin,
259 START_ON_HTTP,
260 REGULAR_LINK,
261 NO_REDIRECT,
262 CURRENT_TAB,
263 blink::WebMouseEvent::ButtonLeft,
264 EXPECT_ORIGIN_AS_REFERRER);
267 // User initiated navigation, from HTTPS to HTTP.
268 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsLeftClickOrigin) {
269 RunReferrerTest(blink::WebReferrerPolicyOrigin,
270 START_ON_HTTPS,
271 REGULAR_LINK,
272 NO_REDIRECT,
273 CURRENT_TAB,
274 blink::WebMouseEvent::ButtonLeft,
275 EXPECT_ORIGIN_AS_REFERRER);
278 // User initiated navigation, middle click, from HTTP to HTTP.
279 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MiddleClickOrigin) {
280 RunReferrerTest(blink::WebReferrerPolicyOrigin,
281 START_ON_HTTP,
282 REGULAR_LINK,
283 NO_REDIRECT,
284 NEW_BACKGROUND_TAB,
285 blink::WebMouseEvent::ButtonMiddle,
286 EXPECT_ORIGIN_AS_REFERRER);
289 // User initiated navigation, middle click, from HTTPS to HTTP.
290 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsMiddleClickOrigin) {
291 RunReferrerTest(blink::WebReferrerPolicyOrigin,
292 START_ON_HTTPS,
293 REGULAR_LINK,
294 NO_REDIRECT,
295 NEW_BACKGROUND_TAB,
296 blink::WebMouseEvent::ButtonMiddle,
297 EXPECT_ORIGIN_AS_REFERRER);
300 // User initiated navigation, target blank, from HTTP to HTTP.
301 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, TargetBlankOrigin) {
302 RunReferrerTest(blink::WebReferrerPolicyOrigin,
303 START_ON_HTTP,
304 LINk_WITH_TARGET_BLANK,
305 NO_REDIRECT,
306 NEW_FOREGROUND_TAB,
307 blink::WebMouseEvent::ButtonLeft,
308 EXPECT_ORIGIN_AS_REFERRER);
311 // User initiated navigation, target blank, from HTTPS to HTTP.
312 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsTargetBlankOrigin) {
313 RunReferrerTest(blink::WebReferrerPolicyOrigin,
314 START_ON_HTTPS,
315 LINk_WITH_TARGET_BLANK,
316 NO_REDIRECT,
317 NEW_FOREGROUND_TAB,
318 blink::WebMouseEvent::ButtonLeft,
319 EXPECT_ORIGIN_AS_REFERRER);
322 // User initiated navigation, middle click, target blank, from HTTP to HTTP.
323 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MiddleClickTargetBlankOrigin) {
324 RunReferrerTest(blink::WebReferrerPolicyOrigin,
325 START_ON_HTTP,
326 LINk_WITH_TARGET_BLANK,
327 NO_REDIRECT,
328 NEW_FOREGROUND_TAB,
329 blink::WebMouseEvent::ButtonMiddle,
330 EXPECT_ORIGIN_AS_REFERRER);
333 // User initiated navigation, middle click, target blank, from HTTPS to HTTP.
334 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsMiddleClickTargetBlankOrigin) {
335 RunReferrerTest(blink::WebReferrerPolicyOrigin,
336 START_ON_HTTPS,
337 LINk_WITH_TARGET_BLANK,
338 NO_REDIRECT,
339 NEW_FOREGROUND_TAB,
340 blink::WebMouseEvent::ButtonMiddle,
341 EXPECT_ORIGIN_AS_REFERRER);
344 // Context menu, from HTTP to HTTP.
345 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_ContextMenuOrigin) {
346 ContextMenuNotificationObserver context_menu_observer(
347 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
348 RunReferrerTest(blink::WebReferrerPolicyOrigin,
349 START_ON_HTTP,
350 REGULAR_LINK,
351 NO_REDIRECT,
352 NEW_FOREGROUND_TAB,
353 blink::WebMouseEvent::ButtonRight,
354 EXPECT_ORIGIN_AS_REFERRER);
357 // Context menu, from HTTPS to HTTP.
358 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_HttpsContextMenuOrigin) {
359 ContextMenuNotificationObserver context_menu_observer(
360 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
361 RunReferrerTest(blink::WebReferrerPolicyOrigin,
362 START_ON_HTTPS,
363 REGULAR_LINK,
364 NO_REDIRECT,
365 NEW_FOREGROUND_TAB,
366 blink::WebMouseEvent::ButtonRight,
367 EXPECT_ORIGIN_AS_REFERRER);
370 // Content initiated navigation, from HTTP to HTTP via server redirect.
371 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, Redirect) {
372 RunReferrerTest(blink::WebReferrerPolicyOrigin,
373 START_ON_HTTP,
374 REGULAR_LINK,
375 SERVER_REDIRECT,
376 CURRENT_TAB,
377 blink::WebMouseEvent::ButtonNone,
378 EXPECT_ORIGIN_AS_REFERRER);
381 // Content initiated navigation, from HTTPS to HTTP via server redirect.
382 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsRedirect) {
383 RunReferrerTest(blink::WebReferrerPolicyOrigin,
384 START_ON_HTTPS,
385 REGULAR_LINK,
386 SERVER_REDIRECT,
387 CURRENT_TAB,
388 blink::WebMouseEvent::ButtonNone,
389 EXPECT_ORIGIN_AS_REFERRER);
392 // User initiated navigation, from HTTP to HTTP via server redirect.
393 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, LeftClickRedirect) {
394 RunReferrerTest(blink::WebReferrerPolicyOrigin,
395 START_ON_HTTP,
396 REGULAR_LINK,
397 SERVER_REDIRECT,
398 CURRENT_TAB,
399 blink::WebMouseEvent::ButtonLeft,
400 EXPECT_ORIGIN_AS_REFERRER);
403 // User initiated navigation, from HTTPS to HTTP via server redirect.
404 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsLeftClickRedirect) {
405 RunReferrerTest(blink::WebReferrerPolicyOrigin,
406 START_ON_HTTPS,
407 REGULAR_LINK,
408 SERVER_REDIRECT,
409 CURRENT_TAB,
410 blink::WebMouseEvent::ButtonLeft,
411 EXPECT_ORIGIN_AS_REFERRER);
414 // User initiated navigation, middle click, from HTTP to HTTP via server
415 // redirect.
416 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MiddleClickRedirect) {
417 RunReferrerTest(blink::WebReferrerPolicyOrigin,
418 START_ON_HTTP,
419 REGULAR_LINK,
420 SERVER_REDIRECT,
421 NEW_BACKGROUND_TAB,
422 blink::WebMouseEvent::ButtonMiddle,
423 EXPECT_ORIGIN_AS_REFERRER);
426 // User initiated navigation, middle click, from HTTPS to HTTP via server
427 // redirect.
428 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsMiddleClickRedirect) {
429 RunReferrerTest(blink::WebReferrerPolicyOrigin,
430 START_ON_HTTPS,
431 REGULAR_LINK,
432 SERVER_REDIRECT,
433 NEW_BACKGROUND_TAB,
434 blink::WebMouseEvent::ButtonMiddle,
435 EXPECT_ORIGIN_AS_REFERRER);
438 // User initiated navigation, target blank, from HTTP to HTTP via server
439 // redirect.
440 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, TargetBlankRedirect) {
441 RunReferrerTest(blink::WebReferrerPolicyOrigin,
442 START_ON_HTTP,
443 LINk_WITH_TARGET_BLANK,
444 SERVER_REDIRECT,
445 NEW_FOREGROUND_TAB,
446 blink::WebMouseEvent::ButtonLeft,
447 EXPECT_ORIGIN_AS_REFERRER);
450 // User initiated navigation, target blank, from HTTPS to HTTP via server
451 // redirect.
452 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsTargetBlankRedirect) {
453 RunReferrerTest(blink::WebReferrerPolicyOrigin,
454 START_ON_HTTPS,
455 LINk_WITH_TARGET_BLANK,
456 SERVER_REDIRECT,
457 NEW_FOREGROUND_TAB,
458 blink::WebMouseEvent::ButtonLeft,
459 EXPECT_ORIGIN_AS_REFERRER);
462 // User initiated navigation, middle click, target blank, from HTTP to HTTP via
463 // server redirect.
464 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MiddleClickTargetBlankRedirect) {
465 RunReferrerTest(blink::WebReferrerPolicyOrigin,
466 START_ON_HTTP,
467 LINk_WITH_TARGET_BLANK,
468 SERVER_REDIRECT,
469 NEW_FOREGROUND_TAB,
470 blink::WebMouseEvent::ButtonMiddle,
471 EXPECT_ORIGIN_AS_REFERRER);
474 // User initiated navigation, middle click, target blank, from HTTPS to HTTP
475 // via server redirect.
476 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest,
477 HttpsMiddleClickTargetBlankRedirect) {
478 RunReferrerTest(blink::WebReferrerPolicyOrigin,
479 START_ON_HTTPS,
480 LINk_WITH_TARGET_BLANK,
481 SERVER_REDIRECT,
482 NEW_FOREGROUND_TAB,
483 blink::WebMouseEvent::ButtonMiddle,
484 EXPECT_ORIGIN_AS_REFERRER);
487 // Context menu, from HTTP to HTTP via server redirect.
488 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_ContextMenuRedirect) {
489 ContextMenuNotificationObserver context_menu_observer(
490 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
491 RunReferrerTest(blink::WebReferrerPolicyOrigin,
492 START_ON_HTTP,
493 REGULAR_LINK,
494 SERVER_REDIRECT,
495 NEW_FOREGROUND_TAB,
496 blink::WebMouseEvent::ButtonRight,
497 EXPECT_ORIGIN_AS_REFERRER);
500 // Context menu, from HTTPS to HTTP via server redirect.
501 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_HttpsContextMenuRedirect) {
502 ContextMenuNotificationObserver context_menu_observer(
503 IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
504 RunReferrerTest(blink::WebReferrerPolicyOrigin,
505 START_ON_HTTPS,
506 REGULAR_LINK,
507 SERVER_REDIRECT,
508 NEW_FOREGROUND_TAB,
509 blink::WebMouseEvent::ButtonRight,
510 EXPECT_ORIGIN_AS_REFERRER);
513 // Tests history navigation actions: Navigate from A to B with a referrer
514 // policy, then navigate to C, back to B, and reload.
515 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, History) {
516 // Navigate from A to B.
517 GURL start_url = RunReferrerTest(blink::WebReferrerPolicyOrigin,
518 START_ON_HTTPS,
519 REGULAR_LINK,
520 SERVER_REDIRECT,
521 CURRENT_TAB,
522 blink::WebMouseEvent::ButtonLeft,
523 EXPECT_ORIGIN_AS_REFERRER);
525 // Navigate to C.
526 ui_test_utils::NavigateToURL(browser(), test_server_->GetURL(std::string()));
528 base::string16 expected_title =
529 GetExpectedTitle(start_url, EXPECT_ORIGIN_AS_REFERRER);
530 content::WebContents* tab =
531 browser()->tab_strip_model()->GetActiveWebContents();
532 scoped_ptr<content::TitleWatcher> title_watcher(
533 new content::TitleWatcher(tab, expected_title));
535 // Watch for all possible outcomes to avoid timeouts if something breaks.
536 AddAllPossibleTitles(start_url, title_watcher.get());
538 // Go back to B.
539 chrome::GoBack(browser(), CURRENT_TAB);
540 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
542 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
543 AddAllPossibleTitles(start_url, title_watcher.get());
545 // Reload to B.
546 chrome::Reload(browser(), CURRENT_TAB);
547 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
549 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
550 AddAllPossibleTitles(start_url, title_watcher.get());
552 // Shift-reload to B.
553 chrome::ReloadIgnoringCache(browser(), CURRENT_TAB);
554 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
557 // Tests that reloading a site for "request tablet version" correctly clears
558 // the referrer.
559 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, RequestTabletSite) {
560 GURL start_url = RunReferrerTest(blink::WebReferrerPolicyOrigin,
561 START_ON_HTTPS,
562 REGULAR_LINK,
563 SERVER_REDIRECT_ON_HTTP,
564 CURRENT_TAB,
565 blink::WebMouseEvent::ButtonLeft,
566 EXPECT_ORIGIN_AS_REFERRER);
568 base::string16 expected_title =
569 GetExpectedTitle(start_url, EXPECT_EMPTY_REFERRER);
570 content::WebContents* tab =
571 browser()->tab_strip_model()->GetActiveWebContents();
572 content::TitleWatcher title_watcher(tab, expected_title);
574 // Watch for all possible outcomes to avoid timeouts if something breaks.
575 AddAllPossibleTitles(start_url, &title_watcher);
577 // Request tablet version.
578 chrome::ToggleRequestTabletSite(browser());
579 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
582 // Test that an iframes gets the parent frames referrer and referrer policy if
583 // the load was triggered by the parent, or from the iframe itself, if the
584 // navigations was started by the iframe.
585 IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, IFrame) {
586 browser()->profile()->GetPrefs()->SetBoolean(
587 prefs::kWebKitAllowRunningInsecureContent, true);
588 content::WebContents* tab =
589 browser()->tab_strip_model()->GetActiveWebContents();
590 base::string16 expected_title(base::ASCIIToUTF16("loaded"));
591 scoped_ptr<content::TitleWatcher> title_watcher(
592 new content::TitleWatcher(tab, expected_title));
594 // Load a page that loads an iframe.
595 ui_test_utils::NavigateToURL(
596 browser(),
597 ssl_test_server_->GetURL(
598 std::string("files/referrer-policy-iframe.html?") +
599 base::IntToString(test_server_->host_port_pair().port())));
600 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
602 // Verify that the referrer policy was honored and the main page's origin was
603 // send as referrer.
604 content::RenderFrameHost* frame = content::FrameMatchingPredicate(
605 tab, base::Bind(&content::FrameIsChildOfMainFrame));
606 std::string title;
607 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
608 frame,
609 "window.domAutomationController.send(document.title)",
610 &title));
611 EXPECT_EQ("Referrer is " + ssl_test_server_->GetURL(std::string()).spec(),
612 title);
614 // Reload the iframe.
615 expected_title = base::ASCIIToUTF16("reset");
616 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
617 EXPECT_TRUE(content::ExecuteScript(tab, "document.title = 'reset'"));
618 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
620 expected_title = base::ASCIIToUTF16("loaded");
621 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
622 EXPECT_TRUE(content::ExecuteScript(frame, "location.reload()"));
623 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
625 // Verify that the full url of the iframe was used as referrer.
626 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
627 frame,
628 "window.domAutomationController.send(document.title)",
629 &title));
630 EXPECT_EQ("Referrer is " +
631 test_server_->GetURL("files/referrer-policy-log.html").spec(),
632 title);