Convert JavascriptAlertActivatesTab to browser_tests framework.
This should make it non-flaky, so I un-disabled the test. I also added necessary plumbing so we can wait for AppModalDialog to appear and close it. TEST=Covered by browser_tests. http://crbug.com/16062 Review URL: http://codereview.chromium.org/149460 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20400 0039d316-1c4b-4281-b951-d872f2087c98
Esse commit está contido em:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -215,6 +215,16 @@ class NotificationType {
|
||||
// Linux.
|
||||
ACTIVE_WINDOW_CHANGED,
|
||||
|
||||
// Application-modal dialogs -----------------------------------------------
|
||||
|
||||
// Sent after an application-modal dialog has been shown. The source
|
||||
// is the dialog.
|
||||
APP_MODAL_DIALOG_SHOWN,
|
||||
|
||||
// Sent after an application-modal dialog has been closed. The source
|
||||
// is the dialog.
|
||||
APP_MODAL_DIALOG_CLOSED,
|
||||
|
||||
// Tabs --------------------------------------------------------------------
|
||||
|
||||
// This notification is sent after a tab has been appended to the
|
||||
|
||||
@@ -194,6 +194,41 @@ class DownloadsCompleteObserver : public DownloadManager::Observer,
|
||||
DISALLOW_COPY_AND_ASSIGN(DownloadsCompleteObserver);
|
||||
};
|
||||
|
||||
// Used to block until an application modal dialog is shown.
|
||||
class AppModalDialogObserver : public NotificationObserver {
|
||||
public:
|
||||
AppModalDialogObserver() {}
|
||||
|
||||
AppModalDialog* WaitForAppModalDialog() {
|
||||
registrar_.Add(this, NotificationType::APP_MODAL_DIALOG_SHOWN,
|
||||
NotificationService::AllSources());
|
||||
dialog_ = NULL;
|
||||
ui_test_utils::RunMessageLoop();
|
||||
DCHECK(dialog_);
|
||||
return dialog_;
|
||||
}
|
||||
|
||||
virtual void Observe(NotificationType type,
|
||||
const NotificationSource& source,
|
||||
const NotificationDetails& details) {
|
||||
if (type == NotificationType::APP_MODAL_DIALOG_SHOWN) {
|
||||
registrar_.Remove(this, NotificationType::APP_MODAL_DIALOG_SHOWN,
|
||||
NotificationService::AllSources());
|
||||
dialog_ = Source<AppModalDialog>(source).ptr();
|
||||
MessageLoopForUI::current()->Quit();
|
||||
} else {
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
NotificationRegistrar registrar_;
|
||||
|
||||
AppModalDialog* dialog_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void RunMessageLoop() {
|
||||
@@ -330,4 +365,9 @@ void WaitForDownloadCount(DownloadManager* download_manager, size_t count) {
|
||||
DownloadsCompleteObserver download_observer(download_manager, count);
|
||||
}
|
||||
|
||||
AppModalDialog* WaitForAppModalDialog() {
|
||||
AppModalDialogObserver observer;
|
||||
return observer.WaitForAppModalDialog();
|
||||
}
|
||||
|
||||
} // namespace ui_test_utils
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "base/string16.h"
|
||||
#include "chrome/common/notification_observer.h"
|
||||
|
||||
class AppModalDialog;
|
||||
class Browser;
|
||||
class DownloadManager;
|
||||
class GURL;
|
||||
@@ -85,6 +86,10 @@ GURL GetTestUrl(const std::wstring& dir, const std::wstring file);
|
||||
// Creates an observer that waits for |download_manager| to report that it
|
||||
// has a total of |count| downloads that have been handles
|
||||
void WaitForDownloadCount(DownloadManager* download_manager, size_t count);
|
||||
|
||||
// Blocks until an application modal dialog is showns and returns it.
|
||||
AppModalDialog* WaitForAppModalDialog();
|
||||
|
||||
}
|
||||
|
||||
#endif // CHROME_TEST_UI_TEST_UTILS_H_
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário