OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/prefs/pref_service.h" |
6 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 11 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
11 #include "chrome/browser/tab_contents/render_view_context_menu_browsertest_util.
h" | 12 #include "chrome/browser/tab_contents/render_view_context_menu_browsertest_util.
h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_commands.h" | 14 #include "chrome/browser/ui/browser_commands.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
23 #include "net/test/spawned_test_server/spawned_test_server.h" | 25 #include "net/test/spawned_test_server/spawned_test_server.h" |
24 #include "third_party/WebKit/public/web/WebInputEvent.h" | 26 #include "third_party/WebKit/public/web/WebInputEvent.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 default: | 117 default: |
116 NOTREACHED(); | 118 NOTREACHED(); |
117 return ""; | 119 return ""; |
118 } | 120 } |
119 } | 121 } |
120 | 122 |
121 enum StartOnProtocol { START_ON_HTTP, START_ON_HTTPS, }; | 123 enum StartOnProtocol { START_ON_HTTP, START_ON_HTTPS, }; |
122 | 124 |
123 enum LinkType { REGULAR_LINK, LINk_WITH_TARGET_BLANK, }; | 125 enum LinkType { REGULAR_LINK, LINk_WITH_TARGET_BLANK, }; |
124 | 126 |
125 enum RedirectType { NO_REDIRECT, SERVER_REDIRECT, }; | 127 enum RedirectType { NO_REDIRECT, SERVER_REDIRECT, SERVER_REDIRECT_ON_HTTP, }; |
| 128 |
| 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"; |
| 137 } |
| 138 NOTREACHED(); |
| 139 return ""; |
| 140 } |
126 | 141 |
127 // Navigates from a page with a given |referrer_policy| and checks that the | 142 // Navigates from a page with a given |referrer_policy| and checks that the |
128 // reported referrer matches the expectation. | 143 // reported referrer matches the expectation. |
129 // Parameters: | 144 // Parameters: |
130 // referrer_policy: The referrer policy to test. | 145 // referrer_policy: The referrer policy to test. |
131 // start_protocol: The protocol the test should start on. | 146 // start_protocol: The protocol the test should start on. |
132 // link_type: The link type that is used to trigger the navigation. | 147 // link_type: The link type that is used to trigger the navigation. |
133 // redirect: Whether the link target should redirect and how. | 148 // redirect: Whether the link target should redirect and how. |
134 // disposition: The disposition for the navigation. | 149 // disposition: The disposition for the navigation. |
135 // button: If not WebMouseEvent::ButtonNone, click on the | 150 // button: If not WebMouseEvent::ButtonNone, click on the |
(...skipping 12 matching lines...) Expand all Loading... |
148 GURL start_url; | 163 GURL start_url; |
149 net::SpawnedTestServer* start_server = start_protocol == START_ON_HTTPS | 164 net::SpawnedTestServer* start_server = start_protocol == START_ON_HTTPS |
150 ? ssl_test_server_.get() | 165 ? ssl_test_server_.get() |
151 : test_server_.get(); | 166 : test_server_.get(); |
152 start_url = start_server->GetURL( | 167 start_url = start_server->GetURL( |
153 std::string("files/referrer-policy-start.html?") + "policy=" + | 168 std::string("files/referrer-policy-start.html?") + "policy=" + |
154 ReferrerPolicyToString(referrer_policy) + "&port=" + | 169 ReferrerPolicyToString(referrer_policy) + "&port=" + |
155 base::IntToString(test_server_->host_port_pair().port()) + | 170 base::IntToString(test_server_->host_port_pair().port()) + |
156 "&ssl_port=" + | 171 "&ssl_port=" + |
157 base::IntToString(ssl_test_server_->host_port_pair().port()) + | 172 base::IntToString(ssl_test_server_->host_port_pair().port()) + |
158 "&redirect=" + (redirect == NO_REDIRECT ? "false" : "true") + "&link=" + | 173 "&redirect=" + RedirectTypeToString(redirect) + "&link=" + |
159 (button == blink::WebMouseEvent::ButtonNone ? "false" : "true") + | 174 (button == blink::WebMouseEvent::ButtonNone ? "false" : "true") + |
160 "&target=" + (link_type == LINk_WITH_TARGET_BLANK ? "_blank" : "")); | 175 "&target=" + (link_type == LINk_WITH_TARGET_BLANK ? "_blank" : "")); |
161 | 176 |
162 ui_test_utils::WindowedTabAddedNotificationObserver tab_added_observer( | 177 ui_test_utils::WindowedTabAddedNotificationObserver tab_added_observer( |
163 content::NotificationService::AllSources()); | 178 content::NotificationService::AllSources()); |
164 | 179 |
165 base::string16 expected_title = | 180 base::string16 expected_title = |
166 GetExpectedTitle(start_url, expected_referrer); | 181 GetExpectedTitle(start_url, expected_referrer); |
167 content::WebContents* tab = | 182 content::WebContents* tab = |
168 browser()->tab_strip_model()->GetActiveWebContents(); | 183 browser()->tab_strip_model()->GetActiveWebContents(); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 chrome::Reload(browser(), CURRENT_TAB); | 542 chrome::Reload(browser(), CURRENT_TAB); |
528 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); | 543 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); |
529 | 544 |
530 title_watcher.reset(new content::TitleWatcher(tab, expected_title)); | 545 title_watcher.reset(new content::TitleWatcher(tab, expected_title)); |
531 AddAllPossibleTitles(start_url, title_watcher.get()); | 546 AddAllPossibleTitles(start_url, title_watcher.get()); |
532 | 547 |
533 // Shift-reload to B. | 548 // Shift-reload to B. |
534 chrome::ReloadIgnoringCache(browser(), CURRENT_TAB); | 549 chrome::ReloadIgnoringCache(browser(), CURRENT_TAB); |
535 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); | 550 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); |
536 } | 551 } |
| 552 |
| 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); |
| 563 |
| 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); |
| 569 |
| 570 // Watch for all possible outcomes to avoid timeouts if something breaks. |
| 571 AddAllPossibleTitles(start_url, &title_watcher); |
| 572 |
| 573 // Request tablet version. |
| 574 chrome::ToggleRequestTabletSite(browser()); |
| 575 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 576 } |
| 577 |
| 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)); |
| 589 |
| 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()); |
| 597 |
| 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); |
| 608 |
| 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()); |
| 614 |
| 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()); |
| 620 |
| 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); |
| 630 } |
OLD | NEW |