summaryrefslogtreecommitdiffstats
path: root/chrome/test/automation/automation_proxy_uitest.cc
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/automation/automation_proxy_uitest.cc
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/automation/automation_proxy_uitest.cc')
-rw-r--r--chrome/test/automation/automation_proxy_uitest.cc88
1 files changed, 88 insertions, 0 deletions
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