michael@0: XPCOMUtils.defineLazyModuleGetter(this, "Feeds", michael@0: "resource:///modules/Feeds.jsm"); michael@0: michael@0: function test() { michael@0: var exampleUri = makeURI("http://example.com/"); michael@0: var secman = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager); michael@0: var principal = secman.getSimpleCodebasePrincipal(exampleUri); michael@0: michael@0: function testIsFeed(aTitle, aHref, aType, aKnown) { michael@0: var link = { title: aTitle, href: aHref, type: aType }; michael@0: return Feeds.isValidFeed(link, principal, aKnown); michael@0: } michael@0: michael@0: var href = "http://example.com/feed/"; michael@0: var atomType = "application/atom+xml"; michael@0: var funkyAtomType = " aPPLICAtion/Atom+XML "; michael@0: var rssType = "application/rss+xml"; michael@0: var funkyRssType = " Application/RSS+XML "; michael@0: var rdfType = "application/rdf+xml"; michael@0: var texmlType = "text/xml"; michael@0: var appxmlType = "application/xml"; michael@0: var noRss = "Foo"; michael@0: var rss = "RSS"; michael@0: michael@0: // things that should be valid michael@0: ok(testIsFeed(noRss, href, atomType, false) == atomType, michael@0: "detect Atom feed"); michael@0: ok(testIsFeed(noRss, href, funkyAtomType, false) == atomType, michael@0: "clean up and detect Atom feed"); michael@0: ok(testIsFeed(noRss, href, rssType, false) == rssType, michael@0: "detect RSS feed"); michael@0: ok(testIsFeed(noRss, href, funkyRssType, false) == rssType, michael@0: "clean up and detect RSS feed"); michael@0: michael@0: // things that should not be feeds michael@0: ok(testIsFeed(noRss, href, rdfType, false) == null, michael@0: "should not detect RDF non-feed"); michael@0: ok(testIsFeed(rss, href, rdfType, false) == null, michael@0: "should not detect RDF feed from type and title"); michael@0: ok(testIsFeed(noRss, href, texmlType, false) == null, michael@0: "should not detect text/xml non-feed"); michael@0: ok(testIsFeed(rss, href, texmlType, false) == null, michael@0: "should not detect text/xml feed from type and title"); michael@0: ok(testIsFeed(noRss, href, appxmlType, false) == null, michael@0: "should not detect application/xml non-feed"); michael@0: ok(testIsFeed(rss, href, appxmlType, false) == null, michael@0: "should not detect application/xml feed from type and title"); michael@0: michael@0: // security check only, returns cleaned up type or "application/rss+xml" michael@0: ok(testIsFeed(noRss, href, atomType, true) == atomType, michael@0: "feed security check should return Atom type"); michael@0: ok(testIsFeed(noRss, href, funkyAtomType, true) == atomType, michael@0: "feed security check should return cleaned up Atom type"); michael@0: ok(testIsFeed(noRss, href, rssType, true) == rssType, michael@0: "feed security check should return RSS type"); michael@0: ok(testIsFeed(noRss, href, funkyRssType, true) == rssType, michael@0: "feed security check should return cleaned up RSS type"); michael@0: ok(testIsFeed(noRss, href, "", true) == rssType, michael@0: "feed security check without type should return RSS type"); michael@0: ok(testIsFeed(noRss, href, "garbage", true) == "garbage", michael@0: "feed security check with garbage type should return garbage"); michael@0: }