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 the test page. | |
| 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 and SiteInstance from the | |
|
Charlie Reis
2017/04/14 22:28:33
nit: different process, SiteInstance, and Browsing
Łukasz Anforowicz
2017/04/18 16:50:22
Done.
| |
| 234 // old contents. | |
| 235 EXPECT_NE(main_contents->GetMainFrame()->GetProcess(), | |
| 236 new_contents->GetMainFrame()->GetProcess()); | |
| 237 EXPECT_NE(main_contents->GetMainFrame()->GetSiteInstance(), | |
| 238 new_contents->GetMainFrame()->GetSiteInstance()); | |
| 239 EXPECT_FALSE(main_contents->GetSiteInstance()->IsRelatedSiteInstance( | |
| 240 new_contents->GetSiteInstance())); | |
| 241 | |
| 242 // Verify that |new_contents| truly is in a brand new browsing instance. | |
|
Charlie Reis
2017/04/14 22:28:33
Let's say: Verify that the new BrowsingInstance ca
| |
| 243 { | |
| 244 // Double-check that main_contents has expected window.name set. | |
| 245 // (this is a sanity check of test setup; this is not a product test). | |
|
Charlie Reis
2017/04/14 22:28:33
nit: Capitalize first "this", remove extra space a
Łukasz Anforowicz
2017/04/18 16:50:22
Done.
| |
| 246 std::string name_of_main_contents_window; | |
| 247 ASSERT_TRUE(ExecuteScriptAndExtractString( | |
| 248 main_contents, "window.domAutomationController.send(window.name)", | |
| 249 &name_of_main_contents_window)); | |
| 250 EXPECT_EQ("main_contents", name_of_main_contents_window); | |
| 251 | |
| 252 // Verify that the new contents doesn't have a window.opener set. | |
| 253 bool window_opener_cast_to_bool; | |
| 254 ASSERT_TRUE(ExecuteScriptAndExtractBool( | |
| 255 new_contents, "window.domAutomationController.send(!!window.opener)", | |
| 256 &window_opener_cast_to_bool)); | |
| 257 EXPECT_FALSE(window_opener_cast_to_bool); | |
| 258 | |
| 259 // Verify that the new contents cannot find the old contents via | |
| 260 // window.open. (i.e. window.open should open a new window, rather than | |
| 261 // returning a reference to main_contents / old window). | |
| 262 content::WebContentsAddedObserver window_open_observer; | |
| 263 std::string location_of_opened_window; | |
| 264 ASSERT_TRUE(ExecuteScriptAndExtractString( | |
| 265 new_contents, | |
| 266 "w = window.open('about:blank', 'main_contents');" | |
|
Charlie Reis
2017/04/14 22:28:33
This looks wrong to me-- my manual testing shows t
Łukasz Anforowicz
2017/04/18 16:50:22
Argh... you're right - I should be using an empty
alexmos
2017/04/18 17:26:27
I'm a bit confused here. :) Isn't the point of th
Charlie Reis
2017/04/19 20:11:10
Right-- I'm happy with the new approach. Alex is
| |
| 267 "window.domAutomationController.send(w.location.href);", | |
| 268 &location_of_opened_window)); | |
| 269 content::WebContents* found_contents = | |
| 270 window_open_observer.GetWebContents(); | |
| 271 EXPECT_TRUE(WaitForLoadStop(found_contents)); | |
| 272 EXPECT_TRUE(found_contents->GetLastCommittedURL().IsAboutBlank()); | |
| 273 EXPECT_EQ(url::kAboutBlankURL, location_of_opened_window); | |
| 274 } | |
| 275 } | |
| 276 | |
| 192 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { | 277 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { |
| 193 public: | 278 public: |
| 194 ChromeNavigationPortMappedBrowserTest() {} | 279 ChromeNavigationPortMappedBrowserTest() {} |
| 195 ~ChromeNavigationPortMappedBrowserTest() override {} | 280 ~ChromeNavigationPortMappedBrowserTest() override {} |
| 196 | 281 |
| 197 void SetUpCommandLine(base::CommandLine* command_line) override { | 282 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 198 ASSERT_TRUE(embedded_test_server()->Start()); | 283 ASSERT_TRUE(embedded_test_server()->Start()); |
| 199 | 284 |
| 200 // Use the command line parameter for the host resolver, so URLs without | 285 // 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 | 286 // 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( | 335 browser()->tab_strip_model()->GetWebContentsAt( |
| 251 browser()->tab_strip_model()->count() - 1); | 336 browser()->tab_strip_model()->count() - 1); |
| 252 WaitForLoadStop(new_web_contents); | 337 WaitForLoadStop(new_web_contents); |
| 253 | 338 |
| 254 // If the test is unsuccessful, the return value from GetLastCommittedURL | 339 // If the test is unsuccessful, the return value from GetLastCommittedURL |
| 255 // will be the virtual URL for the created NavigationEntry. | 340 // 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 | 341 // 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. | 342 // prepended and one less ":" character after the host. |
| 258 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); | 343 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); |
| 259 } | 344 } |
| OLD | NEW |