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 open up in a new renderer process. |
| 193 // See also https://crbug.com/23815 |
| 194 IN_PROC_BROWSER_TEST_F(ChromeNavigationBrowserTest, |
| 195 CtrlClickShouldEndUpInNewProcess) { |
| 196 // Navigate to anchor_targeting_remote_frame.html. |
| 197 GURL main_url(embedded_test_server()->GetURL( |
| 198 "/frame_tree/anchor_to_same_site_location.html")); |
| 199 ui_test_utils::NavigateToURL(browser(), main_url); |
| 200 |
| 201 // Verify that there is only 1 active tab (with the right contents committed). |
| 202 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 203 content::WebContents* main_contents = |
| 204 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 205 EXPECT_EQ(main_url, main_contents->GetLastCommittedURL()); |
| 206 |
| 207 // Ctrl-click the anchor/link in the page. |
| 208 content::WebContents* new_contents = nullptr; |
| 209 { |
| 210 content::WebContentsAddedObserver new_tab_observer; |
| 211 #if defined(OS_MACOSX) |
| 212 std::string new_tab_click_script = |
| 213 "simulateClick(\"test-anchor-no-target\", { metaKey: true });"; |
| 214 #else |
| 215 std::string new_tab_click_script = |
| 216 "simulateClick(\"test-anchor-no-target\", { ctrlKey: true });"; |
| 217 #endif |
| 218 EXPECT_TRUE(ExecuteScript(main_contents, new_tab_click_script)); |
| 219 |
| 220 // Wait for a new tab to appear (the whole point of this test). |
| 221 new_contents = new_tab_observer.GetWebContents(); |
| 222 } |
| 223 |
| 224 // Verify that the new tab has the right contents and is in the right, new |
| 225 // place in the tab strip. |
| 226 EXPECT_TRUE(WaitForLoadStop(new_contents)); |
| 227 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 228 EXPECT_EQ(new_contents, browser()->tab_strip_model()->GetWebContentsAt(1)); |
| 229 GURL expected_url(embedded_test_server()->GetURL("/title1.html")); |
| 230 EXPECT_EQ(expected_url, new_contents->GetLastCommittedURL()); |
| 231 |
| 232 // Verify that the new tab is in a different process from the old contents. |
| 233 EXPECT_NE(main_contents->GetMainFrame()->GetProcess(), |
| 234 new_contents->GetMainFrame()->GetProcess()); |
| 235 |
| 236 // Verify that |new_contents| truly is in a brand new browsing instance. |
| 237 { |
| 238 // Double-check that main_contents has expected window.name set. |
| 239 // (this is a sanity check of test setup; this is not a product test). |
| 240 std::string name_of_main_contents_window; |
| 241 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 242 main_contents->GetMainFrame(), |
| 243 "window.domAutomationController.send(window.name)", |
| 244 &name_of_main_contents_window)); |
| 245 EXPECT_EQ("main_contents", name_of_main_contents_window); |
| 246 |
| 247 // Verify that the new contents doesn't have a window.opener set. |
| 248 bool window_opener_cast_to_bool; |
| 249 ASSERT_TRUE(ExecuteScriptAndExtractBool( |
| 250 new_contents->GetMainFrame(), |
| 251 "window.domAutomationController.send(!!window.opener)", |
| 252 &window_opener_cast_to_bool)); |
| 253 EXPECT_FALSE(window_opener_cast_to_bool); |
| 254 |
| 255 // Verify that the new contents cannot find the old contents via |
| 256 // window.open. |
| 257 // (i.e. window.open should open a new window, rather than returning a |
| 258 // reference to main_contents / old window). |
| 259 content::WebContentsAddedObserver window_open_observer; |
| 260 std::string location_of_opened_window; |
| 261 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 262 new_contents->GetMainFrame(), |
| 263 "w = window.open('', 'main_contents');" |
| 264 "window.domAutomationController.send(w.location.href);", |
| 265 &location_of_opened_window)); |
| 266 content::WebContents* found_contents = |
| 267 window_open_observer.GetWebContents(); |
| 268 // Expecting "false" -> expecting to be at a non-PAGE_TYPE_NORMAL page. |
| 269 EXPECT_FALSE(WaitForLoadStop(found_contents)); |
| 270 EXPECT_EQ(GURL(), found_contents->GetLastCommittedURL()); |
| 271 EXPECT_EQ("about:blank", location_of_opened_window); |
| 272 } |
| 273 } |
| 274 |
192 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { | 275 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { |
193 public: | 276 public: |
194 ChromeNavigationPortMappedBrowserTest() {} | 277 ChromeNavigationPortMappedBrowserTest() {} |
195 ~ChromeNavigationPortMappedBrowserTest() override {} | 278 ~ChromeNavigationPortMappedBrowserTest() override {} |
196 | 279 |
197 void SetUpCommandLine(base::CommandLine* command_line) override { | 280 void SetUpCommandLine(base::CommandLine* command_line) override { |
198 ASSERT_TRUE(embedded_test_server()->Start()); | 281 ASSERT_TRUE(embedded_test_server()->Start()); |
199 | 282 |
200 // Use the command line parameter for the host resolver, so URLs without | 283 // 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 | 284 // 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( | 333 browser()->tab_strip_model()->GetWebContentsAt( |
251 browser()->tab_strip_model()->count() - 1); | 334 browser()->tab_strip_model()->count() - 1); |
252 WaitForLoadStop(new_web_contents); | 335 WaitForLoadStop(new_web_contents); |
253 | 336 |
254 // If the test is unsuccessful, the return value from GetLastCommittedURL | 337 // If the test is unsuccessful, the return value from GetLastCommittedURL |
255 // will be the virtual URL for the created NavigationEntry. | 338 // 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 | 339 // 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. | 340 // prepended and one less ":" character after the host. |
258 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); | 341 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); |
259 } | 342 } |
OLD | NEW |