toolkit/components/places/tests/chrome/test_reloadLivemarks.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet
michael@0 4 href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 5 <window title="Reload Livemarks"
michael@0 6 xmlns:html="http://www.w3.org/1999/xhtml"
michael@0 7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 8 onload="runTest()" onunload="cleanup()">
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11
michael@0 12 <body xmlns="http://www.w3.org/1999/xhtml" />
michael@0 13
michael@0 14 <script type="application/javascript">
michael@0 15 <![CDATA[
michael@0 16 // Test that for concurrent reload of livemarks.
michael@0 17
michael@0 18 SimpleTest.waitForExplicitFinish();
michael@0 19
michael@0 20 const Cc = Components.classes;
michael@0 21 const Ci = Components.interfaces;
michael@0 22 const Cr = Components.results;
michael@0 23
michael@0 24 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 25 Components.utils.import("resource://gre/modules/NetUtil.jsm");
michael@0 26 Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
michael@0 27
michael@0 28 let gLivemarks = [
michael@0 29 { id: -1,
michael@0 30 title: "foo",
michael@0 31 parentId: PlacesUtils.toolbarFolderId,
michael@0 32 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 33 feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items.rss")
michael@0 34 },
michael@0 35 { id: -1,
michael@0 36 title: "bar",
michael@0 37 parentId: PlacesUtils.toolbarFolderId,
michael@0 38 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 39 feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items-no-site-uri.rss")
michael@0 40 },
michael@0 41 ];
michael@0 42
michael@0 43 function runTest()
michael@0 44 {
michael@0 45 addLivemarks(function () {
michael@0 46 reloadLivemarks(false, function () {
michael@0 47 reloadLivemarks(true, function () {
michael@0 48 removeLivemarks(SimpleTest.finish);
michael@0 49 });
michael@0 50 });
michael@0 51 // Ensure this normal reload doesn't overwrite the forced one.
michael@0 52 PlacesUtils.livemarks.reloadLivemarks();
michael@0 53 });
michael@0 54 }
michael@0 55
michael@0 56 function addLivemarks(aCallback) {
michael@0 57 info("Adding livemarks");
michael@0 58 let count = gLivemarks.length;
michael@0 59 gLivemarks.forEach(function(aLivemarkData) {
michael@0 60 PlacesUtils.livemarks.addLivemark(aLivemarkData)
michael@0 61 .then(function (aLivemark) {
michael@0 62 ok(aLivemark.feedURI.equals(aLivemarkData.feedURI), "Livemark added");
michael@0 63 aLivemarkData.id = aLivemark.id;
michael@0 64 if (--count == 0) {
michael@0 65 aCallback();
michael@0 66 }
michael@0 67 },
michael@0 68 function () {
michael@0 69 is(true, false, "Should not fail adding a livemark.");
michael@0 70 aCallback();
michael@0 71 });
michael@0 72 });
michael@0 73 }
michael@0 74
michael@0 75 function reloadLivemarks(aForceUpdate, aCallback) {
michael@0 76 info("Reloading livemarks with forceUpdate: " + aForceUpdate);
michael@0 77 let count = gLivemarks.length;
michael@0 78 gLivemarks.forEach(function(aLivemarkData) {
michael@0 79 PlacesUtils.livemarks.getLivemark(aLivemarkData)
michael@0 80 .then(aLivemark => {
michael@0 81 ok(aLivemark.feedURI.equals(aLivemarkData.feedURI), "Livemark found");
michael@0 82 aLivemarkData._observer = new resultObserver(aLivemark, function() {
michael@0 83 if (++count == gLivemarks.length) {
michael@0 84 aCallback();
michael@0 85 }
michael@0 86 });
michael@0 87 if (--count == 0) {
michael@0 88 PlacesUtils.livemarks.reloadLivemarks(aForceUpdate);
michael@0 89 }
michael@0 90 },
michael@0 91 function() {
michael@0 92 is(true, false, "Should not fail getting a livemark.");
michael@0 93 aCallback();
michael@0 94 }
michael@0 95 );
michael@0 96 });
michael@0 97 }
michael@0 98
michael@0 99 function removeLivemarks(aCallback) {
michael@0 100 info("Removing livemarks");
michael@0 101 let count = gLivemarks.length;
michael@0 102 gLivemarks.forEach(function(aLivemarkData) {
michael@0 103 PlacesUtils.livemarks.removeLivemark(aLivemarkData).then(
michael@0 104 function (aLivemark) {
michael@0 105 if (--count == 0) {
michael@0 106 aCallback();
michael@0 107 }
michael@0 108 },
michael@0 109 function() {
michael@0 110 is(true, false, "Should not fail adding a livemark.");
michael@0 111 aCallback();
michael@0 112 }
michael@0 113 );
michael@0 114 });
michael@0 115 }
michael@0 116
michael@0 117 function resultObserver(aLivemark, aCallback) {
michael@0 118 this._node = {};
michael@0 119 this._livemark = aLivemark;
michael@0 120 this._callback = aCallback;
michael@0 121 this._livemark.registerForUpdates(this._node, this);
michael@0 122 }
michael@0 123 resultObserver.prototype = {
michael@0 124 nodeInserted: function() {},
michael@0 125 nodeRemoved: function() {},
michael@0 126 nodeAnnotationChanged: function() {},
michael@0 127 nodeTitleChanged: function() {},
michael@0 128 nodeHistoryDetailsChanged: function() {},
michael@0 129 nodeMoved: function() {},
michael@0 130 ontainerStateChanged: function () {},
michael@0 131 sortingChanged: function() {},
michael@0 132 batching: function() {},
michael@0 133 invalidateContainer: function(aContainer) {
michael@0 134 // Wait for load finish.
michael@0 135 if (this._livemark.status == Ci.mozILivemark.STATUS_LOADING)
michael@0 136 return;
michael@0 137
michael@0 138 this._terminate();
michael@0 139 this._callback();
michael@0 140 },
michael@0 141 _terminate: function () {
michael@0 142 if (!this._terminated) {
michael@0 143 this._livemark.unregisterForUpdates(this._node);
michael@0 144 this._terminated = true;
michael@0 145 }
michael@0 146 }
michael@0 147 };
michael@0 148
michael@0 149 function cleanup() {
michael@0 150 gLivemarks.forEach(function(aLivemarkData) {
michael@0 151 if (aLivemarkData._observer)
michael@0 152 aLivemarkData._observer._terminate();
michael@0 153 });
michael@0 154 }
michael@0 155 ]]>
michael@0 156 </script>
michael@0 157 </window>

mercurial