summaryrefslogtreecommitdiffstats
path: root/chrome/test/pyautolib
diff options
context:
space:
mode:
authornirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-23 18:24:19 +0000
committernirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-23 18:24:19 +0000
commit3ba3430731e35b3b542872ec90356098ad26fcf2 (patch)
tree33e21a81d1ac7e55cd0aa53dc323595fbf9f218e /chrome/test/pyautolib
parent1aef9813f6edaead72c9dfe24ccd07ec525c75b3 (diff)
downloadchromium_src-3ba3430731e35b3b542872ec90356098ad26fcf2.zip
chromium_src-3ba3430731e35b3b542872ec90356098ad26fcf2.tar.gz
chromium_src-3ba3430731e35b3b542872ec90356098ad26fcf2.tar.bz2
PyAuto: Fix some methods that assume that they're working on the first window.
- Provide args to specifiy tab_index or window_index. - Re-order the methods to group by functionality, rather than from where they are implemented. Review URL: http://codereview.chromium.org/650106 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39745 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r--chrome/test/pyautolib/pyautolib.cc40
-rw-r--r--chrome/test/pyautolib/pyautolib.h28
-rw-r--r--chrome/test/pyautolib/pyautolib.i95
3 files changed, 105 insertions, 58 deletions
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index 8465e39..ebfb565 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -30,32 +30,40 @@ void PyUITestSuite::NavigateToURL(const char* url_string) {
UITestBase::NavigateToURL(url);
}
+void PyUITestSuite::NavigateToURL(
+ const char* url_string, int window_index, int tab_index) {
+ GURL url(url_string);
+ UITestBase::NavigateToURL(url, window_index, tab_index);
+}
+
bool PyUITestSuite::AppendTab(const GURL& tab_url, int window_index) {
scoped_refptr<BrowserProxy> browser_proxy =
- automation()->GetBrowserWindow(window_index);
+ automation()->GetBrowserWindow(window_index);
return browser_proxy->AppendTab(tab_url);
}
bool PyUITestSuite::ApplyAccelerator(int id, int window_index) {
scoped_refptr<BrowserProxy> browser_proxy =
- automation()->GetBrowserWindow(window_index);
+ automation()->GetBrowserWindow(window_index);
return browser_proxy->ApplyAccelerator(id);
}
bool PyUITestSuite::ActivateTab(int tab_index, int window_index) {
scoped_refptr<BrowserProxy> browser_proxy =
- automation()->GetBrowserWindow(window_index);
+ automation()->GetBrowserWindow(window_index);
return browser_proxy->ActivateTab(tab_index);
}
-void PyUITestSuite::SetShelfVisible(bool is_visible) {
- scoped_refptr<BrowserProxy> browser_proxy = automation()->GetBrowserWindow(0);
+void PyUITestSuite::SetDownloadShelfVisible(bool is_visible, int window_index) {
+ scoped_refptr<BrowserProxy> browser_proxy =
+ automation()->GetBrowserWindow(window_index);
ASSERT_TRUE(browser_proxy.get());
EXPECT_TRUE(browser_proxy->SetShelfVisible(is_visible));
}
-bool PyUITestSuite::IsShelfVisible() {
- scoped_refptr<BrowserProxy> browser_proxy = automation()->GetBrowserWindow(0);
+bool PyUITestSuite::IsDownloadShelfVisible(int window_index) {
+ scoped_refptr<BrowserProxy> browser_proxy =
+ automation()->GetBrowserWindow(window_index);
EXPECT_TRUE(browser_proxy.get());
if (!browser_proxy.get())
return false;
@@ -64,18 +72,24 @@ bool PyUITestSuite::IsShelfVisible() {
return visible;
}
-GURL PyUITestSuite::GetActiveTabURL() {
- return UITestBase::GetActiveTabURL();
+int PyUITestSuite::GetTabCount(int window_index) {
+ return UITestBase::GetTabCount(window_index);
}
-void PyUITestSuite::OpenFindInPage() {
- scoped_refptr<BrowserProxy> browser_proxy = automation()->GetBrowserWindow(0);
+GURL PyUITestSuite::GetActiveTabURL(int window_index) {
+ return UITestBase::GetActiveTabURL(window_index);
+}
+
+void PyUITestSuite::OpenFindInPage(int window_index) {
+ scoped_refptr<BrowserProxy> browser_proxy =
+ automation()->GetBrowserWindow(window_index);
ASSERT_TRUE(browser_proxy.get());
EXPECT_TRUE(browser_proxy->OpenFindInPage());
}
-bool PyUITestSuite::IsFindInPageVisible() {
- scoped_refptr<BrowserProxy> browser_proxy = automation()->GetBrowserWindow(0);
+bool PyUITestSuite::IsFindInPageVisible(int window_index) {
+ scoped_refptr<BrowserProxy> browser_proxy =
+ automation()->GetBrowserWindow(window_index);
EXPECT_TRUE(browser_proxy.get());
if (!browser_proxy.get())
return false;
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index 5d1b77c..767b2bd 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -12,6 +12,13 @@
#include "chrome/test/ui/ui_test.h"
#include "chrome/test/ui/ui_test_suite.h"
+// The C++ style guide forbids using default arguments but I'm taking the
+// liberty of allowing it in this file. The sole purpose of this (and the
+// .cc) is to support the python interface, and default args are allowed in
+// python. Strictly adhering to the guide here would mean having to re-define
+// all methods in python just for the sake of providing default args. This
+// seems cumbersome and unwanted.
+
// TODO(nirnimesh): separate out the UITestSuite and UITestBase parts
// crbug.com/32292
@@ -27,15 +34,17 @@ class PyUITestSuite : public UITestSuite, public UITestBase {
virtual void SetUp();
virtual void TearDown();
+ // Navigate to the given URL in the active tab. Blocks until page loaded.
void NavigateToURL(const char* url_string);
- // Get the URL of the active tab.
- GURL GetActiveTabURL();
+ // Navigate to the given URL in given tab in the given window.
+ // Blocks until page loaded.
+ void NavigateToURL(const char* url_string, int window_index, int tab_index);
- // BrowserProxy methods
+ // Get the URL of the active tab.
+ GURL GetActiveTabURL(int window_index = 0);
- // Shows or hides the download shelf.
- void SetShelfVisible(bool is_visible);
+ int GetTabCount(int window_index = 0);
// Appends a new tab with the given URL in the given or first browser window.
bool AppendTab(const GURL& tab_url, int window_index = 0);
@@ -50,14 +59,17 @@ class PyUITestSuite : public UITestSuite, public UITestBase {
// Returns true if the call was successful.
bool ApplyAccelerator(int id, int window_index = 0);
+ // Shows or hides the download shelf.
+ void SetDownloadShelfVisible(bool is_visible, int window_index = 0);
+
// Determines the visibility of the download shelf
- bool IsShelfVisible();
+ bool IsDownloadShelfVisible(int window_index = 0);
// Open the Find box
- void OpenFindInPage();
+ void OpenFindInPage(int window_index = 0);
// Determines the visibility of the Find box
- bool IsFindInPageVisible();
+ bool IsFindInPageVisible(int window_index = 0);
// Get the path to the downloads directory
std::string GetDownloadDirectory();
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index 0b8781e..631317f 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -88,63 +88,84 @@ class PyUITestSuite {
"Closes all windows and destroys the browser.") TearDown;
virtual void TearDown();
- %feature("docstring", "Navigate to the given url in the active tab. "
- "Blocks until page has loaded.") NavigateToURL;
+ // Navigation Methods
+ %feature("docstring", "Navigate to the given url in the given tab and given "
+ "window (or active tab in first window if indexes not given). "
+ "Note that this method also activates the corresponding tab/window "
+ "if it's not active already. Blocks until page has loaded.")
+ NavigateToURL;
void NavigateToURL(const char* url_string);
+ void NavigateToURL(const char* url_string, int window_index, int tab_index);
// BrowserProxy methods
- %feature("docstring", "Set download shelf visibility.") SetShelfVisible;
- void SetShelfVisible(bool is_visible);
- %feature("docstring", "Create a new tab at the end of given or first browser "
- "window and activate it. Blocks until the page is loaded. "
- "Returns True on success.") AppendTab;
- bool AppendTab(const GURL& tab_url, int window_index=0);
- %feature("docstring", "Activate the tab at the given zero-based index in "
- "the given or first window. Returns True on success.") ActivateTab;
- bool ActivateTab(int tab_index, int window_index=0);
%feature("docstring", "Apply the accelerator with given id "
"(IDC_BACK, IDC_NEWTAB ...) to the given or first window. "
"The list can be found at chrome/app/chrome_dll_resource.h. "
+ "Note that this method just schedules the accelerator, but does "
+ "not wait for it to actually finish doing anything."
"Returns True on success.")
ApplyAccelerator;
bool ApplyAccelerator(int id, int window_index=0);
- // TabProxy methods
- %feature("docstring",
- "Determine if the download shelf is visible.") IsShelfVisible;
- bool IsShelfVisible();
- %feature("docstring", "Open the Find box.") OpenFindInPage;
- void OpenFindInPage();
- %feature("docstring",
- "Determine if the find box is visible.") IsFindInPageVisible;
- bool IsFindInPageVisible();
+ // Get/fetch properties
%feature("docstring",
"Get the path to download directory.") GetDownloadDirectory;
std::string GetDownloadDirectory();
- // AutomationProxy methods
+ %feature("docstring", "Get the path to profile directory.") user_data_dir;
+ FilePath user_data_dir() const;
+
+ %feature("docstring", "Set download shelf visibility for the given or "
+ "first browser window.") SetDownloadShelfVisible;
+ void SetDownloadShelfVisible(bool is_visible, int window_index=0);
+
+ %feature("docstring", "Determine if the download shelf is visible in the "
+ "given or first browser window.") IsDownloadShelfVisible;
+ bool IsDownloadShelfVisible(int window_index=0);
+
+ %feature("docstring", "Open the Find box in the given or first browser "
+ "window.") OpenFindInPage;
+ void OpenFindInPage(int window_index=0);
+
+ %feature("docstring", "Determine if the find box is visible in the "
+ "given or first browser window.") IsFindInPageVisible;
+ bool IsFindInPageVisible(int window_index=0);
+
+ // Tabs and windows methods
%feature("docstring", "Open a new browser window.") OpenNewBrowserWindow;
bool OpenNewBrowserWindow(bool show);
- %feature("docstring", "Install an extension from the given file. Returns "
- "True if successfully installed and loaded.") InstallExtension;
- bool InstallExtension(const FilePath& crx_file);
- // UITestBase methods
- %feature("docstring", "Path to download directory.") user_data_dir;
- FilePath user_data_dir() const;
- %feature("docstring", "Get the index of the active tab.") GetActiveTabIndex;
- int GetActiveTabIndex();
- %feature("docstring", "Get the title of the active tab.") GetActiveTabTitle;
- std::wstring GetActiveTabTitle();
- %feature("docstring", "Get the URL for the active tab. "
- "Returns an instance of GURL") GetActiveTabURL;
- GURL GetActiveTabURL();
+ %feature("docstring", "Get the index of the active tab in the given or "
+ "first window. Indexes are zero-based.") GetActiveTabIndex;
+ int GetActiveTabIndex(int window_index=0);
+ %feature("docstring", "Activate the tab at the given zero-based index in "
+ "the given or first window. Returns True on success.") ActivateTab;
+ bool ActivateTab(int tab_index, int window_index=0);
+
+ %feature("docstring", "Get the title of the active tab for the given or "
+ "first window.") GetActiveTabTitle;
+ std::wstring GetActiveTabTitle(int window_index=0);
+
+ %feature("docstring", "Get the URL for the active tab. for the given or "
+ "first window. Returns an instance of GURL") GetActiveTabURL;
+ GURL GetActiveTabURL(int window_index=0);
+
+ %feature("docstring", "Count of the number of tabs in the given or "
+ "first window.") GetTabCount;
+ int GetTabCount(int window_index=0);
+ %feature("docstring", "Create a new tab at the end of given or first browser "
+ "window and activate it. Blocks until the page is loaded. "
+ "Returns True on success.") AppendTab;
+ bool AppendTab(const GURL& tab_url, int window_index=0);
+
+ // Misc methods
%feature("docstring", "Determine if the browser is running. "
"Returns False if user closed the window or if the browser died")
IsBrowserRunning;
bool IsBrowserRunning();
- %feature("docstring",
- "Count of the number of tabs in the front window.") GetTabCount;
- int GetTabCount();
+
+ %feature("docstring", "Install an extension from the given file. Returns "
+ "True if successfully installed and loaded.") InstallExtension;
+ bool InstallExtension(const FilePath& crx_file);
};