|
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" |
|
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 |
|
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 INITIALSITESPEC = "http://mochi.test:8888/"; |
|
32 const FEEDSITESPEC = "http://example.org/"; |
|
33 |
|
34 PlacesUtils.livemarks.addLivemark( |
|
35 { title: "foo" |
|
36 , parentId: PlacesUtils.toolbarFolderId |
|
37 , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
|
38 , feedURI: NetUtil.newURI(FEEDSPEC) |
|
39 , siteURI: NetUtil.newURI(INITIALSITESPEC) |
|
40 }) |
|
41 .then(function (aLivemark) { |
|
42 is(aLivemark.siteURI.spec, INITIALSITESPEC, |
|
43 "Has correct initial livemark site URI"); |
|
44 |
|
45 waitForLivemarkLoad(aLivemark, function (aLivemark) { |
|
46 is(aLivemark.siteURI.spec, FEEDSITESPEC, |
|
47 "livemark site URI set to value in feed"); |
|
48 |
|
49 PlacesUtils.bookmarks.removeItem(aLivemark.id); |
|
50 SimpleTest.finish(); |
|
51 }); |
|
52 }, function () { |
|
53 is(true, false, "Should not fail adding a livemark"); |
|
54 } |
|
55 ); |
|
56 } |
|
57 |
|
58 function waitForLivemarkLoad(aLivemark, aCallback) { |
|
59 // Don't need a real node here. |
|
60 let node = {}; |
|
61 let resultObserver = { |
|
62 nodeInserted: function() {}, |
|
63 nodeRemoved: function() {}, |
|
64 nodeAnnotationChanged: function() {}, |
|
65 nodeTitleChanged: function() {}, |
|
66 nodeHistoryDetailsChanged: function() {}, |
|
67 nodeMoved: function() {}, |
|
68 ontainerStateChanged: function () {}, |
|
69 sortingChanged: function() {}, |
|
70 batching: function() {}, |
|
71 invalidateContainer: function(node) { |
|
72 isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED, |
|
73 "Loading livemark should success"); |
|
74 if (aLivemark.status == Ci.mozILivemark.STATUS_READY) { |
|
75 aLivemark.unregisterForUpdates(node, resultObserver); |
|
76 aCallback(aLivemark); |
|
77 } |
|
78 } |
|
79 }; |
|
80 aLivemark.registerForUpdates(node, resultObserver); |
|
81 aLivemark.reload(); |
|
82 } |
|
83 |
|
84 ]]> |
|
85 </script> |
|
86 |
|
87 </window> |