| 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" | 5 #include "base/command_line.h" |
| 6 #include "chrome/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
| 7 #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" | 8 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/public/browser/navigation_handle.h" | 13 #include "content/public/browser/navigation_handle.h" |
| 14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/render_frame_host.h" |
| 16 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "content/public/common/context_menu_params.h" | 18 #include "content/public/common/context_menu_params.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/public/test/test_navigation_observer.h" | 20 #include "content/public/test/test_navigation_observer.h" |
| 19 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 20 | 22 |
| 21 class ChromeNavigationBrowserTest : public InProcessBrowserTest { | 23 class ChromeNavigationBrowserTest : public InProcessBrowserTest { |
| 22 public: | 24 public: |
| 23 ChromeNavigationBrowserTest() {} | 25 ChromeNavigationBrowserTest() {} |
| 24 ~ChromeNavigationBrowserTest() override {} | 26 ~ChromeNavigationBrowserTest() override {} |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 DidStartNavigationObserver nav_observer(new_web_contents); | 127 DidStartNavigationObserver nav_observer(new_web_contents); |
| 126 EXPECT_TRUE(content::ExecuteScript( | 128 EXPECT_TRUE(content::ExecuteScript( |
| 127 main_web_contents, "navigate('" + error_url.spec() + "');")); | 129 main_web_contents, "navigate('" + error_url.spec() + "');")); |
| 128 nav_observer.Wait(); | 130 nav_observer.Wait(); |
| 129 EXPECT_EQ(error_url, new_web_contents->GetVisibleURL()); | 131 EXPECT_EQ(error_url, new_web_contents->GetVisibleURL()); |
| 130 EXPECT_TRUE(new_web_contents->GetController().GetTransientEntry()); | 132 EXPECT_TRUE(new_web_contents->GetController().GetTransientEntry()); |
| 131 EXPECT_FALSE(new_web_contents->IsLoading()); | 133 EXPECT_FALSE(new_web_contents->IsLoading()); |
| 132 } | 134 } |
| 133 } | 135 } |
| 134 | 136 |
| 137 // Verify that ctrl-click results open up in a new renderer process. |
| 138 // See also https://crbug.com/23815 |
| 139 IN_PROC_BROWSER_TEST_F(ChromeNavigationBrowserTest, |
| 140 CtrlClickShouldEndUpInNewProcess) { |
| 141 // Navigate to anchor_targeting_remote_frame.html. |
| 142 GURL main_url(embedded_test_server()->GetURL( |
| 143 "/frame_tree/anchor_to_same_site_location.html")); |
| 144 ui_test_utils::NavigateToURL(browser(), main_url); |
| 145 |
| 146 // Verify that there is only 1 active tab (with the right contents committed). |
| 147 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 148 content::WebContents* main_contents = |
| 149 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 150 EXPECT_EQ(main_url, main_contents->GetLastCommittedURL()); |
| 151 |
| 152 // Ctrl-click the anchor/link in the page. |
| 153 content::WebContents* new_contents = nullptr; |
| 154 { |
| 155 content::WebContentsAddedObserver new_tab_observer; |
| 156 #if defined(OS_MACOSX) |
| 157 std::string new_tab_click_script = |
| 158 "simulateClick(\"test-anchor-no-target\", { metaKey: true });"; |
| 159 #else |
| 160 std::string new_tab_click_script = |
| 161 "simulateClick(\"test-anchor-no-target\", { ctrlKey: true });"; |
| 162 #endif |
| 163 EXPECT_TRUE(ExecuteScript(main_contents, new_tab_click_script)); |
| 164 |
| 165 // Wait for a new tab to appear (the whole point of this test). |
| 166 new_contents = new_tab_observer.GetWebContents(); |
| 167 } |
| 168 |
| 169 // Verify that the new tab has the right contents and is in the right, new |
| 170 // place in the tab strip. |
| 171 EXPECT_TRUE(WaitForLoadStop(new_contents)); |
| 172 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 173 EXPECT_EQ(new_contents, browser()->tab_strip_model()->GetWebContentsAt(1)); |
| 174 GURL expected_url(embedded_test_server()->GetURL("/title1.html")); |
| 175 EXPECT_EQ(expected_url, new_contents->GetLastCommittedURL()); |
| 176 |
| 177 // Verify that the new tab is in a different process from the old contents. |
| 178 EXPECT_NE(main_contents->GetMainFrame()->GetProcess(), |
| 179 new_contents->GetMainFrame()->GetProcess()); |
| 180 |
| 181 // Verify that |new_contents| truly is in a brand new browsing instance. |
| 182 { |
| 183 // Double-check that main_contents has expected window.name set. |
| 184 // (this is a sanity check of test setup; this is not a product test). |
| 185 std::string name_of_main_contents_window; |
| 186 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 187 main_contents->GetMainFrame(), |
| 188 "window.domAutomationController.send(window.name)", |
| 189 &name_of_main_contents_window)); |
| 190 EXPECT_EQ("main_contents", name_of_main_contents_window); |
| 191 |
| 192 // Verify that the new contents doesn't have a window.opener set. |
| 193 bool window_opener_cast_to_bool; |
| 194 ASSERT_TRUE(ExecuteScriptAndExtractBool( |
| 195 new_contents->GetMainFrame(), |
| 196 "window.domAutomationController.send(!!window.opener)", |
| 197 &window_opener_cast_to_bool)); |
| 198 EXPECT_FALSE(window_opener_cast_to_bool); |
| 199 |
| 200 // Verify that the new contents cannot find the old contents via |
| 201 // window.open. |
| 202 // (i.e. window.open should open a new window, rather than returning a |
| 203 // reference to main_contents / old window). |
| 204 content::WebContentsAddedObserver window_open_observer; |
| 205 std::string location_of_opened_window; |
| 206 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 207 new_contents->GetMainFrame(), |
| 208 "w = window.open('', 'main_contents');" |
| 209 "window.domAutomationController.send(w.location.href);", |
| 210 &location_of_opened_window)); |
| 211 content::WebContents* found_contents = |
| 212 window_open_observer.GetWebContents(); |
| 213 // Expecting "false" -> expecting to be at a non-PAGE_TYPE_NORMAL page. |
| 214 EXPECT_FALSE(WaitForLoadStop(found_contents)); |
| 215 EXPECT_EQ(GURL(), found_contents->GetLastCommittedURL()); |
| 216 EXPECT_EQ("about:blank", location_of_opened_window); |
| 217 } |
| 218 } |
| 219 |
| 220 // Verify that ctrl-click results open up in a new renderer process (in case of |
| 221 // an anchor with target="_blank"). See also https://crbug.com/23815 |
| 222 IN_PROC_BROWSER_TEST_F(ChromeNavigationBrowserTest, |
| 223 CtrlClickOfTargetBlankAnchorShouldEndUpInNewProcess) { |
| 224 // Navigate to anchor_targeting_remote_frame.html. |
| 225 GURL main_url(embedded_test_server()->GetURL( |
| 226 "/frame_tree/anchor_to_same_site_location.html")); |
| 227 ui_test_utils::NavigateToURL(browser(), main_url); |
| 228 |
| 229 // Verify that there is only 1 active tab (with the right contents committed). |
| 230 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 231 content::WebContents* main_contents = |
| 232 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 233 EXPECT_EQ(main_url, main_contents->GetLastCommittedURL()); |
| 234 |
| 235 // Ctrl-click the anchor/link in the page. |
| 236 content::WebContents* new_contents = nullptr; |
| 237 { |
| 238 content::WebContentsAddedObserver new_tab_observer; |
| 239 #if defined(OS_MACOSX) |
| 240 std::string new_tab_click_script = |
| 241 "simulateClick(\"test-anchor-with-blank-target\", { metaKey: true });"; |
| 242 #else |
| 243 std::string new_tab_click_script = |
| 244 "simulateClick(\"test-anchor-with-blank-target\", { ctrlKey: true });"; |
| 245 #endif |
| 246 EXPECT_TRUE(ExecuteScript(main_contents, new_tab_click_script)); |
| 247 |
| 248 // Wait for a new tab to appear (the whole point of this test). |
| 249 new_contents = new_tab_observer.GetWebContents(); |
| 250 } |
| 251 |
| 252 // Verify that the new tab has the right contents and is in the right, new |
| 253 // place in the tab strip. |
| 254 EXPECT_TRUE(WaitForLoadStop(new_contents)); |
| 255 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 256 EXPECT_EQ(new_contents, browser()->tab_strip_model()->GetWebContentsAt(1)); |
| 257 GURL expected_url(embedded_test_server()->GetURL("/title1.html")); |
| 258 EXPECT_EQ(expected_url, new_contents->GetLastCommittedURL()); |
| 259 |
| 260 // Verify that the new tab is in a different process from the old contents. |
| 261 EXPECT_NE(main_contents->GetMainFrame()->GetProcess(), |
| 262 new_contents->GetMainFrame()->GetProcess()); |
| 263 |
| 264 // Verify that |new_contents| truly is in a brand new browsing instance. |
| 265 { |
| 266 // Double-check that main_contents has expected window.name set. |
| 267 // (this is a sanity check of test setup; this is not a product test). |
| 268 std::string name_of_main_contents_window; |
| 269 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 270 main_contents->GetMainFrame(), |
| 271 "window.domAutomationController.send(window.name)", |
| 272 &name_of_main_contents_window)); |
| 273 EXPECT_EQ("main_contents", name_of_main_contents_window); |
| 274 |
| 275 // Verify that the new contents doesn't have a window.opener set. |
| 276 bool window_opener_cast_to_bool; |
| 277 ASSERT_TRUE(ExecuteScriptAndExtractBool( |
| 278 new_contents->GetMainFrame(), |
| 279 "window.domAutomationController.send(!!window.opener)", |
| 280 &window_opener_cast_to_bool)); |
| 281 EXPECT_FALSE(window_opener_cast_to_bool); |
| 282 |
| 283 // Verify that the new contents cannot find the old contents via |
| 284 // window.open. |
| 285 // (i.e. window.open should open a new window, rather than returning a |
| 286 // reference to main_contents / old window). |
| 287 content::WebContentsAddedObserver window_open_observer; |
| 288 std::string location_of_opened_window; |
| 289 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 290 new_contents->GetMainFrame(), |
| 291 "w = window.open('', 'main_contents');" |
| 292 "window.domAutomationController.send(w.location.href);", |
| 293 &location_of_opened_window)); |
| 294 EXPECT_EQ("about:blank", location_of_opened_window); |
| 295 content::WebContents* found_contents = |
| 296 window_open_observer.GetWebContents(); |
| 297 // Expecting "false" -> expecting to be at a non-PAGE_TYPE_NORMAL page. |
| 298 EXPECT_FALSE(WaitForLoadStop(found_contents)); |
| 299 EXPECT_EQ(GURL(), found_contents->GetLastCommittedURL()); |
| 300 } |
| 301 } |
| 302 |
| 135 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { | 303 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { |
| 136 public: | 304 public: |
| 137 ChromeNavigationPortMappedBrowserTest() {} | 305 ChromeNavigationPortMappedBrowserTest() {} |
| 138 ~ChromeNavigationPortMappedBrowserTest() override {} | 306 ~ChromeNavigationPortMappedBrowserTest() override {} |
| 139 | 307 |
| 140 void SetUpCommandLine(base::CommandLine* command_line) override { | 308 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 141 ASSERT_TRUE(embedded_test_server()->Start()); | 309 ASSERT_TRUE(embedded_test_server()->Start()); |
| 142 | 310 |
| 143 // Use the command line parameter for the host resolver, so URLs without | 311 // 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 | 312 // explicit port numbers can be mapped under the hood to the port number |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 browser()->tab_strip_model()->GetWebContentsAt( | 361 browser()->tab_strip_model()->GetWebContentsAt( |
| 194 browser()->tab_strip_model()->count() - 1); | 362 browser()->tab_strip_model()->count() - 1); |
| 195 WaitForLoadStop(new_web_contents); | 363 WaitForLoadStop(new_web_contents); |
| 196 | 364 |
| 197 // If the test is unsuccessful, the return value from GetLastCommittedURL | 365 // If the test is unsuccessful, the return value from GetLastCommittedURL |
| 198 // will be the virtual URL for the created NavigationEntry. | 366 // 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 | 367 // 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. | 368 // prepended and one less ":" character after the host. |
| 201 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); | 369 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); |
| 202 } | 370 } |
| OLD | NEW |