Chromium Code Reviews| 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/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 browser()->tab_strip_model()->GetWebContentsAt(1); | 182 browser()->tab_strip_model()->GetWebContentsAt(1); |
| 183 ASSERT_NE(new_web_contents, web_contents); | 183 ASSERT_NE(new_web_contents, web_contents); |
| 184 WaitForLoadStop(new_web_contents); | 184 WaitForLoadStop(new_web_contents); |
| 185 | 185 |
| 186 GURL view_frame_source_url(content::kViewSourceScheme + std::string(":") + | 186 GURL view_frame_source_url(content::kViewSourceScheme + std::string(":") + |
| 187 iframe_target_url.spec()); | 187 iframe_target_url.spec()); |
| 188 EXPECT_EQ(url_formatter::FormatUrl(view_frame_source_url), | 188 EXPECT_EQ(url_formatter::FormatUrl(view_frame_source_url), |
| 189 new_web_contents->GetTitle()); | 189 new_web_contents->GetTitle()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Verify that ctrl-click results 1) open up in a new renderer process | |
| 193 // https://crbug.com/23815) and 2) are in a new browsing instance (e.g. | |
| 194 // cannot find the opener's window by name - https://crbug.com/658386). | |
| 195 IN_PROC_BROWSER_TEST_F(ChromeNavigationBrowserTest, | |
| 196 CtrlClickShouldEndUpInNewProcess) { | |
| 197 // Navigate to anchor_targeting_remote_frame.html. | |
| 198 GURL main_url(embedded_test_server()->GetURL( | |
| 199 "/frame_tree/anchor_to_same_site_location.html")); | |
| 200 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 201 | |
| 202 // Verify that there is only 1 active tab (with the right contents committed). | |
| 203 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | |
| 204 content::WebContents* main_contents = | |
| 205 browser()->tab_strip_model()->GetWebContentsAt(0); | |
| 206 EXPECT_EQ(main_url, main_contents->GetLastCommittedURL()); | |
| 207 | |
| 208 // Ctrl-click the anchor/link in the page. | |
| 209 content::WebContents* new_contents = nullptr; | |
| 210 { | |
| 211 content::WebContentsAddedObserver new_tab_observer; | |
| 212 #if defined(OS_MACOSX) | |
| 213 std::string new_tab_click_script = | |
| 214 "simulateClick(\"test-anchor-no-target\", { metaKey: true });"; | |
| 215 #else | |
| 216 std::string new_tab_click_script = | |
| 217 "simulateClick(\"test-anchor-no-target\", { ctrlKey: true });"; | |
| 218 #endif | |
| 219 EXPECT_TRUE(ExecuteScript(main_contents, new_tab_click_script)); | |
| 220 | |
| 221 // Wait for a new tab to appear (the whole point of this test). | |
| 222 new_contents = new_tab_observer.GetWebContents(); | |
| 223 } | |
| 224 | |
| 225 // Verify that the new tab has the right contents and is in the right, new | |
| 226 // place in the tab strip. | |
| 227 EXPECT_TRUE(WaitForLoadStop(new_contents)); | |
| 228 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | |
| 229 EXPECT_EQ(new_contents, browser()->tab_strip_model()->GetWebContentsAt(1)); | |
| 230 GURL expected_url(embedded_test_server()->GetURL("/title1.html")); | |
| 231 EXPECT_EQ(expected_url, new_contents->GetLastCommittedURL()); | |
| 232 | |
| 233 // Verify that the new tab is in a different process from the old contents. | |
| 234 EXPECT_NE(main_contents->GetMainFrame()->GetProcess(), | |
| 235 new_contents->GetMainFrame()->GetProcess()); | |
|
alexmos
2017/02/09 22:58:36
Might be good to compare their SiteInstances as we
Łukasz Anforowicz
2017/02/10 00:38:18
Done.
| |
| 236 | |
| 237 // Verify that |new_contents| truly is in a brand new browsing instance. | |
| 238 { | |
| 239 // Double-check that main_contents has expected window.name set. | |
| 240 // (this is a sanity check of test setup; this is not a product test). | |
| 241 std::string name_of_main_contents_window; | |
| 242 ASSERT_TRUE(ExecuteScriptAndExtractString( | |
| 243 main_contents->GetMainFrame(), | |
| 244 "window.domAutomationController.send(window.name)", | |
| 245 &name_of_main_contents_window)); | |
| 246 EXPECT_EQ("main_contents", name_of_main_contents_window); | |
| 247 | |
| 248 // Verify that the new contents doesn't have a window.opener set. | |
| 249 bool window_opener_cast_to_bool; | |
| 250 ASSERT_TRUE(ExecuteScriptAndExtractBool( | |
| 251 new_contents->GetMainFrame(), | |
| 252 "window.domAutomationController.send(!!window.opener)", | |
| 253 &window_opener_cast_to_bool)); | |
| 254 EXPECT_FALSE(window_opener_cast_to_bool); | |
| 255 | |
| 256 // Verify that the new contents cannot find the old contents via | |
| 257 // window.open. | |
| 258 // (i.e. window.open should open a new window, rather than returning a | |
| 259 // reference to main_contents / old window). | |
| 260 content::WebContentsAddedObserver window_open_observer; | |
| 261 std::string location_of_opened_window; | |
| 262 ASSERT_TRUE(ExecuteScriptAndExtractString( | |
| 263 new_contents->GetMainFrame(), | |
| 264 "w = window.open('', 'main_contents');" | |
| 265 "window.domAutomationController.send(w.location.href);", | |
| 266 &location_of_opened_window)); | |
| 267 content::WebContents* found_contents = | |
| 268 window_open_observer.GetWebContents(); | |
| 269 // Expecting "false" -> expecting to be at a non-PAGE_TYPE_NORMAL page. | |
| 270 EXPECT_FALSE(WaitForLoadStop(found_contents)); | |
| 271 EXPECT_EQ(GURL(), found_contents->GetLastCommittedURL()); | |
| 272 EXPECT_EQ("about:blank", location_of_opened_window); | |
| 273 } | |
| 274 } | |
| 275 | |
| 192 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { | 276 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { |
| 193 public: | 277 public: |
| 194 ChromeNavigationPortMappedBrowserTest() {} | 278 ChromeNavigationPortMappedBrowserTest() {} |
| 195 ~ChromeNavigationPortMappedBrowserTest() override {} | 279 ~ChromeNavigationPortMappedBrowserTest() override {} |
| 196 | 280 |
| 197 void SetUpCommandLine(base::CommandLine* command_line) override { | 281 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 198 ASSERT_TRUE(embedded_test_server()->Start()); | 282 ASSERT_TRUE(embedded_test_server()->Start()); |
| 199 | 283 |
| 200 // Use the command line parameter for the host resolver, so URLs without | 284 // Use the command line parameter for the host resolver, so URLs without |
| 201 // explicit port numbers can be mapped under the hood to the port number | 285 // 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... | |
| 250 browser()->tab_strip_model()->GetWebContentsAt( | 334 browser()->tab_strip_model()->GetWebContentsAt( |
| 251 browser()->tab_strip_model()->count() - 1); | 335 browser()->tab_strip_model()->count() - 1); |
| 252 WaitForLoadStop(new_web_contents); | 336 WaitForLoadStop(new_web_contents); |
| 253 | 337 |
| 254 // If the test is unsuccessful, the return value from GetLastCommittedURL | 338 // If the test is unsuccessful, the return value from GetLastCommittedURL |
| 255 // will be the virtual URL for the created NavigationEntry. | 339 // will be the virtual URL for the created NavigationEntry. |
| 256 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme | 340 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme |
| 257 // prepended and one less ":" character after the host. | 341 // prepended and one less ":" character after the host. |
| 258 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); | 342 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); |
| 259 } | 343 } |
| OLD | NEW |