summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 02:12:34 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 02:12:34 +0000
commiteddfd88a922c7dc4c633d826ce52c428a5efc83f (patch)
tree0c06f87299c5bcea4c940516872c099415f63423 /chrome/test
parent8654c77d7660cbd4ca5b5bd5fbd0b64ad45f6e29 (diff)
downloadchromium_src-eddfd88a922c7dc4c633d826ce52c428a5efc83f.zip
chromium_src-eddfd88a922c7dc4c633d826ce52c428a5efc83f.tar.gz
chromium_src-eddfd88a922c7dc4c633d826ce52c428a5efc83f.tar.bz2
Add pyauto tests for the New Tab page.
BUG=63816 TEST=none Review URL: http://codereview.chromium.org/5255005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68268 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/functional/ntp.py225
-rw-r--r--chrome/test/functional/test_utils.py51
-rw-r--r--chrome/test/pyautolib/pyautolib.cc9
-rw-r--r--chrome/test/pyautolib/pyautolib.h3
-rw-r--r--chrome/test/pyautolib/pyautolib.i3
5 files changed, 278 insertions, 13 deletions
diff --git a/chrome/test/functional/ntp.py b/chrome/test/functional/ntp.py
index 2be4960..5d13314d 100644
--- a/chrome/test/functional/ntp.py
+++ b/chrome/test/functional/ntp.py
@@ -7,6 +7,7 @@ import os
import pyauto_functional # Must be imported before pyauto
import pyauto
+import test_utils
class NTPTest(pyauto.PyUITest):
@@ -34,6 +35,14 @@ class NTPTest(pyauto.PyUITest):
self.PAGES = map(lambda url, title: {'url': url, 'title': title},
urls, titles)
+ def _NTPContainsThumbnail(self, check_thumbnail):
+ """Returns whether the NTP's Most Visited section contains the given
+ thumbnail."""
+ for thumbnail in self.GetNTPThumbnails():
+ if check_thumbnail['url'] == thumbnail['url']:
+ return True
+ return False
+
def testFreshProfile(self):
"""Tests that the NTP with a fresh profile is correct"""
thumbnails = self.GetNTPThumbnails()
@@ -57,19 +66,10 @@ class NTPTest(pyauto.PyUITest):
"""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'])
+ thumbnail = self.GetNTPThumbnails()[0]
+ self.assertEqual(self.PAGES[1]['url'], thumbnail['url'])
+ self.assertEqual(self.PAGES[1]['title'], thumbnail['title'])
+ self.assertFalse(thumbnail['is_pinned'])
def testMoveThumbnailBasic(self):
"""Tests moving a thumbnail to a different index"""
@@ -94,6 +94,205 @@ class NTPTest(pyauto.PyUITest):
self.UnpinNTPThumbnail(thumbnail1)
self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1))
+ def testRemoveThumbnail(self):
+ """Tests removing a thumbnail works"""
+ self.RemoveNTPDefaultThumbnails()
+ for page in self.PAGES:
+ self.AppendTab(pyauto.GURL(page['url']))
+
+ thumbnails = self.GetNTPThumbnails()
+ for thumbnail in thumbnails:
+ self.assertEquals(thumbnail, self.GetNTPThumbnails()[0])
+ self.RemoveNTPThumbnail(thumbnail)
+ self.assertFalse(self._NTPContainsThumbnail(thumbnail))
+ self.assertFalse(self.GetNTPThumbnails())
+
+ def testIncognitoNotAppearInMostVisited(self):
+ """Tests that visiting a page in incognito mode does cause it to appear in
+ the Most Visited section"""
+ self.RemoveNTPDefaultThumbnails()
+ self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
+ self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
+ self.assertFalse(self.GetNTPThumbnails())
+
+ def testRestoreOncePinnedThumbnail(self):
+ """Tests that after restoring a once pinned thumbnail, the thumbnail is
+ not pinned"""
+ self.RemoveNTPDefaultThumbnails()
+ self.NavigateToURL(self.PAGES[0]['url'])
+ thumbnail1 = self.GetNTPThumbnails()[0]
+ self.PinNTPThumbnail(thumbnail1)
+ self.RemoveNTPThumbnail(thumbnail1)
+ self.RestoreAllNTPThumbnails()
+ self.RemoveNTPDefaultThumbnails()
+ self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1))
+
+ def testThumbnailPersistence(self):
+ """Tests that thumbnails persist across Chrome restarts"""
+ self.RemoveNTPDefaultThumbnails()
+ for page in self.PAGES:
+ self.AppendTab(pyauto.GURL(page['url']))
+ thumbnails = self.GetNTPThumbnails()
+ self.MoveNTPThumbnail(thumbnails[0], 1)
+ thumbnails = self.GetNTPThumbnails()
+
+ self.RestartBrowser(clear_profile=False)
+ self.assertEqual(thumbnails, self.GetNTPThumbnails())
+
+ def testRestoreAllRemovedThumbnails(self):
+ """Tests restoring all removed thumbnails"""
+ for page in self.PAGES:
+ self.AppendTab(pyauto.GURL(page['url']))
+
+ thumbnails = self.GetNTPThumbnails()
+ for thumbnail in thumbnails:
+ self.RemoveNTPThumbnail(thumbnail)
+
+ self.RestoreAllNTPThumbnails()
+ self.assertEquals(thumbnails, self.GetNTPThumbnails())
+
+ def testThumbnailRanking(self):
+ """Tests that the thumbnails are ordered according to visit count"""
+ self.RemoveNTPDefaultThumbnails()
+ for page in self.PAGES:
+ self.AppendTab(pyauto.GURL(page['url']))
+ thumbnails = self.GetNTPThumbnails()
+ self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[0]['url'])
+ self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
+ self.assertEqual(self.PAGES[1]['url'], self.GetNTPThumbnails()[0]['url'])
+ self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
+ self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
+ self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[0]['url'])
+
+ def testPinnedThumbnailNeverMoves(self):
+ """Tests that once a thumnail is pinned it never moves"""
+ self.RemoveNTPDefaultThumbnails()
+ for page in self.PAGES:
+ self.AppendTab(pyauto.GURL(page['url']))
+ self.PinNTPThumbnail(self.GetNTPThumbnails()[0])
+ thumbnails = self.GetNTPThumbnails()
+ self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
+ self.assertEqual(thumbnails, self.GetNTPThumbnails())
+
+ def testThumbnailTitleChangeAfterPageTitleChange(self):
+ """Tests that once a page title changes, the thumbnail title changes too"""
+ self.RemoveNTPDefaultThumbnails()
+ self.NavigateToURL(self.PAGES[0]['url'])
+ self.assertEqual(self.PAGES[0]['title'],
+ self.GetNTPThumbnails()[0]['title'])
+ self.ExecuteJavascript('window.domAutomationController.send(' +
+ 'document.title = "new title")')
+ self.assertEqual('new title', self.GetNTPThumbnails()[0]['title'])
+
+ def testCloseOneTab(self):
+ """Tests that closing a tab populates the recently closed 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 testCloseOneWindow(self):
+ """Tests that closing a window populates the recently closed list"""
+ self.RemoveNTPDefaultThumbnails()
+ self.OpenNewBrowserWindow(True)
+ self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
+ self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1)
+ self.CloseBrowserWindow(1)
+ expected = [{ u'type': u'window',
+ u'tabs': [
+ { u'type': u'tab',
+ u'url': self.PAGES[0]['url'],
+ u'direction': u'ltr' },
+ { u'type': u'tab',
+ u'url': self.PAGES[1]['url']}]
+ }]
+ self.assertEquals(expected, test_utils.StripUnmatchedKeys(
+ self.GetNTPRecentlyClosed(), expected))
+
+ def testCloseMultipleTabs(self):
+ """Tests closing multiple tabs populates the Recently Closed section in
+ order"""
+ self.RemoveNTPDefaultThumbnails()
+ self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
+ self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
+ self.GetBrowserWindow(0).GetTab(2).Close(True)
+ self.GetBrowserWindow(0).GetTab(1).Close(True)
+ expected = [{ u'type': u'tab',
+ u'url': self.PAGES[0]['url']
+ },
+ { u'type': u'tab',
+ u'url': self.PAGES[1]['url']
+ }]
+ self.assertEquals(expected, test_utils.StripUnmatchedKeys(
+ self.GetNTPRecentlyClosed(), expected))
+
+ def testCloseWindowWithOneTab(self):
+ """Tests that closing a window with only one tab only shows up as a tab in
+ the Recently Closed section"""
+ self.RemoveNTPDefaultThumbnails()
+ self.OpenNewBrowserWindow(True)
+ self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
+ self.CloseBrowserWindow(1)
+ expected = [{ u'type': u'tab',
+ u'url': self.PAGES[0]['url']
+ }]
+ self.assertEquals(expected, test_utils.StripUnmatchedKeys(
+ self.GetNTPRecentlyClosed(), expected))
+
+ def testCloseMultipleWindows(self):
+ """Tests closing multiple windows populates the Recently Closed list"""
+ self.RemoveNTPDefaultThumbnails()
+ self.OpenNewBrowserWindow(True)
+ self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
+ self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1)
+ self.OpenNewBrowserWindow(True)
+ self.NavigateToURL(self.PAGES[1]['url'], 2, 0)
+ self.AppendTab(pyauto.GURL(self.PAGES[0]['url']), 2)
+ self.CloseBrowserWindow(2)
+ self.CloseBrowserWindow(1)
+ expected = [{ u'type': u'window',
+ u'tabs': [
+ { u'type': u'tab',
+ u'url': self.PAGES[0]['url'],
+ u'direction': u'ltr' },
+ { u'type': u'tab',
+ u'url': self.PAGES[1]['url']}]
+ },
+ { u'type': u'window',
+ u'tabs': [
+ { u'type': u'tab',
+ u'url': self.PAGES[1]['url'],
+ u'direction': u'ltr' },
+ { u'type': u'tab',
+ u'url': self.PAGES[0]['url']}]
+ }]
+ self.assertEquals(expected, test_utils.StripUnmatchedKeys(
+ self.GetNTPRecentlyClosed(), expected))
+
+ def testRecentlyClosedShowsUniqueItems(self):
+ """Tests that the Recently Closed section does not show duplicate items"""
+ self.RemoveNTPDefaultThumbnails()
+ self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
+ self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
+ self.GetBrowserWindow(0).GetTab(1).Close(True)
+ self.GetBrowserWindow(0).GetTab(1).Close(True)
+ self.assertEquals(1, len(self.GetNTPRecentlyClosed()))
+
+ def testRecentlyClosedIncognito(self):
+ """Tests that we don't record closure of Incognito tabs or windows"""
+ #self.RemoveNTPDefaultThumbnails()
+ self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
+ self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
+ self.AppendTab(pyauto.GURL(self.PAGES[0]['url']), 1)
+ self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1)
+ self.GetBrowserWindow(1).GetTab(0).Close(True)
+ self.assertFalse(self.GetNTPRecentlyClosed())
+ self.CloseBrowserWindow(1)
+ self.assertFalse(self.GetNTPRecentlyClosed())
+
if __name__ == '__main__':
pyauto_functional.Main()
diff --git a/chrome/test/functional/test_utils.py b/chrome/test/functional/test_utils.py
index ad64ce7..39bffd8 100644
--- a/chrome/test/functional/test_utils.py
+++ b/chrome/test/functional/test_utils.py
@@ -4,9 +4,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import copy
import email
import os
import smtplib
+import types
import pyauto_functional
import pyauto_utils
@@ -138,3 +140,52 @@ def SendMail(send_from, send_to, subject, text, smtp, file_to_send=None):
smtp_obj.sendmail(send_from, send_to, msg.as_string())
smtp_obj.close()
+
+def StripUnmatchedKeys(item_to_strip, reference_item):
+ """Returns a copy of 'item_to_strip' where unmatched key-value pairs in
+ every dictionary are removed.
+
+ This will examine each dictionary in 'item_to_strip' recursively, and will
+ remove keys that are not found in the corresponding dictionary in
+ 'reference_item'. This is useful for testing equality of a subset of data.
+
+ Items may contain dictionaries, lists, or primitives, but only corresponding
+ dictionaries will be stripped. A corresponding entry is one which is found
+ in the same index in the corresponding parent array or at the same key in the
+ corresponding parent dictionary.
+
+ Arg:
+ item_to_strip: item to copy and remove all unmatched key-value pairs
+ reference_item: item that serves as a reference for which keys-value pairs
+ to strip from 'item_to_strip'
+
+ Returns:
+ a copy of 'item_to_strip' where all key-value pairs that do not have a
+ matching key in 'reference_item' are removed
+
+ Example:
+ item_to_strip = {'tabs': 3,
+ 'time': 5908}
+ reference_item = {'tabs': 2}
+ StripUnmatchedKeys(item_to_strip, reference_item) will return {'tabs': 3}
+ """
+ def StripList(list1, list2):
+ return_list = copy.deepcopy(list2)
+ for i in range(min(len(list1), len(list2))):
+ return_list[i] = StripUnmatchedKeys(list1[i], list2[i])
+ return return_list
+
+ def StripDict(dict1, dict2):
+ return_dict = {}
+ for key in dict1:
+ if key in dict2:
+ return_dict[key] = StripUnmatchedKeys(dict1[key], dict2[key])
+ return return_dict
+
+ item_to_strip_type = type(item_to_strip)
+ if item_to_strip_type is type(reference_item):
+ if item_to_strip_type is types.ListType:
+ return StripList(item_to_strip, reference_item)
+ elif item_to_strip_type is types.DictType:
+ return StripDict(item_to_strip, reference_item)
+ return copy.deepcopy(item_to_strip)
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index 6d35548..6e5a0a9 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -171,6 +171,15 @@ bool PyUITestBase::OpenNewBrowserWindow(bool show) {
return automation()->OpenNewBrowserWindow(Browser::TYPE_NORMAL, show);
}
+bool PyUITestBase::CloseBrowserWindow(int window_index) {
+ scoped_refptr<BrowserProxy> browser_proxy =
+ automation()->GetBrowserWindow(window_index);
+ if (!browser_proxy.get())
+ return false;
+ bool app_closed;
+ return CloseBrowser(browser_proxy.get(), &app_closed);
+}
+
int PyUITestBase::GetBrowserWindowCount() {
int num_windows = 0;
EXPECT_TRUE(automation()->GetBrowserWindowCount(&num_windows));
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index a12ca8f..fe03779 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -103,6 +103,9 @@ class PyUITestBase : public UITestBase {
// Open a new browser window. Returns false on failure.
bool OpenNewBrowserWindow(bool show);
+ // Close a browser window. Returns false on failure.
+ bool CloseBrowserWindow(int window_index);
+
// Fetch the number of browser windows. Includes popups.
int GetBrowserWindowCount();
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index f228a88..3a88b13 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -302,6 +302,9 @@ class PyUITestBase {
%feature("docstring", "Open a new browser window.") OpenNewBrowserWindow;
bool OpenNewBrowserWindow(bool show);
+ %feature("docstring", "Close a browser window.") CloseBrowserWindow;
+ bool CloseBrowserWindow(int window_index);
+
%feature("docstring", "Fetch the number of browser windows. Includes popups.")
GetBrowserWindowCount;
int GetBrowserWindowCount();