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