| 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/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 14 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 15 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
| 18 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/location_bar/location_bar.h" | 21 #include "chrome/browser/ui/location_bar/location_bar.h" |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-many.html")); | 337 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-many.html")); |
| 337 ui_test_utils::NavigateToURL(browser(), url); | 338 ui_test_utils::NavigateToURL(browser(), url); |
| 338 ASSERT_EQ(2, GetBlockedContentsCount()); | 339 ASSERT_EQ(2, GetBlockedContentsCount()); |
| 339 } | 340 } |
| 340 | 341 |
| 341 // Verify that popups are launched on browser back button. | 342 // Verify that popups are launched on browser back button. |
| 342 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, | 343 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, |
| 343 AllowPopupThroughContentSetting) { | 344 AllowPopupThroughContentSetting) { |
| 344 GURL url(embedded_test_server()->GetURL( | 345 GURL url(embedded_test_server()->GetURL( |
| 345 "/popup_blocker/popup-blocked-to-post-blank.html")); | 346 "/popup_blocker/popup-blocked-to-post-blank.html")); |
| 346 browser()->profile()->GetHostContentSettingsMap() | 347 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 347 ->SetContentSetting(ContentSettingsPattern::FromURL(url), | 348 ->SetContentSetting(ContentSettingsPattern::FromURL(url), |
| 348 ContentSettingsPattern::Wildcard(), | 349 ContentSettingsPattern::Wildcard(), |
| 349 CONTENT_SETTINGS_TYPE_POPUPS, | 350 CONTENT_SETTINGS_TYPE_POPUPS, |
| 350 std::string(), | 351 std::string(), |
| 351 CONTENT_SETTING_ALLOW); | 352 CONTENT_SETTING_ALLOW); |
| 352 | 353 |
| 353 NavigateAndCheckPopupShown(url, ExpectTab); | 354 NavigateAndCheckPopupShown(url, ExpectTab); |
| 354 } | 355 } |
| 355 | 356 |
| 356 // Verify that content settings are applied based on the top-level frame URL. | 357 // Verify that content settings are applied based on the top-level frame URL. |
| 357 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, | 358 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, |
| 358 AllowPopupThroughContentSettingIFrame) { | 359 AllowPopupThroughContentSettingIFrame) { |
| 359 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-frames.html")); | 360 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-frames.html")); |
| 360 browser()->profile()->GetHostContentSettingsMap() | 361 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 361 ->SetContentSetting(ContentSettingsPattern::FromURL(url), | 362 ->SetContentSetting(ContentSettingsPattern::FromURL(url), |
| 362 ContentSettingsPattern::Wildcard(), | 363 ContentSettingsPattern::Wildcard(), |
| 363 CONTENT_SETTINGS_TYPE_POPUPS, | 364 CONTENT_SETTINGS_TYPE_POPUPS, |
| 364 std::string(), | 365 std::string(), |
| 365 CONTENT_SETTING_ALLOW); | 366 CONTENT_SETTING_ALLOW); |
| 366 | 367 |
| 367 // Popup from the iframe should be allowed since the top-level URL is | 368 // Popup from the iframe should be allowed since the top-level URL is |
| 368 // whitelisted. | 369 // whitelisted. |
| 369 NavigateAndCheckPopupShown(url, ExpectTab); | 370 NavigateAndCheckPopupShown(url, ExpectTab); |
| 370 | 371 |
| 371 // Whitelist iframe URL instead. | 372 // Whitelist iframe URL instead. |
| 372 GURL::Replacements replace_host; | 373 GURL::Replacements replace_host; |
| 373 replace_host.SetHostStr("www.a.com"); | 374 replace_host.SetHostStr("www.a.com"); |
| 374 GURL frame_url(embedded_test_server() | 375 GURL frame_url(embedded_test_server() |
| 375 ->GetURL("/popup_blocker/popup-frames-iframe.html") | 376 ->GetURL("/popup_blocker/popup-frames-iframe.html") |
| 376 .ReplaceComponents(replace_host)); | 377 .ReplaceComponents(replace_host)); |
| 377 browser()->profile()->GetHostContentSettingsMap()->ClearSettingsForOneType( | 378 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 378 CONTENT_SETTINGS_TYPE_POPUPS); | 379 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS); |
| 379 browser()->profile()->GetHostContentSettingsMap() | 380 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 380 ->SetContentSetting(ContentSettingsPattern::FromURL(frame_url), | 381 ->SetContentSetting(ContentSettingsPattern::FromURL(frame_url), |
| 381 ContentSettingsPattern::Wildcard(), | 382 ContentSettingsPattern::Wildcard(), |
| 382 CONTENT_SETTINGS_TYPE_POPUPS, | 383 CONTENT_SETTINGS_TYPE_POPUPS, |
| 383 std::string(), | 384 std::string(), |
| 384 CONTENT_SETTING_ALLOW); | 385 CONTENT_SETTING_ALLOW); |
| 385 | 386 |
| 386 // Popup should be blocked. | 387 // Popup should be blocked. |
| 387 ui_test_utils::NavigateToURL(browser(), url); | 388 ui_test_utils::NavigateToURL(browser(), url); |
| 388 ASSERT_EQ(1, GetBlockedContentsCount()); | 389 ASSERT_EQ(1, GetBlockedContentsCount()); |
| 389 } | 390 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 558 |
| 558 // The popup from the unload event handler should not show up for about:blank. | 559 // The popup from the unload event handler should not show up for about:blank. |
| 559 ASSERT_EQ(0, GetBlockedContentsCount()); | 560 ASSERT_EQ(0, GetBlockedContentsCount()); |
| 560 } | 561 } |
| 561 | 562 |
| 562 // Verify that app modal prompts can't be used to create pop unders. | 563 // Verify that app modal prompts can't be used to create pop unders. |
| 563 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) { | 564 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) { |
| 564 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 565 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 565 GURL url( | 566 GURL url( |
| 566 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); | 567 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); |
| 567 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 568 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 568 ContentSettingsPattern::FromURL(url), ContentSettingsPattern::Wildcard(), | 569 ->SetContentSetting(ContentSettingsPattern::FromURL(url), |
| 569 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), CONTENT_SETTING_ALLOW); | 570 ContentSettingsPattern::Wildcard(), |
| 571 CONTENT_SETTINGS_TYPE_POPUPS, |
| 572 std::string(), |
| 573 CONTENT_SETTING_ALLOW); |
| 570 | 574 |
| 571 NavigateAndCheckPopupShown(url, ExpectPopup); | 575 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 572 | 576 |
| 573 Browser* popup_browser = | 577 Browser* popup_browser = |
| 574 chrome::FindLastActiveWithHostDesktopType(browser()->host_desktop_type()); | 578 chrome::FindLastActiveWithHostDesktopType(browser()->host_desktop_type()); |
| 575 ASSERT_NE(popup_browser, browser()); | 579 ASSERT_NE(popup_browser, browser()); |
| 576 | 580 |
| 577 // Showing an alert will raise the tab over the popup. | 581 // Showing an alert will raise the tab over the popup. |
| 578 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); | 582 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
| 579 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 583 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 wait_for_new_tab.Wait(); | 707 wait_for_new_tab.Wait(); |
| 704 | 708 |
| 705 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 709 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 706 browser()->host_desktop_type())); | 710 browser()->host_desktop_type())); |
| 707 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 711 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 708 // Check that we create the background tab. | 712 // Check that we create the background tab. |
| 709 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 713 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 710 } | 714 } |
| 711 | 715 |
| 712 } // namespace | 716 } // namespace |
| OLD | NEW |