| 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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 527 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 528 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, | 528 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 529 std::string(), CONTENT_SETTING_ALLOW); | 529 std::string(), CONTENT_SETTING_ALLOW); |
| 530 | 530 |
| 531 NavigateAndCheckPopupShown(url, ExpectPopup); | 531 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 532 | 532 |
| 533 Browser* popup_browser = chrome::FindLastActive(); | 533 Browser* popup_browser = chrome::FindLastActive(); |
| 534 ASSERT_NE(popup_browser, browser()); | 534 ASSERT_NE(popup_browser, browser()); |
| 535 | 535 |
| 536 // Showing an alert will raise the tab over the popup. | 536 // Showing an alert will raise the tab over the popup. |
| 537 #if !defined(OS_MACOSX) |
| 538 // Mac doesn't activate the browser during modal dialogs, see |
| 539 // https://crbug.com/687732 for details. |
| 540 ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); |
| 541 #endif |
| 537 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); | 542 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
| 538 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 543 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 544 #if !defined(OS_MACOSX) |
| 545 if (chrome::FindLastActive() != browser()) |
| 546 alert_waiter.WaitForActivation(); |
| 547 #endif |
| 539 | 548 |
| 540 // Verify that after the dialog is closed, the popup is in front again. | 549 // Verify that after the dialog is closed, the popup is in front again. |
| 541 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); | 550 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 551 app_modal::JavaScriptAppModalDialog* js_dialog = |
| 552 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
| 553 |
| 554 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 555 js_dialog->native_dialog()->AcceptAppModalDialog(); |
| 556 waiter.WaitForActivation(); |
| 557 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 558 } |
| 559 |
| 560 // Verify that setting the window.opener doesn't interfere with popup blocking. |
| 561 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderWindowOpener) { |
| 562 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 563 GURL url( |
| 564 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); |
| 565 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 566 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 567 std::string(), CONTENT_SETTING_ALLOW); |
| 568 |
| 569 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 570 |
| 571 Browser* popup_browser = chrome::FindLastActive(); |
| 572 ASSERT_NE(popup_browser, browser()); |
| 573 |
| 574 // Modify window.opener in the popup. |
| 575 WebContents* popup = popup_browser->tab_strip_model()->GetActiveWebContents(); |
| 576 ASSERT_TRUE(popup_browser->is_type_popup()); |
| 577 content::ExecuteScriptAndGetValue(popup->GetMainFrame(), |
| 578 "window.open('', 'mywindow')"); |
| 579 |
| 580 // Showing an alert will raise the tab over the popup. |
| 581 #if !defined(OS_MACOSX) |
| 582 // Mac doesn't activate the browser during modal dialogs, see |
| 583 // https://crbug.com/687732 for details. |
| 584 ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); |
| 585 #endif |
| 586 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
| 587 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 588 #if !defined(OS_MACOSX) |
| 589 if (chrome::FindLastActive() != browser()) |
| 590 alert_waiter.WaitForActivation(); |
| 591 #endif |
| 592 |
| 593 // Verify that after the dialog is closed, the popup is in front again. |
| 594 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 595 app_modal::JavaScriptAppModalDialog* js_dialog = |
| 596 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
| 597 |
| 598 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 599 js_dialog->native_dialog()->AcceptAppModalDialog(); |
| 600 waiter.WaitForActivation(); |
| 601 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 602 } |
| 603 |
| 604 // Verify that popups without an opener don't interfere with popup blocking. |
| 605 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderNoOpener) { |
| 606 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 607 GURL url(embedded_test_server()->GetURL( |
| 608 "/popup_blocker/popup-window-open-noopener.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()); |
| 542 app_modal::JavaScriptAppModalDialog* js_dialog = | 633 app_modal::JavaScriptAppModalDialog* js_dialog = |
| 543 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); | 634 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
| 544 | 635 |
| 545 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); | 636 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 546 js_dialog->native_dialog()->AcceptAppModalDialog(); | 637 js_dialog->native_dialog()->AcceptAppModalDialog(); |
| 547 waiter.WaitForActivation(); | 638 waiter.WaitForActivation(); |
| 548 ASSERT_EQ(popup_browser, chrome::FindLastActive()); | 639 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 549 } | 640 } |
| 550 | 641 |
| 551 // Verify that app modal prompts can't be used to create pop unders, while the | 642 // Verify that app modal prompts can't be used to create pop unders, while the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 576 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 667 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 577 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, | 668 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 578 std::string(), CONTENT_SETTING_ALLOW); | 669 std::string(), CONTENT_SETTING_ALLOW); |
| 579 | 670 |
| 580 NavigateAndCheckPopupShown(url, ExpectPopup); | 671 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 581 | 672 |
| 582 Browser* popup_browser = chrome::FindLastActive(); | 673 Browser* popup_browser = chrome::FindLastActive(); |
| 583 ASSERT_NE(popup_browser, browser()); | 674 ASSERT_NE(popup_browser, browser()); |
| 584 | 675 |
| 585 // Showing an alert will raise the tab over the popup. | 676 // Showing an alert will raise the tab over the popup. |
| 677 #if !defined(OS_MACOSX) |
| 678 // Mac doesn't activate the browser during modal dialogs, see |
| 679 // https://crbug.com/687732 for details. |
| 680 ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); |
| 681 #endif |
| 586 scoped_refptr<content::MessageLoopRunner> runner = | 682 scoped_refptr<content::MessageLoopRunner> runner = |
| 587 new content::MessageLoopRunner; | 683 new content::MessageLoopRunner; |
| 588 js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure()); | 684 js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure()); |
| 589 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); | 685 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
| 590 runner->Run(); | 686 runner->Run(); |
| 687 #if !defined(OS_MACOSX) |
| 688 if (chrome::FindLastActive() != browser()) |
| 689 alert_waiter.WaitForActivation(); |
| 690 #endif |
| 591 | 691 |
| 592 // Verify that after the dialog is closed, the popup is in front again. | 692 // Verify that after the dialog is closed, the popup is in front again. |
| 593 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); | 693 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 594 tab_strip->ActivateTabAt(1, true); | 694 tab_strip->ActivateTabAt(1, true); |
| 595 waiter.WaitForActivation(); | 695 waiter.WaitForActivation(); |
| 596 ASSERT_EQ(popup_browser, chrome::FindLastActive()); | 696 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 597 } | 697 } |
| 598 | 698 |
| 599 #if BUILDFLAG(ENABLE_EXTENSIONS) | 699 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 600 #define MAYBE_ModalPopUnderViaGuestView DISABLED_ModalPopUnderViaGuestView | 700 #define MAYBE_ModalPopUnderViaGuestView DISABLED_ModalPopUnderViaGuestView |
| 601 #else | 701 #else |
| 602 #define MAYBE_ModalPopUnderViaGuestView ModalPopUnderViaGuestView | 702 #define MAYBE_ModalPopUnderViaGuestView ModalPopUnderViaGuestView |
| 603 #endif | 703 #endif |
| 604 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, | 704 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, |
| 605 MAYBE_ModalPopUnderViaGuestView) { | 705 MAYBE_ModalPopUnderViaGuestView) { |
| 606 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 706 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 607 GURL url( | 707 GURL url( |
| 608 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); | 708 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); |
| 609 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 709 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 610 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, | 710 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 611 std::string(), CONTENT_SETTING_ALLOW); | 711 std::string(), CONTENT_SETTING_ALLOW); |
| 612 | 712 |
| 613 NavigateAndCheckPopupShown(url, ExpectPopup); | 713 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 614 | 714 |
| 615 Browser* popup_browser = chrome::FindLastActive(); | 715 Browser* popup_browser = chrome::FindLastActive(); |
| 616 ASSERT_NE(popup_browser, browser()); | 716 ASSERT_NE(popup_browser, browser()); |
| 617 | 717 |
| 618 // Showing an alert will raise the tab over the popup. | 718 // Showing an alert will raise the tab over the popup. |
| 719 #if !defined(OS_MACOSX) |
| 720 // Mac doesn't activate the browser during modal dialogs, see |
| 721 // https://crbug.com/687732 for details. |
| 722 ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); |
| 723 #endif |
| 619 tab->GetMainFrame()->ExecuteJavaScriptForTests( | 724 tab->GetMainFrame()->ExecuteJavaScriptForTests( |
| 620 base::UTF8ToUTF16("var o = document.createElement('object'); o.data = " | 725 base::UTF8ToUTF16("var o = document.createElement('object'); o.data = " |
| 621 "'/alert_dialog.pdf'; document.body.appendChild(o);")); | 726 "'/alert_dialog.pdf'; document.body.appendChild(o);")); |
| 622 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 727 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 728 #if !defined(OS_MACOSX) |
| 729 if (chrome::FindLastActive() != browser()) |
| 730 alert_waiter.WaitForActivation(); |
| 731 #endif |
| 623 | 732 |
| 624 // Verify that after the dialog was closed, the popup is in front again. | 733 // Verify that after the dialog was closed, the popup is in front again. |
| 625 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); | 734 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 626 app_modal::JavaScriptAppModalDialog* js_dialog = | 735 app_modal::JavaScriptAppModalDialog* js_dialog = |
| 627 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); | 736 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
| 628 | 737 |
| 629 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); | 738 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 630 js_dialog->native_dialog()->AcceptAppModalDialog(); | 739 js_dialog->native_dialog()->AcceptAppModalDialog(); |
| 631 waiter.WaitForActivation(); | 740 waiter.WaitForActivation(); |
| 632 ASSERT_EQ(popup_browser, chrome::FindLastActive()); | 741 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 643 NavigateAndCheckPopupShown(url, ExpectPopup); | 752 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 644 | 753 |
| 645 Browser* popup_browser = chrome::FindLastActive(); | 754 Browser* popup_browser = chrome::FindLastActive(); |
| 646 ASSERT_NE(popup_browser, browser()); | 755 ASSERT_NE(popup_browser, browser()); |
| 647 | 756 |
| 648 // Showing an http auth dialog will raise the tab over the popup. | 757 // Showing an http auth dialog will raise the tab over the popup. |
| 649 LoginPromptBrowserTestObserver observer; | 758 LoginPromptBrowserTestObserver observer; |
| 650 content::NavigationController* controller = &tab->GetController(); | 759 content::NavigationController* controller = &tab->GetController(); |
| 651 observer.Register(content::Source<content::NavigationController>(controller)); | 760 observer.Register(content::Source<content::NavigationController>(controller)); |
| 652 { | 761 { |
| 762 #if !defined(OS_MACOSX) |
| 763 // Mac doesn't activate the browser during modal dialogs, see |
| 764 // https://crbug.com/687732 for details. |
| 765 ui_test_utils::BrowserActivationWaiter raised_waiter(browser()); |
| 766 #endif |
| 653 WindowedAuthNeededObserver auth_needed_observer(controller); | 767 WindowedAuthNeededObserver auth_needed_observer(controller); |
| 654 tab->GetMainFrame()->ExecuteJavaScriptForTests( | 768 tab->GetMainFrame()->ExecuteJavaScriptForTests( |
| 655 base::UTF8ToUTF16("var f = document.createElement('iframe'); f.src = " | 769 base::UTF8ToUTF16("var f = document.createElement('iframe'); f.src = " |
| 656 "'/auth-basic'; document.body.appendChild(f);")); | 770 "'/auth-basic'; document.body.appendChild(f);")); |
| 657 auth_needed_observer.Wait(); | 771 auth_needed_observer.Wait(); |
| 658 ASSERT_FALSE(observer.handlers().empty()); | 772 ASSERT_FALSE(observer.handlers().empty()); |
| 773 #if !defined(OS_MACOSX) |
| 774 if (chrome::FindLastActive() != browser()) |
| 775 raised_waiter.WaitForActivation(); |
| 776 #endif |
| 659 } | 777 } |
| 660 | 778 |
| 661 { | 779 { |
| 662 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); | 780 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 663 LoginHandler* handler = *observer.handlers().begin(); | 781 LoginHandler* handler = *observer.handlers().begin(); |
| 664 handler->CancelAuth(); | 782 handler->CancelAuth(); |
| 665 waiter.WaitForActivation(); | 783 waiter.WaitForActivation(); |
| 666 ASSERT_EQ(popup_browser, chrome::FindLastActive()); | 784 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 667 } | 785 } |
| 668 } | 786 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 | 835 |
| 718 wait_for_new_tab.Wait(); | 836 wait_for_new_tab.Wait(); |
| 719 | 837 |
| 720 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 838 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
| 721 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 839 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 722 // Check that we create the background tab. | 840 // Check that we create the background tab. |
| 723 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 841 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 724 } | 842 } |
| 725 | 843 |
| 726 } // namespace | 844 } // namespace |
| OLD | NEW |