Commit 31f87366 authored by avi's avatar avi Committed by Commit bot

Turn on auto-dismissing dialogs for trunk builds.

BUG=629964

Review-Url: https://codereview.chromium.org/2784533002
Cr-Commit-Position: refs/heads/master@{#468636}
parent 82ca516c
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
...@@ -30,8 +32,6 @@ ...@@ -30,8 +32,6 @@
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "chromeos/login/auth/key.h" #include "chromeos/login/auth/key.h"
#include "chromeos/login/auth/user_context.h" #include "chromeos/login/auth/user_context.h"
#include "components/app_modal/javascript_app_modal_dialog.h"
#include "components/app_modal/native_app_modal_dialog.h"
#include "components/browser_sync/browser_sync_switches.h" #include "components/browser_sync/browser_sync_switches.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/account_id/account_id.h" #include "components/signin/core/account_id/account_id.h"
...@@ -54,8 +54,6 @@ ...@@ -54,8 +54,6 @@
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
using app_modal::AppModalDialog;
using app_modal::JavaScriptAppModalDialog;
using net::test_server::BasicHttpResponse; using net::test_server::BasicHttpResponse;
using net::test_server::HttpRequest; using net::test_server::HttpRequest;
using net::test_server::HttpResponse; using net::test_server::HttpResponse;
...@@ -802,12 +800,19 @@ IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) { ...@@ -802,12 +800,19 @@ IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) {
StartNewUserSession(false); StartNewUserSession(false);
// Try to open a page from google.com. // Try to open a page from google.com.
Browser* browser = Browser* browser = FindOrCreateVisibleBrowser(profile());
FindOrCreateVisibleBrowser(profile());
ui_test_utils::NavigateToURLWithDisposition( ui_test_utils::NavigateToURLWithDisposition(
browser, fake_google_page_url_, WindowOpenDisposition::CURRENT_TAB, browser, fake_google_page_url_, WindowOpenDisposition::CURRENT_TAB,
ui_test_utils::BROWSER_TEST_NONE); ui_test_utils::BROWSER_TEST_NONE);
// JavaScript dialog wait setup.
content::WebContents* tab =
browser->tab_strip_model()->GetActiveWebContents();
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(tab);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
// Wait until we get send merge session request. // Wait until we get send merge session request.
WaitForMergeSessionToStart(); WaitForMergeSessionToStart();
...@@ -830,11 +835,8 @@ IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) { ...@@ -830,11 +835,8 @@ IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) {
// Check that real page is no longer blocked by the throttle and that the // Check that real page is no longer blocked by the throttle and that the
// real page pops up JS dialog. // real page pops up JS dialog.
AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); js_helper->HandleJavaScriptDialog(tab, true, nullptr);
JavaScriptAppModalDialog* js_dialog =
static_cast<JavaScriptAppModalDialog*>(dialog);
js_dialog->native_dialog()->AcceptAppModalDialog();
ui_test_utils::GetCurrentTabTitle(browser, &title); ui_test_utils::GetCurrentTabTitle(browser, &title);
DVLOG(1) << "Loaded page at the end : " << title; DVLOG(1) << "Loaded page at the end : " << title;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -18,11 +19,10 @@ ...@@ -18,11 +19,10 @@
#include "chrome/browser/extensions/extension_with_management_policy_apitest.h" #include "chrome/browser/extensions/extension_with_management_policy_apitest.h"
#include "chrome/browser/extensions/test_extension_dir.h" #include "chrome/browser/extensions/test_extension_dir.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/app_modal/javascript_dialog_extensions_client.h"
#include "components/app_modal/javascript_dialog_manager.h"
#include "content/public/browser/javascript_dialog_manager.h" #include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -89,107 +89,6 @@ testing::AssertionResult CheckStyleInjection(Browser* browser, ...@@ -89,107 +89,6 @@ testing::AssertionResult CheckStyleInjection(Browser* browser,
return testing::AssertionSuccess(); return testing::AssertionSuccess();
} }
class DialogClient;
// A helper class to hijack the dialog manager's ExtensionsClient, so that we
// know when dialogs are being opened.
// NOTE: The default implementation of the JavaScriptDialogExtensionsClient
// doesn't do anything, so it's safe to override it. If, at some stage, this
// has behavior (like if we move this into app shell), we'll need to update
// this (by, e.g., making DialogClient a wrapper around the implementation).
class DialogHelper {
public:
explicit DialogHelper(content::WebContents* web_contents);
~DialogHelper();
// Notifies the DialogHelper that a dialog was opened. Runs |quit_closure_|,
// if it is non-null.
void DialogOpened();
// Closes any active dialogs.
void CloseDialogs();
void set_quit_closure(const base::Closure& quit_closure) {
quit_closure_ = quit_closure;
}
size_t dialog_count() const { return dialog_count_; }
private:
// The number of dialogs to appear.
size_t dialog_count_;
// The WebContents this helper is associated with.
content::WebContents* web_contents_;
// The dialog manager for |web_contents_|.
content::JavaScriptDialogManager* dialog_manager_;
// The dialog client override.
DialogClient* client_;
// The quit closure to run when a dialog appears.
base::Closure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(DialogHelper);
};
// The client override for the DialogHelper.
class DialogClient : public app_modal::JavaScriptDialogExtensionsClient {
public:
explicit DialogClient(DialogHelper* helper) : helper_(helper) {}
~DialogClient() override {}
void set_helper(DialogHelper* helper) { helper_ = helper; }
private:
// app_modal::JavaScriptDialogExtensionsClient:
void OnDialogOpened(content::WebContents* web_contents) override {
if (helper_)
helper_->DialogOpened();
}
void OnDialogClosed(content::WebContents* web_contents) override {}
bool GetExtensionName(content::WebContents* web_contents,
const GURL& origin_url,
std::string* name_out) override {
return false;
}
// The dialog helper to notify of any open dialogs.
DialogHelper* helper_;
DISALLOW_COPY_AND_ASSIGN(DialogClient);
};
DialogHelper::DialogHelper(content::WebContents* web_contents)
: dialog_count_(0),
web_contents_(web_contents),
dialog_manager_(nullptr),
client_(nullptr) {
app_modal::JavaScriptDialogManager* dialog_manager_impl =
app_modal::JavaScriptDialogManager::GetInstance();
client_ = new DialogClient(this);
dialog_manager_impl->SetExtensionsClient(base::WrapUnique(client_));
dialog_manager_ =
web_contents_->GetDelegate()->GetJavaScriptDialogManager(web_contents_);
}
DialogHelper::~DialogHelper() {
client_->set_helper(nullptr);
}
void DialogHelper::CloseDialogs() {
dialog_manager_->CancelDialogs(web_contents_, false);
}
void DialogHelper::DialogOpened() {
++dialog_count_;
if (!quit_closure_.is_null()) {
quit_closure_.Run();
quit_closure_ = base::Closure();
}
}
// Runs all pending tasks in the renderer associated with |web_contents|, and // Runs all pending tasks in the renderer associated with |web_contents|, and
// then all pending tasks in the browser process. // then all pending tasks in the browser process.
// Returns true on success. // Returns true on success.
...@@ -546,9 +445,10 @@ IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptBlockingScript) { ...@@ -546,9 +445,10 @@ IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptBlockingScript) {
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
DialogHelper dialog_helper(web_contents); JavaScriptDialogTabHelper* js_helper =
base::RunLoop run_loop; JavaScriptDialogTabHelper::FromWebContents(web_contents);
dialog_helper.set_quit_closure(run_loop.QuitClosure()); base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
ExtensionTestMessageListener listener("done", false); ExtensionTestMessageListener listener("done", false);
listener.set_extension_id(ext2->id()); listener.set_extension_id(ext2->id());
...@@ -558,12 +458,11 @@ IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptBlockingScript) { ...@@ -558,12 +458,11 @@ IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptBlockingScript) {
browser(), embedded_test_server()->GetURL("/empty.html"), browser(), embedded_test_server()->GetURL("/empty.html"),
WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
run_loop.Run(); dialog_wait.Run();
// Right now, the alert dialog is showing and blocking injection of anything // Right now, the alert dialog is showing and blocking injection of anything
// after it, so the listener shouldn't be satisfied. // after it, so the listener shouldn't be satisfied.
EXPECT_FALSE(listener.was_satisfied()); EXPECT_FALSE(listener.was_satisfied());
EXPECT_EQ(1u, dialog_helper.dialog_count()); js_helper->HandleJavaScriptDialog(web_contents, true, nullptr);
dialog_helper.CloseDialogs();
// After closing the dialog, the rest of the scripts should be able to // After closing the dialog, the rest of the scripts should be able to
// inject. // inject.
...@@ -599,21 +498,22 @@ IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ...@@ -599,21 +498,22 @@ IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
DialogHelper dialog_helper(web_contents); JavaScriptDialogTabHelper* js_helper =
base::RunLoop run_loop; JavaScriptDialogTabHelper::FromWebContents(web_contents);
dialog_helper.set_quit_closure(run_loop.QuitClosure()); base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
ExtensionTestMessageListener listener("done", false); ExtensionTestMessageListener listener("done", false);
listener.set_extension_id(ext2->id()); listener.set_extension_id(ext2->id());
// Navitate! // Navigate!
ui_test_utils::NavigateToURLWithDisposition( ui_test_utils::NavigateToURLWithDisposition(
browser(), embedded_test_server()->GetURL("/empty.html"), browser(), embedded_test_server()->GetURL("/empty.html"),
WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
// Now, instead of closing the dialog, just close the tab. Later scripts // Now, instead of closing the dialog, just close the tab. Later scripts
// should never get a chance to run (and we shouldn't crash). // should never get a chance to run (and we shouldn't crash).
run_loop.Run(); dialog_wait.Run();
EXPECT_FALSE(listener.was_satisfied()); EXPECT_FALSE(listener.was_satisfied());
EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
browser()->tab_strip_model()->active_index(), 0)); browser()->tab_strip_model()->active_index(), 0));
...@@ -637,22 +537,22 @@ IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ...@@ -637,22 +537,22 @@ IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
DialogHelper dialog_helper(web_contents); JavaScriptDialogTabHelper* js_helper =
base::RunLoop run_loop; JavaScriptDialogTabHelper::FromWebContents(web_contents);
dialog_helper.set_quit_closure(run_loop.QuitClosure()); base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
// Navigate! // Navigate!
ui_test_utils::NavigateToURLWithDisposition( ui_test_utils::NavigateToURLWithDisposition(
browser(), embedded_test_server()->GetURL("/empty.html"), browser(), embedded_test_server()->GetURL("/empty.html"),
WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
run_loop.Run(); dialog_wait.Run();
// The extension will have injected at idle, but it should only inject once. // The extension will have injected at idle, but it should only inject once.
EXPECT_EQ(1u, dialog_helper.dialog_count()); js_helper->HandleJavaScriptDialog(web_contents, true, nullptr);
dialog_helper.CloseDialogs();
EXPECT_TRUE(RunAllPending(web_contents)); EXPECT_TRUE(RunAllPending(web_contents));
EXPECT_EQ(1u, dialog_helper.dialog_count()); EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
} }
// Bug fix for crbug.com/507461. // Bug fix for crbug.com/507461.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
...@@ -12,10 +13,10 @@ ...@@ -12,10 +13,10 @@
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/app_modal/app_modal_dialog.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
...@@ -158,10 +159,15 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) { ...@@ -158,10 +159,15 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) {
EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab)); EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab));
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(tab);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
// Cancel the dialog. // Cancel the dialog.
alert->CloseModalDialog(); js_helper->HandleJavaScriptDialog(tab, false, nullptr);
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16("done()")); tab->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16("done()"));
const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
...@@ -523,7 +522,7 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Regress427477) { ...@@ -523,7 +522,7 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Regress427477) {
ASSERT_EQ(0, GetBlockedContentsCount()); ASSERT_EQ(0, GetBlockedContentsCount());
} }
// Verify that app modal prompts can't be used to create pop unders. // Verify that JavaScript dialogs can't be used to create pop unders.
IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) { IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) {
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
GURL url( GURL url(
...@@ -543,20 +542,20 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) { ...@@ -543,20 +542,20 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) {
// https://crbug.com/687732 for details. // https://crbug.com/687732 for details.
ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); ui_test_utils::BrowserActivationWaiter alert_waiter(browser());
#endif #endif
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(tab);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
if (chrome::FindLastActive() != browser()) if (chrome::FindLastActive() != browser())
alert_waiter.WaitForActivation(); alert_waiter.WaitForActivation();
#endif #endif
// Verify that after the dialog is closed, the popup is in front again. // Verify that after the dialog is closed, the popup is in front again.
ASSERT_TRUE(dialog->IsJavaScriptModalDialog());
app_modal::JavaScriptAppModalDialog* js_dialog =
static_cast<app_modal::JavaScriptAppModalDialog*>(dialog);
ui_test_utils::BrowserActivationWaiter waiter(popup_browser); ui_test_utils::BrowserActivationWaiter waiter(popup_browser);
js_dialog->native_dialog()->AcceptAppModalDialog(); js_helper->HandleJavaScriptDialog(tab, true, nullptr);
waiter.WaitForActivation(); waiter.WaitForActivation();
ASSERT_EQ(popup_browser, chrome::FindLastActive()); ASSERT_EQ(popup_browser, chrome::FindLastActive());
} }
...@@ -587,20 +586,20 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderWindowOpener) { ...@@ -587,20 +586,20 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderWindowOpener) {
// https://crbug.com/687732 for details. // https://crbug.com/687732 for details.
ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); ui_test_utils::BrowserActivationWaiter alert_waiter(browser());
#endif #endif
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(tab);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
if (chrome::FindLastActive() != browser()) if (chrome::FindLastActive() != browser())
alert_waiter.WaitForActivation(); alert_waiter.WaitForActivation();
#endif #endif
// Verify that after the dialog is closed, the popup is in front again. // Verify that after the dialog is closed, the popup is in front again.
ASSERT_TRUE(dialog->IsJavaScriptModalDialog());
app_modal::JavaScriptAppModalDialog* js_dialog =
static_cast<app_modal::JavaScriptAppModalDialog*>(dialog);
ui_test_utils::BrowserActivationWaiter waiter(popup_browser); ui_test_utils::BrowserActivationWaiter waiter(popup_browser);
js_dialog->native_dialog()->AcceptAppModalDialog(); js_helper->HandleJavaScriptDialog(tab, true, nullptr);
waiter.WaitForActivation(); waiter.WaitForActivation();
ASSERT_EQ(popup_browser, chrome::FindLastActive()); ASSERT_EQ(popup_browser, chrome::FindLastActive());
} }
...@@ -625,20 +624,20 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderSubframe) { ...@@ -625,20 +624,20 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderSubframe) {
// https://crbug.com/687732 for details. // https://crbug.com/687732 for details.
ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); ui_test_utils::BrowserActivationWaiter alert_waiter(browser());
#endif #endif
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(tab);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
if (chrome::FindLastActive() != browser()) if (chrome::FindLastActive() != browser())
alert_waiter.WaitForActivation(); alert_waiter.WaitForActivation();
#endif #endif
// Verify that after the dialog is closed, the popup is in front again. // Verify that after the dialog is closed, the popup is in front again.
ASSERT_TRUE(dialog->IsJavaScriptModalDialog());
app_modal::JavaScriptAppModalDialog* js_dialog =
static_cast<app_modal::JavaScriptAppModalDialog*>(dialog);
ui_test_utils::BrowserActivationWaiter waiter(popup_browser); ui_test_utils::BrowserActivationWaiter waiter(popup_browser);
js_dialog->native_dialog()->AcceptAppModalDialog(); js_helper->HandleJavaScriptDialog(tab, true, nullptr);
waiter.WaitForActivation(); waiter.WaitForActivation();
ASSERT_EQ(popup_browser, chrome::FindLastActive()); ASSERT_EQ(popup_browser, chrome::FindLastActive());
} }
...@@ -663,69 +662,12 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderNoOpener) { ...@@ -663,69 +662,12 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnderNoOpener) {
// https://crbug.com/687732 for details. // https://crbug.com/687732 for details.
ui_test_utils::BrowserActivationWaiter alert_waiter(browser()); ui_test_utils::BrowserActivationWaiter alert_waiter(browser());
#endif #endif
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
#if !defined(OS_MACOSX)
if (chrome::FindLastActive() != browser())
alert_waiter.WaitForActivation();
#endif
// Verify that after the dialog is closed, the popup is in front again.
ASSERT_TRUE(dialog->IsJavaScriptModalDialog());
app_modal::JavaScriptAppModalDialog* js_dialog =
static_cast<app_modal::JavaScriptAppModalDialog*>(dialog);
ui_test_utils::BrowserActivationWaiter waiter(popup_browser);
js_dialog->native_dialog()->AcceptAppModalDialog();
waiter.WaitForActivation();
ASSERT_EQ(popup_browser, chrome::FindLastActive());
}
// Verify that app modal prompts can't be used to create pop unders, while the
// new auto-dismissing JavaScript dialogs are enabled.
IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
ModalPopUnderAutoDismissingDialogs) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs);
// One tab to test in.
TabStripModel* tab_strip = browser()->tab_strip_model();
WebContents* tab = tab_strip->GetActiveWebContents();
EXPECT_EQ(1, tab_strip->count());
// One blank tab for later.
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL(url::kAboutBlankURL),
WindowOpenDisposition::NEW_BACKGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_EQ(2, tab_strip->count());
ASSERT_EQ(0, tab_strip->GetIndexOfWebContents(tab));
// Show a popup.
JavaScriptDialogTabHelper* js_helper = JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(tab); JavaScriptDialogTabHelper::FromWebContents(tab);
GURL url( base::RunLoop dialog_wait;
embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
HostContentSettingsMapFactory::GetForProfile(browser()->profile())
->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS,
std::string(), CONTENT_SETTING_ALLOW);
NavigateAndCheckPopupShown(url, ExpectPopup);
Browser* popup_browser = chrome::FindLastActive();
ASSERT_NE(popup_browser, browser());
// Showing an alert will raise the tab over the popup.
#if !defined(OS_MACOSX)
// Mac doesn't activate the browser during modal dialogs, see
// https://crbug.com/687732 for details.
ui_test_utils::BrowserActivationWaiter alert_waiter(browser());
#endif
scoped_refptr<content::MessageLoopRunner> runner =
new content::MessageLoopRunner;
js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure());
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
runner->Run(); dialog_wait.Run();
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
if (chrome::FindLastActive() != browser()) if (chrome::FindLastActive() != browser())
alert_waiter.WaitForActivation(); alert_waiter.WaitForActivation();
...@@ -733,7 +675,7 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ...@@ -733,7 +675,7 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
// Verify that after the dialog is closed, the popup is in front again. // Verify that after the dialog is closed, the popup is in front again.
ui_test_utils::BrowserActivationWaiter waiter(popup_browser); ui_test_utils::BrowserActivationWaiter waiter(popup_browser);
tab_strip->ActivateTabAt(1, true); js_helper->HandleJavaScriptDialog(tab, true, nullptr);
waiter.WaitForActivation(); waiter.WaitForActivation();
ASSERT_EQ(popup_browser, chrome::FindLastActive()); ASSERT_EQ(popup_browser, chrome::FindLastActive());
} }
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "chrome/browser/ui/extensions/app_launch_params.h" #include "chrome/browser/ui/extensions/app_launch_params.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
#include "chrome/browser/ui/search/search_tab_helper.h" #include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h" #include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/startup/startup_browser_creator_impl.h" #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
...@@ -492,10 +493,14 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) { ...@@ -492,10 +493,14 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) {
EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
WebContents* second_tab = browser()->tab_strip_model()->GetWebContentsAt(1); WebContents* second_tab = browser()->tab_strip_model()->GetWebContentsAt(1);
ASSERT_TRUE(second_tab); ASSERT_TRUE(second_tab);
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(second_tab);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
second_tab->GetMainFrame()->ExecuteJavaScriptForTests( second_tab->GetMainFrame()->ExecuteJavaScriptForTests(
ASCIIToUTF16("alert('Activate!');")); ASCIIToUTF16("alert('Activate!');"));
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
alert->CloseModalDialog(); js_helper->HandleJavaScriptDialog(second_tab, true, nullptr);
EXPECT_EQ(2, browser()->tab_strip_model()->count()); EXPECT_EQ(2, browser()->tab_strip_model()->count());
EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
} }
...@@ -600,17 +605,19 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_CrossProcessNavCancelsDialogs) { ...@@ -600,17 +605,19 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_CrossProcessNavCancelsDialogs) {
// even if the renderer tries to synchronously create more. // even if the renderer tries to synchronously create more.
// See http://crbug.com/312490. // See http://crbug.com/312490.
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(contents);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
contents->GetMainFrame()->ExecuteJavaScriptForTests( contents->GetMainFrame()->ExecuteJavaScriptForTests(
ASCIIToUTF16("alert('one'); alert('two');")); ASCIIToUTF16("alert('one'); alert('two');"));
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
EXPECT_TRUE(alert->IsValid()); EXPECT_TRUE(js_helper->IsShowingDialogForTesting());
AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
EXPECT_TRUE(dialog_queue->HasActiveDialog());
// A cross-site navigation should force the dialog to close. // A cross-site navigation should force the dialog to close.
GURL url2("http://www.example.com/empty.html"); GURL url2("http://www.example.com/empty.html");
ui_test_utils::NavigateToURL(browser(), url2); ui_test_utils::NavigateToURL(browser(), url2);
EXPECT_FALSE(dialog_queue->HasActiveDialog()); EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
// Make sure input events still work in the renderer process. // Make sure input events still work in the renderer process.
EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents()); EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents());
...@@ -657,14 +664,16 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) { ...@@ -657,14 +664,16 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) {
browser(), GURL("data:text/html, <html><body></body></html>")); browser(), GURL("data:text/html, <html><body></body></html>"));
// Create an iframe that opens an alert dialog. // Create an iframe that opens an alert dialog.
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(contents);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
contents->GetMainFrame()->ExecuteJavaScriptForTests( contents->GetMainFrame()->ExecuteJavaScriptForTests(
ASCIIToUTF16("f = document.createElement('iframe');" ASCIIToUTF16("f = document.createElement('iframe');"
"f.srcdoc = '<script>alert(1)</script>';" "f.srcdoc = '<script>alert(1)</script>';"
"document.body.appendChild(f);")); "document.body.appendChild(f);"));
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
EXPECT_TRUE(alert->IsValid()); EXPECT_TRUE(js_helper->IsShowingDialogForTesting());
AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
EXPECT_TRUE(dialog_queue->HasActiveDialog());
// Crash the renderer process and ensure the dialog is gone. // Crash the renderer process and ensure the dialog is gone.
content::RenderProcessHost* child_process = contents->GetRenderProcessHost(); content::RenderProcessHost* child_process = contents->GetRenderProcessHost();
...@@ -673,7 +682,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) { ...@@ -673,7 +682,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) {
content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
child_process->Shutdown(0, false); child_process->Shutdown(0, false);
crash_observer.Wait(); crash_observer.Wait();
EXPECT_FALSE(dialog_queue->HasActiveDialog()); EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
// Make sure subsequent navigations work. // Make sure subsequent navigations work.
GURL url2("data:text/html,foo"); GURL url2("data:text/html,foo");
...@@ -683,17 +692,19 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) { ...@@ -683,17 +692,19 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) {
// Make sure modal dialogs within a guestview are closed when an interstitial // Make sure modal dialogs within a guestview are closed when an interstitial
// page is showing. See crbug.com/482380. // page is showing. See crbug.com/482380.
IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCancelsGuestViewDialogs) { IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCancelsGuestViewDialogs) {
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(contents);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
// Navigate to a PDF, which is loaded within a guestview. // Navigate to a PDF, which is loaded within a guestview.
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
GURL pdf_with_dialog(embedded_test_server()->GetURL("/alert_dialog.pdf")); GURL pdf_with_dialog(embedded_test_server()->GetURL("/alert_dialog.pdf"));
ui_test_utils::NavigateToURL(browser(), pdf_with_dialog); ui_test_utils::NavigateToURL(browser(), pdf_with_dialog);
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
EXPECT_TRUE(alert->IsValid()); EXPECT_TRUE(js_helper->IsShowingDialogForTesting());
AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
EXPECT_TRUE(dialog_queue->HasActiveDialog());
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
TestInterstitialPage* interstitial = TestInterstitialPage* interstitial =
new TestInterstitialPage(contents, false, GURL()); new TestInterstitialPage(contents, false, GURL());
...@@ -701,7 +712,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCancelsGuestViewDialogs) { ...@@ -701,7 +712,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCancelsGuestViewDialogs) {
// The interstitial should have closed the dialog. // The interstitial should have closed the dialog.
EXPECT_TRUE(contents->ShowingInterstitialPage()); EXPECT_TRUE(contents->ShowingInterstitialPage());
EXPECT_FALSE(dialog_queue->HasActiveDialog()); EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
interstitial->DontProceed(); interstitial->DontProceed();
} }
...@@ -1886,12 +1897,14 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) { ...@@ -1886,12 +1897,14 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
JavaScriptDialogTabHelper* js_helper =
JavaScriptDialogTabHelper::FromWebContents(contents);
base::RunLoop dialog_wait;
js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
contents->GetMainFrame()->ExecuteJavaScriptForTests( contents->GetMainFrame()->ExecuteJavaScriptForTests(
ASCIIToUTF16("alert('Dialog showing!');")); ASCIIToUTF16("alert('Dialog showing!');"));
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); dialog_wait.Run();
EXPECT_TRUE(alert->IsValid()); EXPECT_TRUE(js_helper->IsShowingDialogForTesting());
AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
EXPECT_TRUE(dialog_queue->HasActiveDialog());
TestInterstitialPage* interstitial = TestInterstitialPage* interstitial =
new TestInterstitialPage(contents, false, GURL()); new TestInterstitialPage(contents, false, GURL());
...@@ -1899,7 +1912,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) { ...@@ -1899,7 +1912,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) {
// The interstitial should have closed the dialog. // The interstitial should have closed the dialog.
EXPECT_TRUE(contents->ShowingInterstitialPage()); EXPECT_TRUE(contents->ShowingInterstitialPage());
EXPECT_FALSE(dialog_queue->HasActiveDialog()); EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
// Don't proceed and wait for interstitial to detach. This doesn't destroy // Don't proceed and wait for interstitial to detach. This doesn't destroy
// |contents|. // |contents|.
......
...@@ -88,6 +88,10 @@ void JavaScriptDialogTabHelper::SetDialogShownCallbackForTesting( ...@@ -88,6 +88,10 @@ void JavaScriptDialogTabHelper::SetDialogShownCallbackForTesting(
dialog_shown_ = callback; dialog_shown_ = callback;
} }
bool JavaScriptDialogTabHelper::IsShowingDialogForTesting() const {
return !!dialog_;
}
void JavaScriptDialogTabHelper::RunJavaScriptDialog( void JavaScriptDialogTabHelper::RunJavaScriptDialog(
content::WebContents* alerting_web_contents, content::WebContents* alerting_web_contents,
const GURL& origin_url, const GURL& origin_url,
......
...@@ -37,6 +37,7 @@ class JavaScriptDialogTabHelper ...@@ -37,6 +37,7 @@ class JavaScriptDialogTabHelper
~JavaScriptDialogTabHelper() override; ~JavaScriptDialogTabHelper() override;
void SetDialogShownCallbackForTesting(base::Closure callback); void SetDialogShownCallbackForTesting(base::Closure callback);
bool IsShowingDialogForTesting() const;
// JavaScriptDialogManager: // JavaScriptDialogManager:
void RunJavaScriptDialog(content::WebContents* web_contents, void RunJavaScriptDialog(content::WebContents* web_contents,
......
...@@ -112,6 +112,24 @@ ...@@ -112,6 +112,24 @@
] ]
} }
], ],
"AutoDismissingDialogs": [
{
"platforms": [
"chromeos",
"linux",
"mac",
"win"
],
"experiments": [
{
"name": "Enabled",
"enable_features": [
"AutoDismissingDialogs"
]
}
]
}
],
"AutodetectEncoding": [ "AutodetectEncoding": [
{ {
"platforms": [ "platforms": [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment