summaryrefslogtreecommitdiffstats
path: root/chrome/test/pyautolib
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 00:24:48 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 00:24:48 +0000
commit5783990a51c446198b76cb1e27c0dec2a67c2e31 (patch)
tree8b042945a66eeb8fea62aeb08d3665bfd03ce58b /chrome/test/pyautolib
parent155f48eb76e559cbbe69dda978757ad47acfd457 (diff)
downloadchromium_src-5783990a51c446198b76cb1e27c0dec2a67c2e31.zip
chromium_src-5783990a51c446198b76cb1e27c0dec2a67c2e31.tar.gz
chromium_src-5783990a51c446198b76cb1e27c0dec2a67c2e31.tar.bz2
Add pyauto hook for getting and manipulating the data underneath the NTP.
BUG=49113 TEST=none Review URL: http://codereview.chromium.org/5088001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66709 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r--chrome/test/pyautolib/pyauto.py185
-rw-r--r--chrome/test/pyautolib/pyauto_errors.py5
2 files changed, 190 insertions, 0 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 39d03a3..f09bcd9 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -86,6 +86,7 @@ import omnibox_info
import plugins_info
import prefs_info
from pyauto_errors import JSONInterfaceError
+from pyauto_errors import NTPThumbnailNotShownError
import simplejson as json # found in third_party
@@ -1781,6 +1782,190 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
return self._GetResultFromJSONRequest(cmd_dict)['success']
+ def GetNTPThumbnails(self):
+ """Return a list of info about the sites in the NTP most visited section.
+ SAMPLE:
+ [{ u'title': u'Google',
+ u'url': u'http://www.google.com',
+ u'is_pinned': False},
+ {
+ u'title': u'Yahoo',
+ u'url': u'http://www.yahoo.com',
+ u'is_pinned': True}]
+ """
+ return self._GetNTPInfo()['most_visited']
+
+ def GetNTPThumbnailIndex(self, thumbnail):
+ """Returns the index of the given NTP thumbnail, or -1 if it is not shown.
+
+ Args:
+ thumbnail: a thumbnail dict received from |GetNTPThumbnails|
+ """
+ thumbnails = self.GetNTPThumbnails()
+ for i in range(len(thumbnails)):
+ if thumbnails[i]['url'] == thumbnail['url']:
+ return i
+ return -1
+
+ def MoveNTPThumbnail(self, thumbnail, new_index):
+ """Moves the given thumbnail to a new index. The indices in the NTP Most
+ Visited sites section look like:
+ 0 1 2 3
+ 4 5 6 7
+
+ When a thumbnail is moved, it is automatically pinned.
+
+ Args:
+ thumbnail: a thumbnail dict received from |GetNTPThumbnails|
+ new_index: the index to be moved to in the Most Visited sites section
+
+ Raises:
+ IndexError if there is no thumbnail at the index
+ """
+ if new_index < 0 or new_index >= len(self.GetNTPThumbnails()):
+ raise IndexError()
+ self._CheckNTPThumbnailShown(thumbnail)
+ cmd_dict = {
+ 'command': 'MoveNTPMostVisitedThumbnail',
+ 'url': thumbnail['url'],
+ 'index': new_index,
+ 'old_index': self.GetNTPThumbnailIndex(thumbnail)
+ }
+ self._GetResultFromJSONRequest(cmd_dict)
+
+ def RemoveNTPThumbnail(self, thumbnail):
+ """Removes the NTP thumbnail and returns true on success.
+
+ Args:
+ thumbnail: a thumbnail dict received from |GetNTPThumbnails|
+ """
+ self._CheckNTPThumbnailShown(thumbnail)
+ cmd_dict = {
+ 'command': 'RemoveNTPMostVisitedThumbnail',
+ 'url': thumbnail['url']
+ }
+ self._GetResultFromJSONRequest(cmd_dict)
+
+ def PinNTPThumbnail(self, thumbnail):
+ """Pins the NTP thumbnail.
+
+ Args:
+ thumbnail: a thumbnail dict received from |GetNTPThumbnails|
+ """
+ self._CheckNTPThumbnailShown(thumbnail)
+ self.MoveNTPThumbnail(thumbnail, self.GetNTPThumbnailIndex(thumbnail))
+
+ def UnpinNTPThumbnail(self, thumbnail):
+ """Unpins the NTP thumbnail and returns true on success.
+
+ Args:
+ thumbnail: a thumbnail dict received from |GetNTPThumbnails|
+ """
+ self._CheckNTPThumbnailShown(thumbnail)
+ cmd_dict = {
+ 'command': 'UnpinNTPMostVisitedThumbnail',
+ 'url': thumbnail['url']
+ }
+ self._GetResultFromJSONRequest(cmd_dict)
+
+ def IsNTPThumbnailPinned(self, thumbnail):
+ """Returns whether the NTP thumbnail is pinned.
+
+ Args:
+ thumbnail: a thumbnail dict received from |GetNTPThumbnails|
+ """
+ self._CheckNTPThumbnailShown(thumbnail)
+ index = self.GetNTPThumbnailIndex(thumbnail)
+ return self.GetNTPThumbnails()[index]['is_pinned']
+
+ def RestoreAllNTPThumbnails(self):
+ """Restores all the removed NTP thumbnails.
+ Note:
+ the default thumbnails may come back into the Most Visited sites
+ section after doing this
+ """
+ cmd_dict = {
+ 'command': 'RestoreAllNTPMostVisitedThumbnails'
+ }
+ self._GetResultFromJSONRequest(cmd_dict)
+
+ def GetNTPDefaultSites(self):
+ """Returns a list of URLs for all the default NTP sites, regardless of
+ whether they are showing or not.
+
+ These sites are the ones present in the NTP on a fresh install of Chrome.
+ """
+ return self._GetNTPInfo()['default_sites']
+
+ def RemoveNTPDefaultThumbnails(self):
+ """Removes all thumbnails for default NTP sites, regardless of whether they
+ are showing or not."""
+ cmd_dict = { 'command': 'RemoveNTPMostVisitedThumbnail' }
+ for site in self.GetNTPDefaultSites():
+ cmd_dict['url'] = site
+ self._GetResultFromJSONRequest(cmd_dict)
+
+ def GetNTPRecentlyClosed(self):
+ """Return a list of info about the items in the NTP recently closed section.
+ SAMPLE:
+ [{
+ u'type': u'tab',
+ u'url': u'http://www.bing.com',
+ u'title': u'Bing',
+ u'timestamp': 2139082.03912, # Seconds since epoch (Jan 1, 1970)
+ u'direction': u'ltr'},
+ {
+ u'type': u'window',
+ u'timestamp': 2130821.90812,
+ u'tabs': [
+ {
+ u'type': u'tab',
+ u'url': u'http://www.cnn.com',
+ u'title': u'CNN',
+ u'timestamp': 2129082.12098,
+ u'direction': u'ltr'}]},
+ {
+ u'type': u'tab',
+ u'url': u'http://www.altavista.com',
+ u'title': u'Altavista',
+ u'timestamp': 21390820.12903,
+ u'direction': u'rtl'}]
+ """
+ return self._GetNTPInfo()['recently_closed']
+
+ def _GetNTPInfo(self):
+ """Get info about the NTP. This does not retrieve the actual info shown
+ in a particular NTP, but the current data that would be used to display
+ a NTP.
+
+ This includes info about the most visited sites, the recently closed
+ tabs and windows, and the default NTP sites.
+
+ TODO(kkania): Add info about apps.
+
+ Returns:
+ a dictionary containing info about NTP info. See details about the
+ sections in their respective methods.
+
+ SAMPLE:
+ { u'most_visited': [ ... ],
+ u'recently_closed': [ ... ]
+ u'default_sites': [ ... ]
+ }
+
+ Raises:
+ pyauto_errors.JSONInterfaceError if the automation call returns an error.
+ """
+ cmd_dict = {
+ 'command': 'GetNTPInfo',
+ }
+ return self._GetResultFromJSONRequest(cmd_dict)
+
+ def _CheckNTPThumbnailShown(self, thumbnail):
+ if self.GetNTPThumbnailIndex(thumbnail) == -1:
+ raise NTPThumbnailNotShownError()
+
+
class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite):
"""Base TestSuite for PyAuto UI tests."""
diff --git a/chrome/test/pyautolib/pyauto_errors.py b/chrome/test/pyautolib/pyauto_errors.py
index 901874d..86a56f0 100644
--- a/chrome/test/pyautolib/pyauto_errors.py
+++ b/chrome/test/pyautolib/pyauto_errors.py
@@ -9,3 +9,8 @@
class JSONInterfaceError(RuntimeError):
"""Represent an error in the JSON ipc interface."""
pass
+
+class NTPThumbnailNotShownError(RuntimeError):
+ """Represent an error from attempting to manipulate a NTP thumbnail that
+ is not visible to a real user."""
+ pass