diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-11 20:13:44 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-11 20:13:44 +0000 |
commit | c274acc67753226943c28e01f24307610bb8c5c0 (patch) | |
tree | 96a8342ddb53a3162f0748ebe90dc167bde86230 /chrome/test/automation | |
parent | 00b64f3980da6ce2c42007c14952f613c4adc640 (diff) | |
download | chromium_src-c274acc67753226943c28e01f24307610bb8c5c0.zip chromium_src-c274acc67753226943c28e01f24307610bb8c5c0.tar.gz chromium_src-c274acc67753226943c28e01f24307610bb8c5c0.tar.bz2 |
Only block alert() requests from blocked popups; not all popups.
Add two unit tests to make sure we do the right thing; required
adding a bunch of stuff to the automation layer.
Review URL: http://codereview.chromium.org/10282
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5198 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automation')
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 9 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.cc | 47 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.h | 9 |
3 files changed, 62 insertions, 3 deletions
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index d6a321a8..4d19a89 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -795,11 +795,16 @@ IPC_BEGIN_MESSAGES(Automation, 0) // This messages sets an int-value preference. IPC_MESSAGE_ROUTED3(AutomationMsg_SetIntPreferenceRequest, - int /* browser handle */, + int /* browser handle */, std::wstring /* pref name */, int /* value */) IPC_MESSAGE_ROUTED1(AutomationMsg_SetIntPreferenceResponse, bool /* success */) -IPC_END_MESSAGES(Automation) + // Queries whether an app modal dialog is currently being shown. (i.e. a + // javascript alert). + IPC_MESSAGE_ROUTED0(AutomationMsg_ShowingAppModalDialogRequest) + IPC_MESSAGE_ROUTED1(AutomationMsg_ShowingAppModalDialogResponse, + bool /* showing dialog */) +IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index 5588ea8..348ce0f 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -302,6 +302,53 @@ bool AutomationProxy::WaitForWindowCountToBecome(int count, return false; } +bool AutomationProxy::GetShowingAppModalDialog(bool* showing_app_modal_dialog) { + if (!showing_app_modal_dialog) { + 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) + return false; + + 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; + } + + delete response; + return succeeded; +} + +bool AutomationProxy::WaitForAppModalDialog(int wait_timeout) { + const TimeTicks start = TimeTicks::Now(); + const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); + while (TimeTicks::Now() - start < timeout) { + bool dialog_shown = false; + bool succeeded = GetShowingAppModalDialog(&dialog_shown); + if (!succeeded) { + // Try again next round, but log it. + DLOG(ERROR) << "GetShowingAppModalDialog returned false"; + } else if (dialog_shown) { + return true; + } + Sleep(automation::kSleepTime); + } + // Dialog never shown. + return false; +} + bool AutomationProxy::SetFilteredInet(bool enabled) { return Send(new AutomationMsg_SetFilteredInet(0, enabled)); } diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h index 8491832..5621b011 100644 --- a/chrome/test/automation/automation_proxy.h +++ b/chrome/test/automation/automation_proxy.h @@ -108,6 +108,14 @@ class AutomationProxy : public IPC::Channel::Listener, // Returns true on success. 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); + + // Block the thread until a modal dialog is displayed. Returns true on + // success. + bool WaitForAppModalDialog(int wait_timeout); + // Returns the BrowserProxy for the browser window at the given index, // transferring ownership of the pointer to the caller. // On failure, returns NULL. @@ -217,4 +225,3 @@ class AutomationProxy : public IPC::Channel::Listener, }; #endif // CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H__ - |