| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 """History: python representation for history. | |
| 6 | |
| 7 Obtain one of these from PyUITestSuite::GetHistoryInfo() call. | |
| 8 | |
| 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']) | |
| 17 | |
| 18 See more tests in chrome/test/functional/history.py. | |
| 19 """ | |
| 20 | |
| 21 import simplejson as json | |
| 22 | |
| 23 from pyauto_errors import JSONInterfaceError | |
| 24 | |
| 25 | |
| 26 class HistoryInfo(object): | |
| 27 """Represent info about browsing history. | |
| 28 | |
| 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. | |
| 34 | |
| 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 }, ] } | |
| 44 | |
| 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 | |
| 50 | |
| 51 def History(self): | |
| 52 """Get history list. | |
| 53 | |
| 54 History is ordered latest first, that is in the same order as | |
| 55 chrome://history/ would list. | |
| 56 | |
| 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/'}] | |
| 68 | |
| 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. | |
| 73 | |
| 74 Returns: | |
| 75 [item1, item2, ...] | |
| 76 """ | |
| 77 return self.historydict.get('history', []) | |
| OLD | NEW |