diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-29 21:41:43 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-29 21:41:43 +0000 |
commit | 9f463b0e52b26505bfb083ae1fa4efa6986b9fc1 (patch) | |
tree | 14297ec5205c8ea3809e2e39cb6ad1cf08aa7491 /chrome/test | |
parent | a401a8f379227022dbcb15911bc0f637b4ef2cde (diff) | |
download | chromium_src-9f463b0e52b26505bfb083ae1fa4efa6986b9fc1.zip chromium_src-9f463b0e52b26505bfb083ae1fa4efa6986b9fc1.tar.gz chromium_src-9f463b0e52b26505bfb083ae1fa4efa6986b9fc1.tar.bz2 |
Moved private functions into it's own seperate utils file for commonly used functions.
Review URL: http://codereview.chromium.org/4148012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64490 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/functional/find_in_page.py | 30 | ||||
-rw-r--r-- | chrome/test/functional/test_utils.py | 44 |
2 files changed, 50 insertions, 24 deletions
diff --git a/chrome/test/functional/find_in_page.py b/chrome/test/functional/find_in_page.py index a6f9d54..43419a9 100644 --- a/chrome/test/functional/find_in_page.py +++ b/chrome/test/functional/find_in_page.py @@ -8,6 +8,7 @@ import unittest import pyauto_functional import pyauto +import test_utils class FindMatchTests(pyauto.PyUITest): @@ -74,6 +75,7 @@ class FindMatchTests(pyauto.PyUITest): """Verify search for text within special URLs such as chrome:history. chrome://history, chrome://downloads, pyAuto Data directory """ + zip_file = 'a_zip_file.zip' self.NavigateToURL(self.GetFileURLForPath(self.DataDir())) # search in Data directory self.assertEqual(1, @@ -86,35 +88,15 @@ class FindMatchTests(pyauto.PyUITest): expect_retval=1) self.assertEqual(1, self.FindInPage('data', tab_index=1)['match_count']) # search in Downloads page - self._DownloadZipFile() + test_utils.DownloadFileFromDownloadsDataDir(self, zip_file) self.AppendTab(pyauto.GURL('chrome://downloads')) # the contents in the downloads page load asynchronously after tab loads self.WaitUntil( - lambda: self.FindInPage('a_zip_file.zip', tab_index=2)['match_count'], + lambda: self.FindInPage(zip_file, tab_index=2)['match_count'], expect_retval=2) self.assertEqual(2, - self.FindInPage('a_zip_file.zip', tab_index=2)['match_count']) - self._RemoveZipFile() - - def _DownloadZipFile(self): - """Download a zip file.""" - zip_file = 'a_zip_file.zip' - download_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') - file_path = os.path.join(download_dir, zip_file) - file_url = self.GetFileURLForPath(file_path) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), zip_file) - # Check if zip file already exists. If so then delete it. - if os.path.exists(downloaded_pkg): - self._RemoveZipFile() - self.DownloadAndWaitForStart(file_url) - # Wait for the download to finish - self.WaitForAllDownloadsToComplete() - - def _RemoveZipFile(self): - """Delete a_zip_file.zip from the download directory.""" - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - 'a_zip_file.zip') - os.remove(downloaded_pkg) + self.FindInPage(zip_file, tab_index=2)['match_count']) + test_utils.RemoveDownloadedTestFile(self, zip_file) if __name__ == '__main__': diff --git a/chrome/test/functional/test_utils.py b/chrome/test/functional/test_utils.py new file mode 100644 index 0000000..838e85e --- /dev/null +++ b/chrome/test/functional/test_utils.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os + +import pyauto_functional +import pyauto_utils + + +"""Commonly used functions for PyAuto tests.""" + +def DownloadFileFromDownloadsDataDir(test, file_name): + """Download a file from downloads data directory. + + Args: + test: derived from pyauto.PyUITest - base class for UI test cases + file_name: name of file to download + """ + download_dir = os.path.join(os.path.abspath(test.DataDir()), 'downloads') + file_path = os.path.join(download_dir, file_name) + file_url = test.GetFileURLForPath(file_path) + downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), + file_name) + # Check if zip file already exists. If so then delete it. + if os.path.exists(downloaded_pkg): + self.RemoveDownloadedTestFile(test, file_name) + test.DownloadAndWaitForStart(file_url) + test.WaitForAllDownloadsToComplete() + + +def RemoveDownloadedTestFile(test, file_name): + """Delete a file from the downloads directory. + + Arg: + test: derived from pyauto.PyUITest - base class for UI test cases + file_name: name of file to remove + """ + downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), + file_name) + pyauto_utils.RemovePath(downloaded_pkg) + pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') |