summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 17:27:29 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 17:27:29 +0000
commitbbe6aa04e14d5c7d176f303c199e2bf85ea40de7 (patch)
tree860ebcf3339fc0446c17a94b78f358ccff11425e /chrome/test
parent99f0c0818d6e612e6581f38bd0d53edceae44863 (diff)
downloadchromium_src-bbe6aa04e14d5c7d176f303c199e2bf85ea40de7.zip
chromium_src-bbe6aa04e14d5c7d176f303c199e2bf85ea40de7.tar.gz
chromium_src-bbe6aa04e14d5c7d176f303c199e2bf85ea40de7.tar.bz2
Add an AddHistoryItem() API to PyAuto with example use.
Change GetHistory time value from int to float to keep precision. BUG=none TEST=run pyautolib Review URL: http://codereview.chromium.org/2036004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46704 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/functional/history.py26
-rw-r--r--chrome/test/pyautolib/pyauto.py26
2 files changed, 52 insertions, 0 deletions
diff --git a/chrome/test/functional/history.py b/chrome/test/functional/history.py
index 992e2e5..f149ed8 100644
--- a/chrome/test/functional/history.py
+++ b/chrome/test/functional/history.py
@@ -4,6 +4,7 @@
# found in the LICENSE file.
import os
+import time
import pyauto_functional # Must be imported before pyauto
import pyauto
@@ -170,6 +171,31 @@ class HistoryTest(pyauto.PyUITest):
self.assertEqual(2, len(history))
self.assertEqual(landing_url, history[0]['url'])
+ def testForge(self):
+ """Brief test of forging history items.
+
+ Note the history system can tweak values (e.g. lower-case a URL or
+ append an '/' on it) so be careful with exact comparison.
+ """
+ assert not self.GetHistoryInfo().History(), 'Expecting clean history.'
+ # Minimal interface
+ self.AddHistoryItem({'url': 'http://ZOINKS'})
+ history = self.GetHistoryInfo().History()
+ self.assertEqual(1, len(history))
+ self.assertTrue('zoinks' in history[0]['url']) # yes it gets lower-cased.
+ # Full interface (specify both title and url)
+ now = time.time()
+ self.AddHistoryItem({'title': 'Google',
+ 'url': 'http://www.google.com',
+ 'time': now})
+ # Expect a second item
+ history = self.GetHistoryInfo().History()
+ self.assertEqual(2, len(history))
+ # And make sure our forged item is there.
+ self.assertEqual('Google', history[0]['title'])
+ self.assertTrue('google.com' in history[0]['url'])
+ self.assertTrue(abs(now - history[0]['time']) < 1.0)
+
if __name__ == '__main__':
pyauto_functional.Main()
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 6438c5f..700d156 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -330,6 +330,32 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
return history_info.HistoryInfo(
self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ def AddHistoryItem(self, item):
+ """Forge a history item for Chrome.
+
+ Args:
+ item: a python dictionary representing the history item. Example:
+ {
+ # URL is the only mandatory item.
+ 'url': 'http://news.google.com',
+ # Title is optional.
+ 'title': 'Google News',
+ # Time is optional; if not set, assume "now". Time is in
+ # seconds since the Epoch. The python construct to get "Now"
+ # in the right scale is "time.time()". Can be float or int.
+ 'time': 1271781612
+ }
+ """
+ cmd_dict = { # Prepare command for the json interface
+ 'command': 'AddHistoryItem',
+ 'item': item
+ }
+ if not 'url' in item:
+ raise JSONInterfaceError('must specify url')
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
+
def GetPluginsInfo(self):
"""Return info about plugins.