browser/base/content/test/general/browser_bug413915.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial