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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug413915.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +XPCOMUtils.defineLazyModuleGetter(this, "Feeds",
     1.5 +  "resource:///modules/Feeds.jsm");
     1.6 +
     1.7 +function test() {
     1.8 +  var exampleUri = makeURI("http://example.com/");
     1.9 +  var secman = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
    1.10 +  var principal = secman.getSimpleCodebasePrincipal(exampleUri);
    1.11 +
    1.12 +  function testIsFeed(aTitle, aHref, aType, aKnown) {
    1.13 +    var link = { title: aTitle, href: aHref, type: aType };
    1.14 +    return Feeds.isValidFeed(link, principal, aKnown);
    1.15 +  }
    1.16 +
    1.17 +  var href = "http://example.com/feed/";
    1.18 +  var atomType = "application/atom+xml";
    1.19 +  var funkyAtomType = " aPPLICAtion/Atom+XML ";
    1.20 +  var rssType = "application/rss+xml";
    1.21 +  var funkyRssType = " Application/RSS+XML  ";
    1.22 +  var rdfType = "application/rdf+xml";
    1.23 +  var texmlType = "text/xml";
    1.24 +  var appxmlType = "application/xml";
    1.25 +  var noRss = "Foo";
    1.26 +  var rss = "RSS";
    1.27 +
    1.28 +  // things that should be valid
    1.29 +  ok(testIsFeed(noRss, href, atomType, false) == atomType,
    1.30 +     "detect Atom feed");
    1.31 +  ok(testIsFeed(noRss, href, funkyAtomType, false) == atomType,
    1.32 +     "clean up and detect Atom feed");
    1.33 +  ok(testIsFeed(noRss, href, rssType, false) == rssType,
    1.34 +     "detect RSS feed");
    1.35 +  ok(testIsFeed(noRss, href, funkyRssType, false) == rssType,
    1.36 +     "clean up and detect RSS feed");
    1.37 +
    1.38 +  // things that should not be feeds
    1.39 +  ok(testIsFeed(noRss, href, rdfType, false) == null,
    1.40 +     "should not detect RDF non-feed");
    1.41 +  ok(testIsFeed(rss, href, rdfType, false) == null,
    1.42 +     "should not detect RDF feed from type and title");
    1.43 +  ok(testIsFeed(noRss, href, texmlType, false) == null,
    1.44 +     "should not detect text/xml non-feed");
    1.45 +  ok(testIsFeed(rss, href, texmlType, false) == null,
    1.46 +     "should not detect text/xml feed from type and title");
    1.47 +  ok(testIsFeed(noRss, href, appxmlType, false) == null,
    1.48 +     "should not detect application/xml non-feed");
    1.49 +  ok(testIsFeed(rss, href, appxmlType, false) == null,
    1.50 +     "should not detect application/xml feed from type and title");
    1.51 +
    1.52 +  // security check only, returns cleaned up type or "application/rss+xml"
    1.53 +  ok(testIsFeed(noRss, href, atomType, true) == atomType,
    1.54 +     "feed security check should return Atom type");
    1.55 +  ok(testIsFeed(noRss, href, funkyAtomType, true) == atomType,
    1.56 +     "feed security check should return cleaned up Atom type");
    1.57 +  ok(testIsFeed(noRss, href, rssType, true) == rssType,
    1.58 +     "feed security check should return RSS type");
    1.59 +  ok(testIsFeed(noRss, href, funkyRssType, true) == rssType,
    1.60 +     "feed security check should return cleaned up RSS type");
    1.61 +  ok(testIsFeed(noRss, href, "", true) == rssType,
    1.62 +     "feed security check without type should return RSS type");
    1.63 +  ok(testIsFeed(noRss, href, "garbage", true) == "garbage",
    1.64 +     "feed security check with garbage type should return garbage");
    1.65 +}

mercurial