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

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

Issue 23600041: Add tests for recent popup blocker fixes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/data/popup_blocker/popup-dos.html » ('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/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 browser()->profile()->GetHostContentSettingsMap() 251 browser()->profile()->GetHostContentSettingsMap()
252 ->SetContentSetting(ContentSettingsPattern::FromURL(url), 252 ->SetContentSetting(ContentSettingsPattern::FromURL(url),
253 ContentSettingsPattern::Wildcard(), 253 ContentSettingsPattern::Wildcard(),
254 CONTENT_SETTINGS_TYPE_POPUPS, 254 CONTENT_SETTINGS_TYPE_POPUPS,
255 std::string(), 255 std::string(),
256 CONTENT_SETTING_ALLOW); 256 CONTENT_SETTING_ALLOW);
257 257
258 NavigateAndCheckPopupShown(url); 258 NavigateAndCheckPopupShown(url);
259 } 259 }
260 260
261 // Verify that content settings are applied based on the top-level frame URL.
262 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
263 AllowPopupThroughContentSettingIFrame) {
264 GURL url(ui_test_utils::GetTestUrl(
265 base::FilePath(kTestDir),
266 base::FilePath(FILE_PATH_LITERAL("popup-frames.html"))));
267 browser()->profile()->GetHostContentSettingsMap()
268 ->SetContentSetting(ContentSettingsPattern::FromURL(url),
269 ContentSettingsPattern::Wildcard(),
270 CONTENT_SETTINGS_TYPE_POPUPS,
271 std::string(),
272 CONTENT_SETTING_ALLOW);
273
274 // Popup from the iframe should be allowed since the top-level URL is
275 // whitelisted.
276 NavigateAndCheckPopupShown(url);
277
278 // Whitelist iframe URL instead.
279 GURL frame_url(ui_test_utils::GetTestUrl(
280 base::FilePath(kTestDir),
281 base::FilePath(FILE_PATH_LITERAL("popup-frames-iframe.html"))));
282 browser()->profile()->GetHostContentSettingsMap()->ClearSettingsForOneType(
283 CONTENT_SETTINGS_TYPE_POPUPS);
284 browser()->profile()->GetHostContentSettingsMap()
285 ->SetContentSetting(ContentSettingsPattern::FromURL(frame_url),
286 ContentSettingsPattern::Wildcard(),
287 CONTENT_SETTINGS_TYPE_POPUPS,
288 std::string(),
289 CONTENT_SETTING_ALLOW);
290
291 // Popup should be blocked.
292 ui_test_utils::NavigateToURL(browser(), url);
293 ASSERT_EQ(1, GetBlockedContentsCount());
294 }
295
261 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, 296 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
262 PopupsLaunchWhenTabIsClosed) { 297 PopupsLaunchWhenTabIsClosed) {
263 CommandLine::ForCurrentProcess()->AppendSwitch( 298 CommandLine::ForCurrentProcess()->AppendSwitch(
264 switches::kDisablePopupBlocking); 299 switches::kDisablePopupBlocking);
265 GURL url = ui_test_utils::GetTestUrl( 300 GURL url = ui_test_utils::GetTestUrl(
266 base::FilePath(kTestDir), 301 base::FilePath(kTestDir),
267 base::FilePath(FILE_PATH_LITERAL("popup-on-unload.html"))); 302 base::FilePath(FILE_PATH_LITERAL("popup-on-unload.html")));
268 ui_test_utils::NavigateToURL(browser(), url); 303 ui_test_utils::NavigateToURL(browser(), url);
269 304
270 NavigateAndCheckPopupShown(GURL(content::kAboutBlankURL)); 305 NavigateAndCheckPopupShown(GURL(content::kAboutBlankURL));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 WebContents* popup = 395 WebContents* popup =
361 RunCheckTest(browser(), 396 RunCheckTest(browser(),
362 base::FilePath(FILE_PATH_LITERAL("popup-webui.html")), 397 base::FilePath(FILE_PATH_LITERAL("popup-webui.html")),
363 true, 398 true,
364 false); 399 false);
365 400
366 // Check that the new popup displays about:blank. 401 // Check that the new popup displays about:blank.
367 EXPECT_EQ(GURL(content::kAboutBlankURL), popup->GetURL()); 402 EXPECT_EQ(GURL(content::kAboutBlankURL), popup->GetURL());
368 } 403 }
369 404
405 // Verify that the renderer can't DOS the browser by creating arbitrarily many
406 // popups.
407 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) {
408 GURL url(ui_test_utils::GetTestUrl(
409 base::FilePath(kTestDir),
410 base::FilePath(FILE_PATH_LITERAL("popup-dos.html"))));
411 ui_test_utils::NavigateToURL(browser(), url);
412 ASSERT_EQ(25, GetBlockedContentsCount());
413 }
414
370 } // namespace 415 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/popup_blocker/popup-dos.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698