diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 22:36:40 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 22:36:40 +0000 |
commit | d3cc8b5ea31322def5fecd2aa245fb7a7b8291cd (patch) | |
tree | aafa5d40c42a0fd913fe59a8bbe6871b3e3d025c | |
parent | aee746fa720bec218bec090746df7e04f26d9f5b (diff) | |
download | chromium_src-d3cc8b5ea31322def5fecd2aa245fb7a7b8291cd.zip chromium_src-d3cc8b5ea31322def5fecd2aa245fb7a7b8291cd.tar.gz chromium_src-d3cc8b5ea31322def5fecd2aa245fb7a7b8291cd.tar.bz2 |
Add tests to verify bookmark ordering and nesting of groups.
testOrdering - from Srikanth
testDeepNesting - from Ismail
Review URL: http://codereview.chromium.org/1250004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42549 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/functional/bookmarks.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/chrome/test/functional/bookmarks.py b/chrome/test/functional/bookmarks.py index 8fa2124..10f2924 100644 --- a/chrome/test/functional/bookmarks.py +++ b/chrome/test/functional/bookmarks.py @@ -6,7 +6,9 @@ # Must import this first import pyauto_functional +import logging import os +import sys import unittest import pyauto @@ -275,6 +277,105 @@ class BookmarksTest(pyauto.PyUITest): self.assertEqual(other_child_0['name'], list_of_titles[3]) self.assertEqual(other_child_0['url'], list_of_urls[3]) + def testOrdering(self): + """Add/delete a set of bookmarks, and verify their ordering.""" + bookmarks = self.GetBookmarkModel() + bar_id = bookmarks.BookmarkBar()['id'] + orig_nodes_count = bookmarks.NodeCount() + + url_data = self._GetTestURLs("urls_and_titles") + list_of_titles = url_data.values() + + for index, (url, name) in enumerate(url_data.iteritems()): + self.AddBookmarkURL(bar_id, index, name, url) + + # check that we added them correctly + bookmarks = self.GetBookmarkModel() + self.assertEqual(orig_nodes_count + len(url_data) , bookmarks.NodeCount()) + + for node, (url, name) in zip(bookmarks.BookmarkBar()['children'], + url_data.iteritems()): + self.assertEqual(node['type'], 'url') + self.assertEqual(node['name'], name) + self.assertEqual(node['url'], url) + + # remove a few of them. + remove_indices = [3, 5, 9, 12] + new_list_of_titles = list_of_titles[:] + assert len(remove_indices) <= len(url_data) and \ + max(remove_indices) < len(url_data) + + for index in remove_indices: + node = bookmarks.FindByTitle(list_of_titles[index]) + self.RemoveBookmark(node[0]['id']) + new_list_of_titles.remove(list_of_titles[index]) + logging.debug('Removed: %s' % [list_of_titles[x] for x in remove_indices]) + + # Confirm removal. + bookmarks = self.GetBookmarkModel() + for index in remove_indices: + nodes = bookmarks.FindByTitle(list_of_titles[index]) + self.assertEqual(0, len(nodes)) + + # Confirm that other bookmarks were not removed and their order is intact. + self.assertEqual(len(new_list_of_titles), + len(bookmarks.BookmarkBar()['children'])) + for title, node in zip(new_list_of_titles, + bookmarks.BookmarkBar()['children']): + self.assertEqual(title, node['name']) + + def testDeepNesting(self): + """Deep nested folders. Move a bookmark around.""" + 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() + + bar_folder_id = bookmarks.BookmarkBar()['id'] + + # Created deep nested folders + num_folders = 15 + assert num_folders >= 3 + for i in range(num_folders): + self.AddBookmarkGroup(bar_folder_id, 0 ,'Group %d' % i) + bookmarks = self.GetBookmarkModel() + added_nodes = bookmarks.FindByID(bar_folder_id)['children'] + self.assertEqual(1, len(added_nodes)) + self.assertEqual('Group %d' % i, added_nodes[0]['name']) + bar_folder_id = added_nodes[0]['id'] + + self.assertEqual(nodes + num_folders, bookmarks.NodeCount()) + + # Add a bookmark to the leaf folder + a_url = list_of_urls[0] + a_title = list_of_titles[0] + leaf_folder = bookmarks.FindByTitle('Group %d' % (num_folders - 1))[0] + self.AddBookmarkURL(leaf_folder['id'], 0, a_title, a_url) + + bookmarks = self.GetBookmarkModel() + nodes = bookmarks.FindByTitle('Group %d' % (num_folders - 1)) + self.assertEqual(1, len(nodes)) + mynode = nodes[0]['children'][0] + self.assertEqual(a_title, mynode['name']) + self.assertEqual(a_url, mynode['url']) + + # Move bookmark to another group, say Group 2 + self.ReparentBookmark(bookmarks.FindByTitle(a_title)[0]['id'], + bookmarks.FindByTitle('Group 2')[0]['id'], 0) + + bookmarks = self.GetBookmarkModel() + # Bookmark moves to right place + node = bookmarks.FindByTitle('Group 2')[0] + self.assertEqual(2, len(node['children'])) + self.assertEqual(a_title, node['children'][0]['name']) + self.assertEqual(a_url, node['children'][0]['url']) + + # Bookmark removed from leaf folder + nodes = bookmarks.FindByTitle('Group %d' % (num_folders - 1)) + self.assertEqual([], nodes[0]['children']) + if __name__ == '__main__': pyauto_functional.Main() |