michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: let testURL = "data:text/plain,nothing but plain text"; michael@0: let testTag = "581253_tag"; michael@0: let timerID = -1; michael@0: michael@0: function test() { michael@0: registerCleanupFunction(function() { michael@0: PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); michael@0: if (timerID > 0) { michael@0: clearTimeout(timerID); michael@0: } michael@0: }); michael@0: waitForExplicitFinish(); michael@0: michael@0: let tab = gBrowser.selectedTab = gBrowser.addTab(); michael@0: tab.linkedBrowser.addEventListener("load", (function(event) { michael@0: tab.linkedBrowser.removeEventListener("load", arguments.callee, true); michael@0: michael@0: let uri = makeURI(testURL); michael@0: let bmTxn = michael@0: new PlacesCreateBookmarkTransaction(uri, michael@0: PlacesUtils.unfiledBookmarksFolderId, michael@0: -1, "", null, []); michael@0: PlacesUtils.transactionManager.doTransaction(bmTxn); michael@0: michael@0: ok(PlacesUtils.bookmarks.isBookmarked(uri), "the test url is bookmarked"); michael@0: waitForStarChange(true, onStarred); michael@0: }), true); michael@0: michael@0: content.location = testURL; michael@0: } michael@0: michael@0: function waitForStarChange(aValue, aCallback) { michael@0: let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED michael@0: : BookmarkingUI.STATUS_UNSTARRED; michael@0: if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING || michael@0: BookmarkingUI.status != expectedStatus) { michael@0: info("Waiting for star button change."); michael@0: setTimeout(waitForStarChange, 50, aValue, aCallback); michael@0: return; michael@0: } michael@0: aCallback(); michael@0: } michael@0: michael@0: function onStarred() { michael@0: is(BookmarkingUI.status, BookmarkingUI.STATUS_STARRED, michael@0: "star button indicates that the page is bookmarked"); michael@0: michael@0: let uri = makeURI(testURL); michael@0: let tagTxn = new PlacesTagURITransaction(uri, [testTag]); michael@0: PlacesUtils.transactionManager.doTransaction(tagTxn); michael@0: michael@0: StarUI.panel.addEventListener("popupshown", onPanelShown, false); michael@0: BookmarkingUI.star.click(); michael@0: } michael@0: michael@0: function onPanelShown(aEvent) { michael@0: if (aEvent.target == StarUI.panel) { michael@0: StarUI.panel.removeEventListener("popupshown", arguments.callee, false); michael@0: let tagsField = document.getElementById("editBMPanel_tagsField"); michael@0: ok(tagsField.value == testTag, "tags field value was set"); michael@0: tagsField.focus(); michael@0: michael@0: StarUI.panel.addEventListener("popuphidden", onPanelHidden, false); michael@0: let removeButton = document.getElementById("editBookmarkPanelRemoveButton"); michael@0: removeButton.click(); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Clears history invoking callback when done. michael@0: */ michael@0: function waitForClearHistory(aCallback) michael@0: { michael@0: let observer = { michael@0: observe: function(aSubject, aTopic, aData) michael@0: { michael@0: Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED); michael@0: aCallback(aSubject, aTopic, aData); michael@0: } michael@0: }; michael@0: Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); michael@0: PlacesUtils.bhistory.removeAllPages(); michael@0: } michael@0: michael@0: function onPanelHidden(aEvent) { michael@0: if (aEvent.target == StarUI.panel) { michael@0: StarUI.panel.removeEventListener("popuphidden", arguments.callee, false); michael@0: michael@0: executeSoon(function() { michael@0: ok(!PlacesUtils.bookmarks.isBookmarked(makeURI(testURL)), michael@0: "the bookmark for the test url has been removed"); michael@0: is(BookmarkingUI.status, BookmarkingUI.STATUS_UNSTARRED, michael@0: "star button indicates that the bookmark has been removed"); michael@0: gBrowser.removeCurrentTab(); michael@0: waitForClearHistory(finish); michael@0: }); michael@0: } michael@0: }