|
1 XPCOMUtils.defineLazyModuleGetter(this, "Feeds", |
|
2 "resource:///modules/Feeds.jsm"); |
|
3 |
|
4 function test() { |
|
5 var exampleUri = makeURI("http://example.com/"); |
|
6 var secman = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager); |
|
7 var principal = secman.getSimpleCodebasePrincipal(exampleUri); |
|
8 |
|
9 function testIsFeed(aTitle, aHref, aType, aKnown) { |
|
10 var link = { title: aTitle, href: aHref, type: aType }; |
|
11 return Feeds.isValidFeed(link, principal, aKnown); |
|
12 } |
|
13 |
|
14 var href = "http://example.com/feed/"; |
|
15 var atomType = "application/atom+xml"; |
|
16 var funkyAtomType = " aPPLICAtion/Atom+XML "; |
|
17 var rssType = "application/rss+xml"; |
|
18 var funkyRssType = " Application/RSS+XML "; |
|
19 var rdfType = "application/rdf+xml"; |
|
20 var texmlType = "text/xml"; |
|
21 var appxmlType = "application/xml"; |
|
22 var noRss = "Foo"; |
|
23 var rss = "RSS"; |
|
24 |
|
25 // things that should be valid |
|
26 ok(testIsFeed(noRss, href, atomType, false) == atomType, |
|
27 "detect Atom feed"); |
|
28 ok(testIsFeed(noRss, href, funkyAtomType, false) == atomType, |
|
29 "clean up and detect Atom feed"); |
|
30 ok(testIsFeed(noRss, href, rssType, false) == rssType, |
|
31 "detect RSS feed"); |
|
32 ok(testIsFeed(noRss, href, funkyRssType, false) == rssType, |
|
33 "clean up and detect RSS feed"); |
|
34 |
|
35 // things that should not be feeds |
|
36 ok(testIsFeed(noRss, href, rdfType, false) == null, |
|
37 "should not detect RDF non-feed"); |
|
38 ok(testIsFeed(rss, href, rdfType, false) == null, |
|
39 "should not detect RDF feed from type and title"); |
|
40 ok(testIsFeed(noRss, href, texmlType, false) == null, |
|
41 "should not detect text/xml non-feed"); |
|
42 ok(testIsFeed(rss, href, texmlType, false) == null, |
|
43 "should not detect text/xml feed from type and title"); |
|
44 ok(testIsFeed(noRss, href, appxmlType, false) == null, |
|
45 "should not detect application/xml non-feed"); |
|
46 ok(testIsFeed(rss, href, appxmlType, false) == null, |
|
47 "should not detect application/xml feed from type and title"); |
|
48 |
|
49 // security check only, returns cleaned up type or "application/rss+xml" |
|
50 ok(testIsFeed(noRss, href, atomType, true) == atomType, |
|
51 "feed security check should return Atom type"); |
|
52 ok(testIsFeed(noRss, href, funkyAtomType, true) == atomType, |
|
53 "feed security check should return cleaned up Atom type"); |
|
54 ok(testIsFeed(noRss, href, rssType, true) == rssType, |
|
55 "feed security check should return RSS type"); |
|
56 ok(testIsFeed(noRss, href, funkyRssType, true) == rssType, |
|
57 "feed security check should return cleaned up RSS type"); |
|
58 ok(testIsFeed(noRss, href, "", true) == rssType, |
|
59 "feed security check without type should return RSS type"); |
|
60 ok(testIsFeed(noRss, href, "garbage", true) == "garbage", |
|
61 "feed security check with garbage type should return garbage"); |
|
62 } |