Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 GURL frame_url(ui_test_utils::GetTestUrl( | |
|
Bernhard Bauer
2013/09/12 13:39:22
Nit: You could move this declaration down to where
| |
| 268 base::FilePath(kTestDir), | |
| 269 base::FilePath(FILE_PATH_LITERAL("popup-frames-iframe.html")))); | |
| 270 browser()->profile()->GetHostContentSettingsMap() | |
|
Bernhard Bauer
2013/09/12 13:39:22
Nit: Extract the HCSM into a local variable?
| |
| 271 ->SetContentSetting(ContentSettingsPattern::FromURL(url), | |
| 272 ContentSettingsPattern::Wildcard(), | |
| 273 CONTENT_SETTINGS_TYPE_POPUPS, | |
| 274 std::string(), | |
| 275 CONTENT_SETTING_ALLOW); | |
| 276 | |
| 277 // Popup from the iframe should be allowed since the top-level URL is | |
| 278 // whitelisted. | |
| 279 NavigateAndCheckPopupShown(url); | |
| 280 | |
| 281 // Whitelist iframe URL instead. | |
| 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 Loading... | |
| 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 // popus. | |
|
Bernhard Bauer
2013/09/12 13:39:22
Nit: "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 |
| OLD | NEW |