summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-21 01:21:48 +0000
committerstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-21 01:21:48 +0000
commit82a200191df08bab26f78240af1883ca46b1942f (patch)
tree0ff39c52e8e86e0eff79f88d74d35bd003e8960e /chrome/test
parent58567187439fdcad4cf4fdc39a1d92668b7afbb8 (diff)
downloadchromium_src-82a200191df08bab26f78240af1883ca46b1942f.zip
chromium_src-82a200191df08bab26f78240af1883ca46b1942f.tar.gz
chromium_src-82a200191df08bab26f78240af1883ca46b1942f.tar.bz2
Refactor automation wrappers. Move the methods from AutomationProxy to the appropriate classes.
Review URL: http://codereview.chromium.org/18335 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_tests.cc4
-rw-r--r--chrome/test/automation/automation_proxy.cc82
-rw-r--r--chrome/test/automation/automation_proxy.h21
-rw-r--r--chrome/test/automation/automation_proxy_uitest.cc16
-rw-r--r--chrome/test/automation/browser_proxy.cc49
-rw-r--r--chrome/test/automation/browser_proxy.h14
-rw-r--r--chrome/test/automation/window_proxy.cc31
-rw-r--r--chrome/test/automation/window_proxy.h8
-rw-r--r--chrome/test/reliability/page_load_test.cc3
-rw-r--r--chrome/test/ui/omnibox_uitest.cc5
10 files changed, 114 insertions, 119 deletions
diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc
index 81d0f0b..0a4981e 100644
--- a/chrome/test/automated_ui_tests/automated_ui_tests.cc
+++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc
@@ -825,13 +825,13 @@ bool AutomatedUITest::DragActiveTab(bool drag_right, bool drag_out) {
WindowProxy* AutomatedUITest::GetAndActivateWindowForBrowser(
BrowserProxy* browser) {
- WindowProxy* window = automation()->GetWindowForBrowser(browser);
-
bool did_timeout;
if (!browser->BringToFrontWithTimeout(action_max_timeout_ms(), &did_timeout)) {
AddWarningAttribute("failed_to_bring_window_to_front");
return NULL;
}
+
+ WindowProxy* window = browser->GetWindow();
return window;
}
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc
index 59303b6..9f3c886 100644
--- a/chrome/test/automation/automation_proxy.cc
+++ b/chrome/test/automation/automation_proxy.cc
@@ -9,7 +9,6 @@
#include "base/logging.h"
#include "base/ref_counted.h"
#include "chrome/common/ipc_message_macros.h"
-#include "chrome/test/automation/autocomplete_edit_proxy.h"
#include "chrome/test/automation/automation_constants.h"
#include "chrome/test/automation/automation_messages.h"
#include "chrome/test/automation/browser_proxy.h"
@@ -473,87 +472,6 @@ BrowserProxy* AutomationProxy::GetLastActiveBrowserWindow() {
return new BrowserProxy(this, tracker_.get(), handle);
}
-BrowserProxy* AutomationProxy::GetBrowserForWindow(WindowProxy* window) {
- return GetBrowserForWindowWithTimeout(window, INFINITE, NULL);
-}
-
-BrowserProxy* AutomationProxy::GetBrowserForWindowWithTimeout(
- WindowProxy* window, uint32 timeout_ms, bool* is_timeout) {
- DCHECK(window);
- if (!window->is_valid() || !window->handle())
- return false;
-
- IPC::Message* response = NULL;
- bool succeeded = SendAndWaitForResponseWithTimeout(
- new AutomationMsg_BrowserForWindowRequest(0, window->handle()), &response,
- AutomationMsg_BrowserForWindowResponse::ID, timeout_ms, is_timeout);
- if (!succeeded)
- return NULL;
-
- scoped_ptr<IPC::Message> response_deleter(response); // Delete on exit.
- int browser_handle = 0;
- void* iter = NULL;
- bool handle_ok;
- succeeded = response->ReadBool(&iter, &handle_ok);
- if (succeeded)
- succeeded = response->ReadInt(&iter, &browser_handle);
-
- if (succeeded) {
- return new BrowserProxy(this, tracker_.get(), browser_handle);
- } else {
- return NULL;
- }
-}
-
-WindowProxy* AutomationProxy::GetWindowForBrowser(BrowserProxy* browser) {
- if (!browser->is_valid() || !browser->handle())
- return false;
-
- IPC::Message* response = NULL;
- bool succeeded = SendAndWaitForResponse(
- new AutomationMsg_WindowForBrowserRequest(0, browser->handle()), &response,
- AutomationMsg_WindowForBrowserResponse::ID);
- if (!succeeded)
- return NULL;
-
- scoped_ptr<IPC::Message> response_deleter(response); // Delete on exit.
- int window_handle;
- void* iter = NULL;
- bool handle_ok;
- succeeded = response->ReadBool(&iter, &handle_ok);
- if (succeeded)
- succeeded = response->ReadInt(&iter, &window_handle);
-
- if (succeeded) {
- return new WindowProxy(this, tracker_.get(), window_handle);
- } else {
- return NULL;
- }
-}
-
-AutocompleteEditProxy* AutomationProxy::GetAutocompleteEditForBrowser(
- BrowserProxy* browser) {
- if (!browser->is_valid() || !browser->handle())
- return NULL;
-
- IPC::Message* response = NULL;
- if (!SendAndWaitForResponse(
- new AutomationMsg_AutocompleteEditForBrowserRequest(0, browser->handle()),
- &response, AutomationMsg_AutocompleteEditForBrowserResponse::ID))
- return NULL;
- scoped_ptr<IPC::Message> response_deleter(response);
-
- int autocomplete_edit_handle;
- void* iter = NULL;
- bool handle_ok;
- if (!response->ReadBool(&iter, &handle_ok) ||
- !response->ReadInt(&iter, &autocomplete_edit_handle))
- return NULL;
-
- return new AutocompleteEditProxy(this, tracker_.get(),
- autocomplete_edit_handle);
-}
-
bool AutomationProxy::Send(IPC::Message* message) {
if (channel_.get())
return channel_->Send(message);
diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h
index 6632604..e388333 100644
--- a/chrome/test/automation/automation_proxy.h
+++ b/chrome/test/automation/automation_proxy.h
@@ -141,27 +141,6 @@ class AutomationProxy : public IPC::Channel::Listener,
// On failure, returns NULL.
WindowProxy* GetActiveWindow();
- // Returns the browser this window corresponds to, or NULL if this window
- // is not a browser. The caller owns the returned BrowserProxy.
- BrowserProxy* GetBrowserForWindow(WindowProxy* window);
-
- // Same as GetBrowserForWindow except return NULL if response isn't received
- // before the specified timeout.
- BrowserProxy* GetBrowserForWindowWithTimeout(WindowProxy* window,
- uint32 timeout_ms,
- bool* is_timeout);
-
- // Returns the WindowProxy for this browser's window. It can be used to
- // retreive view bounds, simulate clicks and key press events. The caller
- // owns the returned WindowProxy.
- // On failure, returns NULL.
- WindowProxy* GetWindowForBrowser(BrowserProxy* browser);
-
- // Returns an AutocompleteEdit for this browser's window. It can be used to
- // manipulate the omnibox. The caller owns the returned pointer.
- // On failure, returns NULL.
- AutocompleteEditProxy* GetAutocompleteEditForBrowser(BrowserProxy* browser);
-
// Tells the browser to enable or disable network request filtering. Returns
// false if the message fails to send to the browser.
bool SetFilteredInet(bool enabled);
diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc
index add33f4..bc109885 100644
--- a/chrome/test/automation/automation_proxy_uitest.cc
+++ b/chrome/test/automation/automation_proxy_uitest.cc
@@ -67,8 +67,7 @@ TEST_F(AutomationProxyVisibleTest, WindowGetViewBounds) {
{
scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
- scoped_ptr<WindowProxy> window(
- automation()->GetWindowForBrowser(browser.get()));
+ scoped_ptr<WindowProxy> window(browser->GetWindow());
ASSERT_TRUE(window.get());
scoped_ptr<TabProxy> tab1(browser->GetTab(0));
@@ -445,8 +444,7 @@ TEST_F(AutomationProxyTest, Cookies) {
TEST_F(AutomationProxyTest, GetHWND) {
scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
- scoped_ptr<WindowProxy> window(
- automation()->GetWindowForBrowser(browser.get()));
+ scoped_ptr<WindowProxy> window(browser->GetWindow());
ASSERT_TRUE(window.get());
HWND handle;
@@ -767,7 +765,7 @@ TEST_F(AutomationProxyTest, AutocompleteGetSetText) {
scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
scoped_ptr<AutocompleteEditProxy> edit(
- automation()->GetAutocompleteEditForBrowser(browser.get()));
+ browser->GetAutocompleteEdit());
ASSERT_TRUE(edit.get());
EXPECT_TRUE(edit->is_valid());
const std::wstring text_to_set = L"Lollerskates";
@@ -776,7 +774,7 @@ TEST_F(AutomationProxyTest, AutocompleteGetSetText) {
EXPECT_TRUE(edit->GetText(&actual_text));
EXPECT_EQ(text_to_set, actual_text);
scoped_ptr<AutocompleteEditProxy> edit2(
- automation()->GetAutocompleteEditForBrowser(browser.get()));
+ browser->GetAutocompleteEdit());
EXPECT_TRUE(edit2->GetText(&actual_text));
EXPECT_EQ(text_to_set, actual_text);
}
@@ -785,13 +783,13 @@ TEST_F(AutomationProxyTest, AutocompleteParallelProxy) {
scoped_ptr<BrowserProxy> browser1(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser1.get());
scoped_ptr<AutocompleteEditProxy> edit1(
- automation()->GetAutocompleteEditForBrowser(browser1.get()));
+ browser1->GetAutocompleteEdit());
ASSERT_TRUE(edit1.get());
EXPECT_TRUE(browser1->ApplyAccelerator(IDC_NEW_WINDOW));
scoped_ptr<BrowserProxy> browser2(automation()->GetBrowserWindow(1));
ASSERT_TRUE(browser2.get());
scoped_ptr<AutocompleteEditProxy> edit2(
- automation()->GetAutocompleteEditForBrowser(browser2.get()));
+ browser2->GetAutocompleteEdit());
ASSERT_TRUE(edit2.get());
EXPECT_TRUE(browser2->GetTab(0)->WaitForTabToBeRestored(
action_max_timeout_ms()));
@@ -810,7 +808,7 @@ TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) {
scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
scoped_ptr<AutocompleteEditProxy> edit(
- automation()->GetAutocompleteEditForBrowser(browser.get()));
+ browser->GetAutocompleteEdit());
ASSERT_TRUE(edit.get());
EXPECT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION));
EXPECT_TRUE(edit->is_valid());
diff --git a/chrome/test/automation/browser_proxy.cc b/chrome/test/automation/browser_proxy.cc
index cab64bf..a08fdc6 100644
--- a/chrome/test/automation/browser_proxy.cc
+++ b/chrome/test/automation/browser_proxy.cc
@@ -8,10 +8,12 @@
#include "base/logging.h"
#include "base/time.h"
+#include "chrome/test/automation/autocomplete_edit_proxy.h"
#include "chrome/test/automation/automation_constants.h"
#include "chrome/test/automation/automation_messages.h"
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/automation/window_proxy.h"
using base::TimeDelta;
using base::TimeTicks;
@@ -477,3 +479,50 @@ bool BrowserProxy::SetBooleanPreference(const std::wstring& name,
return false;
}
+
+WindowProxy* BrowserProxy::GetWindow() {
+ if (!is_valid())
+ return false;
+
+ IPC::Message* response = NULL;
+ bool succeeded = sender_->SendAndWaitForResponse(
+ new AutomationMsg_WindowForBrowserRequest(0, handle_), &response,
+ AutomationMsg_WindowForBrowserResponse::ID);
+ if (!succeeded)
+ return NULL;
+
+ scoped_ptr<IPC::Message> response_deleter(response); // Delete on exit.
+ int window_handle;
+ void* iter = NULL;
+ bool handle_ok;
+ succeeded = response->ReadBool(&iter, &handle_ok);
+ if (succeeded)
+ succeeded = response->ReadInt(&iter, &window_handle);
+
+ if (succeeded) {
+ return new WindowProxy(sender_, tracker_, window_handle);
+ } else {
+ return NULL;
+ }
+}
+
+AutocompleteEditProxy* BrowserProxy::GetAutocompleteEdit() {
+ if (!is_valid())
+ return NULL;
+
+ IPC::Message* response = NULL;
+ if (!sender_->SendAndWaitForResponse(
+ new AutomationMsg_AutocompleteEditForBrowserRequest(0, handle_),
+ &response, AutomationMsg_AutocompleteEditForBrowserResponse::ID))
+ return NULL;
+ scoped_ptr<IPC::Message> response_deleter(response);
+
+ int autocomplete_edit_handle;
+ void* iter = NULL;
+ bool handle_ok;
+ if (!response->ReadBool(&iter, &handle_ok) ||
+ !response->ReadInt(&iter, &autocomplete_edit_handle))
+ return NULL;
+
+ return new AutocompleteEditProxy(sender_, tracker_, autocomplete_edit_handle);
+}
diff --git a/chrome/test/automation/browser_proxy.h b/chrome/test/automation/browser_proxy.h
index c67dd33..4df9269 100644
--- a/chrome/test/automation/browser_proxy.h
+++ b/chrome/test/automation/browser_proxy.h
@@ -11,6 +11,8 @@
class GURL;
class TabProxy;
+class WindowProxy;
+class AutocompleteEditProxy;
namespace gfx {
class Rect;
@@ -91,6 +93,18 @@ class BrowserProxy : public AutomationResourceProxy {
// the specified timout.
TabProxy* GetActiveTabWithTimeout(uint32 timeout_ms, bool* is_timeout) const;
+ // Returns the WindowProxy for this browser's window. It can be used to
+ // retreive view bounds, simulate clicks and key press events. The caller
+ // owns the returned WindowProxy.
+ // On failure, returns NULL.
+ WindowProxy* GetWindow();
+
+ // Returns an AutocompleteEdit for this browser's window. It can be used to
+ // manipulate the omnibox. The caller owns the returned pointer.
+ // On failure, returns NULL.
+ AutocompleteEditProxy* GetAutocompleteEdit();
+
+
// Apply the accelerator with given id (IDC_BACK, IDC_NEWTAB ...)
// Returns true if the call was successful.
//
diff --git a/chrome/test/automation/window_proxy.cc b/chrome/test/automation/window_proxy.cc
index 986b41d2..1780956 100644
--- a/chrome/test/automation/window_proxy.cc
+++ b/chrome/test/automation/window_proxy.cc
@@ -160,3 +160,34 @@ bool WindowProxy::GetFocusedViewID(int* view_id) {
return false;
}
+
+BrowserProxy* WindowProxy::GetBrowser() {
+ return GetBrowserWithTimeout(INFINITE, NULL);
+}
+
+BrowserProxy* WindowProxy::GetBrowserWithTimeout(uint32 timeout_ms,
+ bool* is_timeout) {
+ if (!is_valid())
+ return false;
+
+ IPC::Message* response = NULL;
+ bool succeeded = sender_->SendAndWaitForResponseWithTimeout(
+ new AutomationMsg_BrowserForWindowRequest(0, handle_), &response,
+ AutomationMsg_BrowserForWindowResponse::ID, timeout_ms, is_timeout);
+ if (!succeeded)
+ return NULL;
+
+ scoped_ptr<IPC::Message> response_deleter(response); // Delete on exit.
+ int browser_handle = 0;
+ void* iter = NULL;
+ bool handle_ok;
+ succeeded = response->ReadBool(&iter, &handle_ok);
+ if (succeeded)
+ succeeded = response->ReadInt(&iter, &browser_handle);
+
+ if (succeeded) {
+ return new BrowserProxy(sender_, tracker_, browser_handle);
+ } else {
+ return NULL;
+ }
+}
diff --git a/chrome/test/automation/window_proxy.h b/chrome/test/automation/window_proxy.h
index 30d6612..1f3da79 100644
--- a/chrome/test/automation/window_proxy.h
+++ b/chrome/test/automation/window_proxy.h
@@ -77,6 +77,14 @@ class WindowProxy : public AutomationResourceProxy {
// was retrieved.
bool GetFocusedViewID(int* view_id);
+ // Returns the browser this window corresponds to, or NULL if this window
+ // is not a browser. The caller owns the returned BrowserProxy.
+ BrowserProxy* GetBrowser();
+
+ // Same as GetWindow except return NULL if response isn't received
+ // before the specified timeout.
+ BrowserProxy* GetBrowserWithTimeout(uint32 timeout_ms, bool* is_timeout);
+
private:
DISALLOW_EVIL_CONSTRUCTORS(WindowProxy);
};
diff --git a/chrome/test/reliability/page_load_test.cc b/chrome/test/reliability/page_load_test.cc
index 0dfe427..b451006 100644
--- a/chrome/test/reliability/page_load_test.cc
+++ b/chrome/test/reliability/page_load_test.cc
@@ -154,8 +154,7 @@ class PageLoadTest : public UITest {
// Page down twice.
scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
if (browser.get()) {
- scoped_ptr<WindowProxy> window(
- automation()->GetWindowForBrowser(browser.get()));
+ scoped_ptr<WindowProxy> window(browser->GetWindow());
if (window.get()) {
bool activation_timeout;
browser->BringToFrontWithTimeout(action_max_timeout_ms(),
diff --git a/chrome/test/ui/omnibox_uitest.cc b/chrome/test/ui/omnibox_uitest.cc
index 7b317af..f77a301 100644
--- a/chrome/test/ui/omnibox_uitest.cc
+++ b/chrome/test/ui/omnibox_uitest.cc
@@ -75,10 +75,9 @@ bool OmniboxTest::IsMatch(const std::wstring& input_text,
void OmniboxTest::RunQueryChain(const std::wstring& input_text) {
// Get a handle on the omnibox and give it focus.
scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- scoped_ptr<WindowProxy> window(
- automation()->GetWindowForBrowser(browser.get()));
+ scoped_ptr<WindowProxy> window(browser->GetWindow());
scoped_ptr<AutocompleteEditProxy> autocomplete_edit(
- automation()->GetAutocompleteEditForBrowser(browser.get()));
+ browser->GetAutocompleteEdit());
ASSERT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION));
// Try every proper prefix of input_text. There's no use trying