diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 00:54:55 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 00:54:55 +0000 |
commit | 855a74d04d3edd9817660f1889ff4066ed804053 (patch) | |
tree | 89629b4d7d774cec4c8f6e3561b176f3f4b50531 | |
parent | 03e7d58d70ce8ceb784ab7ff13d0d1244e01c533 (diff) | |
download | chromium_src-855a74d04d3edd9817660f1889ff4066ed804053.zip chromium_src-855a74d04d3edd9817660f1889ff4066ed804053.tar.gz chromium_src-855a74d04d3edd9817660f1889ff4066ed804053.tar.bz2 |
Add a few PyAuto tests for bookmarks.
The first two tests are from rohitbm and the rest from krisrs.
testUnicodeStrings -- test bookmarks with unicode strings
testSizes -- test bookmarks with different sized strings
testAddingBookmarksToBarAndOther - add bookmarks to diff locations
testAddingFoldersToBarAndOther -- add bookmark groups to diff locations
testAddingFoldersWithChildrenToBarAndOther -- add bookmarks and groups to
different locations
Review URL: http://codereview.chromium.org/1191002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42417 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/data/bookmarks/long-and-short-names | 12 | ||||
-rw-r--r-- | chrome/test/data/bookmarks/urls_and_titles | 28 | ||||
-rw-r--r-- | chrome/test/functional/bookmarks.py | 162 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 5 |
4 files changed, 207 insertions, 0 deletions
diff --git a/chrome/test/data/bookmarks/long-and-short-names b/chrome/test/data/bookmarks/long-and-short-names new file mode 100644 index 0000000..dd98ecd --- /dev/null +++ b/chrome/test/data/bookmarks/long-and-short-names @@ -0,0 +1,12 @@ +# A list of URLs and titles for bookmarks with short and long strings and +# some uncommon characters. +# Used by: chrome/test/functional/bookmarks.py + +{ + "http://www.bing.com/" : u"", + "https://www.blogger.com/start" : u"Blogger+:-&*** Create your free blog", + "http://www.llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogochuchaf.org.uk/" : u"\u042f\u043d\u0434\u0435\u043a\u0441\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053 \u65b0\u6d6a\u9996\u9875 \u65b0\u6d6a\u9996\u9875 \u65b0\u6d6a\u9996\u9875 \u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053", + "http://www.microsoft.com/en/us/default.aspx" : u"Microsoft Corporation", + "http://www.msn.com/" : u"The big question is size reduction, and to that our game console laptop guru suggests that, given the constraints due to a DVD drive, the best we can expect is a one-inch drop in height (standing console)", + "http://www.myspace.com/" : u"MySpace", +} diff --git a/chrome/test/data/bookmarks/urls_and_titles b/chrome/test/data/bookmarks/urls_and_titles new file mode 100644 index 0000000..7b185b8 --- /dev/null +++ b/chrome/test/data/bookmarks/urls_and_titles @@ -0,0 +1,28 @@ +# A list of URLs and titles for bookmarks. Also contains unicode strings +# Used by: chrome/test/functional/bookmarks.py + +{ + "http://www.bing.com/" : u"Bing", + "https://www.blogger.com/start" : u"Blogger: Create your free blog", + "http://www.google.com/" : u"Google", + "http://www.microsoft.com/en/us/default.aspx" : u"Microsoft Corporation", + "http://www.msn.com/" : u"MSN.com", + "http://www.myspace.com/" : u"MySpace", + "http://www.rapidshare.com/" : u"RapidShare: 1-CLICK Web hosting - Easy Filehosting", + "http://twitter.com/" : u"Twitter", + "http://www.baidu.com/" : u"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053", + "http://www.facebook.com/" : u"Welcome to Facebook", + "http://www.wikipedia.org/" : u"Wikipedia", + "http://vkontakte.ru/" : u"\u0412 \u041a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 | \u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c", + "http://wordpress.com/" : u"WordPress.com \u2014 Get a Free Blog Here", + "http://www.yahoo.com/" : u"Yahoo!", + "http://www.yandex.ru/" : u"\u042f\u043d\u0434\u0435\u043a\u0441", + "http://www.yahoo.co.jp/" : u"Yahoo! JAPAN", + "http://www.qq.com/" : u"\u817e\u8baf\u9996\u9875", + "http://www.youtube.com/" : u"YouTube - Broadcast Yourself.", + "http://www.ebay.com/" : u"eBay - New & used electronics, cars, apparel, collectibles, sporting goods & more at low prices", + "http://www.fc2.com/" : u"FC2 - Free Website Access Analysis Blog Rental Server SEO Countermeasures etc. -", + "http://www.amazon.com/" : u"Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more", + "http://www.sina.com.cn/" : u"\u65b0\u6d6a\u9996\u9875", + "http://www.flickr.com/" : u"Welcome to Flickr - Photo Sharing", +} diff --git a/chrome/test/functional/bookmarks.py b/chrome/test/functional/bookmarks.py index 8b91bb4..8fa2124 100644 --- a/chrome/test/functional/bookmarks.py +++ b/chrome/test/functional/bookmarks.py @@ -6,6 +6,7 @@ # Must import this first import pyauto_functional +import os import unittest import pyauto @@ -113,6 +114,167 @@ class BookmarksTest(pyauto.PyUITest): nodes = bookmarks.FindByTitle('Group2') self.assertEqual(1, len(nodes[0]['children'])) + def _GetTestURLs(self, filename): + """Read the given data file and return a dictionary of items.""" + data_file = os.path.join(self.DataDir(), "bookmarks", filename) + contents = open(data_file).read() + try: + dictionary = eval(contents, {'__builtins__': None}, None) + except: + print >>sys.stderr, "%s is an invalid data file." % data_file + raise + return dictionary + + def testUnicodeStrings(self): + """Test bookmarks with unicode strings.""" + bookmarks = self.GetBookmarkModel() + bar_id = bookmarks.BookmarkBar()['id'] + orig_nodes_count = bookmarks.NodeCount() + + sites = self._GetTestURLs("urls_and_titles") + # Add bookmarks + for index, (url, name) in enumerate(sites.iteritems()): + self.AddBookmarkURL(bar_id, index, name, url) + + # Fetch the added bookmarks and verify them. + bookmarks = self.GetBookmarkModel() + self.assertEqual(orig_nodes_count + len(sites), bookmarks.NodeCount()) + + for node, k in zip(bookmarks.BookmarkBar()['children'], sites.keys()): + self.assertEqual(node['type'], 'url') + self.assertEqual(node['name'], sites[k]) + self.assertEqual(node['url'], k) + + def testSizes(self): + """Verify bookmarks with short and long names.""" + bookmarks = self.GetBookmarkModel() + bar_id = bookmarks.BookmarkBar()['id'] + orig_nodes_count = bookmarks.NodeCount() + + sites = self._GetTestURLs("long-and-short-names") + # Add bookmarks + for index, (url, name) in enumerate(sites.iteritems()): + self.AddBookmarkURL(bar_id, index, name, url) + + # Fetch the added urls and verify them. + bookmarks = self.GetBookmarkModel() + self.assertEqual(orig_nodes_count + len(sites), bookmarks.NodeCount()) + + for node, k in zip(bookmarks.BookmarkBar()['children'], sites.keys()): + self.assertEqual(node['type'], 'url') + self.assertEqual(node['name'], sites[k]) + self.assertEqual(node['url'], k) + + def testAddingBookmarksToBarAndOther(self): + """Add bookmarks to the Bookmark Bar and "Other Bookmarks" group.""" + url_data = self._GetTestURLs("urls_and_titles") + list_of_urls = url_data.keys() + list_of_titles = url_data.values() + + # We need at least 3 URLs for this test to run + self.assertTrue(len(list_of_urls) > 2) + + bookmarks = self.GetBookmarkModel() + nodes = bookmarks.NodeCount() + + # Add bookmarks to the bar and other + bar_id = bookmarks.BookmarkBar()['id'] + self.AddBookmarkURL(bar_id, 0, list_of_titles[0], list_of_urls[0]) + + other_id = bookmarks.Other()['id'] + self.AddBookmarkURL(other_id, 0, list_of_titles[1], list_of_urls[1]) + + # Now check that we added them + bookmarks = self.GetBookmarkModel() + self.assertEqual(nodes + 2, bookmarks.NodeCount()) + + bar_child = bookmarks.BookmarkBar()['children'][0] + self.assertEqual(bar_child['type'], 'url') + self.assertEqual(bar_child['name'], list_of_titles[0]) + self.assertEqual(bar_child['url'], list_of_urls[0]) + + other_child = bookmarks.Other()['children'][0] + self.assertEqual(other_child['type'], 'url') + self.assertEqual(other_child['name'], list_of_titles[1]) + self.assertEqual(other_child['url'], list_of_urls[1]) + + def testAddingFoldersToBarAndOther(self): + """Add folders to the Bookmark Bar and "Other Bookmarks" group.""" + url_data = self._GetTestURLs("urls_and_titles") + list_of_titles = url_data.values() + + bookmarks = self.GetBookmarkModel() + nodes = bookmarks.NodeCount() + + # Add folders to the bar and other + bar_id = bookmarks.BookmarkBar()['id'] + self.AddBookmarkGroup(bar_id, 0, list_of_titles[0]) + + other_id = bookmarks.Other()['id'] + self.AddBookmarkGroup(other_id, 0, list_of_titles[1]) + + # Now check that we added them + bookmarks = self.GetBookmarkModel() + self.assertEqual(nodes + 2, bookmarks.NodeCount()) + + bar_child = bookmarks.BookmarkBar()['children'][0] + self.assertEqual(bar_child['type'], 'folder') + self.assertEqual(bar_child['name'], list_of_titles[0]) + + other_child = bookmarks.Other()['children'][0] + self.assertEqual(other_child['type'], 'folder') + self.assertEqual(other_child['name'], list_of_titles[1]) + + def testAddingFoldersWithChildrenToBarAndOther(self): + """Add folders with children to the bar and "Other Bookmarks" group.""" + url_data = self._GetTestURLs("urls_and_titles") + list_of_urls = url_data.keys() + list_of_titles = url_data.values() + + bookmarks = self.GetBookmarkModel() + nodes = bookmarks.NodeCount() + + # Add a folder to the bar + bar_id = bookmarks.BookmarkBar()['id'] + self.AddBookmarkGroup(bar_id, 0, list_of_titles[0]) + + # Get a handle on the folder, and add a bookmark in it + bookmarks = self.GetBookmarkModel() + bar_folder_id = bookmarks.BookmarkBar()['children'][0]['id'] + self.AddBookmarkURL(bar_folder_id, 0, list_of_titles[1], list_of_urls[1]) + + # Add a folder to other + other_id = bookmarks.Other()['id'] + self.AddBookmarkGroup(other_id, 0, list_of_titles[2]) + + # Get a handle on the folder, and add a bookmark in it + bookmarks = self.GetBookmarkModel() + other_folder_id = bookmarks.Other()['children'][0]['id'] + self.AddBookmarkURL(other_folder_id, 0, list_of_titles[3], list_of_urls[3]) + + # Verify we have added a folder in the bar and other, and each folder has + # a URL in it + bookmarks = self.GetBookmarkModel() + self.assertEqual(nodes + 4, bookmarks.NodeCount()) + + bar_child = bookmarks.BookmarkBar()['children'][0] + self.assertEqual(bar_child['type'], 'folder') + self.assertEqual(bar_child['name'], list_of_titles[0]) + + bar_child_0 = bar_child['children'][0] + self.assertEqual(bar_child_0['type'], 'url') + self.assertEqual(bar_child_0['name'], list_of_titles[1]) + self.assertEqual(bar_child_0['url'], list_of_urls[1]) + + other_child = bookmarks.Other()['children'][0] + self.assertEqual(other_child['type'], 'folder') + self.assertEqual(other_child['name'], list_of_titles[2]) + + other_child_0 = other_child['children'][0] + self.assertEqual(other_child_0['type'], 'url') + self.assertEqual(other_child_0['name'], list_of_titles[3]) + self.assertEqual(other_child_0['url'], list_of_urls[3]) + if __name__ == '__main__': pyauto_functional.Main() diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 7f9efc8..0e29411 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -129,6 +129,11 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): def tearDown(self): self.TearDown() # Destroy browser + @staticmethod + def DataDir(): + """Returns the path to the data dir chrome/test/data.""" + return os.path.join(os.path.dirname(__file__), os.pardir, "data") + def GetBookmarkModel(self): """Return the bookmark model as a BookmarkModel object. |