| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); | 592 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 593 app_modal::JavaScriptAppModalDialog* js_dialog = | 593 app_modal::JavaScriptAppModalDialog* js_dialog = |
| 594 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); | 594 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
| 595 | 595 |
| 596 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); | 596 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 597 js_dialog->native_dialog()->AcceptAppModalDialog(); | 597 js_dialog->native_dialog()->AcceptAppModalDialog(); |
| 598 waiter.WaitForActivation(); | 598 waiter.WaitForActivation(); |
| 599 ASSERT_EQ(popup_browser, chrome::FindLastActive()); | 599 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 600 } | 600 } |
| 601 | 601 |
| 602 // Verify that popunders from subframes are prevented. https://crbug.com/705316 |
| 603 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderSubframe) { |
| 604 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 605 GURL url(embedded_test_server()->GetURL( |
| 606 "/popup_blocker/popup-window-subframe-open.html")); |
| 607 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 608 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 609 std::string(), CONTENT_SETTING_ALLOW); |
| 610 |
| 611 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 612 |
| 613 Browser* popup_browser = chrome::FindLastActive(); |
| 614 ASSERT_NE(popup_browser, browser()); |
| 615 |
| 616 // Showing an alert will raise the tab over the popup. |
| 617 #if !defined(OS_MACOSX) |
| 618 // Mac doesn't activate the browser during modal dialogs, see |
| 619 // https://crbug.com/687732 for details. |
| 620 ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); |
| 621 #endif |
| 622 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
| 623 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 624 #if !defined(OS_MACOSX) |
| 625 if (chrome::FindLastActive() != browser()) |
| 626 alert_waiter.WaitForActivation(); |
| 627 #endif |
| 628 |
| 629 // Verify that after the dialog is closed, the popup is in front again. |
| 630 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 631 app_modal::JavaScriptAppModalDialog* js_dialog = |
| 632 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
| 633 |
| 634 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 635 js_dialog->native_dialog()->AcceptAppModalDialog(); |
| 636 waiter.WaitForActivation(); |
| 637 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 638 } |
| 639 |
| 602 // Verify that popups without an opener don't interfere with popup blocking. | 640 // Verify that popups without an opener don't interfere with popup blocking. |
| 603 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderNoOpener) { | 641 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderNoOpener) { |
| 604 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 642 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 605 GURL url(embedded_test_server()->GetURL( | 643 GURL url(embedded_test_server()->GetURL( |
| 606 "/popup_blocker/popup-window-open-noopener.html")); | 644 "/popup_blocker/popup-window-open-noopener.html")); |
| 607 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 645 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 608 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, | 646 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 609 std::string(), CONTENT_SETTING_ALLOW); | 647 std::string(), CONTENT_SETTING_ALLOW); |
| 610 | 648 |
| 611 NavigateAndCheckPopupShown(url, ExpectPopup); | 649 NavigateAndCheckPopupShown(url, ExpectPopup); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 | 871 |
| 834 wait_for_new_tab.Wait(); | 872 wait_for_new_tab.Wait(); |
| 835 | 873 |
| 836 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 874 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
| 837 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 875 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 838 // Check that we create the background tab. | 876 // Check that we create the background tab. |
| 839 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 877 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 840 } | 878 } |
| 841 | 879 |
| 842 } // namespace | 880 } // namespace |
| OLD | NEW |