diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/app_modal_dialog.cc | 24 | ||||
-rw-r--r-- | chrome/browser/app_modal_dialog.h | 3 | ||||
-rw-r--r-- | chrome/browser/browser_browsertest.cc | 19 | ||||
-rw-r--r-- | chrome/browser/browser_uitest.cc | 19 |
4 files changed, 43 insertions, 22 deletions
diff --git a/chrome/browser/app_modal_dialog.cc b/chrome/browser/app_modal_dialog.cc index afabff8..aa876cc 100644 --- a/chrome/browser/app_modal_dialog.cc +++ b/chrome/browser/app_modal_dialog.cc @@ -50,6 +50,13 @@ void AppModalDialog::Observe(NotificationType type, CloseModalDialog(); } +void AppModalDialog::SendCloseNotification() { + NotificationService::current()->Notify( + NotificationType::APP_MODAL_DIALOG_CLOSED, + Source<AppModalDialog>(this), + NotificationService::NoDetails()); +} + void AppModalDialog::InitNotifications() { // Make sure we get navigation notifications so we know when our parent // contents will disappear or navigate to a different page. @@ -70,6 +77,11 @@ void AppModalDialog::ShowModalDialog() { tab_contents_->Activate(); CreateAndShowDialog(); + + NotificationService::current()->Notify( + NotificationType::APP_MODAL_DIALOG_SHOWN, + Source<AppModalDialog>(this), + NotificationService::NoDetails()); } void AppModalDialog::OnCancel() { @@ -85,6 +97,8 @@ void AppModalDialog::OnCancel() { tab_contents_->OnJavaScriptMessageBoxClosed(reply_msg_, false, std::wstring()); } + + SendCloseNotification(); } void AppModalDialog::OnAccept(const std::wstring& prompt_text, @@ -98,10 +112,14 @@ void AppModalDialog::OnAccept(const std::wstring& prompt_text, if (suppress_js_messages) tab_contents()->set_suppress_javascript_messages(true); } + + SendCloseNotification(); } void AppModalDialog::OnClose() { - if (tab_contents_) { - tab_contents_->OnJavaScriptMessageBoxWindowDestroyed(); - } + if (tab_contents_) { + tab_contents_->OnJavaScriptMessageBoxWindowDestroyed(); + } + + SendCloseNotification(); } diff --git a/chrome/browser/app_modal_dialog.h b/chrome/browser/app_modal_dialog.h index 325c222..8d44d64 100644 --- a/chrome/browser/app_modal_dialog.h +++ b/chrome/browser/app_modal_dialog.h @@ -95,6 +95,9 @@ class AppModalDialog : public NotificationObserver { const NotificationSource& source, const NotificationDetails& details); + // Sends APP_MODAL_DIALOG_CLOSED notification. + void SendCloseNotification(); + NotificationRegistrar registrar_; // A reference to the platform native dialog box. diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index 69ef1b8..f209837 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -5,9 +5,11 @@ #include <string> #include "app/l10n_util.h" +#include "chrome/browser/app_modal_dialog.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/page_transition_types.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" #include "testing/gtest/include/gtest/gtest.h" @@ -79,3 +81,20 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, Title) { ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title)); EXPECT_EQ(WideToUTF16(test_title), tab_title); } + +IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) { + GURL url(ui_test_utils::GetTestUrl(L".", L"title1.html")); + ui_test_utils::NavigateToURL(browser(), url); + browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, + true, 0, false, NULL); + EXPECT_EQ(2, browser()->tab_count()); + EXPECT_EQ(0, browser()->selected_index()); + TabContents* second_tab = browser()->GetTabContentsAt(1); + ASSERT_TRUE(second_tab); + second_tab->render_view_host()->ExecuteJavascriptInWebFrame(L"", + L"alert('Activate!');"); + AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); + alert->CloseModalDialog(); + EXPECT_EQ(2, browser()->tab_count()); + EXPECT_EQ(1, browser()->selected_index()); +} diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc index a65499f..57fc6b5 100644 --- a/chrome/browser/browser_uitest.cc +++ b/chrome/browser/browser_uitest.cc @@ -113,25 +113,6 @@ TEST_F(BrowserTest, WindowsSessionEnd) { } #endif -// This test is flakey, see bug 5668 for details. -TEST_F(BrowserTest, DISABLED_JavascriptAlertActivatesTab) { - scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); - int start_index; - ASSERT_TRUE(window->GetActiveTabIndex(&start_index)); - ASSERT_TRUE(window->AppendTab(GURL("about:blank"))); - int javascript_tab_index; - ASSERT_TRUE(window->GetActiveTabIndex(&javascript_tab_index)); - scoped_refptr<TabProxy> javascript_tab = window->GetActiveTab(); - ASSERT_TRUE(javascript_tab.get()); - // Switch back to the starting tab, then send the second tab a javascript - // alert, which should force it to become active. - ASSERT_TRUE(window->ActivateTab(start_index)); - ASSERT_TRUE( - javascript_tab->NavigateToURLAsync(GURL("javascript:alert('Alert!')"))); - ASSERT_TRUE(window->WaitForTabToBecomeActive(javascript_tab_index, - action_max_timeout_ms())); -} - // Test that scripts can fork a new renderer process for a tab in a particular // case (which matches following a link in Gmail). The script must open a new // tab, set its window.opener to null, and redirect it to a cross-site URL. |