1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/feeds/test/test_registerHandler.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=402788 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 402788</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=402788">Mozilla Bug 402788</a> 1.16 +<p id="display"></p> 1.17 +<div id="content" style="display: none"> 1.18 + 1.19 +</div> 1.20 +<pre id="test"> 1.21 +<script class="testbody" type="text/javascript"> 1.22 + 1.23 +/** Test for Bug 402788 **/ 1.24 + 1.25 + // return false if an exception has been catched, true otherwise 1.26 + function testRegisterHandler(aIsProtocol, aTxt, aUri, aTitle) 1.27 + { 1.28 + try { 1.29 + if (aIsProtocol) 1.30 + navigator.registerProtocolHandler(aTxt, aUri, aTitle); 1.31 + else 1.32 + navigator.registerContentHandler(aTxt, aUri, aTitle); 1.33 + } 1.34 + catch(e) { 1.35 + return false; 1.36 + } 1.37 + 1.38 + return true; 1.39 + } 1.40 + 1.41 + ok(navigator.registerProtocolHandler, "navigator.registerProtocolHandler should be defined"); 1.42 + ok(navigator.registerContentHandler, "navigator.registerContentHandler should be defined"); 1.43 + 1.44 + // testing a generic case 1.45 + is(true, testRegisterHandler(true, "foo", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler should work"); 1.46 + is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler should work"); 1.47 + 1.48 + // testing with wrong uris 1.49 + is(false, testRegisterHandler(true, "foo", "http://mochi.test:8888/", "Foo handler"), "a protocol handler uri should contain %s"); 1.50 + is(false, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/", "Foo handler"), "a content handler uri should contain %s"); 1.51 + 1.52 + // the spec explicitly allows relative urls to be passed 1.53 + is(true, testRegisterHandler(true, "foo", "foo/%s", "Foo handler"), "a protocol handler uri should be valid"); 1.54 + is(true, testRegisterHandler(false, "application/rss+xml", "foo/%s", "Foo handler"), "a content handler uri should be valid"); 1.55 + 1.56 + // we should only accept to register when the handler has the same host as the current page (bug 402287) 1.57 + is(false, testRegisterHandler(true, "foo", "http://remotehost:8888/%s", "Foo handler"), "registering a foo protocol handler with a different host should not work"); 1.58 + is(false, testRegisterHandler(false, "application/rss+xml", "http://remotehost:8888/%s", "Foo handler"), "registering a foo content handler with a different host should not work"); 1.59 + 1.60 + // restriction to http(s) for the uri of the handler (bug 401343) 1.61 + // https should work (http already tested in the generic case) 1.62 + is(true, testRegisterHandler(true, "foo", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with https scheme should work"); 1.63 + is(true, testRegisterHandler(false, "application/rss+xml", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with https scheme should work"); 1.64 + // ftp should not work 1.65 + is(false, testRegisterHandler(true, "foo", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with ftp scheme should not work"); 1.66 + is(false, testRegisterHandler(false, "application/rss+xml", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with ftp scheme should not work"); 1.67 + // chrome should not work 1.68 + is(false, testRegisterHandler(true, "foo", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with chrome scheme should not work"); 1.69 + is(false, testRegisterHandler(false, "application/rss+xml", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with chrome scheme should not work"); 1.70 + // foo should not work 1.71 + is(false, testRegisterHandler(true, "foo", "foo://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with foo scheme should not work"); 1.72 + is(false, testRegisterHandler(false, "application/rss+xml", "foo://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with foo scheme should not work"); 1.73 + 1.74 + // for security reasons, protocol handlers should never be registered for some schemes (chrome, vbscript, ...) (bug 402788) 1.75 + is(false, testRegisterHandler(true, "chrome", "http://mochi.test:8888/%s", "chrome handler"), "registering a chrome protocol handler should not work"); 1.76 + is(false, testRegisterHandler(true, "vbscript", "http://mochi.test:8888/%s", "vbscript handler"), "registering a vbscript protocol handler should not work"); 1.77 + is(false, testRegisterHandler(true, "javascript", "http://mochi.test:8888/%s", "javascript handler"), "registering a javascript protocol handler should not work"); 1.78 + is(false, testRegisterHandler(true, "moz-icon", "http://mochi.test:8888/%s", "moz-icon handler"), "registering a moz-icon protocol handler should not work"); 1.79 + 1.80 + // for security reasons, content handlers should never be registered for some types (html, ...) 1.81 + is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering rss content handlers should work"); 1.82 + is(true, testRegisterHandler(false, "application/atom+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering atom content handlers should work"); 1.83 + todo(false, testRegisterHandler(false, "text/html", "http://mochi.test:8888/%s", "Foo handler"), "registering html content handlers should not work"); // bug 403798 1.84 + 1.85 +</script> 1.86 +</pre> 1.87 +</body> 1.88 +</html>