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 class CtrlClickShouldEndUpInNewProcessTest | |
193 : public ChromeNavigationBrowserTest, | |
194 public ::testing::WithParamInterface<const char*> {}; | |
Charlie Reis
2017/04/14 22:39:28
Personally I find parameterized tests really confu
Łukasz Anforowicz
2017/04/20 01:15:13
I've switched to separate tests that call to a sha
| |
195 | |
192 // Verify that ctrl-click results 1) open up in a new renderer process | 196 // 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. | 197 // (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). | 198 // cannot find the opener's window by name - https://crbug.com/658386). |
195 IN_PROC_BROWSER_TEST_F(ChromeNavigationBrowserTest, | 199 IN_PROC_BROWSER_TEST_P(CtrlClickShouldEndUpInNewProcessTest, Test) { |
196 CtrlClickShouldEndUpInNewProcess) { | |
197 // Navigate to the test page. | 200 // Navigate to the test page. |
198 GURL main_url(embedded_test_server()->GetURL( | 201 GURL main_url(embedded_test_server()->GetURL( |
199 "/frame_tree/anchor_to_same_site_location.html")); | 202 "/frame_tree/anchor_to_same_site_location.html")); |
200 ui_test_utils::NavigateToURL(browser(), main_url); | 203 ui_test_utils::NavigateToURL(browser(), main_url); |
201 | 204 |
202 // Verify that there is only 1 active tab (with the right contents committed). | 205 // Verify that there is only 1 active tab (with the right contents committed). |
203 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 206 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
204 content::WebContents* main_contents = | 207 content::WebContents* main_contents = |
205 browser()->tab_strip_model()->GetWebContentsAt(0); | 208 browser()->tab_strip_model()->GetWebContentsAt(0); |
206 EXPECT_EQ(main_url, main_contents->GetLastCommittedURL()); | 209 EXPECT_EQ(main_url, main_contents->GetLastCommittedURL()); |
207 | 210 |
208 // Ctrl-click the anchor/link in the page. | 211 // Ctrl-click the anchor/link in the page. |
209 content::WebContents* new_contents = nullptr; | 212 content::WebContents* new_contents = nullptr; |
210 { | 213 { |
211 content::WebContentsAddedObserver new_tab_observer; | 214 content::WebContentsAddedObserver new_tab_observer; |
212 #if defined(OS_MACOSX) | 215 #if defined(OS_MACOSX) |
213 std::string new_tab_click_script = | 216 const char* new_tab_click_script_template = |
214 "simulateClick(\"test-anchor-no-target\", { metaKey: true });"; | 217 "simulateClick(\"%s\", { metaKey: true });"; |
215 #else | 218 #else |
216 std::string new_tab_click_script = | 219 const char* new_tab_click_script_template = |
217 "simulateClick(\"test-anchor-no-target\", { ctrlKey: true });"; | 220 "simulateClick(\"%s\", { ctrlKey: true });"; |
218 #endif | 221 #endif |
222 const char* name_of_anchor_to_click = GetParam(); | |
223 std::string new_tab_click_script = base::StringPrintf( | |
224 new_tab_click_script_template, name_of_anchor_to_click); | |
219 EXPECT_TRUE(ExecuteScript(main_contents, new_tab_click_script)); | 225 EXPECT_TRUE(ExecuteScript(main_contents, new_tab_click_script)); |
220 | 226 |
221 // Wait for a new tab to appear (the whole point of this test). | 227 // Wait for a new tab to appear (the whole point of this test). |
222 new_contents = new_tab_observer.GetWebContents(); | 228 new_contents = new_tab_observer.GetWebContents(); |
223 } | 229 } |
224 | 230 |
225 // Verify that the new tab has the right contents and is in the right, new | 231 // Verify that the new tab has the right contents and is in the right, new |
226 // place in the tab strip. | 232 // place in the tab strip. |
227 EXPECT_TRUE(WaitForLoadStop(new_contents)); | 233 EXPECT_TRUE(WaitForLoadStop(new_contents)); |
228 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 234 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 "window.domAutomationController.send(w.location.href);", | 273 "window.domAutomationController.send(w.location.href);", |
268 &location_of_opened_window)); | 274 &location_of_opened_window)); |
269 content::WebContents* found_contents = | 275 content::WebContents* found_contents = |
270 window_open_observer.GetWebContents(); | 276 window_open_observer.GetWebContents(); |
271 EXPECT_TRUE(WaitForLoadStop(found_contents)); | 277 EXPECT_TRUE(WaitForLoadStop(found_contents)); |
272 EXPECT_TRUE(found_contents->GetLastCommittedURL().IsAboutBlank()); | 278 EXPECT_TRUE(found_contents->GetLastCommittedURL().IsAboutBlank()); |
273 EXPECT_EQ(url::kAboutBlankURL, location_of_opened_window); | 279 EXPECT_EQ(url::kAboutBlankURL, location_of_opened_window); |
274 } | 280 } |
275 } | 281 } |
276 | 282 |
283 INSTANTIATE_TEST_CASE_P(NoTarget, | |
284 CtrlClickShouldEndUpInNewProcessTest, | |
285 ::testing::Values("test-anchor-no-target")); | |
286 INSTANTIATE_TEST_CASE_P(BlankTarget, | |
287 CtrlClickShouldEndUpInNewProcessTest, | |
288 ::testing::Values("test-anchor-with-blank-target")); | |
289 INSTANTIATE_TEST_CASE_P(SubframeTarget, | |
290 CtrlClickShouldEndUpInNewProcessTest, | |
291 ::testing::Values("test-anchor-with-subframe-target")); | |
292 | |
277 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { | 293 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { |
278 public: | 294 public: |
279 ChromeNavigationPortMappedBrowserTest() {} | 295 ChromeNavigationPortMappedBrowserTest() {} |
280 ~ChromeNavigationPortMappedBrowserTest() override {} | 296 ~ChromeNavigationPortMappedBrowserTest() override {} |
281 | 297 |
282 void SetUpCommandLine(base::CommandLine* command_line) override { | 298 void SetUpCommandLine(base::CommandLine* command_line) override { |
283 ASSERT_TRUE(embedded_test_server()->Start()); | 299 ASSERT_TRUE(embedded_test_server()->Start()); |
284 | 300 |
285 // Use the command line parameter for the host resolver, so URLs without | 301 // Use the command line parameter for the host resolver, so URLs without |
286 // explicit port numbers can be mapped under the hood to the port number | 302 // 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... | |
335 browser()->tab_strip_model()->GetWebContentsAt( | 351 browser()->tab_strip_model()->GetWebContentsAt( |
336 browser()->tab_strip_model()->count() - 1); | 352 browser()->tab_strip_model()->count() - 1); |
337 WaitForLoadStop(new_web_contents); | 353 WaitForLoadStop(new_web_contents); |
338 | 354 |
339 // If the test is unsuccessful, the return value from GetLastCommittedURL | 355 // If the test is unsuccessful, the return value from GetLastCommittedURL |
340 // will be the virtual URL for the created NavigationEntry. | 356 // will be the virtual URL for the created NavigationEntry. |
341 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme | 357 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme |
342 // prepended and one less ":" character after the host. | 358 // prepended and one less ":" character after the host. |
343 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); | 359 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); |
344 } | 360 } |
OLD | NEW |