summaryrefslogtreecommitdiffstats
path: root/chrome/test
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
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')
-rw-r--r--chrome/test/functional/PYAUTO_TESTS2
-rw-r--r--chrome/test/functional/ntp.py99
-rw-r--r--chrome/test/pyautolib/pyauto.py185
-rw-r--r--chrome/test/pyautolib/pyauto_errors.py5
4 files changed, 291 insertions, 0 deletions
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS
index 2a8c25c..32302b6 100644
--- a/chrome/test/functional/PYAUTO_TESTS
+++ b/chrome/test/functional/PYAUTO_TESTS
@@ -30,6 +30,7 @@
'content',
'cookies',
'crash_reporter',
+ 'databases',
'downloads',
'find_in_page',
# Turkish I problem. crbug.com/60638
@@ -40,6 +41,7 @@
'infobars',
'navigation',
'notifications',
+ 'ntp',
'omnibox',
'passwords',
'plugins',
diff --git a/chrome/test/functional/ntp.py b/chrome/test/functional/ntp.py
new file mode 100644
index 0000000..2be4960
--- /dev/null
+++ b/chrome/test/functional/ntp.py
@@ -0,0 +1,99 @@
+#!/usr/bin/python
+# Copyright (c) 2010 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.
+
+import os
+
+import pyauto_functional # Must be imported before pyauto
+import pyauto
+
+
+class NTPTest(pyauto.PyUITest):
+ """Test of the NTP."""
+
+ def Debug(self):
+ """Test method for experimentation.
+
+ This method is not run automatically.
+ """
+ while True:
+ raw_input('Interact with the browser and hit <enter> to dump NTP info...')
+ print '*' * 20
+ import pprint
+ pp = pprint.PrettyPrinter(indent=2)
+ pp.pprint(self._GetNTPInfo())
+
+ def __init__(self, methodName='runTest'):
+ super(NTPTest, self).__init__(methodName)
+
+ # Create some dummy file urls we can use in the tests.
+ filenames = ['title1.html', 'title2.html']
+ titles = [u'', u'Title Of Awesomeness']
+ urls = map(lambda name: self.GetFileURLForDataPath(name), filenames)
+ self.PAGES = map(lambda url, title: {'url': url, 'title': title},
+ urls, titles)
+
+ def testFreshProfile(self):
+ """Tests that the NTP with a fresh profile is correct"""
+ thumbnails = self.GetNTPThumbnails()
+ default_sites = self.GetNTPDefaultSites()
+ self.assertEqual(len(default_sites), len(thumbnails))
+ for thumbnail, default_site in zip(thumbnails, default_sites):
+ self.assertEqual(thumbnail['url'], default_site)
+ self.assertEqual(0, len(self.GetNTPRecentlyClosed()))
+
+ def testRemoveDefaultThumbnails(self):
+ """Tests that the default thumbnails can be removed"""
+ self.RemoveNTPDefaultThumbnails()
+ self.assertFalse(self.GetNTPThumbnails())
+ self.RestoreAllNTPThumbnails()
+ self.assertEqual(len(self.GetNTPDefaultSites()),
+ len(self.GetNTPThumbnails()))
+ self.RemoveNTPDefaultThumbnails()
+ self.assertFalse(self.GetNTPThumbnails())
+
+ def testOneMostVisitedSite(self):
+ """Tests that a site is added to the most visited sites"""
+ self.RemoveNTPDefaultThumbnails()
+ self.NavigateToURL(self.PAGES[1]['url'])
+ self.assertEqual(self.PAGES[1]['url'], self.GetNTPThumbnails()[0]['url'])
+ self.assertEqual(self.PAGES[1]['title'],
+ self.GetNTPThumbnails()[0]['title'])
+
+ def testOneRecentlyClosedTab(self):
+ """Tests that closing a tab populates the recently closed tabs list"""
+ self.RemoveNTPDefaultThumbnails()
+ self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
+ self.GetBrowserWindow(0).GetTab(1).Close(True)
+ self.assertEqual(self.PAGES[1]['url'],
+ self.GetNTPRecentlyClosed()[0]['url'])
+ self.assertEqual(self.PAGES[1]['title'],
+ self.GetNTPRecentlyClosed()[0]['title'])
+
+ def testMoveThumbnailBasic(self):
+ """Tests moving a thumbnail to a different index"""
+ self.RemoveNTPDefaultThumbnails()
+ self.NavigateToURL(self.PAGES[0]['url'])
+ self.NavigateToURL(self.PAGES[1]['url'])
+ thumbnails = self.GetNTPThumbnails()
+ self.MoveNTPThumbnail(thumbnails[0], 1)
+ self.assertTrue(self.IsNTPThumbnailPinned(thumbnails[0]))
+ self.assertFalse(self.IsNTPThumbnailPinned(thumbnails[1]))
+ self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[1]['url'])
+ self.assertEqual(1, self.GetNTPThumbnailIndex(thumbnails[0]))
+
+ def testPinningThumbnailBasic(self):
+ """Tests that we can pin/unpin a thumbnail"""
+ self.RemoveNTPDefaultThumbnails()
+ self.NavigateToURL(self.PAGES[0]['url'])
+ thumbnail1 = self.GetNTPThumbnails()[0]
+ self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1))
+ self.PinNTPThumbnail(thumbnail1)
+ self.assertTrue(self.IsNTPThumbnailPinned(thumbnail1))
+ self.UnpinNTPThumbnail(thumbnail1)
+ self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1))
+
+
+if __name__ == '__main__':
+ pyauto_functional.Main()
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