diff options
author | feldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 20:00:06 +0000 |
---|---|---|
committer | feldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 20:00:06 +0000 |
commit | f0c2a66e82c2aa1f4d756150e525df7623e38c18 (patch) | |
tree | 4ae21ded97a27a2a976774b77a6c7d51622ef17f | |
parent | 9d053ecf5d481a8161fe5ebffed5687bc28a4c2e (diff) | |
download | chromium_src-f0c2a66e82c2aa1f4d756150e525df7623e38c18.zip chromium_src-f0c2a66e82c2aa1f4d756150e525df7623e38c18.tar.gz chromium_src-f0c2a66e82c2aa1f4d756150e525df7623e38c18.tar.bz2 |
Add more tests to bookmark manager api
Add Subtree and folders only tests, enable copy/paste tests on mac, and add test
for copying empty folders.
BUG=none
TEST=browser_tests --gtest_filter=ExtensionApiTest.BookmarkManager
Review URL: http://codereview.chromium.org/1594011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43514 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/data/extensions/api_test/bookmark_manager/test.js | 231 |
1 files changed, 157 insertions, 74 deletions
diff --git a/chrome/test/data/extensions/api_test/bookmark_manager/test.js b/chrome/test/data/extensions/api_test/bookmark_manager/test.js index b7001b2..f9d2cdd 100644 --- a/chrome/test/data/extensions/api_test/bookmark_manager/test.js +++ b/chrome/test/data/extensions/api_test/bookmark_manager/test.js @@ -7,9 +7,9 @@ const assertEq = chrome.test.assertEq; const assertTrue = chrome.test.assertTrue; const bookmarks = chrome.bookmarks; const bookmarkManager = chrome.experimental.bookmarkManager; -const MAC = /Mac/.test(navigator.platform); -var node, node2, count; +var node, node2, count, emptyFolder, emptyFolder2; var folder, nodeA, nodeB; +var childFolder, grandChildFolder, childNodeA, childNodeB; var tests = [ function getStrings() { @@ -53,88 +53,171 @@ var tests = [ assertEq(nodeA.id, children[0].id); assertEq(nodeB.id, children[1].id); })); - } -]; + }, -// Mac does not yet support the clipboard API. -if (!MAC) { - tests.push( - - // The clipboard test is split into different parts to allow asynchronous - // operations to finish. - function clipboard() { - // Create a new bookmark. - node = { - parentId: '1', - title: 'Foo', - url: 'http://www.example.com/foo' - }; - - bookmarks.create(node, pass(function(result) { - node.id = result.id; - node.index = result.index; - count = result.index + 1; + function setupSubtree() { + childFolder = { + parentId: folder.id, + title: 'Child Folder' + }; + childNodeA = { + title: 'childNodeA', + url: 'http://www.example.com/childNodeA' + }; + childNodeB = { + title: 'childNodeB', + url: 'http://www.example.com/childNodeB' + }; + grandChildFolder = { + title: 'grandChildFolder' + }; + bookmarks.create(childFolder, pass(function(result) { + childFolder.id = result.id; + childNodeA.parentId = childFolder.id; + childNodeB.parentId = childFolder.id; + grandChildFolder.parentId = childFolder.id; + + bookmarks.create(childNodeA, pass(function(result) { + childNodeA.id = result.id; })); - }, + bookmarks.create(childNodeB, pass(function(result) { + childNodeB.id = result.id; + })); + bookmarks.create(grandChildFolder, pass(function(result) { + grandChildFolder.id = result.id; + })); + })) + }, - function clipboard2() { - // Copy it. - bookmarkManager.copy([node.id]); + function getSubtree() { + bookmarkManager.getSubtree(childFolder.id, false, pass(function(result) { + var children = result[0].children; + assertEq(3, children.length); + assertEq(childNodeA.id, children[0].id); + assertEq(childNodeB.id, children[1].id); + assertEq(grandChildFolder.id, children[2].id); + })) + }, - // Ensure canPaste is now true. - bookmarkManager.canPaste('1', pass(function(result) { - assertTrue(result, 'Should be able to paste now'); - })); + function getSubtreeFoldersOnly() { + bookmarkManager.getSubtree(childFolder.id, true, pass(function(result) { + var children = result[0].children; + assertEq(1, children.length); + assertEq(grandChildFolder.id, children[0].id); + })) + }, - // Paste it. - bookmarkManager.paste('1'); + // The clipboard test is split into different parts to allow asynchronous + // operations to finish. + function clipboard() { + // Create a new bookmark. + node = { + parentId: '1', + title: 'Foo', + url: 'http://www.example.com/foo' + }; + + emptyFolder = { + parentId: '1', + title: 'Empty Folder' + } - // Ensure it got added. - bookmarks.getChildren('1', pass(function(result) { - count++; - assertEq(count, result.length); + bookmarks.create(node, pass(function(result) { + node.id = result.id; + node.index = result.index; + count = result.index + 1; + })); + + bookmarks.create(emptyFolder, pass(function(result) { + emptyFolder.id = result.id; + emptyFolder.index = result.index; + count = result.index + 1; + })); + }, - node2 = result[result.length - 1]; + function clipboard2() { + // Copy it. + bookmarkManager.copy([node.id]); - assertEq(node.title, node2.title); - assertEq(node.url, node2.url); - assertEq(node.parentId, node2.parentId); - })); - }, + // Ensure canPaste is now true. + bookmarkManager.canPaste('1', pass(function(result) { + assertTrue(result, 'Should be able to paste now'); + })); - function clipboard3() { - // Cut this and the previous bookmark. - bookmarkManager.cut([node.id, node2.id]); + // Paste it. + bookmarkManager.paste('1'); - // Ensure count decreased by 2. - bookmarks.getChildren('1', pass(function(result) { - count -= 2; - assertEq(count, result.length); - })); + // Ensure it got added. + bookmarks.getChildren('1', pass(function(result) { + count++; + assertEq(count, result.length); - // Ensure canPaste is still true. - bookmarkManager.canPaste('1', pass(function(result) { - assertTrue(result, 'Should be able to paste now'); - })); - }, - - function clipboard4() { - // Paste. - bookmarkManager.paste('1'); - - // Check the last two bookmarks. - bookmarks.getChildren('1', pass(function(result) { - count += 2; - assertEq(count, result.length); - - var last = result[result.length - 2]; - var last2 = result[result.length - 1]; - assertEq(last.title, last2.title); - assertEq(last.url, last2.url); - assertEq(last.parentId, last2.parentId); - })); - } - ); -} + node2 = result[result.length - 1]; + + assertEq(node.title, node2.title); + assertEq(node.url, node2.url); + assertEq(node.parentId, node2.parentId); + })); + }, + + function clipboard3() { + // Cut this and the previous bookmark. + bookmarkManager.cut([node.id, node2.id]); + + // Ensure count decreased by 2. + bookmarks.getChildren('1', pass(function(result) { + count -= 2; + assertEq(count, result.length); + })); + + // Ensure canPaste is still true. + bookmarkManager.canPaste('1', pass(function(result) { + assertTrue(result, 'Should be able to paste now'); + })); + }, + + function clipboard4() { + // Paste. + bookmarkManager.paste('1'); + + // Check the last two bookmarks. + bookmarks.getChildren('1', pass(function(result) { + count += 2; + assertEq(count, result.length); + + var last = result[result.length - 2]; + var last2 = result[result.length - 1]; + assertEq(last.title, last2.title); + assertEq(last.url, last2.url); + assertEq(last.parentId, last2.parentId); + })); + }, + + // Ensure we can copy empty folders + function clipboard5() { + // Copy it. + bookmarkManager.copy([emptyFolder.id]); + + // Ensure canPaste is now true. + bookmarkManager.canPaste('1', pass(function(result) { + assertTrue(result, 'Should be able to paste now'); + })); + + // Paste it. + bookmarkManager.paste('1'); + + // Ensure it got added. + bookmarks.getChildren('1', pass(function(result) { + count++; + assertEq(count, result.length); + + emptyFolder2 = result[result.length - 1]; + + assertEq(emptyFolder2.title, emptyFolder.title); + assertEq(emptyFolder2.url, emptyFolder.url); + assertEq(emptyFolder2.parentId, emptyFolder.parentId); + })); + } +]; chrome.test.runTests(tests); |