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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/scoped_feature_list.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 19 #include "chrome/browser/search_engines/template_url_service_factory.h" |
19 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 20 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
22 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 25 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
24 #include "chrome/browser/ui/location_bar/location_bar.h" | 26 #include "chrome/browser/ui/location_bar/location_bar.h" |
25 #include "chrome/browser/ui/login/login_handler.h" | 27 #include "chrome/browser/ui/login/login_handler.h" |
26 #include "chrome/browser/ui/login/login_handler_test_utils.h" | 28 #include "chrome/browser/ui/login/login_handler_test_utils.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 30 #include "chrome/common/chrome_features.h" |
28 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
30 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
31 #include "chrome/test/base/in_process_browser_test.h" | 34 #include "chrome/test/base/in_process_browser_test.h" |
32 #include "chrome/test/base/search_test_utils.h" | 35 #include "chrome/test/base/search_test_utils.h" |
33 #include "chrome/test/base/ui_test_utils.h" | 36 #include "chrome/test/base/ui_test_utils.h" |
34 #include "components/app_modal/javascript_app_modal_dialog.h" | 37 #include "components/app_modal/javascript_app_modal_dialog.h" |
35 #include "components/app_modal/native_app_modal_dialog.h" | 38 #include "components/app_modal/native_app_modal_dialog.h" |
36 #include "components/content_settings/core/browser/host_content_settings_map.h" | 39 #include "components/content_settings/core/browser/host_content_settings_map.h" |
37 #include "components/omnibox/browser/autocomplete_match.h" | 40 #include "components/omnibox/browser/autocomplete_match.h" |
38 #include "components/omnibox/browser/autocomplete_result.h" | 41 #include "components/omnibox/browser/autocomplete_result.h" |
39 #include "components/omnibox/browser/omnibox_edit_model.h" | 42 #include "components/omnibox/browser/omnibox_edit_model.h" |
40 #include "components/omnibox/browser/omnibox_view.h" | 43 #include "components/omnibox/browser/omnibox_view.h" |
41 #include "content/public/browser/native_web_keyboard_event.h" | 44 #include "content/public/browser/native_web_keyboard_event.h" |
42 #include "content/public/browser/navigation_controller.h" | 45 #include "content/public/browser/navigation_controller.h" |
43 #include "content/public/browser/notification_registrar.h" | 46 #include "content/public/browser/notification_registrar.h" |
44 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/render_frame_host.h" | 48 #include "content/public/browser/render_frame_host.h" |
46 #include "content/public/browser/render_view_host.h" | 49 #include "content/public/browser/render_view_host.h" |
47 #include "content/public/browser/render_widget_host.h" | 50 #include "content/public/browser/render_widget_host.h" |
48 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
49 #include "content/public/browser/web_contents_observer.h" | 52 #include "content/public/browser/web_contents_observer.h" |
50 #include "content/public/common/url_constants.h" | 53 #include "content/public/common/url_constants.h" |
51 #include "content/public/test/browser_test_utils.h" | 54 #include "content/public/test/browser_test_utils.h" |
52 #include "content/public/test/test_navigation_observer.h" | 55 #include "content/public/test/test_navigation_observer.h" |
| 56 #include "content/public/test/test_utils.h" |
53 #include "net/dns/mock_host_resolver.h" | 57 #include "net/dns/mock_host_resolver.h" |
54 #include "net/test/embedded_test_server/embedded_test_server.h" | 58 #include "net/test/embedded_test_server/embedded_test_server.h" |
55 #include "testing/gtest/include/gtest/gtest.h" | 59 #include "testing/gtest/include/gtest/gtest.h" |
56 #include "ui/events/keycodes/dom/dom_code.h" | 60 #include "ui/events/keycodes/dom/dom_code.h" |
57 #include "ui/events/keycodes/dom/keycode_converter.h" | 61 #include "ui/events/keycodes/dom/keycode_converter.h" |
58 | 62 |
59 using content::WebContents; | 63 using content::WebContents; |
60 using content::NativeWebKeyboardEvent; | 64 using content::NativeWebKeyboardEvent; |
61 | 65 |
62 namespace { | 66 namespace { |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 511 |
508 NavigateAndCheckPopupShown(url, ExpectPopup); | 512 NavigateAndCheckPopupShown(url, ExpectPopup); |
509 | 513 |
510 Browser* popup_browser = chrome::FindLastActive(); | 514 Browser* popup_browser = chrome::FindLastActive(); |
511 ASSERT_NE(popup_browser, browser()); | 515 ASSERT_NE(popup_browser, browser()); |
512 | 516 |
513 // Showing an alert will raise the tab over the popup. | 517 // Showing an alert will raise the tab over the popup. |
514 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); | 518 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
515 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 519 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
516 | 520 |
517 // Verify that after the dialog was closed, the popup is in front again. | 521 // Verify that after the dialog is closed, the popup is in front again. |
518 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); | 522 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
519 app_modal::JavaScriptAppModalDialog* js_dialog = | 523 app_modal::JavaScriptAppModalDialog* js_dialog = |
520 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); | 524 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
521 | 525 |
522 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); | 526 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
523 js_dialog->native_dialog()->AcceptAppModalDialog(); | 527 js_dialog->native_dialog()->AcceptAppModalDialog(); |
524 waiter.WaitForActivation(); | 528 waiter.WaitForActivation(); |
525 ASSERT_EQ(popup_browser, chrome::FindLastActive()); | 529 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
526 } | 530 } |
527 | 531 |
| 532 // Verify that app modal prompts can't be used to create pop unders, while the |
| 533 // new auto-dismissing JavaScript dialogs are enabled. |
| 534 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, |
| 535 ModalPopUnderAutoDismissingDialogs) { |
| 536 base::test::ScopedFeatureList feature_list; |
| 537 feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs); |
| 538 |
| 539 // One tab to test in. |
| 540 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 541 WebContents* tab = tab_strip->GetActiveWebContents(); |
| 542 EXPECT_EQ(1, tab_strip->count()); |
| 543 |
| 544 // One blank tab for later. |
| 545 ui_test_utils::NavigateToURLWithDisposition( |
| 546 browser(), GURL(url::kAboutBlankURL), |
| 547 WindowOpenDisposition::NEW_BACKGROUND_TAB, |
| 548 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 549 EXPECT_EQ(2, tab_strip->count()); |
| 550 ASSERT_EQ(0, tab_strip->GetIndexOfWebContents(tab)); |
| 551 |
| 552 // Show a popup. |
| 553 JavaScriptDialogTabHelper* js_helper = |
| 554 JavaScriptDialogTabHelper::FromWebContents(tab); |
| 555 GURL url( |
| 556 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); |
| 557 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 558 ->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 559 std::string(), CONTENT_SETTING_ALLOW); |
| 560 |
| 561 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 562 |
| 563 Browser* popup_browser = chrome::FindLastActive(); |
| 564 ASSERT_NE(popup_browser, browser()); |
| 565 |
| 566 // Showing an alert will raise the tab over the popup. |
| 567 scoped_refptr<content::MessageLoopRunner> runner = |
| 568 new content::MessageLoopRunner; |
| 569 js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure()); |
| 570 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
| 571 runner->Run(); |
| 572 |
| 573 // Verify that after the dialog is closed, the popup is in front again. |
| 574 ui_test_utils::BrowserActivationWaiter waiter(popup_browser); |
| 575 tab_strip->ActivateTabAt(1, true); |
| 576 waiter.WaitForActivation(); |
| 577 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 578 } |
| 579 |
528 #if defined(ENABLE_EXTENSIONS) | 580 #if defined(ENABLE_EXTENSIONS) |
529 #define MAYBE_ModalPopUnderViaGuestView DISABLED_ModalPopUnderViaGuestView | 581 #define MAYBE_ModalPopUnderViaGuestView DISABLED_ModalPopUnderViaGuestView |
530 #else | 582 #else |
531 #define MAYBE_ModalPopUnderViaGuestView ModalPopUnderViaGuestView | 583 #define MAYBE_ModalPopUnderViaGuestView ModalPopUnderViaGuestView |
532 #endif | 584 #endif |
533 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, | 585 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, |
534 MAYBE_ModalPopUnderViaGuestView) { | 586 MAYBE_ModalPopUnderViaGuestView) { |
535 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 587 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
536 GURL url( | 588 GURL url( |
537 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); | 589 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 698 |
647 wait_for_new_tab.Wait(); | 699 wait_for_new_tab.Wait(); |
648 | 700 |
649 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 701 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
650 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 702 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
651 // Check that we create the background tab. | 703 // Check that we create the background tab. |
652 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 704 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
653 } | 705 } |
654 | 706 |
655 } // namespace | 707 } // namespace |
OLD | NEW |