From c274acc67753226943c28e01f24307610bb8c5c0 Mon Sep 17 00:00:00 2001 From: "erg@google.com" Date: Tue, 11 Nov 2008 20:13:44 +0000 Subject: 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 --- .../test/automation/automation_messages_internal.h | 9 ++++- chrome/test/automation/automation_proxy.cc | 47 ++++++++++++++++++++++ chrome/test/automation/automation_proxy.h | 9 ++++- .../test/data/constrained_files/block_alert.html | 17 ++++++++ chrome/test/data/constrained_files/show_alert.html | 15 +++++++ .../test/data/constrained_files/show_alert_2.html | 8 ++++ 6 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 chrome/test/data/constrained_files/block_alert.html create mode 100644 chrome/test/data/constrained_files/show_alert.html create mode 100644 chrome/test/data/constrained_files/show_alert_2.html (limited to 'chrome/test') 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__ - diff --git a/chrome/test/data/constrained_files/block_alert.html b/chrome/test/data/constrained_files/block_alert.html new file mode 100644 index 0000000..063d972 --- /dev/null +++ b/chrome/test/data/constrained_files/block_alert.html @@ -0,0 +1,17 @@ + + + Block alert from blocked popup? + + + +

Block alert from blocked popup?

+ + diff --git a/chrome/test/data/constrained_files/show_alert.html b/chrome/test/data/constrained_files/show_alert.html new file mode 100644 index 0000000..742271e --- /dev/null +++ b/chrome/test/data/constrained_files/show_alert.html @@ -0,0 +1,15 @@ + + + Must show alert to pass! + + + +

Must show alert to pass!

+ + diff --git a/chrome/test/data/constrained_files/show_alert_2.html b/chrome/test/data/constrained_files/show_alert_2.html new file mode 100644 index 0000000..3fbc795 --- /dev/null +++ b/chrome/test/data/constrained_files/show_alert_2.html @@ -0,0 +1,8 @@ + + + Must show alert to pass! + + +

Must show alert to pass!

+ + -- cgit v1.1