|
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 /* |
|
17 Test loading feeds with items that aren't allowed |
|
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/bad_links.atom"; |
|
31 const GOOD_URLS = ["http://example.org/first", "http://example.org/last"]; |
|
32 |
|
33 PlacesUtils.livemarks.addLivemark( |
|
34 { title: "foo" |
|
35 , parentId: PlacesUtils.toolbarFolderId |
|
36 , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
|
37 , feedURI: NetUtil.newURI(FEEDSPEC) |
|
38 , siteURI: NetUtil.newURI("http:/mochi.test/") |
|
39 }) |
|
40 .then(function (aLivemark) { |
|
41 waitForLivemarkLoad(aLivemark, function (aLivemark) { |
|
42 let nodes = aLivemark.getNodesForContainer({}); |
|
43 |
|
44 is(nodes.length, 2, "Created the two good livemark items"); |
|
45 for (let i = 0; i < nodes.length; ++i) { |
|
46 let node = nodes[i]; |
|
47 ok(GOOD_URLS.indexOf(node.uri) != -1, "livemark item created with bad uri " + node.uri); |
|
48 } |
|
49 |
|
50 PlacesUtils.bookmarks.removeItem(aLivemark.id); |
|
51 SimpleTest.finish(); |
|
52 }); |
|
53 }, function () { |
|
54 is(true, false, "Should not fail adding a livemark"); |
|
55 } |
|
56 ); |
|
57 } |
|
58 |
|
59 function waitForLivemarkLoad(aLivemark, aCallback) { |
|
60 // Don't need a real node here. |
|
61 let node = {}; |
|
62 let resultObserver = { |
|
63 nodeInserted: function() {}, |
|
64 nodeRemoved: function() {}, |
|
65 nodeAnnotationChanged: function() {}, |
|
66 nodeTitleChanged: function() {}, |
|
67 nodeHistoryDetailsChanged: function() {}, |
|
68 nodeMoved: function() {}, |
|
69 ontainerStateChanged: function () {}, |
|
70 sortingChanged: function() {}, |
|
71 batching: function() {}, |
|
72 invalidateContainer: function(node) { |
|
73 isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED, |
|
74 "Loading livemark should success"); |
|
75 if (aLivemark.status == Ci.mozILivemark.STATUS_READY) { |
|
76 aLivemark.unregisterForUpdates(node, resultObserver); |
|
77 aCallback(aLivemark); |
|
78 } |
|
79 } |
|
80 }; |
|
81 aLivemark.registerForUpdates(node, resultObserver); |
|
82 aLivemark.reload(); |
|
83 } |
|
84 |
|
85 ]]> |
|
86 </script> |
|
87 |
|
88 </window> |