blob: f8e05b36ee771e97a41d9920ac14d66d3c5172ff [file] [log] [blame]
# Copyright (c) 2011 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.
"""History: python representation for history.
Obtain one of these from PyUITestSuite::GetHistoryInfo() call.
class MyTest(pyauto.PyUITest):
def testBasic(self):
url = ''
history = self.GetHistoryInfo()
self.assertEqual(1, len(history))
self.assertEqual(url, history[0]['url'])
See more tests in chrome/test/functional/
import simplejson as json
from pyauto_errors import JSONInterfaceError
class HistoryInfo(object):
"""Represent info about browsing history.
The info is represented as a list of history items containing url, title,
time, etc.
def __init__(self, history_dict):
"""Initialize a HistoryInfo from a string of json.
json_string: a dictionary as returned by the IPC command 'GetHistoryInfo'.
A typical dict representing history info looks like:
{'history': [
{'url': '',
'title': 'Google',
}, ] }
pyauto_errors.JSONInterfaceError if the automation call returns an error.
# JSON string prepared in GetHistoryInfo() in
self.historydict = history_dict
def History(self):
"""Get history list.
History is ordered latest first, that is in the same order as
chrome://history/ would list.
[ { u'snippet': u'',
u'starred': False,
u'time': 1271781612,
u'title': u'Google News',
u'url': u''},
{ u'snippet': u'',
u'starred': True,
u'time': 1271781602,
u'title': u'Google',
u'url': u''}]
The snippet attribute will be empty in most cases. If GetHistoryInfo() is
provided a non-empty search_text arg, the snippet attribute will contain the
snippet as it would be visible when searching for that text in the
chrome://history/ UI.
[item1, item2, ...]
return self.historydict.get('history', [])