summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 00:37:20 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 00:37:20 +0000
commitfad84eab5e64996804824f2c7b8fce98da13b2cd (patch)
tree2fce4e91880f94c3e94687e9c0521586c37fa916 /chrome/test
parent792e3c941a74c48db7454a945260a0e8b288ffce (diff)
downloadchromium_src-fad84eab5e64996804824f2c7b8fce98da13b2cd.zip
chromium_src-fad84eab5e64996804824f2c7b8fce98da13b2cd.tar.gz
chromium_src-fad84eab5e64996804824f2c7b8fce98da13b2cd.tar.bz2
Adding the capacity to interact with modal dialogs to the automation framework.
This change will be used by Ojan to implement some unload handler tests. TEST=Run the ui tests. Review URL: http://codereview.chromium.org/13113 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/automation/automation.vsprops2
-rw-r--r--chrome/test/automation/automation_messages_internal.h15
-rw-r--r--chrome/test/automation/automation_proxy.cc49
-rw-r--r--chrome/test/automation/automation_proxy.h9
-rw-r--r--chrome/test/automation/automation_proxy_uitest.cc88
5 files changed, 146 insertions, 17 deletions
diff --git a/chrome/test/automation/automation.vsprops b/chrome/test/automation/automation.vsprops
index 4cc3b79..23a5fc4 100644
--- a/chrome/test/automation/automation.vsprops
+++ b/chrome/test/automation/automation.vsprops
@@ -3,7 +3,7 @@
ProjectType="Visual C++"
Version="8.00"
Name="automation"
- InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\skia\using_skia.vsprops"
+ InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)third_party\wtl\using_wtl.vsprops"
>
<Tool
Name="VCCLCompilerTool"
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h
index b71457d..165b606 100644
--- a/chrome/test/automation/automation_messages_internal.h
+++ b/chrome/test/automation/automation_messages_internal.h
@@ -802,14 +802,23 @@ IPC_BEGIN_MESSAGES(Automation, 0)
bool /* success */)
// Queries whether an app modal dialog is currently being shown. (i.e. a
- // javascript alert).
+ // javascript alert) and which buttons it contains.
IPC_MESSAGE_ROUTED0(AutomationMsg_ShowingAppModalDialogRequest)
- IPC_MESSAGE_ROUTED1(AutomationMsg_ShowingAppModalDialogResponse,
- bool /* showing dialog */)
+ IPC_MESSAGE_ROUTED2(AutomationMsg_ShowingAppModalDialogResponse,
+ bool /* showing dialog */,
+ int /* view::DelegateDialog::DialogButton */)
// Returns the ordinal and the number of matches found as a response to
// a AutomationMsg_FindRequest.
IPC_MESSAGE_ROUTED2(AutomationMsg_FindInPageResponse2,
int /* active_ordinal */,
int /* matches_found */)
+
+ // This message triggers the specified button for the currently showing
+ // modal dialog.
+ IPC_MESSAGE_ROUTED1(AutomationMsg_ClickAppModalDialogButtonRequest,
+ int /* view::DelegateDialog::DialogButton */)
+ IPC_MESSAGE_ROUTED1(AutomationMsg_ClickAppModalDialogButtonResponse,
+ bool /* success */)
+
IPC_END_MESSAGES(Automation)
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc
index 348ce0f..60806b5 100644
--- a/chrome/test/automation/automation_proxy.cc
+++ b/chrome/test/automation/automation_proxy.cc
@@ -15,6 +15,7 @@
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
+#include "chrome/views/dialog_delegate.h"
using base::TimeDelta;
using base::TimeTicks;
@@ -302,32 +303,56 @@ bool AutomationProxy::WaitForWindowCountToBecome(int count,
return false;
}
-bool AutomationProxy::GetShowingAppModalDialog(bool* showing_app_modal_dialog) {
- if (!showing_app_modal_dialog) {
+bool AutomationProxy::GetShowingAppModalDialog(
+ bool* showing_app_modal_dialog,
+ views::DialogDelegate::DialogButton* button) {
+ if (!showing_app_modal_dialog || !button) {
NOTREACHED();
return false;
}
IPC::Message* response = NULL;
bool is_timeout = true;
- bool succeeded = SendAndWaitForResponseWithTimeout(
- new AutomationMsg_ShowingAppModalDialogRequest(0), &response,
- AutomationMsg_ShowingAppModalDialogResponse::ID,
- kMaxCommandExecutionTime, &is_timeout);
- if (!succeeded)
+ if (!SendAndWaitForResponseWithTimeout(
+ new AutomationMsg_ShowingAppModalDialogRequest(0), &response,
+ AutomationMsg_ShowingAppModalDialogResponse::ID,
+ kMaxCommandExecutionTime, &is_timeout)) {
return false;
+ }
+ scoped_ptr<IPC::Message> response_deleter(response); // Delete on exit.
if (is_timeout) {
DLOG(ERROR) << "ShowingAppModalDialog did not complete in a timely fashion";
return false;
}
void* iter = NULL;
- if (!response->ReadBool(&iter, showing_app_modal_dialog)) {
- succeeded = false;
+ int button_int = 0;
+ if (!response->ReadBool(&iter, showing_app_modal_dialog) ||
+ !response->ReadInt(&iter, &button_int))
+ return false;
+
+ *button = static_cast<views::DialogDelegate::DialogButton>(button_int);
+ return true;
+}
+
+bool AutomationProxy::ClickAppModalDialogButton(
+ views::DialogDelegate::DialogButton button) {
+ IPC::Message* response = NULL;
+ bool is_timeout = true;
+ if (!SendAndWaitForResponseWithTimeout(
+ new AutomationMsg_ClickAppModalDialogButtonRequest(0, button),
+ &response,
+ AutomationMsg_ClickAppModalDialogButtonResponse::ID,
+ kMaxCommandExecutionTime, &is_timeout)) {
+ return false;
}
- delete response;
+ bool succeeded = false;
+ void* iter = NULL;
+ if (!response->ReadBool(&iter, &succeeded))
+ return false;
+
return succeeded;
}
@@ -336,7 +361,9 @@ bool AutomationProxy::WaitForAppModalDialog(int wait_timeout) {
const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout);
while (TimeTicks::Now() - start < timeout) {
bool dialog_shown = false;
- bool succeeded = GetShowingAppModalDialog(&dialog_shown);
+ views::DialogDelegate::DialogButton button =
+ views::DialogDelegate::DIALOGBUTTON_NONE;
+ bool succeeded = GetShowingAppModalDialog(&dialog_shown, &button);
if (!succeeded) {
// Try again next round, but log it.
DLOG(ERROR) << "GetShowingAppModalDialog returned false";
diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h
index 5621b011..0c147fa 100644
--- a/chrome/test/automation/automation_proxy.h
+++ b/chrome/test/automation/automation_proxy.h
@@ -14,6 +14,7 @@
#include "chrome/common/ipc_message.h"
#include "chrome/test/automation/automation_handle_tracker.h"
#include "chrome/test/automation/automation_messages.h"
+#include "chrome/views/dialog_delegate.h"
class AutomationRequest;
class BrowserProxy;
@@ -109,8 +110,12 @@ class AutomationProxy : public IPC::Channel::Listener,
bool WaitForWindowCountToBecome(int target_count, int wait_timeout);
// Returns whether an app modal dialog window is showing right now (i.e., a
- // javascript alert).
- bool GetShowingAppModalDialog(bool* showing_app_modal_dialog);
+ // javascript alert), and what buttons it contains.
+ bool GetShowingAppModalDialog(bool* showing_app_modal_dialog,
+ views::DialogDelegate::DialogButton* button);
+
+ // Simulates a click on a dialog button.
+ bool ClickAppModalDialogButton(views::DialogDelegate::DialogButton button);
// Block the thread until a modal dialog is displayed. Returns true on
// success.
diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc
index aa24354..ece5fd8 100644
--- a/chrome/test/automation/automation_proxy_uitest.cc
+++ b/chrome/test/automation/automation_proxy_uitest.cc
@@ -17,12 +17,14 @@
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
+#include "chrome/views/dialog_delegate.h"
#include "chrome/views/event.h"
#include "net/base/net_util.h"
class AutomationProxyTest : public UITest {
protected:
AutomationProxyTest() {
+ dom_automation_enabled_ = true;
CommandLine::AppendSwitchWithValue(&launch_arguments_,
switches::kLang,
L"en-us");
@@ -818,3 +820,89 @@ TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) {
EXPECT_TRUE(edit->GetAutocompleteMatches(&matches));
EXPECT_FALSE(matches.empty());
}
+
+TEST_F(AutomationProxyTest, AppModalDialogTest) {
+ scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+ scoped_ptr<TabProxy> tab(browser->GetTab(0));
+ tab.reset(browser->GetTab(0));
+ ASSERT_TRUE(tab.get());
+
+ bool modal_dialog_showing = false;
+ views::DialogDelegate::DialogButton button =
+ views::DialogDelegate::DIALOGBUTTON_NONE;
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &button));
+ EXPECT_FALSE(modal_dialog_showing);
+ EXPECT_EQ(views::DialogDelegate::DIALOGBUTTON_NONE, button);
+
+ // Show a simple alert.
+ std::string content =
+ "data:text/html,<html><head><script>function onload() {"
+ "setTimeout(\"alert('hello');\", 1000); }</script></head>"
+ "<body onload='onload()'></body></html>";
+ tab->NavigateToURL(GURL(content));
+ EXPECT_TRUE(automation()->WaitForAppModalDialog(3000));
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &button));
+ EXPECT_TRUE(modal_dialog_showing);
+ EXPECT_EQ(views::DialogDelegate::DIALOGBUTTON_OK, button);
+
+ // Test that clicking missing button fails graciously and does not close the
+ // dialog.
+ EXPECT_FALSE(automation()->ClickAppModalDialogButton(
+ views::DialogDelegate::DIALOGBUTTON_CANCEL));
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &button));
+ EXPECT_TRUE(modal_dialog_showing);
+
+ // Now click OK, that should close the dialog.
+ EXPECT_TRUE(automation()->ClickAppModalDialogButton(
+ views::DialogDelegate::DIALOGBUTTON_OK));
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &button));
+ EXPECT_FALSE(modal_dialog_showing);
+
+ // Show a confirm dialog.
+ content =
+ "data:text/html,<html><head><script>var result = -1; function onload() {"
+ "setTimeout(\"result = confirm('hello') ? 0 : 1;\", 1000);} </script>"
+ "</head><body onload='onload()'></body></html>";
+ tab->NavigateToURL(GURL(content));
+ EXPECT_TRUE(automation()->WaitForAppModalDialog(3000));
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &button));
+ EXPECT_TRUE(modal_dialog_showing);
+ EXPECT_EQ(views::DialogDelegate::DIALOGBUTTON_OK |
+ views::DialogDelegate::DIALOGBUTTON_CANCEL, button);
+
+ // Click OK.
+ EXPECT_TRUE(automation()->ClickAppModalDialogButton(
+ views::DialogDelegate::DIALOGBUTTON_OK));
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &button));
+ EXPECT_FALSE(modal_dialog_showing);
+ int result = -1;
+ EXPECT_TRUE(tab->ExecuteAndExtractInt(
+ L"", L"window.domAutomationController.send(result);", &result));
+ EXPECT_EQ(0, result);
+
+ // Try again.
+ tab->NavigateToURL(GURL(content));
+ EXPECT_TRUE(automation()->WaitForAppModalDialog(3000));
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &button));
+ EXPECT_TRUE(modal_dialog_showing);
+ EXPECT_EQ(views::DialogDelegate::DIALOGBUTTON_OK |
+ views::DialogDelegate::DIALOGBUTTON_CANCEL, button);
+
+ // Click Cancel this time.
+ EXPECT_TRUE(automation()->ClickAppModalDialogButton(
+ views::DialogDelegate::DIALOGBUTTON_CANCEL));
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &button));
+ EXPECT_FALSE(modal_dialog_showing);
+ EXPECT_TRUE(tab->ExecuteAndExtractInt(
+ L"", L"window.domAutomationController.send(result);", &result));
+ EXPECT_EQ(1, result);
+} \ No newline at end of file