OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/command_line.h" |
| 6 #include "chrome/app/chrome_command_ids.h" |
5 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
6 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
8 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
9 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
10 #include "content/public/browser/navigation_handle.h" | 13 #include "content/public/browser/navigation_handle.h" |
11 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "content/public/common/context_menu_params.h" |
13 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
14 #include "content/public/test/test_navigation_observer.h" | 18 #include "content/public/test/test_navigation_observer.h" |
| 19 #include "net/dns/mock_host_resolver.h" |
15 | 20 |
16 class ChromeNavigationBrowserTest : public InProcessBrowserTest { | 21 class ChromeNavigationBrowserTest : public InProcessBrowserTest { |
17 public: | 22 public: |
18 ChromeNavigationBrowserTest() {} | 23 ChromeNavigationBrowserTest() {} |
19 ~ChromeNavigationBrowserTest() override {} | 24 ~ChromeNavigationBrowserTest() override {} |
20 | 25 |
21 void SetUpCommandLine(base::CommandLine* command_line) override { | 26 void SetUpCommandLine(base::CommandLine* command_line) override { |
22 ASSERT_TRUE(embedded_test_server()->Start()); | 27 ASSERT_TRUE(embedded_test_server()->Start()); |
23 } | 28 } |
24 | 29 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 { | 124 { |
120 DidStartNavigationObserver nav_observer(new_web_contents); | 125 DidStartNavigationObserver nav_observer(new_web_contents); |
121 EXPECT_TRUE(content::ExecuteScript( | 126 EXPECT_TRUE(content::ExecuteScript( |
122 main_web_contents, "navigate('" + error_url.spec() + "');")); | 127 main_web_contents, "navigate('" + error_url.spec() + "');")); |
123 nav_observer.Wait(); | 128 nav_observer.Wait(); |
124 EXPECT_EQ(error_url, new_web_contents->GetVisibleURL()); | 129 EXPECT_EQ(error_url, new_web_contents->GetVisibleURL()); |
125 EXPECT_TRUE(new_web_contents->GetController().GetTransientEntry()); | 130 EXPECT_TRUE(new_web_contents->GetController().GetTransientEntry()); |
126 EXPECT_FALSE(new_web_contents->IsLoading()); | 131 EXPECT_FALSE(new_web_contents->IsLoading()); |
127 } | 132 } |
128 } | 133 } |
| 134 |
| 135 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { |
| 136 public: |
| 137 ChromeNavigationPortMappedBrowserTest() {} |
| 138 ~ChromeNavigationPortMappedBrowserTest() override {} |
| 139 |
| 140 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 141 ASSERT_TRUE(embedded_test_server()->Start()); |
| 142 |
| 143 // Use the command line parameter for the host resolver, so URLs without |
| 144 // explicit port numbers can be mapped under the hood to the port number |
| 145 // the |embedded_test_server| uses. It is required to test with potentially |
| 146 // malformed URLs. |
| 147 std::string port = |
| 148 base::IntToString(embedded_test_server()->host_port_pair().port()); |
| 149 command_line->AppendSwitchASCII( |
| 150 "host-resolver-rules", |
| 151 "MAP * 127.0.0.1:" + port + ", EXCLUDE 127.0.0.1*"); |
| 152 } |
| 153 |
| 154 private: |
| 155 DISALLOW_COPY_AND_ASSIGN(ChromeNavigationPortMappedBrowserTest); |
| 156 }; |
| 157 |
| 158 // Test to verify that a malformed URL set as the virtual URL of a |
| 159 // NavigationEntry will result in the navigation being dropped. |
| 160 // See https://crbug.com/657720. |
| 161 IN_PROC_BROWSER_TEST_F(ChromeNavigationPortMappedBrowserTest, |
| 162 ContextMenuNavigationToInvalidUrl) { |
| 163 GURL initial_url = embedded_test_server()->GetURL("/title1.html"); |
| 164 GURL new_tab_url( |
| 165 "www.foo.com::/server-redirect?http%3A%2F%2Fbar.com%2Ftitle2.html"); |
| 166 |
| 167 // Navigate to an initial page, to ensure we have a committed document |
| 168 // from which to perform a context menu initiated navigation. |
| 169 ui_test_utils::NavigateToURL(browser(), initial_url); |
| 170 content::WebContents* web_contents = |
| 171 browser()->tab_strip_model()->GetActiveWebContents(); |
| 172 |
| 173 // This corresponds to "Open link in new tab". |
| 174 content::ContextMenuParams params; |
| 175 params.is_editable = false; |
| 176 params.media_type = blink::WebContextMenuData::MediaTypeNone; |
| 177 params.page_url = initial_url; |
| 178 params.link_url = new_tab_url; |
| 179 |
| 180 content::WindowedNotificationObserver tab_added_observer( |
| 181 chrome::NOTIFICATION_TAB_ADDED, |
| 182 content::NotificationService::AllSources()); |
| 183 |
| 184 TestRenderViewContextMenu menu(web_contents->GetMainFrame(), params); |
| 185 menu.Init(); |
| 186 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, 0); |
| 187 |
| 188 // Wait for the new tab to be created and for loading to stop. The |
| 189 // navigation should not be allowed, therefore there should not be a last |
| 190 // committed URL in the new tab. |
| 191 tab_added_observer.Wait(); |
| 192 content::WebContents* new_web_contents = |
| 193 browser()->tab_strip_model()->GetWebContentsAt( |
| 194 browser()->tab_strip_model()->count() - 1); |
| 195 WaitForLoadStop(new_web_contents); |
| 196 |
| 197 // If the test is unsuccessful, the return value from GetLastCommittedURL |
| 198 // will be the virtual URL for the created NavigationEntry. |
| 199 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme |
| 200 // prepended and one less ":" character after the host. |
| 201 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); |
| 202 } |
OLD | NEW |