|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet |
|
4 href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
|
5 <window title="Update Livemark SiteURI, null to start" |
|
6 xmlns:html="http://www.w3.org/1999/xhtml" |
|
7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
8 onload="runTest()"> |
|
9 <script type="application/javascript" |
|
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
11 |
|
12 <body xmlns="http://www.w3.org/1999/xhtml" /> |
|
13 |
|
14 <script type="application/javascript"> |
|
15 <![CDATA[ |
|
16 /* |
|
17 Test updating livemark siteURI to the value from the feed, when it's null |
|
18 */ |
|
19 SimpleTest.waitForExplicitFinish(); |
|
20 |
|
21 const Cc = Components.classes; |
|
22 const Ci = Components.interfaces; |
|
23 const Cr = Components.results; |
|
24 |
|
25 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
26 Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
|
27 Components.utils.import("resource://gre/modules/PlacesUtils.jsm"); |
|
28 |
|
29 function runTest() { |
|
30 const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/sample_feed.atom"; |
|
31 const FEEDSITESPEC = "http://example.org/"; |
|
32 |
|
33 PlacesUtils.livemarks.addLivemark( |
|
34 { title: "foo" |
|
35 , parentId: PlacesUtils.toolbarFolderId |
|
36 , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
|
37 , feedURI: NetUtil.newURI(FEEDSPEC) |
|
38 }) |
|
39 .then(function (aLivemark) { |
|
40 is(aLivemark.siteURI, null, "Has null livemark site URI"); |
|
41 |
|
42 waitForLivemarkLoad(aLivemark, function (aLivemark) { |
|
43 is(aLivemark.siteURI.spec, FEEDSITESPEC, |
|
44 "livemark site URI set to value in feed"); |
|
45 |
|
46 PlacesUtils.bookmarks.removeItem(aLivemark.id); |
|
47 SimpleTest.finish(); |
|
48 }); |
|
49 }, function () { |
|
50 is(true, false, "Should not fail adding a livemark"); |
|
51 } |
|
52 ); |
|
53 } |
|
54 |
|
55 function waitForLivemarkLoad(aLivemark, aCallback) { |
|
56 // Don't need a real node here. |
|
57 let node = {}; |
|
58 let resultObserver = { |
|
59 nodeInserted: function() {}, |
|
60 nodeRemoved: function() {}, |
|
61 nodeAnnotationChanged: function() {}, |
|
62 nodeTitleChanged: function() {}, |
|
63 nodeHistoryDetailsChanged: function() {}, |
|
64 nodeMoved: function() {}, |
|
65 ontainerStateChanged: function () {}, |
|
66 sortingChanged: function() {}, |
|
67 batching: function() {}, |
|
68 invalidateContainer: function(node) { |
|
69 isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED, |
|
70 "Loading livemark should success"); |
|
71 if (aLivemark.status == Ci.mozILivemark.STATUS_READY) { |
|
72 aLivemark.unregisterForUpdates(node, resultObserver); |
|
73 aCallback(aLivemark); |
|
74 } |
|
75 } |
|
76 }; |
|
77 aLivemark.registerForUpdates(node, resultObserver); |
|
78 aLivemark.reload(); |
|
79 } |
|
80 |
|
81 ]]> |
|
82 </script> |
|
83 |
|
84 </window> |