diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 21:44:46 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 21:44:46 +0000 |
commit | fe534f020d93a61ed8b51dd16b121b6855642807 (patch) | |
tree | 8add3d7eb5daba40d8276766d1fba8552af47e74 /chrome | |
parent | 14a000d1e7ced20cb4866a727323e4ea99f78bf7 (diff) | |
download | chromium_src-fe534f020d93a61ed8b51dd16b121b6855642807.zip chromium_src-fe534f020d93a61ed8b51dd16b121b6855642807.tar.gz chromium_src-fe534f020d93a61ed8b51dd16b121b6855642807.tar.bz2 |
Add 2 tests for history.
testDownloadNoHistory,testRedirectHistory -- from Deepak.
Also, move _DownloadAndWaitForStart (re-used by the new tests) to a common
location.
TEST=python chrome/test/funtional/history.py
Review URL: http://codereview.chromium.org/1702010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45987 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/test/data/History/landing.html | 11 | ||||
-rw-r--r-- | chrome/test/data/History/redirector.html | 12 | ||||
-rw-r--r-- | chrome/test/functional/downloads.py | 22 | ||||
-rw-r--r-- | chrome/test/functional/history.py | 29 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 16 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.i | 6 |
6 files changed, 77 insertions, 19 deletions
diff --git a/chrome/test/data/History/landing.html b/chrome/test/data/History/landing.html new file mode 100644 index 0000000..767b66c --- /dev/null +++ b/chrome/test/data/History/landing.html @@ -0,0 +1,11 @@ +<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN"> +<HTML> + <HEAD> + <TITLE> + A Small Hello + </TITLE> + </HEAD> +<BODY> + <H1>Hi</H1> +</BODY> +</HTML> diff --git a/chrome/test/data/History/redirector.html b/chrome/test/data/History/redirector.html new file mode 100644 index 0000000..ff16609 --- /dev/null +++ b/chrome/test/data/History/redirector.html @@ -0,0 +1,12 @@ +<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN"> +<!-- Redirector page. Used by chrome/test/functional/history.py --> +<HTML> +<HEAD> +<META HTTP-EQUIV="Refresh" + CONTENT="0; URL=landing.html"> +<TITLE> REDIRECT PAGE </TITLE> +</HEAD> +<BODY> +<P> REDIRECT TO landing.html </P> +</BODY> +</HTML> diff --git a/chrome/test/functional/downloads.py b/chrome/test/functional/downloads.py index ec831d6..39cde57 100644 --- a/chrome/test/functional/downloads.py +++ b/chrome/test/functional/downloads.py @@ -29,22 +29,6 @@ class DownloadsTest(pyauto.PyUITest): """Make sure "wait for downloads" returns quickly if we have none.""" self.WaitForAllDownloadsToComplete() - def _DownloadAndWaitForStart(self, file_url): - """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 - anything which isn't registered by the history service won't be noticed. - This is not thread-safe, but it's fine to call this method to start - downloading multiple files in parallel. That is after starting a - 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. - # 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)) - def testZip(self): """Download a zip and verify that it downloaded correctly. Also verify that the download shelf showed up. @@ -57,7 +41,7 @@ class DownloadsTest(pyauto.PyUITest): 'a_zip_file.zip') os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) - self._DownloadAndWaitForStart(file_url) + self.DownloadAndWaitForStart(file_url) # Wait for the download to finish. self.WaitForAllDownloadsToComplete() @@ -95,7 +79,7 @@ class DownloadsTest(pyauto.PyUITest): 'a_zip_file (%d).zip' % i) renamed_files.append(expected_filename) os.path.exists(expected_filename) and os.remove(expected_filename) - self._DownloadAndWaitForStart(file_url) + self.DownloadAndWaitForStart(file_url) self.WaitForAllDownloadsToComplete() @@ -142,7 +126,7 @@ class DownloadsTest(pyauto.PyUITest): file_url = self.GetFileURLForPath(file_path) downloaded_file = os.path.join(download_dir, filename) os.path.exists(downloaded_file) and os.remove(downloaded_file) - self._DownloadAndWaitForStart(file_url) + self.DownloadAndWaitForStart(file_url) self.WaitForAllDownloadsToComplete() # Verify downloads. diff --git a/chrome/test/functional/history.py b/chrome/test/functional/history.py index ec25ce6..c7b23cc 100644 --- a/chrome/test/functional/history.py +++ b/chrome/test/functional/history.py @@ -141,6 +141,35 @@ class HistoryTest(pyauto.PyUITest): for i in range(num_urls): self.assertEqual(urls[-1 - i], history[i]['url']) + def testDownloadNoHistory(self): + """Downloaded URLs should not show up in history.""" + assert not self.GetHistoryInfo().History(), 'Expecting clean history.' + file_url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'downloads', + 'a_zip_file.zip')) + downloaded_file = os.path.join(self.GetDownloadDirectory().value(), + 'a_zip_file.zip') + os.path.exists(downloaded_file) and os.remove(downloaded_file) + self.DownloadAndWaitForStart(file_url) + self.WaitForAllDownloadsToComplete() + os.path.exists(downloaded_file) and os.remove(downloaded_file) + # We shouldn't have any history + history = self.GetHistoryInfo().History() + self.assertEqual(0, len(history)) + + def testRedirectHistory(self): + """HTTP meta-refresh redirects should have separate history entries.""" + assert not self.GetHistoryInfo().History(), 'Expecting clean history.' + test_dir = os.path.join(os.path.abspath(self.DataDir()), 'history') + file_url = self.GetFileURLForPath(os.path.join(test_dir, 'redirector.html')) + landing_url = self.GetFileURLForPath(os.path.join(test_dir, 'landing.html')) + tab = self.GetBrowserWindow(0).GetTab(0) + tab.NavigateToURLBlockUntilNavigationsComplete(pyauto.GURL(file_url), 2) + self.assertEqual(landing_url, self.GetActiveTabURL().spec()) + # We should have two history items + history = self.GetHistoryInfo().History() + self.assertEqual(2, len(history)) + self.assertEqual(landing_url, history[0]['url']) + if __name__ == '__main__': pyauto_functional.Main() diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index b00f071..e8975126 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -283,6 +283,22 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): self._SendJSONRequest(0, json.dumps({'command': 'WaitForAllDownloadsToComplete'})) + def DownloadAndWaitForStart(self, file_url): + """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 + anything which isn't registered by the history service won't be noticed. + This is not thread-safe, but it's fine to call this method to start + downloading multiple files in parallel. That is after starting a + 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. + # 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)) + def GetHistoryInfo(self, search_text=''): """Return info about browsing history. diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i index 1c36526..626303f 100644 --- a/chrome/test/pyautolib/pyautolib.i +++ b/chrome/test/pyautolib/pyautolib.i @@ -105,6 +105,12 @@ class TabProxy { %feature("docstring", "Navigates to a given GURL. " "Blocks until the navigation completes. ") NavigateToURL; AutomationMsg_NavigationResponseValues NavigateToURL(const GURL& url); + %feature("docstring", "Navigates to a given GURL. Blocks until the given " + "number of navigations complete.") + NavigateToURLBlockUntilNavigationsComplete; + AutomationMsg_NavigationResponseValues + NavigateToURLBlockUntilNavigationsComplete( + const GURL& url, int number_of_navigations); %feature("docstring", "Equivalent to hitting the Back button. " "Blocks until navigation completes.") GoBack; AutomationMsg_NavigationResponseValues GoBack(); |