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