|
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="Add Bad Livemarks" |
|
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 // Test that for feeds with items that have no link: |
|
17 // * the link-less items are present in the database. |
|
18 // * the feed's site URI is substituted for each item's link. |
|
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 const LIVEMARKS = [ |
|
30 { feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items.rss"), |
|
31 siteURI: NetUtil.newURI("http://mochi.test:8888/"), |
|
32 urls: [ |
|
33 "http://feed-item-link.com/", |
|
34 "http://feed-link.com/", |
|
35 "http://feed-item-link.com/", |
|
36 ], |
|
37 message: "Ensure link-less livemark item picked up site uri.", |
|
38 }, |
|
39 { feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items-no-site-uri.rss"), |
|
40 siteURI: null, |
|
41 urls: [ |
|
42 "http://feed-item-link.com/", |
|
43 "http://feed-item-link.com/", |
|
44 ], |
|
45 message: "Ensure livemark item links did not inherit site uri." |
|
46 }, |
|
47 ]; |
|
48 |
|
49 function runTest() |
|
50 { |
|
51 function testLivemark(aLivemarkData) { |
|
52 PlacesUtils.livemarks.addLivemark( |
|
53 { title: "foo" |
|
54 , parentId: PlacesUtils.toolbarFolderId |
|
55 , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
|
56 , feedURI: aLivemarkData.feedURI |
|
57 , siteURI: aLivemarkData.siteURI |
|
58 }) |
|
59 .then(function (aLivemark) { |
|
60 is (aLivemark.feedURI.spec, aLivemarkData.feedURI.spec, |
|
61 "Get correct feedURI"); |
|
62 if (aLivemarkData.siteURI) { |
|
63 is (aLivemark.siteURI.spec, aLivemarkData.siteURI.spec, |
|
64 "Get correct siteURI"); |
|
65 } |
|
66 else { |
|
67 is (aLivemark.siteURI, null, "Get correct siteURI"); |
|
68 } |
|
69 |
|
70 waitForLivemarkLoad(aLivemark, function (aLivemark) { |
|
71 let nodes = aLivemark.getNodesForContainer({}); |
|
72 is(nodes.length, aLivemarkData.urls.length, |
|
73 "Ensure all the livemark items were created."); |
|
74 aLivemarkData.urls.forEach(function (aUrl, aIndex) { |
|
75 let node = nodes[aIndex]; |
|
76 is(node.uri, aUrl, aLivemarkData.message); |
|
77 }); |
|
78 |
|
79 PlacesUtils.bookmarks.removeItem(aLivemark.id); |
|
80 |
|
81 if (aLivemark.feedURI.equals(LIVEMARKS[LIVEMARKS.length - 1].feedURI)) { |
|
82 SimpleTest.finish(); |
|
83 } |
|
84 }); |
|
85 }, function () { |
|
86 is(true, false, "Should not fail adding a livemark"); |
|
87 } |
|
88 ); |
|
89 } |
|
90 |
|
91 LIVEMARKS.forEach(testLivemark); |
|
92 } |
|
93 |
|
94 function waitForLivemarkLoad(aLivemark, aCallback) { |
|
95 // Don't need a real node here. |
|
96 let node = {}; |
|
97 let resultObserver = { |
|
98 nodeInserted: function() {}, |
|
99 nodeRemoved: function() {}, |
|
100 nodeAnnotationChanged: function() {}, |
|
101 nodeTitleChanged: function() {}, |
|
102 nodeHistoryDetailsChanged: function() {}, |
|
103 nodeMoved: function() {}, |
|
104 ontainerStateChanged: function () {}, |
|
105 sortingChanged: function() {}, |
|
106 batching: function() {}, |
|
107 invalidateContainer: function(node) { |
|
108 isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED, |
|
109 "Loading livemark should success"); |
|
110 if (aLivemark.status == Ci.mozILivemark.STATUS_READY) { |
|
111 aLivemark.unregisterForUpdates(node, resultObserver); |
|
112 aCallback(aLivemark); |
|
113 } |
|
114 } |
|
115 }; |
|
116 aLivemark.registerForUpdates(node, resultObserver); |
|
117 aLivemark.reload(); |
|
118 } |
|
119 |
|
120 ]]> |
|
121 </script> |
|
122 </window> |