diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-23 16:28:39 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-23 16:28:39 +0000 |
commit | 2fcb5c29cdfa92a209411a3fe4bb3b355fc5a5ad (patch) | |
tree | f3fe9ba5259092a46cc189d7d210fc1aac5e0597 /chrome/test | |
parent | 11f60db5baba6b239972e6aa1866bbd252aca2e4 (diff) | |
download | chromium_src-2fcb5c29cdfa92a209411a3fe4bb3b355fc5a5ad.zip chromium_src-2fcb5c29cdfa92a209411a3fe4bb3b355fc5a5ad.tar.gz chromium_src-2fcb5c29cdfa92a209411a3fe4bb3b355fc5a5ad.tar.bz2 |
Convert the bookmarks pyauto test to chrome tests. The majority of the tests were duplicates of the bookmark model unit test. I added a unit test case for unicode characters and different protocols (not sure if they're really needed, but did this to not lose coverage). I also added browser tests to verify that bookmarks persist after a browser restart, and that they're not shared across multiple profiles.
BUG=143637,138857
Review URL: https://chromiumcodereview.appspot.com/10869025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/data/bookmarks/long-and-short-names | 12 | ||||
-rw-r--r-- | chrome/test/data/bookmarks/url_types | 15 | ||||
-rw-r--r-- | chrome/test/data/bookmarks/urls_and_titles | 28 | ||||
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 11 | ||||
-rwxr-xr-x | chrome/test/functional/bookmarks.py | 702 |
5 files changed, 0 insertions, 768 deletions
diff --git a/chrome/test/data/bookmarks/long-and-short-names b/chrome/test/data/bookmarks/long-and-short-names deleted file mode 100644 index dd98ecd..0000000 --- a/chrome/test/data/bookmarks/long-and-short-names +++ /dev/null @@ -1,12 +0,0 @@ -# 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/url_types b/chrome/test/data/bookmarks/url_types deleted file mode 100644 index eac8ba9..0000000 --- a/chrome/test/data/bookmarks/url_types +++ /dev/null @@ -1,15 +0,0 @@ -# Data file for different types of urls. http:// https:// ftp:// and so on -# Used by: chrome/test/functional/bookmarks.py - -{ - "http://muse.jhu.edu/journals/american_literature/" : u"Static URL", - "http://www.springerlink.com/link.asp?id=100408/" : u"Dynamic URL", - "http://www.bioone.org/bioone/?request=get-journals-list&issn=0002-8444**/" :u"Formula URL", - "http://www.google.cn/" : u"Redirection UTL", - "https://www.blogger.com/start/" : u"This is a https url", - "file:///Users/Shared/Library/Application%20Support/" : u"The file URL specifies a file stored", - "ftp://mirrors.xmission.com/debian-cd/" : u"FTP URL", - """javascript:(t13nb=window.t13nb||function(l){var%20t=t13nb,d=document,o=d.body,c="createElement",a="appendChild",w="clientWidth",i=d[c]("span"),s=i.style,x=o[a](d[c]("script"));if(o){if(!t.l){t.l=x.id="t13ns";o[a](i).id="t13n";i.innerHTML="Loading%20transliteration";s.cssText="z-index:99;font-size:18px;background:#FFF1A8;top:0";s.position=d.all?"absolute":"fixed";s.left=((o[w]-i[w])/2)+"px";x.src="http://t13n.googlecode.com/svn/trunk/blet/rt13n.js?l="+l}}else%20setTimeout(t,500)})('hi')""" : u"title [Type in Hindi]", - "http://www.baidu.com/" : u"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053", - "http://www.flickr.com/" : u"Redirection URL Welcome to Flickr - Photo Sharing", -} diff --git a/chrome/test/data/bookmarks/urls_and_titles b/chrome/test/data/bookmarks/urls_and_titles deleted file mode 100644 index 7b185b8..0000000 --- a/chrome/test/data/bookmarks/urls_and_titles +++ /dev/null @@ -1,28 +0,0 @@ -# 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/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 97cdfef..5de4a07 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -36,7 +36,6 @@ 'about_plugins_ui.AboutPluginsUITest', 'apptest', 'autofill', - 'bookmarks', 'browser', 'chromoting.it2me_basic', 'codesign', @@ -146,9 +145,6 @@ # Mysteriously broken? # crbug.com/138857 - '-bookmarks.BookmarksTest.testAddBookmarksInMultiProfileIncognito', - '-bookmarks.BookmarksTest.testEditBookmarksInMultiProfileIncognito', - '-bookmarks.BookmarksTest.testRemoveBookmarksInMultiProfileIncognito', '-multiprofile.MultiprofileTest.testMakeSearchEngineDefaultInMultiprofile', ], @@ -312,13 +308,6 @@ # So one-click infobar tests do tno apply to chromeos. '-infobars.OneClickInfobarTest', # Multi-profile doesn't apply to chromeos yet. - '-bookmarks.BookmarksTest.testAddBookmarkInMultiProfile', - '-bookmarks.BookmarksTest.testRemoveBookmarksInMultiProfile', - '-bookmarks.BookmarksTest.testEditBookmarksInMultiProfile', - '-bookmarks.BookmarksTest.testAddBookmarksInMultiProfileIncognito', - '-bookmarks.BookmarksTest.testRemoveBookmarksInMultiProfileIncognito', - '-bookmarks.BookmarksTest.testEditBookmarksInMultiProfileIncognito', - '-bookmarks.BookmarksTest.testSearchBookmarksInMultiProfile', '-multiprofile', '-ntp.NTPTest.testDifferentProfileNotAppearInMostVisited', # These require a custom setup on ChromeOS and have their own suite for diff --git a/chrome/test/functional/bookmarks.py b/chrome/test/functional/bookmarks.py deleted file mode 100755 index ba6edb7..0000000 --- a/chrome/test/functional/bookmarks.py +++ /dev/null @@ -1,702 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2012 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. - -# Must import this first -import pyauto_functional - -import logging -import os -import sys -import unittest - -import pyauto - - -class BookmarksTest(pyauto.PyUITest): - """Test of bookmarks.""" - - def testBasics(self): - """Basic tests with an empty bookmark model.""" - bookmarks = self.GetBookmarkModel() - # Make sure we have the two root nodes and that they are empty - for node in (bookmarks.BookmarkBar(), bookmarks.Other()): - self.assertEqual(node['type'], 'folder') - self.assertFalse(node['children']) - - def testAddOneNode(self): - """Add a bookmark to the bar; confirm it.""" - bookmarks = self.GetBookmarkModel() - bar_id = bookmarks.BookmarkBar()['id'] - name = 'Google' - url = 'http://www.google.com' - c = bookmarks.NodeCount() - self.AddBookmarkURL(bar_id, 0, name, url) - bookmarks = self.GetBookmarkModel() - node = bookmarks.BookmarkBar()['children'][0] - self.assertEqual(c+1, bookmarks.NodeCount()) - self.assertEqual(node['type'], 'url') - self.assertEqual(node['name'], name) - # URLs may not be exact; e.g. http://www.com --> http://www.com/ - self.assertTrue(url in node['url']) - # Make sure we can search and find the same thing - nodes = bookmarks.FindByTitle(name) - self.assertEqual(1, len(nodes)) - self.assertTrue(nodes[0]['id'] == node['id']) - - def testAddGroup(self): - """Add a group to the bar; confirm it.""" - bookmarks = self.GetBookmarkModel() - c = bookmarks.NodeCount() - parent_id = bookmarks.Other()['id'] - name = 'SuperGroup' - self.AddBookmarkGroup(parent_id, 0, name) - # Confirm group. - bookmarks = self.GetBookmarkModel() - node = bookmarks.Other()['children'][0] - self.assertEqual(c+1, bookmarks.NodeCount()) - self.assertEqual(node['type'], 'folder') - self.assertEqual(node['name'], name) - # Make sure we can search and find the same thing - findnode = bookmarks.FindByID(node['id']) - self.assertEqual(node, findnode) - - def testAddChangeRemove(self): - """Add some bookmarks. Change their title and URL. Remove one.""" - # Add some. - bookmarks = self.GetBookmarkModel() - bar_id = bookmarks.BookmarkBar()['id'] - self.AddBookmarkURL(bar_id, 0, 'Title1', - 'http://www.google.com') - self.AddBookmarkURL(bar_id, 1, 'Title1', - 'http://www.google.com/reader') - # Change a title and URL. - bookmarks = self.GetBookmarkModel() - nodes = bookmarks.FindByTitle('Title1') - self.assertEqual(2, len(nodes)) - self.SetBookmarkTitle(nodes[0]['id'], 'Title2') - self.SetBookmarkURL(nodes[1]['id'], 'http://www.youtube.com') - # Confirm, then remove. - bookmarks = self.GetBookmarkModel() - nodes = bookmarks.FindByTitle('Title1') - self.assertEqual(1, len(nodes)) - self.assertTrue('http://www.youtube.com' in nodes[0]['url']) - nodes = bookmarks.FindByTitle('Title2') - self.assertEqual(1, len(nodes)) - self.assertTrue('google.com' in nodes[0]['url']) - self.RemoveBookmark(nodes[0]['id']) - # Confirm removal. - bookmarks = self.GetBookmarkModel() - nodes = bookmarks.FindByTitle('Title2') - self.assertEqual(0, len(nodes)) - - def testReparent(self): - bookmarks = self.GetBookmarkModel() - bar_id = bookmarks.BookmarkBar()['id'] - # Add some groups - for i in range(3): - self.AddBookmarkGroup(bar_id, i, 'Group' + str(i)) - # Add a bookmark in one group - bookmarks = self.GetBookmarkModel() - nodes = bookmarks.FindByTitle('Group0') - self.AddBookmarkURL(nodes[0]['id'], 0, - 'marked', 'http://www.youtube.com') - # Make sure it's not in a different group - bookmarks = self.GetBookmarkModel() - nodes = bookmarks.FindByTitle('Group2') - self.assertFalse(nodes[0]['children']) - # Move it to that group - self.ReparentBookmark(bookmarks.FindByTitle('marked')[0]['id'], - bookmarks.FindByTitle('Group2')[0]['id'], 0) - # Confirm. - bookmarks = self.GetBookmarkModel() - nodes = bookmarks.FindByTitle('Group0') - self.assertEqual([], nodes[0]['children']) - 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]) - - 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']) - - def testURLTypes(self): - """Test bookmarks with different types of URLS.""" - bookmarks = self.GetBookmarkModel() - bar_id = bookmarks.BookmarkBar()['id'] - orig_nodes_count = bookmarks.NodeCount() - url_data = self._GetTestURLs("url_types") - 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) - - def _VerifyBookmarkURL(self, node, name, url): - """Verify that node is a bookmark URL of the given name and url.""" - self.assertTrue(node) - self.assertEqual(node['type'], 'url') - self.assertEqual(node['name'], name) - self.assertEqual(node['url'], url) - - def testDuplicateBookmarks(self): - """Verify bookmark duplicates.""" - 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_id = bookmarks.BookmarkBar()['id'] - # Create some duplicate bookmarks - self.AddBookmarkURL(bar_id, 0, list_of_titles[0], list_of_urls[0]) - self.AddBookmarkURL(bar_id, 1, list_of_titles[0], list_of_urls[0]) - self.AddBookmarkURL(bar_id, 2, list_of_titles[0], list_of_urls[1]) - self.AddBookmarkURL(bar_id, 3, list_of_titles[1], list_of_urls[0]) - # Create a folder with any existing bookmark title - self.AddBookmarkGroup(bar_id, 4, list_of_titles[0]) - bookmarks = self.GetBookmarkModel() - self.assertEqual(nodes + 5, bookmarks.NodeCount()) - # Verify 1st bookmark is created - bar_child = bookmarks.BookmarkBar()['children'][0] - self._VerifyBookmarkURL(bar_child, list_of_titles[0], list_of_urls[0]) - # Verify this is a duplicate bookmark of 1st bookmark - bar_child = bookmarks.BookmarkBar()['children'][1] - self._VerifyBookmarkURL(bar_child, list_of_titles[0], list_of_urls[0]) - # Verify the bookmark with same title and different URL of 1st bookmark - bar_child = bookmarks.BookmarkBar()['children'][2] - self._VerifyBookmarkURL(bar_child, list_of_titles[0], list_of_urls[1]) - # Verify the bookmark with different title and same URL of 1st bookmark - bar_child = bookmarks.BookmarkBar()['children'][3] - self._VerifyBookmarkURL(bar_child, list_of_titles[1], list_of_urls[0]) - # Verify Bookmark group got created with same title of 1st bookmark - bar_child = bookmarks.BookmarkBar()['children'][4] - self.assertEqual(bar_child['type'], 'folder') - self.assertEqual(bar_child['name'], list_of_titles[0]) - - def testBookmarksPersistence(self): - """Verify that bookmarks and groups persist browser restart.""" - # Populate bookmarks and groups - bookmarks = self.GetBookmarkModel() - bar_id = bookmarks.BookmarkBar()['id'] - other_id = bookmarks.Other()['id'] - self.AddBookmarkURL(bar_id, 0, "Google", "http://www.news.google.com/") - self.AddBookmarkURL(other_id, 0, "Yahoo", "http://www.yahoo.com/") - self.AddBookmarkGroup(bar_id, 0, "MS") - bookmarks = self.GetBookmarkModel() - bar_folder_id = bookmarks.BookmarkBar()['children'][0]['id'] - self.AddBookmarkURL(bar_folder_id, 0, "BING", "http://www.bing.com/") - self.AddBookmarkGroup(other_id, 0, "Oracle") - bookmarks = self.GetBookmarkModel() - other_folder_id = bookmarks.Other()['id'] - self.AddBookmarkURL(other_folder_id, 0, "DB", "http://www.oracle.com/") - - nodes_before = self.GetBookmarkModel().NodeCount() - self.RestartBrowser(clear_profile=False) - # Verify that all bookmarks persist - bookmarks = self.GetBookmarkModel() - node = bookmarks.FindByTitle('Google') - self.assertEqual(nodes_before, bookmarks.NodeCount()) - self._VerifyBookmarkURL(node[0], 'Google', 'http://www.news.google.com/') - self._VerifyBookmarkURL(bookmarks.FindByTitle('Yahoo')[0], - 'Yahoo', 'http://www.yahoo.com/') - bmb_child = bookmarks.BookmarkBar()['children'][0] - self.assertEqual(bmb_child['type'], 'folder') - self.assertEqual(bmb_child['name'],'MS') - self._VerifyBookmarkURL(bmb_child['children'][0], - 'BING', 'http://www.bing.com/') - - def testBookmarksManager(self): - """Verify bookmark title is displayed in bookmarks manager""" - bookmarks = self.GetBookmarkModel() - bar_id = bookmarks.BookmarkBar()['id'] - self.AddBookmarkURL(bar_id, 0, 'GoogleNews', 'http://www.news.google.com/') - self.NavigateToURL('chrome://bookmarks/') - self.assertTrue(self.WaitUntil( - lambda: self.FindInPage('GoogleNews', tab_index=0)['match_count'], - expect_retval=1)) - - def _AddBookmark(self, keyword, url, windex=0): - """Add Bookmark to the page and verify if it is added. - - Args: - keyword: Name for bookmarked url. - url: URL of the page to be bookmarked. - windex: The window index, default is 0. - """ - bookmarks = self.GetBookmarkModel(windex) - bar_id = bookmarks.BookmarkBar()['id'] - self.AddBookmarkURL(bar_id, 0, keyword, url, windex) - self.assertTrue(self.GetBookmarkModel(windex)) - - def _GetProfilePath(self): - """Get profile paths when multiprofile windows are open. - - Returns: - profile: Path for multiprofiles(Default, Profile1, Profile2). - """ - profiles_list = self.GetMultiProfileInfo()['profiles'] - profile1_path = profile2_path = default_path = None - for profile in profiles_list: - if 'Profile 1' in profile['path']: - profile1_path = profile['path'] - elif 'Profile 2' in profile['path']: - profile2_path = profile['path'] - elif 'Default' in profile['path']: - default_path = profile['path'] - return default_path, profile1_path, profile2_path - - def _AssertBookmark(self, keyword, url, windex=0): - """Assert bookmark present. - - Args: - keyword: Name for bookmarked url. - url: URL of the page to be bookmarked. - windex: The window index, default is 0. - """ - bookmarks = self.GetBookmarkModel(windex) - node = bookmarks.FindByTitle(keyword) - self.assertEqual(1, len(node)) - self._VerifyBookmarkURL(node[0], keyword, url) - - def testAddBookmarkInMultiProfile(self): - """Verify adding Bookmarks in multiprofile. - - Adding bookmarks in one profile should not affect other profiles. - """ - # Add 'GoogleNews' as bookmark in profile 1. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('GoogleNews', 'http://news.google.com/', windex=1) - # Add 'YouTube' as bookmark in profile 2. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('YouTube', 'http://www.youtube.com/', windex=2) - default_path, profile1_path, profile2_path = self._GetProfilePath() - # Close profile1/profile2 windows. - self.CloseBrowserWindow(2) - self.CloseBrowserWindow(1) - # Launch profile1, verify bookmark 'GoogleNews'. - self.OpenProfileWindow(path=profile1_path) - self._AssertBookmark('GoogleNews', 'http://news.google.com/', windex=1) - # Launch profile1, verify bookmark 'YouTube'. - self.OpenProfileWindow(path=profile2_path) - self._AssertBookmark('YouTube', 'http://www.youtube.com/', windex=2) - - def testRemoveBookmarksInMultiProfile(self): - """Verify removing Bookmarks in multiprofile. - - Removing bookmark in one profile should not affect other profiles. - """ - # Add 'GoogleNews' as bookmark in profile 1. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('GoogleNews', 'http://news.google.com/', windex=1) - # Confirm, then remove. - self._AssertBookmark('GoogleNews', 'http://news.google.com/', windex=1) - node = self.GetBookmarkModel(1).FindByTitle('GoogleNews') - self.RemoveBookmark(node[0]['id'], 1) - # Add 'GoogleNews' also as bookmark in profile 2. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('GoogleNews', 'http://news.google.com/', windex=2) - default_path, profile1_path, profile2_path = self._GetProfilePath() - # Close profile1/profile2 windows. - self.CloseBrowserWindow(2) - self.CloseBrowserWindow(1) - # Confirm removal in profile1 - self.OpenProfileWindow(path=profile1_path) - bookmarks = self.GetBookmarkModel(windex=1) - node = bookmarks.FindByTitle('GoogleNews') - self.assertEqual(0, len(node)) - # Verify profile2 still has bookmark. - self.OpenProfileWindow(path=profile2_path) - self._AssertBookmark('GoogleNews', 'http://news.google.com/', windex=2) - - def testEditBookmarksInMultiProfile(self): - """Verify editing Bookmarks in multiprofile. - - Changing bookmark in one profile should not affect other profiles. - """ - # Add 'GoogleNews' as bookmark in profile 1. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('GoogleNews', 'http://news.google.com/', windex=1) - # Change a title and URL. - bookmarks = self.GetBookmarkModel(windex=1) - nodes = bookmarks.FindByTitle('GoogleNews') - self.assertEqual(1, len(nodes)) - self.SetBookmarkTitle(nodes[0]['id'], 'YouTube', 1) - self.SetBookmarkURL(nodes[0]['id'], 'http://www.youtube.com', 1) - # Add 'GoogleNews' as bookmark in profile 2. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('GoogleNews', 'http://news.google.com/', windex=2) - default_path, profile1_path, profile2_path = self._GetProfilePath() - # Close profile1/profile2 windows. - self.CloseBrowserWindow(2) - self.CloseBrowserWindow(1) - # Confirm bookmark change in profile1. - self.OpenProfileWindow(path=profile1_path) - self._AssertBookmark('YouTube', 'http://www.youtube.com/', windex=1) - # Confirm profile2 bookmark is still same 'GoogleNews'. - self.OpenProfileWindow(path=profile2_path) - self._AssertBookmark('GoogleNews', 'http://news.google.com/', windex=2) - - def testAddBookmarksInMultiProfileIncognito(self): - """Verify adding Bookmarks for incognito window in multiprofile.""" - # Add 'YouTube' as bookmark in default profile - self._AddBookmark('YouTube', 'http://www.youtube.com/') - # Add 'GoogleNews' as bookmark in profile 1. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('GoogleNews', 'http://news.google.com/', windex=1) - default_path, profile1_path, profile2_path = self._GetProfilePath() - # Lauch incognito window, add bookmark 'BING' - self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) - bar_id = self.GetBookmarkModel(2).BookmarkBar()['id'] - self.AddBookmarkURL(bar_id, 0, 'BING','http://www.bing.com/', 2) - # Close profile1/profile2 windows. - self.CloseBrowserWindow(2) - self.CloseBrowserWindow(1) - # Switch to profile 1, verify 'BING' is not added. - self.OpenProfileWindow(path=profile1_path) - bookmarks = self.GetBookmarkModel(windex=1) - node = bookmarks.FindByTitle('BING') - self.assertEqual(0, len(node)) - - def testRemoveBookmarksInMultiProfileIncognito(self): - """Verify removing Bookmarks in for incognito window in multiprofile.""" - # Add 'GoogleNews' as bookmark in default profile. - self._AddBookmark('GoogleNews', 'http://news.google.com/') - # Add 'GoogleNews' as bookmark in profile 1. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('GoogleNews', 'http://news.google.com/', windex=1) - # launch incognito - self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) - # Confirm, then remove. - self._AssertBookmark('GoogleNews', 'http://news.google.com/', windex=2) - bookmarks = self.GetBookmarkModel(windex=2) - nodes = bookmarks.FindByTitle('GoogleNews') - self.RemoveBookmark(nodes[0]['id'], 2) - default_path, profile1_path, profile2_path = self._GetProfilePath() - # Close profile1/profile2 windows. - self.CloseBrowserWindow(2) - self.CloseBrowserWindow(1) - # Verify profile1 still has bookmark. - self.OpenProfileWindow(path=profile1_path) - bookmarks = self.GetBookmarkModel(windex=1) - node = bookmarks.FindByTitle('GoogleNews') - self.assertEqual(1, len(node)) - - def testEditBookmarksInMultiProfileIncognito(self): - """Verify changing Bookmarks in for incognito window in multiprofile.""" - # Add 'GoogleNews' as bookmark in default profile. - self._AddBookmark('GoogleNews', 'http://news.google.com/') - # Add 'GoogleNews' as bookmark in profile 1. - self.OpenNewBrowserWindowWithNewProfile() - self._AddBookmark('GoogleNews', 'http://news.google.com/', windex=1) - # Launch incognito - self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) - # Change a title and URL to 'YouTube'. - bookmarks = self.GetBookmarkModel(windex=2) - nodes = bookmarks.FindByTitle('GoogleNews') - self.assertEqual(1, len(nodes)) - self.SetBookmarkTitle(nodes[0]['id'], 'YouTube', 2) - self.SetBookmarkURL(nodes[0]['id'], 'http://www.youtube.com', 2) - default_path, profile1_path, profile2_path = self._GetProfilePath() - # Close profile1/profile2 windows. - self.CloseBrowserWindow(2) - self.CloseBrowserWindow(1) - # Launch profile1, verify bookmark is same as before. - self.OpenProfileWindow(path=profile1_path) - self._AssertBookmark('GoogleNews', 'http://news.google.com/', windex=1) - self.CloseBrowserWindow(1) - self._AssertBookmark('YouTube', 'http://www.youtube.com/') - - def testSearchBookmarksInMultiProfile(self): - """Verify user can not search bookmarks in other profile.""" - # Add 'GoogleNews', 'Youtube' as bookmarks in default profile. - self.OpenNewBrowserWindowWithNewProfile() - bookmarks = self.GetBookmarkModel(windex=1) - bar_id = bookmarks.BookmarkBar()['id'] - self.AddBookmarkURL(bar_id, 0, 'GoogleNews', - 'http://news.google.com/', 1) - self.AddBookmarkURL(bar_id, 1, 'YouTube', 'http://www.youtube.com/',1) - # Add 'BING', 'DB' as bookmarks to profile1 - self.OpenNewBrowserWindowWithNewProfile() - bookmarks = self.GetBookmarkModel(windex=2) - bar_id = bookmarks.BookmarkBar()['id'] - self.AddBookmarkURL(bar_id, 0, 'BING', 'http://www.bing.com/', 2) - self.AddBookmarkURL(bar_id, 0, 'DB', 'http://www.oracle.com/', 2) - default_path, profile1_path, profile2_path = self._GetProfilePath() - # Close profile1/profile2 windows. - self.CloseBrowserWindow(2) - self.CloseBrowserWindow(1) - # Search 'BING' in default profile. - self.OpenProfileWindow(path=profile1_path) - bookmarks = self.GetBookmarkModel(windex=1) - node = bookmarks.FindByTitle('BING') - self.assertEqual(0, len(node)) - # Search 'DB' in profile 1. - self.OpenProfileWindow(path=profile2_path) - bookmarks = self.GetBookmarkModel(windex=2) - node = bookmarks.FindByTitle('GoogleNews') - self.assertEqual(0, len(node)) - - -if __name__ == '__main__': - pyauto_functional.Main() |