1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug581253.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +let testURL = "data:text/plain,nothing but plain text"; 1.9 +let testTag = "581253_tag"; 1.10 +let timerID = -1; 1.11 + 1.12 +function test() { 1.13 + registerCleanupFunction(function() { 1.14 + PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); 1.15 + if (timerID > 0) { 1.16 + clearTimeout(timerID); 1.17 + } 1.18 + }); 1.19 + waitForExplicitFinish(); 1.20 + 1.21 + let tab = gBrowser.selectedTab = gBrowser.addTab(); 1.22 + tab.linkedBrowser.addEventListener("load", (function(event) { 1.23 + tab.linkedBrowser.removeEventListener("load", arguments.callee, true); 1.24 + 1.25 + let uri = makeURI(testURL); 1.26 + let bmTxn = 1.27 + new PlacesCreateBookmarkTransaction(uri, 1.28 + PlacesUtils.unfiledBookmarksFolderId, 1.29 + -1, "", null, []); 1.30 + PlacesUtils.transactionManager.doTransaction(bmTxn); 1.31 + 1.32 + ok(PlacesUtils.bookmarks.isBookmarked(uri), "the test url is bookmarked"); 1.33 + waitForStarChange(true, onStarred); 1.34 + }), true); 1.35 + 1.36 + content.location = testURL; 1.37 +} 1.38 + 1.39 +function waitForStarChange(aValue, aCallback) { 1.40 + let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED 1.41 + : BookmarkingUI.STATUS_UNSTARRED; 1.42 + if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING || 1.43 + BookmarkingUI.status != expectedStatus) { 1.44 + info("Waiting for star button change."); 1.45 + setTimeout(waitForStarChange, 50, aValue, aCallback); 1.46 + return; 1.47 + } 1.48 + aCallback(); 1.49 +} 1.50 + 1.51 +function onStarred() { 1.52 + is(BookmarkingUI.status, BookmarkingUI.STATUS_STARRED, 1.53 + "star button indicates that the page is bookmarked"); 1.54 + 1.55 + let uri = makeURI(testURL); 1.56 + let tagTxn = new PlacesTagURITransaction(uri, [testTag]); 1.57 + PlacesUtils.transactionManager.doTransaction(tagTxn); 1.58 + 1.59 + StarUI.panel.addEventListener("popupshown", onPanelShown, false); 1.60 + BookmarkingUI.star.click(); 1.61 +} 1.62 + 1.63 +function onPanelShown(aEvent) { 1.64 + if (aEvent.target == StarUI.panel) { 1.65 + StarUI.panel.removeEventListener("popupshown", arguments.callee, false); 1.66 + let tagsField = document.getElementById("editBMPanel_tagsField"); 1.67 + ok(tagsField.value == testTag, "tags field value was set"); 1.68 + tagsField.focus(); 1.69 + 1.70 + StarUI.panel.addEventListener("popuphidden", onPanelHidden, false); 1.71 + let removeButton = document.getElementById("editBookmarkPanelRemoveButton"); 1.72 + removeButton.click(); 1.73 + } 1.74 +} 1.75 + 1.76 +/** 1.77 + * Clears history invoking callback when done. 1.78 + */ 1.79 +function waitForClearHistory(aCallback) 1.80 +{ 1.81 + let observer = { 1.82 + observe: function(aSubject, aTopic, aData) 1.83 + { 1.84 + Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED); 1.85 + aCallback(aSubject, aTopic, aData); 1.86 + } 1.87 + }; 1.88 + Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); 1.89 + PlacesUtils.bhistory.removeAllPages(); 1.90 +} 1.91 + 1.92 +function onPanelHidden(aEvent) { 1.93 + if (aEvent.target == StarUI.panel) { 1.94 + StarUI.panel.removeEventListener("popuphidden", arguments.callee, false); 1.95 + 1.96 + executeSoon(function() { 1.97 + ok(!PlacesUtils.bookmarks.isBookmarked(makeURI(testURL)), 1.98 + "the bookmark for the test url has been removed"); 1.99 + is(BookmarkingUI.status, BookmarkingUI.STATUS_UNSTARRED, 1.100 + "star button indicates that the bookmark has been removed"); 1.101 + gBrowser.removeCurrentTab(); 1.102 + waitForClearHistory(finish); 1.103 + }); 1.104 + } 1.105 +}