Move render_view_context_menu.* and related files out of tab_contents.
[chromium-blink-merge.git] / chrome / test / pyautolib / history_info.py
blobf8e05b36ee771e97a41d9920ac14d66d3c5172ff
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.
9 Example:
10 class MyTest(pyauto.PyUITest):
11 def testBasic(self):
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.
19 """
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,
30 time, etc.
31 """
32 def __init__(self, history_dict):
33 """Initialize a HistoryInfo from a string of json.
35 Args:
36 json_string: a dictionary as returned by the IPC command 'GetHistoryInfo'.
37 A typical dict representing history info looks like:
38 {'history': [
39 {'url': 'http://www.google.com/',
40 'title': 'Google',
41 ...,
42 ...,
43 }, ] }
45 Raises:
46 pyauto_errors.JSONInterfaceError if the automation call returns an error.
47 """
48 # JSON string prepared in GetHistoryInfo() in automation_provider.cc
49 self.historydict = history_dict
51 def History(self):
52 """Get history list.
54 History is ordered latest first, that is in the same order as
55 chrome://history/ would list.
57 Example:
58 [ { u'snippet': u'',
59 u'starred': False,
60 u'time': 1271781612,
61 u'title': u'Google News',
62 u'url': u'http://news.google.com/'},
63 { u'snippet': u'',
64 u'starred': True,
65 u'time': 1271781602,
66 u'title': u'Google',
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
72 chrome://history/ UI.
74 Returns:
75 [item1, item2, ...]
76 """
77 return self.historydict.get('history', [])