summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorace@chromium.org <ace@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-19 22:20:00 +0000
committerace@chromium.org <ace@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-19 22:20:00 +0000
commit7e4dbb7272648ac892d41097a61dab7856df2040 (patch)
tree9e2fbec58bb414d50768789dcd4a223584d23c8a /chrome/test
parent1a78769eeed2048aa9bb873a197838cc716092be (diff)
downloadchromium_src-7e4dbb7272648ac892d41097a61dab7856df2040.zip
chromium_src-7e4dbb7272648ac892d41097a61dab7856df2040.tar.gz
chromium_src-7e4dbb7272648ac892d41097a61dab7856df2040.tar.bz2
Modifying some downloads hooks to act per-window (so that incognito windows can be correctly targetted) and updating some surrounding test cases.
BUG=59259 Review URL: http://codereview.chromium.org/6159001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71856 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/functional/downloads.py34
-rw-r--r--chrome/test/pyautolib/pyauto.py23
-rw-r--r--chrome/test/pyautolib/pyautolib.cc5
-rw-r--r--chrome/test/pyautolib/pyautolib.h3
-rw-r--r--chrome/test/pyautolib/pyautolib.i3
-rw-r--r--chrome/test/ui/ui_test.cc4
-rw-r--r--chrome/test/ui/ui_test.h3
7 files changed, 52 insertions, 23 deletions
diff --git a/chrome/test/functional/downloads.py b/chrome/test/functional/downloads.py
index 023c551..8f5227f 100644
--- a/chrome/test/functional/downloads.py
+++ b/chrome/test/functional/downloads.py
@@ -133,13 +133,15 @@ class DownloadsTest(pyauto.PyUITest):
downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
'a_zip_file.zip')
self._ClearLocalDownloadState(downloaded_pkg)
+ self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
+
+ # Trigger download and wait in new incognito window.
+ self.DownloadAndWaitForStart(file_url, 1)
+ self.WaitForAllDownloadsToComplete(1)
+ incognito_downloads = self.GetDownloadsInfo(1).Downloads()
- self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) # open incognito window
- # Downloads from incognito window do not figure in GetDownloadsInfo()
- # since the download manager's list doesn't contain it.
- # Using WaitUntil is the only resort.
- self.NavigateToURL(file_url, 1, 0)
- self.assertTrue(self.WaitUntil(lambda: os.path.exists(downloaded_pkg)))
+ # Verify that download info exists in the correct profile.
+ self.assertEqual(len(incognito_downloads), 1)
self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg))
self.assertTrue(self.IsDownloadShelfVisible(1))
@@ -518,7 +520,7 @@ class DownloadsTest(pyauto.PyUITest):
self.PerformActionOnDownload(id, 'open')
self.WaitForAllDownloadsToComplete()
unzip_file_name = downloaded_pkg + '.cpgz'
- # Verify that the file was correctly downloaded
+ # Verify that the file was correctly downloaded.
self.assertTrue(self.WaitUntil(lambda: os.path.exists(unzip_file_name)),
'Unzipped folder %s missing.' % unzip_file_name)
self.assertTrue(os.path.exists(downloaded_pkg),
@@ -548,7 +550,7 @@ class DownloadsTest(pyauto.PyUITest):
return old_percentage == 100 or percent > old_percentage,
self.assertTrue(self.WaitUntil(_PercentInc),
msg='Download percentage value is not increasing')
- # Once download is completed, percentage is 100
+ # Once download is completed, percentage is 100.
self.WaitForAllDownloadsToComplete()
downloads = self.GetDownloadsInfo().Downloads()
self.assertEqual(downloads[0]['PercentComplete'], 100,
@@ -570,17 +572,21 @@ class DownloadsTest(pyauto.PyUITest):
'a_zip_file (1).zip')
self._ClearLocalDownloadState(downloaded_pkg_regul)
self._ClearLocalDownloadState(downloaded_pkg_incog)
- self.NavigateToURL(file_url, 0, 0)
+
+ self.DownloadAndWaitForStart(file_url, 0)
+ self.WaitForAllDownloadsToComplete(0)
+
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
- self.NavigateToURL(file_url, 1, 0)
- self.WaitForAllDownloadsToComplete()
+ self.DownloadAndWaitForStart(file_url, 1)
+ self.WaitForAllDownloadsToComplete(1)
- # Verify download in regular Window.
+ # Verify download in regular window.
self.assertTrue(os.path.exists(downloaded_pkg_regul))
self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul))
- # Verify download in Incognito Window.
- # WaitForAllDownloadsToComplete does not wait for incognito downloads
+ # Verify download in incognito window.
+ # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case.
+ # Using extra WaitUntil until this is resolved.
self.assertTrue(self.WaitUntil(
lambda: os.path.exists(downloaded_pkg_incog)))
self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog))
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 7fb08f6..cfe7a25 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -388,7 +388,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
"""
return bookmark_model.BookmarkModel(self._GetBookmarksAsJSON())
- def GetDownloadsInfo(self):
+ def GetDownloadsInfo(self, windex=0):
"""Return info about downloads.
This includes all the downloads recognized by the history system.
@@ -397,7 +397,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
an instance of downloads_info.DownloadInfo
"""
return download_info.DownloadInfo(
- self._SendJSONRequest(0, json.dumps({'command': 'GetDownloadsInfo'})))
+ self._SendJSONRequest(
+ windex, json.dumps({'command': 'GetDownloadsInfo'})))
def GetOmniboxInfo(self, windex=0):
"""Return info about Omnibox.
@@ -657,13 +658,14 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
self._GetResultFromJSONRequest(cmd_dict)
- def WaitForAllDownloadsToComplete(self):
+ def WaitForAllDownloadsToComplete(self, windex=0):
"""Wait for all downloads to complete.
Note: This method does not work for dangerous downloads. Use
WaitForGivenDownloadsToComplete (below) instead.
"""
- self._GetResultFromJSONRequest({'command': 'WaitForAllDownloadsToComplete'})
+ cmd_dict = {'command': 'WaitForAllDownloadsToComplete'}
+ self._GetResultFromJSONRequest(cmd_dict, windex=windex)
def WaitForDownloadToComplete(self, download_path, timeout=-1):
"""Wait for the given downloads to complete.
@@ -728,7 +730,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
return self._GetResultFromJSONRequest(cmd_dict, windex=window_index)
- def DownloadAndWaitForStart(self, file_url):
+ def DownloadAndWaitForStart(self, file_url, windex=0):
"""Trigger download for the given url and wait for downloads to start.
It waits for download by looking at the download info from Chrome, so
@@ -738,11 +740,16 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
download, it's fine to start another one even if the first one hasn't
completed.
"""
- num_downloads = len(self.GetDownloadsInfo().Downloads())
- self.NavigateToURL(file_url) # Trigger download.
+ try:
+ num_downloads = len(self.GetDownloadsInfo(windex).Downloads())
+ except JSONInterfaceError:
+ num_downloads = 0
+
+ self.NavigateToURL(file_url, windex) # Trigger download.
# It might take a while for the download to kick in, hold on until then.
self.assertTrue(self.WaitUntil(
- lambda: len(self.GetDownloadsInfo().Downloads()) == num_downloads + 1))
+ lambda: len(self.GetDownloadsInfo(windex).Downloads()) >
+ num_downloads))
def SetWindowDimensions(
self, x=None, y=None, width=None, height=None, windex=0):
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index 6e5a0a9..ec415be 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -74,6 +74,11 @@ void PyUITestBase::NavigateToURL(const char* url_string) {
UITestBase::NavigateToURL(url);
}
+void PyUITestBase::NavigateToURL(const char* url_string, int window_index) {
+ GURL url(url_string);
+ UITestBase::NavigateToURL(url, window_index);
+}
+
void PyUITestBase::NavigateToURL(
const char* url_string, int window_index, int tab_index) {
GURL url(url_string);
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index fe03779..ac34b4b 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -54,6 +54,9 @@ class PyUITestBase : public UITestBase {
// Navigate to the given URL in the active tab. Blocks until page loaded.
void NavigateToURL(const char* url_string);
+ // Navigate to the given URL in the active tab in the given window.
+ void NavigateToURL(const char* url_string, int window_index);
+
// 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);
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index 3a88b13..3ed684d 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -220,6 +220,7 @@ class PyUITestBase {
"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);
void NavigateToURL(const char* url_string, int window_index, int tab_index);
%feature("docstring", "Reload the active tab in the given window (or first "
@@ -377,7 +378,7 @@ class PyUITestBase {
"(window, tab, frame) and return the specified DOM value "
"as a string. This is a wrapper around "
"window.domAutomationController.send().") GetDOMValue;
- std::wstring GetDOMValue(const std::wstring& expr,
+ std::wstring GetDOMValue(const std::wstring& expr,
int window_index=0,
int tab_index=0,
const std::wstring& frame_xpath="");
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc
index 60d4f31..28981ab 100644
--- a/chrome/test/ui/ui_test.cc
+++ b/chrome/test/ui/ui_test.cc
@@ -273,6 +273,10 @@ void UITestBase::NavigateToURL(const GURL& url) {
NavigateToURL(url, 0, GetActiveTabIndex(0));
}
+void UITestBase::NavigateToURL(const GURL& url, int window_index) {
+ NavigateToURL(url, window_index, GetActiveTabIndex(window_index));
+}
+
void UITestBase::NavigateToURL(const GURL& url, int window_index, int
tab_index) {
NavigateToURLBlockUntilNavigationsComplete(url, 1, window_index, tab_index);
diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h
index fdea73b..c248d0d 100644
--- a/chrome/test/ui/ui_test.h
+++ b/chrome/test/ui/ui_test.h
@@ -120,6 +120,9 @@ class UITestBase {
// This method doesn't return until the navigation is complete.
void NavigateToURL(const GURL& url);
+ // Navigate to the given URL in the active tab of the given app window.
+ void NavigateToURL(const GURL& url, int window_index);
+
// Same as above, except in the given tab and window.
void NavigateToURL(const GURL& url, int window_index, int tab_index);