summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authornirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-07 05:49:11 +0000
committernirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-07 05:49:11 +0000
commitf5aa79970b40b9c3d873c833022779be96c16444 (patch)
treec8334f69227c6c1890b90743321f1fe4a00a5441 /chrome/test
parent5e4e3aa3099584e473a72b668ffa9c3119ef9a5b (diff)
downloadchromium_src-f5aa79970b40b9c3d873c833022779be96c16444.zip
chromium_src-f5aa79970b40b9c3d873c833022779be96c16444.tar.gz
chromium_src-f5aa79970b40b9c3d873c833022779be96c16444.tar.bz2
Add new downloads tests
testBigZip -- test downloads for a 1 GB file, from Sunand This required methods to temporarily increase automation timeout, since it might not be possible to download 1 GB file in the default 25 secs. testDownloadsPersistence -- verify that download history persists browser restart, from Srikanth Review URL: http://codereview.chromium.org/3046030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55341 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/automation/automation_proxy.h7
-rw-r--r--chrome/test/functional/downloads.py72
-rw-r--r--chrome/test/pyautolib/pyauto.py25
-rw-r--r--chrome/test/pyautolib/pyautolib.i9
-rw-r--r--chrome/test/ui/ui_test.cc11
-rw-r--r--chrome/test/ui/ui_test.h6
6 files changed, 120 insertions, 10 deletions
diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h
index fca2f1b..8b864aa 100644
--- a/chrome/test/automation/automation_proxy.h
+++ b/chrome/test/automation/automation_proxy.h
@@ -236,6 +236,13 @@ class AutomationProxy : public IPC::Channel::Listener,
return static_cast<int>(command_execution_timeout_.InMilliseconds());
}
+ // Sets the timeout for subsequent automation calls.
+ void set_command_execution_timeout_ms(int timeout_ms) {
+ DCHECK(timeout_ms <= 10 * 60 * 1000 ) << "10+ min of automation timeout "
+ "can make the test hang and be killed by buildbot";
+ command_execution_timeout_ = base::TimeDelta::FromMilliseconds(timeout_ms);
+ }
+
// Returns the server version of the server connected. You may only call this
// method after WaitForAppLaunch() has returned SUCCESS or VERSION_MISMATCH.
// If you call it before this, the return value is undefined.
diff --git a/chrome/test/functional/downloads.py b/chrome/test/functional/downloads.py
index 1f2f49b..44a5bf6 100644
--- a/chrome/test/functional/downloads.py
+++ b/chrome/test/functional/downloads.py
@@ -23,7 +23,7 @@ class DownloadsTest(pyauto.PyUITest):
"""Determine if 2 given files have the same contents."""
if not (os.path.exists(file1) and os.path.exists(file2)):
return False
- return filecmp.cmp(file1, file2)
+ return filecmp.cmp(file1, file2, shallow=False)
def testNoDownloadWaitingNeeded(self):
"""Make sure "wait for downloads" returns quickly if we have none."""
@@ -53,13 +53,45 @@ class DownloadsTest(pyauto.PyUITest):
self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg))
def testBigZip(self):
- # TODO: download something "pretty big". The above test will
- # usually wortk even without the WaitForAllDownloadsToComplete().
- # Manual testing shows it isn't just a noop, but an explicit test
- # is needed here. However, if the download is TOO big, we hit a
- # 30sec timeout in our automation proxy / IPC (didn't track down
- # where exactly).
- pass
+ """Verify that we can download a 1GB file.
+
+ This test needs 2 GB of free space, 1 GB for the original zip file and
+ another for the downloaded one.
+
+ Note: This test increases automation timeout to 4 min. Things might seem
+ to hang.
+ """
+ size = 2**30 # 1 GB
+ # Create a 1 GB file on the fly
+ fd, file_path = tempfile.mkstemp(suffix='.zip', prefix='bigfile-')
+ os.lseek(fd, size, os.SEEK_SET)
+ os.write(fd, 'a')
+ os.close(fd)
+ try:
+ file_url = self.GetFileURLForPath(file_path)
+ downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
+ os.path.basename(file_path))
+ os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
+ self.DownloadAndWaitForStart(file_url)
+ # Waiting for big file to download might exceed automation timeout.
+ # Temporarily increase the automation timeout.
+ new_timeout = 4 * 60 * 1000 # 4 min
+ timeout_changer = pyauto.PyUITest.CmdExecutionTimeoutChanger(
+ self, new_timeout)
+ logging.info('Automation execution timeout has been increased. Things '
+ 'might seem to be hung even though it might not really be.')
+ self.WaitForAllDownloadsToComplete()
+ del timeout_changer # reset automation timeout
+ # Verify that the file was correctly downloaded
+ self.assertTrue(os.path.exists(downloaded_pkg),
+ 'Downloaded file %s missing.' % downloaded_pkg)
+ self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg),
+ 'Downloaded file %s does not match original' %
+ downloaded_pkg)
+ finally: # Cleanup. Remove all big files.
+ os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
+ os.path.exists(file_path) and os.remove(file_path)
+
def testFileRenaming(self):
"""Test file renaming when downloading a already-existing filename."""
@@ -136,6 +168,30 @@ class DownloadsTest(pyauto.PyUITest):
finally:
shutil.rmtree(unicode(temp_dir)) # unicode so that win treats nicely.
+ def testDownloadsPersistence(self):
+ """Verify that download history persists on session restart."""
+ test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads')
+ file_url = self.GetFileURLForPath(os.path.join(test_dir, 'a_zip_file.zip'))
+ downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
+ 'a_zip_file.zip')
+ os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
+ self.DownloadAndWaitForStart(file_url)
+ downloads = self.GetDownloadsInfo().Downloads()
+ self.assertEqual(1, len(downloads))
+ self.assertEqual('a_zip_file.zip', downloads[0]['file_name'])
+ file_url = downloads[0]['url']
+ self.RestartBrowser(clear_profile=False)
+ # Trigger the download service to get loaded after restart.
+ self.NavigateToURL('chrome://downloads/')
+ # Verify that there's no download shelf anymore.
+ self.assertFalse(self.IsDownloadShelfVisible(),
+ 'Download shelf persisted browser restart.')
+ # Verify that the download history persists.
+ downloads = self.GetDownloadsInfo().Downloads()
+ self.assertEqual(1, len(downloads))
+ self.assertEqual('a_zip_file.zip', downloads[0]['file_name'])
+ self.assertEqual(file_url, downloads[0]['url'])
+
if __name__ == '__main__':
pyauto_functional.Main()
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index bca01d2..7e0e766 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -292,6 +292,31 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
time.sleep(retry_sleep)
return False
+ class CmdExecutionTimeoutChanger(object):
+ """Facilitate temporary changes to command_execution_timeout_ms.
+
+ Automatically resets to original timeout when object is destroyed.
+ """
+ _saved_timeout = -1 # Saved value for command_execution_timeout_ms
+
+ def __init__(self, ui_test, new_timeout):
+ """Initialize.
+
+ Args:
+ ui_test: a PyUITest object
+ new_timeout: new timeout to use (in milli secs)
+ """
+ self._saved_timeout = ui_test.command_execution_timeout_ms()
+ if new_timeout != self._saved_timeout:
+ ui_test.set_command_execution_timeout_ms(new_timeout)
+ self._ui_test = ui_test
+
+ def __del__(self):
+ """Reset command_execution_timeout_ms to original value."""
+ if self._ui_test.command_execution_timeout_ms() != self._saved_timeout:
+ self._ui_test.set_command_execution_timeout_ms(self._saved_timeout)
+
+
def _GetResultFromJSONRequest(self, cmd_dict, windex=0):
"""Issue call over the JSON automation channel and fetch output.
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index b5fd1a5..875d530 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -187,6 +187,15 @@ class PyUITestBase {
action_max_timeout_ms;
int action_max_timeout_ms() const;
+ %feature("docstring", "Get the timeout (in milli secs) for an automation "
+ "call") command_execution_timeout_ms;
+ int command_execution_timeout_ms() const;
+ %feature("docstring", "Set the timeout (in milli secs) for an automation "
+ "call. This is an internal method. Do not use this directly. "
+ "Use CmdExecutionTimeoutChanger instead")
+ set_command_execution_timeout_ms;
+ void set_command_execution_timeout_ms(int timeout);
+
%feature("docstring", "Launches the browser and IPC testing server.")
LaunchBrowserAndServer;
void LaunchBrowserAndServer();
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc
index 59f25bb..fc7eb42 100644
--- a/chrome/test/ui/ui_test.cc
+++ b/chrome/test/ui/ui_test.cc
@@ -210,6 +210,17 @@ void UITestBase::TearDown() {
EXPECT_EQ(expected_crashes_, actual_crashes) << error_msg;
}
+void UITestBase::set_command_execution_timeout_ms(int timeout) {
+ if (server_.get()) {
+ // automation channel already created. Set its timeout for use by
+ // subsequent automation calls.
+ server_->set_command_execution_timeout_ms(timeout);
+ }
+ command_execution_timeout_ms_ = timeout;
+ LOG(INFO) << "Automation command execution timeout set to "
+ << timeout << " milli secs.";
+}
+
// Pick up the various test time out values from the command line.
void UITestBase::InitializeTimeouts() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h
index a31e1ac..db826f6 100644
--- a/chrome/test/ui/ui_test.h
+++ b/chrome/test/ui/ui_test.h
@@ -406,8 +406,10 @@ class UITestBase {
base::ProcessId browser_process_id() const { return process_id_; }
// Timeout accessors.
- void set_command_execution_timeout_ms(int timeout) {
- command_execution_timeout_ms_ = timeout;
+ void set_command_execution_timeout_ms(int timeout);
+
+ int command_execution_timeout_ms() const {
+ return command_execution_timeout_ms_;
}
int action_timeout_ms() const { return action_timeout_ms_; }