--- a/mobile/chrome/tests/Makefile.in
+++ b/mobile/chrome/tests/Makefile.in
@@ -42,14 +42,18 @@ VPATH = @srcdir@
relativesrcdir = mobile/chrome
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_BROWSER_FILES = \
browser_mainui.js \
browser_tabs.js \
+ browser_bookmarks.js \
+ browser_bookmarks_star.js \
+ browser_bookmarks_folders.js \
+ browser_bookmarks_tags.js \
browser_blank_01.html \
browser_blank_02.html \
$(NULL)
libs:: $(_BROWSER_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_bookmarks.js
@@ -0,0 +1,248 @@
+/*
+ * Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome
+ * code in mobile/chrome/content in terms of integration with Places
+ * component, specifically for bookmark management.
+ */
+
+var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+var thread = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager).currentThread;
+var testURL_01 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
+var testURL_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_02.html";
+var chromeWindow = window;
+
+//------------------------------------------------------------------------------
+// TEST SKELETON: use this template to add new tests. This is based on
+// browser/components/places/tests/browser/browser_bookmarksProperties.js
+/*
+gTests.push({
+ desc: "Bug Description",
+ isCompleted: false,
+
+ run: function() {
+ // Actual test ...
+
+ // indicate test is completed
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+*/
+
+// A queue to order the tests and a handle for each test
+gTests = [];
+gCurrentTest = null;
+
+//------------------------------------------------------------------------------
+// Entry point (must be named 'test')
+function test() {
+ // test testing dependencies
+ ok(isnot, "Mochitest must be in context");
+ ok(ioService, "nsIIOService must be in context");
+ ok(thread, "nsIThreadManager must be in context");
+ ok(PlacesUtils, "PlacesUtils must be in context");
+ ok(EventUtils, "EventUtils must be in context");
+ ok(chromeWindow, "ChromeWindow must be in context");
+
+ ok(true, "*** Starting test browser_bookmarks.js\n");
+ runNextTest();
+}
+
+//------------------------------------------------------------------------------
+// Iterating tests by shifting test out one by one as runNextTest is called.
+function runNextTest() {
+ // Clean up previous test
+ if(gCurrentTest) {
+ ok(true, "*** FINISHED TEST ***");
+ }
+
+ // Run the next test until all tests completed
+ if (gTests.length > 0) {
+ gCurrentTest = gTests.shift();
+ ok(true, gCurrentTest.desc);
+ gCurrentTest.run();
+ while(!gCurrentTest.isCompleted) {
+ thread.processNextEvent(true);
+ }
+ runNextTest();
+ }
+ else {
+ // Cleanup. All tests are completed at this point
+ PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.bookmarks.unfiledBookmarksFolder);
+ ok(true, "*** ALL TESTS COMPLETED ***");
+ }
+}
+
+//------------------------------------------------------------------------------
+// Case: Test adding a bookmark with the Star button
+gTests.push({
+ desc: "Test adding a bookmark with the Star button",
+ isCompleted: false,
+ _currenttab: null,
+
+ run: function() {
+ _currenttab = chromeWindow.Browser.addTab(testURL_02, true);
+ // Need to wait until the page is loaded
+ _currenttab.browser.addEventListener("load",
+ function() {
+ _currenttab.browser.removeEventListener("load", arguments.callee, true);
+ gCurrentTest.verify();
+ },
+ true);
+ },
+
+ verify: function() {
+ chromeWindow.BrowserUI.doCommand("cmd_star");
+
+ var bookmarkItem = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_02));
+ ok(bookmarkItem != -1, testURL_02 + " should be added.");
+ is(PlacesUtils.bookmarks.getItemTitle(bookmarkItem),
+ "Browser Blank Page 02", "the title should match.");
+ is(PlacesUtils.bookmarks.getBookmarkURI(bookmarkItem).spec,
+ chromeWindow.Browser.selectedTab.browser.currentURI.spec, testURL_02 + " should be added.");
+
+ chromeWindow.Browser.closeTab(_currenttab);
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test clicking on a bookmark loads the web page
+gTests.push({
+ desc: "Test clicking on a bookmark loads the web page",
+ isCompleted: false,
+
+ run: function() {
+ isnot(chromeWindow.Browser.selectedTab.browser.currentURI.spec, testURL_02, "Selected tab is not " + testURL_02);
+
+ chromeWindow.BrowserUI.doCommand("cmd_newTab");
+ chromeWindow.BrowserUI.showBookmarks();
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
+ EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
+
+ chromeWindow.Browser.selectedTab.browser.addEventListener("load",
+ function() {
+ chromeWindow.Browser.selectedTab.browser.removeEventListener("load", arguments.callee, true);
+ is(chromeWindow.Browser.selectedTab.browser.currentURI.spec, testURL_02, "Selected tab is " + testURL_02);
+ chromeWindow.Browser.closeTab(chromeWindow.Browser.selectedTab);
+
+ gCurrentTest.isCompleted = true;
+ },
+ true);
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test editing URI of existing bookmark
+gTests.push({
+ desc: "Test editing URI of existing bookmark",
+ isCompleted: false,
+
+ run: function() {
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
+ var editbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "edit-button");
+ editbutton.click();
+
+ var uritextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
+ uritextbox.value = testURL_01;
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ var bookmark = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_02));
+ is(bookmark, -1, testURL_02 + " should no longer in bookmark");
+ bookmark = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_01));
+ isnot(bookmark, -1, testURL_01 + " is in bookmark");
+
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test editing title of existing bookmark
+gTests.push({
+ desc: "Test editing title of existing bookmark",
+ isCompleted: false,
+
+ run: function() {
+ var newtitle = "Changed Title";
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+
+ var bookmark = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_01));
+ is(PlacesUtils.bookmarks.getItemTitle(bookmark), "Browser Blank Page 02", "Title remains the same.");
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_01);
+ var editbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "edit-button");
+ editbutton.click();
+
+ var titletextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
+ titletextbox.value = newtitle;
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ isnot(PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_01)), -1, testURL_01 + " is still in bookmark.");
+ is(PlacesUtils.bookmarks.getItemTitle(bookmark), newtitle, "Title is changed.");
+
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test removing existing bookmark
+gTests.push({
+ desc: "Test removing existing bookmark",
+ isCompleted: false,
+ _ximage: null,
+
+ run: function() {
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_01);
+ // Close button is an image so not loaded immediately, thus need to listen for its load event before usage
+ _ximage = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "close-button");
+ _ximage.addEventListener("load",
+ function() {
+ _ximage.removeEventListener("load", arguments.callee, true);
+ gCurrentTest.verify();
+ },
+ true);
+ },
+
+ verify: function() {
+ EventUtils.synthesizeMouse(_ximage, _ximage.clientWidth / 2, _ximage.clientHeight / 2, {});
+
+ var bookmark = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_02));
+ ok(bookmark == -1, testURL_02 + " should no longer in bookmark");
+ bookmark = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_01));
+ ok(bookmark == -1, testURL_01 + " should no longer in bookmark");
+
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Helpers
+function uri(spec) {
+ return ioService.newURI(spec, null, null);
+}
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_bookmarks_folders.js
@@ -0,0 +1,341 @@
+/*
+ * Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome
+ * code in mobile/chrome/content in terms of integration with Places
+ * component, specifically for bookmark management.
+ */
+
+var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+var thread = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager).currentThread;
+var testURL_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_02.html";
+var chromeWindow = window;
+
+//------------------------------------------------------------------------------
+// TEST SKELETON: use this template to add new tests. This is based on
+// browser/components/places/tests/browser/browser_bookmarksProperties.js
+/*
+gTests.push({
+ desc: "Bug Description",
+ isCompleted: false,
+
+ run: function() {
+ // Actual test ...
+
+ // indicate test is completed
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+*/
+
+// A queue to order the tests and a handle for each test
+var gTests = [];
+var gCurrentTest = null;
+
+//------------------------------------------------------------------------------
+// Entry point (must be named 'test')
+function test() {
+ // test testing dependencies
+ ok(isnot, "Mochitest must be in context");
+ ok(ioService, "nsIIOService must be in context");
+ ok(thread, "nsIThreadManager must be in context");
+ ok(PlacesUtils, "PlacesUtils must be in context");
+ ok(EventUtils, "EventUtils must be in context");
+ ok(chromeWindow, "ChromeWindow must be in context");
+
+ ok(true, "*** Starting test browser_bookmark_folders.js\n");
+ runNextTest();
+}
+
+//------------------------------------------------------------------------------
+// Iterating tests by shifting test out one by one as runNextTest is called.
+function runNextTest() {
+ // Clean up previous test
+ if(gCurrentTest) {
+ ok(true, "*** FINISHED TEST ***");
+ }
+
+ // Run the next test until all tests completed
+ if (gTests.length > 0) {
+ gCurrentTest = gTests.shift();
+ ok(true, gCurrentTest.desc);
+ gCurrentTest.run();
+ while(!gCurrentTest.isCompleted) {
+ thread.processNextEvent(true);
+ }
+ runNextTest();
+ }
+ else {
+ // Cleanup. All tests are completed at this point
+ PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.bookmarks.unfiledBookmarksFolder);
+ ok(true, "*** ALL TESTS COMPLETED ***");
+ }
+}
+
+//------------------------------------------------------------------------------
+// Case: Test adding folder
+gTests.push({
+ desc: "Test adding folder",
+ isCompleted: false,
+
+ run: function() {
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "class", "bookmark-item");
+ is(bookmarkitem, null, "folder does not exist yet");
+
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var newfolderbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "class", "bookmark-folder-new");
+ EventUtils.synthesizeMouse(newfolderbutton, newfolderbutton.clientWidth / 2, newfolderbutton.clientHeight / 2, {});
+
+ bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "title", "New folder");
+ var nametextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
+ nametextbox.value = "Test Folder";
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ is(PlacesUtils.bookmarks.getItemType(bookmarkitem.itemId), PlacesUtils.bookmarks.TYPE_FOLDER, "bookmark item is a folder");
+ is(PlacesUtils.bookmarks.getItemTitle(bookmarkitem.itemId), "Test Folder", "folder is created");
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test editing folder
+gTests.push({
+ desc: "Test editing folder",
+ isCompleted: false,
+
+ run: function() {
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "title", "Test Folder");
+
+ var editbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "edit-button");
+ editbutton.click();
+
+ var nametextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
+ nametextbox.value = "Edited Test Folder";
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ is(PlacesUtils.bookmarks.getItemTitle(bookmarkitem.itemId), "Edited Test Folder", "folder is successfully edited");
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test removing folder
+gTests.push({
+ desc: "Test removing folder",
+ isCompleted: false,
+
+ run: function() {
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "title", "Edited Test Folder");
+ var folderid = bookmarkitem.itemId;
+
+ var closeimagebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "close-button");
+ // Close button is an image so not loaded immediately, thus need to listen for its load event before usage
+ var handleevent2 = function() {
+ closeimagebutton.removeEventListener("load", handleevent2, true);
+ EventUtils.synthesizeMouse(closeimagebutton, closeimagebutton.clientWidth / 2, closeimagebutton.clientHeight / 2, {});
+
+ // To verify a folder is deleted is to call a function using its ID and look for an exception.
+ // Thus need to use a catch block to verify deleted folder.
+ try {
+ var title = PlacesUtils.bookmarks.getItemTitle(folderid);
+ ok(false, "folder is not removed");
+ } catch(error) {
+ ok(error.message, "folder is removed, folder ID is not longer valid");
+ }
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ };
+ closeimagebutton.addEventListener("load", handleevent2, true);
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test moving a bookmark into a folder
+gTests.push({
+ desc: "Test moving a bookmark into a folder",
+ isCompleted: false,
+ _currenttab: null,
+
+ run: function() {
+ _currenttab = chromeWindow.Browser.addTab(testURL_02, true);
+ var handleevent1 = function() {
+ _currenttab.browser.removeEventListener("load", handleevent1, true);
+ gCurrentTest.verify();
+ };
+ _currenttab.browser.addEventListener("load", handleevent1 , true);
+ },
+
+ verify: function() {
+
+ // the test bookmarks a page, then creates a folder, and then moves the bookmark into the folder
+
+ chromeWindow.BrowserUI.doCommand("cmd_star");
+
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var newfolderbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "class", "bookmark-folder-new");
+ EventUtils.synthesizeMouse(newfolderbutton, newfolderbutton.clientWidth / 2, newfolderbutton.clientHeight / 2, {});
+ var folderitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "title", "New folder");
+ var nametextbox = chromeWindow.document.getAnonymousElementByAttribute(folderitem, "anonid", "name");
+ nametextbox.value = "Test Folder 1";
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(folderitem, "anonid", "done-button");
+ donebutton.click();
+
+ var bookmarkitemid = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_02));
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "itemid", bookmarkitemid);
+ var movebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "folder-button");
+ movebutton.click();
+
+ var folderitems = chromeWindow.document.getElementById("folder-items");
+ var destfolder = chromeWindow.document.getAnonymousElementByAttribute(folderitems, "itemid", folderitem.itemId);
+ EventUtils.synthesizeMouse(destfolder, destfolder.clientWidth / 2, destfolder.clientHeight / 2, {});
+
+ isnot(PlacesUtils.bookmarks.getFolderIdForItem(bookmarkitemid), PlacesUtils.bookmarks.unfiledBookmarksFolder,
+ "Bookmark is no longer in Bookmarks Menu top level folder");
+ is(PlacesUtils.bookmarks.getFolderIdForItem(bookmarkitemid), folderitem.itemId, "Bookmark is moved to a folder");
+
+ chromeWindow.BookmarkList.close();
+ chromeWindow.Browser.closeTab(_currenttab);
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test moving a folder into a folder
+gTests.push({
+ desc: "Test moving a folder into a folder",
+ isCompleted: false,
+
+ run: function() {
+
+ // the test creates a new folder ("Test Folder 2"), and then move a previously created folder ("Test Folder 1")
+ // into the newly created folder
+
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+
+ var newfolderbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "class", "bookmark-folder-new");
+ EventUtils.synthesizeMouse(newfolderbutton, newfolderbutton.clientWidth / 2, newfolderbutton.clientHeight / 2, {});
+ var folderitem2 = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "title", "New folder");
+ var nametextbox = chromeWindow.document.getAnonymousElementByAttribute(folderitem2, "anonid", "name");
+ nametextbox.value = "Test Folder 2";
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(folderitem2, "anonid", "done-button");
+ donebutton.click();
+
+ var folderitem1 = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "title", "Test Folder 1");
+ var foldetitem1id = folderitem1.itemId;
+ var movebutton = chromeWindow.document.getAnonymousElementByAttribute(folderitem1, "anonid", "folder-button");
+ movebutton.click();
+
+ var folderitems = chromeWindow.document.getElementById("folder-items");
+ var destfolder = chromeWindow.document.getAnonymousElementByAttribute(folderitems, "itemid", folderitem2.itemId);
+ EventUtils.synthesizeMouse(destfolder, destfolder.clientWidth / 2, destfolder.clientHeight / 2, {});
+
+ isnot(PlacesUtils.bookmarks.getFolderIdForItem(foldetitem1id), PlacesUtils.bookmarks.unfiledBookmarksFolder,
+ "Folder created in previous test is no longer in Bookmarks Menu top level folder");
+ is(PlacesUtils.bookmarks.getFolderIdForItem(foldetitem1id), folderitem2.itemId, "Folder is moved to another folder");
+
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test adding, editing, deleting a subfolder in a folder
+gTests.push({
+ desc: "Test adding a subfolder into a folder",
+ isCompleted: false,
+
+ run: function() {
+ chromeWindow.BrowserUI.showBookmarks();
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+
+ // creates a folder in existing folder ("Test Folder 2")
+
+ var folderitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "title", "Test Folder 2");
+ var folderitemid = folderitem.itemId;
+ EventUtils.synthesizeMouse(folderitem, folderitem.clientWidth / 2, folderitem.clientHeight / 2, {});
+
+ bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ chromeWindow.BookmarkList.toggleManage();
+
+ var newfolderbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "class", "bookmark-folder-new");
+ EventUtils.synthesizeMouse(newfolderbutton, newfolderbutton.clientWidth / 2, newfolderbutton.clientHeight / 2, {});
+
+ var newsubfolder = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "title", "New folder");
+ var nametextbox = chromeWindow.document.getAnonymousElementByAttribute(newsubfolder, "anonid", "name");
+ nametextbox.value = "Test Subfolder 1";
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(newsubfolder, "anonid", "done-button");
+ donebutton.click();
+
+ is(PlacesUtils.bookmarks.getFolderIdForItem(newsubfolder.itemId), folderitemid, "Subfolder is created");
+
+ // edits the folder title
+
+ var editbutton = chromeWindow.document.getAnonymousElementByAttribute(newsubfolder, "anonid", "edit-button");
+ editbutton.click();
+
+ nametextbox = chromeWindow.document.getAnonymousElementByAttribute(newsubfolder, "anonid", "name");
+ nametextbox.value = "Edited Test Subfolder 1";
+ donebutton.click();
+
+ is(PlacesUtils.bookmarks.getItemTitle(newsubfolder.itemId), "Edited Test Subfolder 1", "Subfolder is successfully edited");
+
+ // removes the folder
+
+ var closeimagebutton = chromeWindow.document.getAnonymousElementByAttribute(newsubfolder, "anonid", "close-button");
+ var handleevent3 = function() {
+ closeimagebutton.removeEventListener("load", handleevent3, true);
+ EventUtils.synthesizeMouse(closeimagebutton, closeimagebutton.clientWidth / 2, closeimagebutton.clientHeight / 2, {});
+
+ // To verify a folder is deleted is to call a function using its ID and look for an exception.
+ // Thus need to use a catch block to verify deleted folder.
+ try {
+ var title = PlacesUtils.bookmarks.getItemTitle(newsubfolder.itemId);
+ ok(false, "folder is not removed");
+ } catch(error) {
+ ok(error.message, "Subfolder is removed, folder ID is not longer valid");
+ }
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ };
+ closeimagebutton.addEventListener("load", handleevent3, true);
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Helpers
+function uri(spec) {
+ return ioService.newURI(spec, null, null);
+}
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_bookmarks_star.js
@@ -0,0 +1,171 @@
+/*
+ * Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome
+ * code in mobile/chrome/content in terms of integration with Places
+ * component, specifically for bookmark management.
+ */
+
+//------------------------------------------------------------------------------
+// TEST SKELETON: use this template to add new tests. This is based on
+// browser/components/places/tests/browser/browser_bookmarksProperties.js
+/*
+gTests.push({
+ desc: "Bug Description",
+ isCompleted: false,
+
+ run: function() {
+ // Actual test ...
+
+ // indicate test is completed
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+*/
+
+var thread = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager).currentThread;
+var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+var testURL_01 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
+var testURL_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_02.html";
+var chromeWindow = window;
+
+// A queue to order the tests and a handle for each test
+var gTests = [];
+var gCurrentTest = null;
+
+//------------------------------------------------------------------------------
+// Entry point (must be called 'test')
+function test() {
+ // test testing dependencies
+ ok(isnot, "Mochitest must be in context");
+ ok(ioService, "nsIIOService must be in context");
+ ok(thread, "nsIThreadManager must be in context");
+ ok(PlacesUtils, "PlacesUtils must be in context");
+ ok(EventUtils, "EventUtils must be in context");
+ ok(chromeWindow, "ChromeWindow must be in context");
+
+ ok(true, "*** Starting test browser_bookmark_star.js\n");
+ runNextTest();
+}
+
+//------------------------------------------------------------------------------
+// Iterating tests by shifting test out one by one as runNextTest is called.
+function runNextTest() {
+ // Clean up previous test
+ if(gCurrentTest) {
+ ok(true, "*** FINISHED TEST ***");
+ }
+
+ // Run the next test until all tests completed
+ if (gTests.length > 0) {
+ gCurrentTest = gTests.shift();
+ ok(true, gCurrentTest.desc);
+ gCurrentTest.run();
+ while(!gCurrentTest.isCompleted) {
+ thread.processNextEvent(true);
+ }
+ runNextTest();
+ }
+ else {
+ // Cleanup. All tests are completed at this point
+ PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.bookmarks.unfiledBookmarksFolder);
+ ok(true, "*** ALL TESTS COMPLETED ***");
+ }
+}
+
+//------------------------------------------------------------------------------
+// Case: Test adding tags via star icon
+gTests.push({
+ desc: "Test adding tags via star icon",
+ isCompleted: false,
+ _currenttab: null,
+
+ run: function() {
+ _currenttab = chromeWindow.Browser.addTab(testURL_02, true);
+ var handleevent1 = function() {
+ _currenttab.browser.removeEventListener("load", handleevent1, true);
+ gCurrentTest.onPageLoad();
+ };
+ _currenttab.browser.addEventListener("load", handleevent1 , true);
+ },
+
+ onPageLoad: function() {
+ var starbutton = chromeWindow.document.getElementById("tool-star");
+ starbutton.click();
+ var starbutton = chromeWindow.document.getElementById("tool-star");
+ starbutton.click();
+
+ var bookmarkitem = chromeWindow.document.getElementById("bookmark-item");
+
+ // Since no event to listen, need to loop until all the elements and attributes are ready before form editing
+ while(!bookmarkitem._isEditing) {
+ thread.processNextEvent(true);
+ }
+
+ var uritextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
+ var urispec = uritextbox.value;
+
+ var tagtextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "tags");
+ tagtextbox.value = "tagone, tag two, tag-three, tag4";
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ var tagsarray = PlacesUtils.tagging.getTagsForURI(uri(urispec), {});
+ is(tagsarray.length, 4, "All tags are added.");
+
+ chromeWindow.BrowserUI.closeTab(_currenttab);
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test editing uri via star icon
+gTests.push({
+ desc: "Test editing uri via star icon",
+ isCompleted: false,
+ _currenttab: null,
+
+ run: function() {
+ _currenttab = chromeWindow.Browser.addTab(testURL_02, true);
+ var handleevent2 = function() {
+ _currenttab.browser.removeEventListener("load", handleevent2, true);
+ gCurrentTest.onPageLoad();
+ };
+ _currenttab.browser.addEventListener("load", handleevent2, true);
+ },
+
+ onPageLoad: function() {
+ var starbutton = chromeWindow.document.getElementById("tool-star");
+ starbutton.click();
+
+ var bookmarkitem = chromeWindow.document.getElementById("bookmark-item");
+
+ // Since no event to listen, need to loop until all the elements and attributes are ready before form editing
+ while(!bookmarkitem._isEditing) {
+ thread.processNextEvent(true);
+ }
+
+ var uritextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
+ uritextbox.value = testURL_01;
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ isnot(PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_01)), -1, testURL_01 + " is now bookmarked");
+ is(PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_02)), -1, testURL_02 + " is no longer bookmarked");
+
+ PlacesUtils.bookmarks.removeItem(PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_01)));
+ chromeWindow.BrowserUI.closeTab(_currenttab);
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Helpers
+function uri(spec) {
+ return ioService.newURI(spec, null, null);
+}
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_bookmarks_tags.js
@@ -0,0 +1,195 @@
+/*
+ * Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome
+ * code in mobile/chrome/content in terms of integration with Places
+ * component, specifically for bookmark management.
+ */
+
+var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+var thread = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager).currentThread;
+var testURL_01 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
+var testURL_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_02.html";
+var chromeWindow = window;
+
+//------------------------------------------------------------------------------
+// TEST SKELETON: use this template to add new tests. This is based on
+// browser/components/places/tests/browser/browser_bookmarksProperties.js
+/*
+gTests.push({
+ desc: "Bug Description",
+ isCompleted: false,
+
+ run: function() {
+ // Actual test ...
+
+ // indicate test is completed
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+*/
+
+// A queue to order the tests and a handle for each test
+var gTests = [];
+var gCurrentTest = null;
+
+//------------------------------------------------------------------------------
+// Entry point (must be named 'test')
+function test() {
+ // test testing dependencies
+ ok(isnot, "Mochitest must be in context");
+ ok(ioService, "nsIIOService must be in context");
+ ok(thread, "nsIThreadManager must be in context");
+ ok(PlacesUtils, "PlacesUtils in context");
+ ok(EventUtils, "EventUtils in context");
+ ok(chromeWindow, "ChromeWindow in context");
+
+ ok(true, "*** Starting test browser_bookmark_tags.js\n");
+ runNextTest();
+}
+
+//------------------------------------------------------------------------------
+// Iterating tests by shifting test out one by one as runNextTest is called.
+function runNextTest() {
+ // Clean up previous test
+ if(gCurrentTest) {
+ ok(true, "*** FINISHED TEST ***");
+ }
+
+ // Run the next test until all tests completed
+ if (gTests.length > 0) {
+ gCurrentTest = gTests.shift();
+ ok(true, gCurrentTest.desc);
+ gCurrentTest.run();
+ while(!gCurrentTest.isCompleted) {
+ thread.processNextEvent(true);
+ }
+ runNextTest();
+ }
+ else {
+ // Cleanup. All tests are completed at this point
+ PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.bookmarks.unfiledBookmarksFolder);
+ ok(true, "*** ALL TESTS COMPLETED ***");
+ }
+}
+
+//------------------------------------------------------------------------------
+// Case: Test adding tags to bookmark
+gTests.push({
+ desc: "Test adding tags to a bookmark",
+ isCompleted: false,
+ _currenttab: null,
+
+ run: function() {
+ _currenttab = chromeWindow.Browser.addTab(testURL_02, true);
+ var handlepageload = function() {
+ _currenttab.browser.removeEventListener("load", handlepageload, true);
+ gCurrentTest.onPageLoad();
+ };
+ _currenttab.browser.addEventListener("load", handlepageload , true);
+ },
+
+ onPageLoad: function() {
+ chromeWindow.BrowserUI.doCommand("cmd_star");
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
+ var editbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "edit-button");
+ editbutton.click();
+
+ var tagstextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "tags");
+ tagstextbox.value = "tagone, tag two, tag-three, tag4";
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ var tagsarray = PlacesUtils.tagging.getTagsForURI(uri(testURL_02), {});
+ is(tagsarray.length, 4, "All tags are associated with specified bookmark");
+
+ chromeWindow.BookmarkList.close();
+ chromeWindow.Browser.closeTab(_currenttab);
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Case: Test editing tags to bookmark
+gTests.push({
+ desc: "Test editing tags to bookmark",
+ isCompleted: false,
+
+ run: function() {
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+
+ var taggeduri = PlacesUtils.tagging.getURIsForTag("tag-three");
+ is(taggeduri[0].spec, testURL_02, "Old tag still associated with bookmark");
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
+ var editbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "edit-button");
+ editbutton.click();
+
+ var tagstextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "tags");
+ tagstextbox.value = "tagone, tag two, edited-tag-three, tag4";
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ var untaggeduri = PlacesUtils.tagging.getURIsForTag("tag-three");
+ is(untaggeduri, "", "Old tag is not associated with any bookmark");
+ taggeduri = PlacesUtils.tagging.getURIsForTag("edited-tag-three");
+ is(taggeduri[0].spec, testURL_02, "New tag is added to bookmark");
+ var tagsarray = PlacesUtils.tagging.getTagsForURI(uri(testURL_02), {});
+ is(tagsarray.length, 4, "Bookmark still has same number of tags");
+
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+
+//------------------------------------------------------------------------------
+// Case: Test removing tags from bookmark
+gTests.push({
+ desc: "Test removing tags from a bookmark",
+ _currenttab: null,
+
+ run: function() {
+ chromeWindow.BrowserUI.showBookmarks();
+ chromeWindow.BookmarkList.toggleManage();
+
+ var bookmarkitems = chromeWindow.document.getElementById("bookmark-items");
+ var bookmarkitem = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
+ var editbutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "edit-button");
+ editbutton.click();
+
+ var tagstextbox = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "tags");
+ tagstextbox.value = "tagone, tag two, tag4";
+
+ var donebutton = chromeWindow.document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+ donebutton.click();
+
+ var untaggeduri = PlacesUtils.tagging.getURIsForTag("edited-tag-three");
+ is(untaggeduri, "", "Old tag is not associated with any bookmark");
+ var tagsarray = PlacesUtils.tagging.getTagsForURI(uri(testURL_02), {});
+ is(tagsarray.length, 3, "Tag is successfully deleted");
+
+ PlacesUtils.bookmarks.removeItem(PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_02)));
+ chromeWindow.BookmarkList.close();
+
+ gCurrentTest.isCompleted = true;
+ },
+
+});
+
+//------------------------------------------------------------------------------
+// Helpers
+function uri(spec) {
+ return ioService.newURI(spec, null, null);
+}