Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | let testURL = "data:text/plain,nothing but plain text"; |
michael@0 | 6 | let testTag = "581253_tag"; |
michael@0 | 7 | let timerID = -1; |
michael@0 | 8 | |
michael@0 | 9 | function test() { |
michael@0 | 10 | registerCleanupFunction(function() { |
michael@0 | 11 | PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 12 | if (timerID > 0) { |
michael@0 | 13 | clearTimeout(timerID); |
michael@0 | 14 | } |
michael@0 | 15 | }); |
michael@0 | 16 | waitForExplicitFinish(); |
michael@0 | 17 | |
michael@0 | 18 | let tab = gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 19 | tab.linkedBrowser.addEventListener("load", (function(event) { |
michael@0 | 20 | tab.linkedBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 21 | |
michael@0 | 22 | let uri = makeURI(testURL); |
michael@0 | 23 | let bmTxn = |
michael@0 | 24 | new PlacesCreateBookmarkTransaction(uri, |
michael@0 | 25 | PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 26 | -1, "", null, []); |
michael@0 | 27 | PlacesUtils.transactionManager.doTransaction(bmTxn); |
michael@0 | 28 | |
michael@0 | 29 | ok(PlacesUtils.bookmarks.isBookmarked(uri), "the test url is bookmarked"); |
michael@0 | 30 | waitForStarChange(true, onStarred); |
michael@0 | 31 | }), true); |
michael@0 | 32 | |
michael@0 | 33 | content.location = testURL; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function waitForStarChange(aValue, aCallback) { |
michael@0 | 37 | let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED |
michael@0 | 38 | : BookmarkingUI.STATUS_UNSTARRED; |
michael@0 | 39 | if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING || |
michael@0 | 40 | BookmarkingUI.status != expectedStatus) { |
michael@0 | 41 | info("Waiting for star button change."); |
michael@0 | 42 | setTimeout(waitForStarChange, 50, aValue, aCallback); |
michael@0 | 43 | return; |
michael@0 | 44 | } |
michael@0 | 45 | aCallback(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function onStarred() { |
michael@0 | 49 | is(BookmarkingUI.status, BookmarkingUI.STATUS_STARRED, |
michael@0 | 50 | "star button indicates that the page is bookmarked"); |
michael@0 | 51 | |
michael@0 | 52 | let uri = makeURI(testURL); |
michael@0 | 53 | let tagTxn = new PlacesTagURITransaction(uri, [testTag]); |
michael@0 | 54 | PlacesUtils.transactionManager.doTransaction(tagTxn); |
michael@0 | 55 | |
michael@0 | 56 | StarUI.panel.addEventListener("popupshown", onPanelShown, false); |
michael@0 | 57 | BookmarkingUI.star.click(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function onPanelShown(aEvent) { |
michael@0 | 61 | if (aEvent.target == StarUI.panel) { |
michael@0 | 62 | StarUI.panel.removeEventListener("popupshown", arguments.callee, false); |
michael@0 | 63 | let tagsField = document.getElementById("editBMPanel_tagsField"); |
michael@0 | 64 | ok(tagsField.value == testTag, "tags field value was set"); |
michael@0 | 65 | tagsField.focus(); |
michael@0 | 66 | |
michael@0 | 67 | StarUI.panel.addEventListener("popuphidden", onPanelHidden, false); |
michael@0 | 68 | let removeButton = document.getElementById("editBookmarkPanelRemoveButton"); |
michael@0 | 69 | removeButton.click(); |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | /** |
michael@0 | 74 | * Clears history invoking callback when done. |
michael@0 | 75 | */ |
michael@0 | 76 | function waitForClearHistory(aCallback) |
michael@0 | 77 | { |
michael@0 | 78 | let observer = { |
michael@0 | 79 | observe: function(aSubject, aTopic, aData) |
michael@0 | 80 | { |
michael@0 | 81 | Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
michael@0 | 82 | aCallback(aSubject, aTopic, aData); |
michael@0 | 83 | } |
michael@0 | 84 | }; |
michael@0 | 85 | Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); |
michael@0 | 86 | PlacesUtils.bhistory.removeAllPages(); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function onPanelHidden(aEvent) { |
michael@0 | 90 | if (aEvent.target == StarUI.panel) { |
michael@0 | 91 | StarUI.panel.removeEventListener("popuphidden", arguments.callee, false); |
michael@0 | 92 | |
michael@0 | 93 | executeSoon(function() { |
michael@0 | 94 | ok(!PlacesUtils.bookmarks.isBookmarked(makeURI(testURL)), |
michael@0 | 95 | "the bookmark for the test url has been removed"); |
michael@0 | 96 | is(BookmarkingUI.status, BookmarkingUI.STATUS_UNSTARRED, |
michael@0 | 97 | "star button indicates that the bookmark has been removed"); |
michael@0 | 98 | gBrowser.removeCurrentTab(); |
michael@0 | 99 | waitForClearHistory(finish); |
michael@0 | 100 | }); |
michael@0 | 101 | } |
michael@0 | 102 | } |