summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authoralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 21:14:19 +0000
committeralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 21:14:19 +0000
commita0fc50d70d4f98debbc99c312cec44c3eff5bed5 (patch)
tree6401bbf0c6745dc2beaae8173e381012d3125c70 /chrome/test
parentf0d47ac8879f6f26df2c35a3e78528f0ee4dce05 (diff)
downloadchromium_src-a0fc50d70d4f98debbc99c312cec44c3eff5bed5.zip
chromium_src-a0fc50d70d4f98debbc99c312cec44c3eff5bed5.tar.gz
chromium_src-a0fc50d70d4f98debbc99c312cec44c3eff5bed5.tar.bz2
Clear Browsing Data hook added and some small tests. BUG=36176
Review URL: http://codereview.chromium.org/2909005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/functional/PYAUTO_TESTS1
-rw-r--r--chrome/test/functional/browsing_data.py83
-rw-r--r--chrome/test/pyautolib/pyauto.py25
3 files changed, 109 insertions, 0 deletions
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS
index 12d5adf..5029b06 100644
--- a/chrome/test/functional/PYAUTO_TESTS
+++ b/chrome/test/functional/PYAUTO_TESTS
@@ -25,6 +25,7 @@
'bookmark_bar',
'bookmarks',
'browser',
+ 'browsing_data',
'codesign',
'content',
'downloads',
diff --git a/chrome/test/functional/browsing_data.py b/chrome/test/functional/browsing_data.py
new file mode 100644
index 0000000..f217c5b
--- /dev/null
+++ b/chrome/test/functional/browsing_data.py
@@ -0,0 +1,83 @@
+#!/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 time
+
+import pyauto_functional # Must be imported before pyauto
+import pyauto
+
+
+class BrowsingDataTest(pyauto.PyUITest):
+ """Tests that clearing browsing data works correctly."""
+
+ def testClearHistory(self):
+ """Verify that clearing the history works."""
+ url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html'))
+ self.NavigateToURL(url)
+
+ history = self.GetHistoryInfo().History()
+ self.assertEqual(1, len(history))
+
+ self.ClearBrowsingData(['HISTORY'], 'EVERYTHING')
+ history = self.GetHistoryInfo().History()
+ self.assertEqual(0, len(history))
+
+ def testClearHistoryPastHour(self):
+ """Verify that clearing the history of the past hour works and does not
+ clear history older than one hour.
+ """
+ title = 'Google'
+ num_secs_in_hour = 3600
+
+ # Forge a history item for two hours ago
+ now = time.time()
+ last_hour = now - (2 * num_secs_in_hour)
+ self.AddHistoryItem({'title': title,
+ 'url': 'http://www.google.com',
+ 'time': last_hour})
+
+ # Forge a history item for right now
+ self.AddHistoryItem({'title': 'This Will Be Cleared',
+ 'url': 'http://www.dev.chromium.org',
+ 'time': now})
+
+ history = self.GetHistoryInfo().History()
+ self.assertEqual(2, len(history))
+
+ self.ClearBrowsingData(['HISTORY'], 'LAST_HOUR')
+ history = self.GetHistoryInfo().History()
+ self.assertEqual(1, len(history))
+ self.assertEqual(title, history[0]['title'])
+
+ def testClearHistoryAndDownloads(self):
+ """Verify that we can clear history and downloads at the same time."""
+ # First build up some history and download something.
+ url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html'))
+ self.NavigateToURL(url)
+
+ test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads')
+ file_path = os.path.join(test_dir, 'a_zip_file.zip')
+ file_url = self.GetFileURLForPath(file_path)
+ 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)
+ self.WaitForAllDownloadsToComplete()
+
+ # Verify that the history and download exist.
+ self.assertEqual(1, len(self.GetHistoryInfo().History()))
+ self.assertEqual(1, len(self.GetDownloadsInfo().Downloads()))
+
+ # Clear the history and downloads and verify they're both gone.
+ self.ClearBrowsingData(['HISTORY', 'DOWNLOADS'], 'EVERYTHING')
+ history = self.GetHistoryInfo().History()
+ downloads = self.GetDownloadsInfo().Downloads()
+ self.assertEqual(0, len(history))
+ self.assertEqual(0, len(downloads))
+
+
+if __name__ == '__main__':
+ pyauto_functional.Main()
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 4b94b3d..c25b893 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -757,6 +757,31 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
finally:
shutil.rmtree(tempdir)
+ def ClearBrowsingData(self, to_remove, time_period):
+ """Clear the specified browsing data. Implements the features available in
+ the "ClearBrowsingData" UI.
+
+ Args:
+ to_remove: a list of strings indicating which types of browsing data
+ should be removed. Strings that can be in the list are:
+ HISTORY, DOWNLOADS, COOKIES, PASSWORDS, FORM_DATA, CACHE
+ time_period: a string indicating the time period for the removal.
+ Possible strings are:
+ LAST_HOUR, LAST_DAY, LAST_WEEK, FOUR_WEEKS, EVERYTHING
+
+ Raises:
+ pyauto_errors.JSONInterfaceError if the automation call returns an error.
+ """
+ cmd_dict = { # Prepare command for the json interface
+ 'command': 'ClearBrowsingData',
+ 'to_remove': to_remove,
+ 'time_period': time_period
+ }
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
+ return ret_dict
+
def SetTheme(self, crx_file_path):
"""Installs the given theme synchronously.