Commit d92361a7 authored by philringnalda@gmail.com's avatar philringnalda@gmail.com
Browse files

Bug 377611 - Feed autodiscovery shouldn't treat rel as case-sensitive, patch...

Bug 377611 - Feed autodiscovery shouldn't treat rel as case-sensitive, patch by Ehsan Akhgari <ehsan.akhgari@gmail.com> because I was too slow, r=mano+sayrer
parent e8e5a386
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@ include $(DEPTH)/config/autoconf.mk

include $(topsrcdir)/config/config.mk

ifdef MOZ_MOCHITEST
DIRS += content/test
endif

include $(topsrcdir)/config/rules.mk

DEFINES += -DMOZ_APP_VERSION=$(MOZ_APP_VERSION)
+51 −0
Original line number Diff line number Diff line
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

DEPTH		= ../../../..
topsrcdir	= @top_srcdir@
srcdir		= @srcdir@
VPATH		= @srcdir@
relativesrcdir  = browser/base/content/test

include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk

_TEST_FILES = 	test_feed_discovery.html \
	   feed_discovery.html \
    $(NULL)

libs:: $(_TEST_FILES)
	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+113 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=377611
-->
  <head>
    <title>Test for feed discovery</title>

    <!-- Straight up standard -->
    <link rel="alternate" type="application/atom+xml" title="1" href="/1.atom" />
    <link rel="alternate" type="application/rss+xml" title="2" href="/2.rss" />
    <link rel="feed" title="3" href="/3.xml" />

    <!-- rel is a space-separated list -->
    <link rel=" alternate " type="application/atom+xml" title="4" href="/4.atom" />
    <link rel="foo alternate" type="application/atom+xml" title="5" href="/5.atom" />
    <link rel="alternate foo" type="application/atom+xml" title="6" href="/6.atom" />
    <link rel="foo alternate foo" type="application/atom+xml" title="7" href="/7.atom" />
    <link rel="meat feed cake" title="8" href="/8.atom" />

    <!-- rel is case-insensitive -->
    <link rel="ALTERNate" type="application/atom+xml" title="9" href="/9.atom" />
    <link rel="fEEd" title="10" href="/10.atom" />

    <!-- type can have leading and trailing whitespace -->
    <link rel="alternate" type="  application/atom+xml  " title="11" href="/11.atom" />

    <!-- type is case-insensitive -->
    <link rel="alternate" type="aPPliCAtion/ATom+xML" title="12" href="/12.atom" />

    <!-- tolerate application/rdf+xml if the title includes 'rss' -->
    <link rel="alternate" type="application/rdf+xml" title="13 rss" href="/13.rdf" />

    <!-- tolerate application/xml if the title includes 'rss' -->
    <link rel="alternate" type="application/xml" title="14 rss" href="/14.xml" />

    <!-- tolerate text/xml if the title includes 'rss' -->
    <link rel="alternate" type="text/xml" title="15 rss" href="/15.xml" />

    <!-- "feed stylesheet" is a feed, though "alternate stylesheet" isn't -->
    <link rel="feed stylesheet" title="16" href="/16.atom" />

    <!-- hyphens or letters around rel not allowed -->
    <link rel="disabled-alternate" type="application/atom+xml" title="Bogus1" href="/Bogus1" />
    <link rel="alternates" type="application/atom+xml" title="Bogus2" href="/Bogus2" />
    <link rel=" alternate-like" type="application/atom+xml" title="Bogus3" href="/Bogus3" />

    <!-- don't tolerate text/xml if title includes 'rss' not as a word -->
    <link rel="alternate" type="text/xml" title="Bogus4 scissorsshaped" href="/Bogus4" />

    <!-- don't tolerate application/xml if title includes 'rss' not as a word -->
    <link rel="alternate" type="application/xml" title="Bogus5 scissorsshaped" href="/Bogus5" />

    <!-- don't tolerate application/rdf+xml if title includes 'rss' not as a word -->
    <link rel="alternate" type="application/rdf+xml" title="Bogus6 scissorsshaped" href="/Bogus6" />

    <!-- don't tolerate random types -->
    <link rel="alternate" type="text/plain" title="Bogus7 rss" href="/Bogus7" />

    <!-- don't find Atom by title -->
    <link rel="foopy" type="application/atom+xml" title="Bogus8 Atom and RSS" href="/Bogus8" />

    <!-- don't find application/rss+xml by title -->
    <link rel="goats" type="application/rss+xml" title="Bogus9 RSS and Atom" href="/Bogus9" />

    <!-- alternate and stylesheet isn't a feed -->
    <link rel="alternate stylesheet" type="application/rss+xml" title="Bogus10 RSS" href="/Bogus10" />
  </head>
  <body>
    <script type="text/javascript">
      window.onload = function() {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

        var tests = new Array();

        var currentWindow =
        window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                              .getInterface(Components.interfaces.nsIWebNavigation)
                              .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                              .rootTreeItem
                              .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                              .getInterface(Components.interfaces.nsIDOMWindow);
        var browser = currentWindow.gBrowser.selectedBrowser;

        var discovered = browser.feeds;
        tests.push({ check: discovered.length > 0,
                     message: "some feeds should be discovered" });

        var feeds = [];

        for each (var aFeed in discovered) {
          feeds[aFeed.href] = true;
        }

        for each (var aLink in document.getElementsByTagName("link")) {
          // ignore real stylesheets, and anything without an href property
          if (aLink.type != "text/css" && aLink.href) {
            if (/bogus/i.test(aLink.title)) {
              tests.push({ check: !feeds[aLink.href],
                           message: "don't discover " + aLink.href });
            } else {
              tests.push({ check: feeds[aLink.href],
                           message: "should discover " + aLink.href });
            }
          }
        }
        window.arguments[0].tests = tests;
        window.close();
      }
    </script>
  </body>
</html>
+57 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=377611
-->
<head>
  <title>Test for feed discovery</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=377611">Mozilla Bug 377611</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 377611 **/

var rv = { tests: null };
var testCheckInterval = null;

function startTest() {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

  var url = window.location.href.replace(/test_feed_discovery\.html/,
                                         'feed_discovery.html');
  window.openDialog(url, '', 'dialog=no,width=10,height=10', rv);
  testCheckInterval = window.setInterval(tryIfTestIsFinished, 500);
}

function tryIfTestIsFinished() {
  if (rv.tests) {
    window.clearInterval(testCheckInterval);
    checkTest();
  }
}

function checkTest() {
  for (var i = 0; i < rv.tests.length; ++ i) {
    var test = rv.tests[i];
    ok(test.check, test.message);
  }
  SimpleTest.finish();
}

window.onload = startTest;

SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>
+2 −3
Original line number Diff line number Diff line
@@ -597,8 +597,8 @@ function recognizeFeedFromLink(aLink, aPrincipal)
  if (!aLink || !aPrincipal)
    return null;

  var erel = aLink.rel;
  var etype = aLink.type;
  var erel = aLink.rel && aLink.rel.toLowerCase();
  var etype = aLink.type && aLink.type.toLowerCase();
  var etitle = aLink.title;
  const rssTitleRegex = /(^|\s)rss($|\s)/i;
  var rels = {};
@@ -617,7 +617,6 @@ function recognizeFeedFromLink(aLink, aPrincipal)
    etype = etype.replace(/^\s+/, "");
    etype = etype.replace(/\s+$/, "");
    etype = etype.replace(/\s*;.*/, "");
    etype = etype.toLowerCase();
    isFeed = (etype == "application/rss+xml" ||
              etype == "application/atom+xml");
    if (!isFeed) {