1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """History: python representation for history.
7 Obtain one of these from PyUITestSuite::GetHistoryInfo() call.
10 class MyTest(pyauto.PyUITest):
12 url = 'http://www.google.com/'
13 self.NavigateToURL(url)
14 history = self.GetHistoryInfo()
15 self.assertEqual(1, len(history))
16 self.assertEqual(url, history[0]['url'])
18 See more tests in chrome/test/functional/history.py.
21 import simplejson
as json
23 from pyauto_errors
import JSONInterfaceError
26 class HistoryInfo(object):
27 """Represent info about browsing history.
29 The info is represented as a list of history items containing url, title,
32 def __init__(self
, history_dict
):
33 """Initialize a HistoryInfo from a string of json.
36 json_string: a dictionary as returned by the IPC command 'GetHistoryInfo'.
37 A typical dict representing history info looks like:
39 {'url': 'http://www.google.com/',
46 pyauto_errors.JSONInterfaceError if the automation call returns an error.
48 # JSON string prepared in GetHistoryInfo() in automation_provider.cc
49 self
.historydict
= history_dict
54 History is ordered latest first, that is in the same order as
55 chrome://history/ would list.
61 u'title': u'Google News',
62 u'url': u'http://news.google.com/'},
67 u'url': u'http://www.google.com/'}]
69 The snippet attribute will be empty in most cases. If GetHistoryInfo() is
70 provided a non-empty search_text arg, the snippet attribute will contain the
71 snippet as it would be visible when searching for that text in the
77 return self
.historydict
.get('history', [])