summaryrefslogtreecommitdiffstats
path: root/chrome/test/automation/automation_proxy_uitest.cc
diff options
context:
space:
mode:
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