Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: chrome/browser/chrome_navigation_browsertest.cc

Issue 2686943002: New WebContents created via ctrl-click should be in a new process. (Closed)
Patch Set: Really rebasing... Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
240 // Verify that |new_contents| truly is in a brand new browsing instance.
alexmos 2017/04/11 20:42:39 Might be nice to also check that main_instance->Is
Łukasz Anforowicz 2017/04/11 23:10:37 Done.
241 {
242 // Double-check that main_contents has expected window.name set.
243 // (this is a sanity check of test setup; this is not a product test).
244 std::string name_of_main_contents_window;
245 ASSERT_TRUE(ExecuteScriptAndExtractString(
246 main_contents->GetMainFrame(),
alexmos 2017/04/11 20:42:39 optional: this will also work if you just pass in
Łukasz Anforowicz 2017/04/11 23:10:37 Done.
247 "window.domAutomationController.send(window.name)",
248 &name_of_main_contents_window));
249 EXPECT_EQ("main_contents", name_of_main_contents_window);
250
251 // Verify that the new contents doesn't have a window.opener set.
252 bool window_opener_cast_to_bool;
253 ASSERT_TRUE(ExecuteScriptAndExtractBool(
254 new_contents->GetMainFrame(),
255 "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.
261 // (i.e. window.open should open a new window, rather than returning a
262 // reference to main_contents / old window).
263 content::WebContentsAddedObserver window_open_observer;
264 std::string location_of_opened_window;
265 ASSERT_TRUE(ExecuteScriptAndExtractString(
266 new_contents->GetMainFrame(),
267 "w = window.open('', 'main_contents');"
268 "window.domAutomationController.send(w.location.href);",
269 &location_of_opened_window));
270 content::WebContents* found_contents =
271 window_open_observer.GetWebContents();
272 // Expecting "false" -> expecting to be at a non-PAGE_TYPE_NORMAL page.
alexmos 2017/04/11 20:42:39 I'm curious why this is the case? I.e., why would
Łukasz Anforowicz 2017/04/11 23:10:37 IsLastCommittedEntryOfPageType returns false, beca
alexmos 2017/04/12 22:08:29 Strange. I'd expect the new popup to commit "abou
Łukasz Anforowicz 2017/04/12 22:40:04 Good call: - Previously found_contents->IsLoading(
273 EXPECT_FALSE(WaitForLoadStop(found_contents));
274 EXPECT_EQ(GURL(), found_contents->GetLastCommittedURL());
275 EXPECT_EQ("about:blank", location_of_opened_window);
276 }
277 }
278
192 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { 279 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest {
193 public: 280 public:
194 ChromeNavigationPortMappedBrowserTest() {} 281 ChromeNavigationPortMappedBrowserTest() {}
195 ~ChromeNavigationPortMappedBrowserTest() override {} 282 ~ChromeNavigationPortMappedBrowserTest() override {}
196 283
197 void SetUpCommandLine(base::CommandLine* command_line) override { 284 void SetUpCommandLine(base::CommandLine* command_line) override {
198 ASSERT_TRUE(embedded_test_server()->Start()); 285 ASSERT_TRUE(embedded_test_server()->Start());
199 286
200 // Use the command line parameter for the host resolver, so URLs without 287 // 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 288 // 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
250 browser()->tab_strip_model()->GetWebContentsAt( 337 browser()->tab_strip_model()->GetWebContentsAt(
251 browser()->tab_strip_model()->count() - 1); 338 browser()->tab_strip_model()->count() - 1);
252 WaitForLoadStop(new_web_contents); 339 WaitForLoadStop(new_web_contents);
253 340
254 // If the test is unsuccessful, the return value from GetLastCommittedURL 341 // If the test is unsuccessful, the return value from GetLastCommittedURL
255 // will be the virtual URL for the created NavigationEntry. 342 // 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 343 // 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. 344 // prepended and one less ":" character after the host.
258 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); 345 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL());
259 } 346 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | chrome/browser/extensions/api/tabs/tabs_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698