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

Side by Side Diff: chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc

Issue 527913002: Don't change the window disposition for new windows without a user gesture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 6 years, 3 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
« no previous file with comments | « chrome/browser/extensions/window_open_apitest.cc ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 int GetBlockedContentsCount() { 106 int GetBlockedContentsCount() {
107 // Do a round trip to the renderer first to flush any in-flight IPCs to 107 // Do a round trip to the renderer first to flush any in-flight IPCs to
108 // create a to-be-blocked window. 108 // create a to-be-blocked window.
109 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 109 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
110 CHECK(content::ExecuteScript(tab, std::string())); 110 CHECK(content::ExecuteScript(tab, std::string()));
111 PopupBlockerTabHelper* popup_blocker_helper = 111 PopupBlockerTabHelper* popup_blocker_helper =
112 PopupBlockerTabHelper::FromWebContents(tab); 112 PopupBlockerTabHelper::FromWebContents(tab);
113 return popup_blocker_helper->GetBlockedPopupsCount(); 113 return popup_blocker_helper->GetBlockedPopupsCount();
114 } 114 }
115 115
116 void NavigateAndCheckPopupShown(const GURL& url) {
117 content::WindowedNotificationObserver observer(
118 chrome::NOTIFICATION_TAB_ADDED,
119 content::NotificationService::AllSources());
120 ui_test_utils::NavigateToURL(browser(), url);
121 observer.Wait();
122
123 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(),
124 browser()->host_desktop_type()));
125
126 ASSERT_EQ(0, GetBlockedContentsCount());
127 }
128
129 enum WhatToExpect { 116 enum WhatToExpect {
130 ExpectPopup, 117 ExpectPopup,
131 ExpectTab 118 ExpectTab
132 }; 119 };
133 120
134 enum ShouldCheckTitle { 121 enum ShouldCheckTitle {
135 CheckTitle, 122 CheckTitle,
136 DontCheckTitle 123 DontCheckTitle
137 }; 124 };
138 125
126 void NavigateAndCheckPopupShown(const GURL& url,
127 WhatToExpect what_to_expect) {
128 content::WindowedNotificationObserver observer(
129 chrome::NOTIFICATION_TAB_ADDED,
130 content::NotificationService::AllSources());
131 ui_test_utils::NavigateToURL(browser(), url);
132 observer.Wait();
133
134 if (what_to_expect == ExpectPopup) {
135 ASSERT_EQ(2u,
136 chrome::GetBrowserCount(browser()->profile(),
137 browser()->host_desktop_type()));
138 } else {
139 ASSERT_EQ(1u,
140 chrome::GetBrowserCount(browser()->profile(),
141 browser()->host_desktop_type()));
142 ASSERT_EQ(2, browser()->tab_strip_model()->count());
143 }
144
145 ASSERT_EQ(0, GetBlockedContentsCount());
146 }
147
139 // Navigates to the test indicated by |test_name| using |browser| which is 148 // Navigates to the test indicated by |test_name| using |browser| which is
140 // expected to try to open a popup. Verifies that the popup was blocked and 149 // expected to try to open a popup. Verifies that the popup was blocked and
141 // then opens the blocked popup. Once the popup stopped loading, verifies 150 // then opens the blocked popup. Once the popup stopped loading, verifies
142 // that the title of the page is "PASS" if |check_title| is set. 151 // that the title of the page is "PASS" if |check_title| is set.
143 // 152 //
144 // If |what_to_expect| is ExpectPopup, the popup is expected to open a new 153 // If |what_to_expect| is ExpectPopup, the popup is expected to open a new
145 // window, or a background tab if it is false. 154 // window, or a background tab if it is false.
146 // 155 //
147 // Returns the WebContents of the launched popup. 156 // Returns the WebContents of the launched popup.
148 WebContents* RunCheckTest(Browser* browser, 157 WebContents* RunCheckTest(Browser* browser,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 AllowPopupThroughContentSetting) { 292 AllowPopupThroughContentSetting) {
284 GURL url(embedded_test_server()->GetURL( 293 GURL url(embedded_test_server()->GetURL(
285 "/popup_blocker/popup-blocked-to-post-blank.html")); 294 "/popup_blocker/popup-blocked-to-post-blank.html"));
286 browser()->profile()->GetHostContentSettingsMap() 295 browser()->profile()->GetHostContentSettingsMap()
287 ->SetContentSetting(ContentSettingsPattern::FromURL(url), 296 ->SetContentSetting(ContentSettingsPattern::FromURL(url),
288 ContentSettingsPattern::Wildcard(), 297 ContentSettingsPattern::Wildcard(),
289 CONTENT_SETTINGS_TYPE_POPUPS, 298 CONTENT_SETTINGS_TYPE_POPUPS,
290 std::string(), 299 std::string(),
291 CONTENT_SETTING_ALLOW); 300 CONTENT_SETTING_ALLOW);
292 301
293 NavigateAndCheckPopupShown(url); 302 NavigateAndCheckPopupShown(url, ExpectTab);
294 } 303 }
295 304
296 // Verify that content settings are applied based on the top-level frame URL. 305 // Verify that content settings are applied based on the top-level frame URL.
297 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, 306 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
298 AllowPopupThroughContentSettingIFrame) { 307 AllowPopupThroughContentSettingIFrame) {
299 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-frames.html")); 308 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-frames.html"));
300 browser()->profile()->GetHostContentSettingsMap() 309 browser()->profile()->GetHostContentSettingsMap()
301 ->SetContentSetting(ContentSettingsPattern::FromURL(url), 310 ->SetContentSetting(ContentSettingsPattern::FromURL(url),
302 ContentSettingsPattern::Wildcard(), 311 ContentSettingsPattern::Wildcard(),
303 CONTENT_SETTINGS_TYPE_POPUPS, 312 CONTENT_SETTINGS_TYPE_POPUPS,
304 std::string(), 313 std::string(),
305 CONTENT_SETTING_ALLOW); 314 CONTENT_SETTING_ALLOW);
306 315
307 // Popup from the iframe should be allowed since the top-level URL is 316 // Popup from the iframe should be allowed since the top-level URL is
308 // whitelisted. 317 // whitelisted.
309 NavigateAndCheckPopupShown(url); 318 NavigateAndCheckPopupShown(url, ExpectTab);
310 319
311 // Whitelist iframe URL instead. 320 // Whitelist iframe URL instead.
312 GURL::Replacements replace_host; 321 GURL::Replacements replace_host;
313 std::string host_str("www.a.com"); // Must stay in scope with replace_host 322 std::string host_str("www.a.com"); // Must stay in scope with replace_host
314 replace_host.SetHostStr(host_str); 323 replace_host.SetHostStr(host_str);
315 GURL frame_url(embedded_test_server() 324 GURL frame_url(embedded_test_server()
316 ->GetURL("/popup_blocker/popup-frames-iframe.html") 325 ->GetURL("/popup_blocker/popup-frames-iframe.html")
317 .ReplaceComponents(replace_host)); 326 .ReplaceComponents(replace_host));
318 browser()->profile()->GetHostContentSettingsMap()->ClearSettingsForOneType( 327 browser()->profile()->GetHostContentSettingsMap()->ClearSettingsForOneType(
319 CONTENT_SETTINGS_TYPE_POPUPS); 328 CONTENT_SETTINGS_TYPE_POPUPS);
(...skipping 10 matching lines...) Expand all
330 } 339 }
331 340
332 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, 341 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
333 PopupsLaunchWhenTabIsClosed) { 342 PopupsLaunchWhenTabIsClosed) {
334 CommandLine::ForCurrentProcess()->AppendSwitch( 343 CommandLine::ForCurrentProcess()->AppendSwitch(
335 switches::kDisablePopupBlocking); 344 switches::kDisablePopupBlocking);
336 GURL url( 345 GURL url(
337 embedded_test_server()->GetURL("/popup_blocker/popup-on-unload.html")); 346 embedded_test_server()->GetURL("/popup_blocker/popup-on-unload.html"));
338 ui_test_utils::NavigateToURL(browser(), url); 347 ui_test_utils::NavigateToURL(browser(), url);
339 348
340 NavigateAndCheckPopupShown(embedded_test_server()->GetURL("/popup_blocker/")); 349 NavigateAndCheckPopupShown(embedded_test_server()->GetURL("/popup_blocker/"),
350 ExpectPopup);
341 } 351 }
342 352
343 // Verify that when you unblock popup, the popup shows in history and omnibox. 353 // Verify that when you unblock popup, the popup shows in history and omnibox.
344 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, 354 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
345 UnblockedPopupShowsInHistoryAndOmnibox) { 355 UnblockedPopupShowsInHistoryAndOmnibox) {
346 CommandLine::ForCurrentProcess()->AppendSwitch( 356 CommandLine::ForCurrentProcess()->AppendSwitch(
347 switches::kDisablePopupBlocking); 357 switches::kDisablePopupBlocking);
348 GURL url(embedded_test_server()->GetURL( 358 GURL url(embedded_test_server()->GetURL(
349 "/popup_blocker/popup-blocked-to-post-blank.html")); 359 "/popup_blocker/popup-blocked-to-post-blank.html"));
350 NavigateAndCheckPopupShown(url); 360 NavigateAndCheckPopupShown(url, ExpectTab);
351 361
352 std::string search_string = 362 std::string search_string =
353 "data:text/html,<title>Popup Success!</title>you should not see this " 363 "data:text/html,<title>Popup Success!</title>you should not see this "
354 "message if popup blocker is enabled"; 364 "message if popup blocker is enabled";
355 365
356 ui_test_utils::HistoryEnumerator history(browser()->profile()); 366 ui_test_utils::HistoryEnumerator history(browser()->profile());
357 std::vector<GURL>& history_urls = history.urls(); 367 std::vector<GURL>& history_urls = history.urls();
358 ASSERT_EQ(2u, history_urls.size()); 368 ASSERT_EQ(2u, history_urls.size());
359 ASSERT_EQ(GURL(search_string), history_urls[0]); 369 ASSERT_EQ(GURL(search_string), history_urls[0]);
360 ASSERT_EQ(url, history_urls[1]); 370 ASSERT_EQ(url, history_urls[1]);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 481
472 // Verify that the renderer can't DOS the browser by creating arbitrarily many 482 // Verify that the renderer can't DOS the browser by creating arbitrarily many
473 // popups. 483 // popups.
474 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { 484 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) {
475 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); 485 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html"));
476 ui_test_utils::NavigateToURL(browser(), url); 486 ui_test_utils::NavigateToURL(browser(), url);
477 ASSERT_EQ(25, GetBlockedContentsCount()); 487 ASSERT_EQ(25, GetBlockedContentsCount());
478 } 488 }
479 489
480 } // namespace 490 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/window_open_apitest.cc ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698