Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=402788 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 402788</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=402788">Mozilla Bug 402788</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript"> |
michael@0 | 19 | |
michael@0 | 20 | /** Test for Bug 402788 **/ |
michael@0 | 21 | |
michael@0 | 22 | // return false if an exception has been catched, true otherwise |
michael@0 | 23 | function testRegisterHandler(aIsProtocol, aTxt, aUri, aTitle) |
michael@0 | 24 | { |
michael@0 | 25 | try { |
michael@0 | 26 | if (aIsProtocol) |
michael@0 | 27 | navigator.registerProtocolHandler(aTxt, aUri, aTitle); |
michael@0 | 28 | else |
michael@0 | 29 | navigator.registerContentHandler(aTxt, aUri, aTitle); |
michael@0 | 30 | } |
michael@0 | 31 | catch(e) { |
michael@0 | 32 | return false; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | return true; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | ok(navigator.registerProtocolHandler, "navigator.registerProtocolHandler should be defined"); |
michael@0 | 39 | ok(navigator.registerContentHandler, "navigator.registerContentHandler should be defined"); |
michael@0 | 40 | |
michael@0 | 41 | // testing a generic case |
michael@0 | 42 | is(true, testRegisterHandler(true, "foo", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler should work"); |
michael@0 | 43 | is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler should work"); |
michael@0 | 44 | |
michael@0 | 45 | // testing with wrong uris |
michael@0 | 46 | is(false, testRegisterHandler(true, "foo", "http://mochi.test:8888/", "Foo handler"), "a protocol handler uri should contain %s"); |
michael@0 | 47 | is(false, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/", "Foo handler"), "a content handler uri should contain %s"); |
michael@0 | 48 | |
michael@0 | 49 | // the spec explicitly allows relative urls to be passed |
michael@0 | 50 | is(true, testRegisterHandler(true, "foo", "foo/%s", "Foo handler"), "a protocol handler uri should be valid"); |
michael@0 | 51 | is(true, testRegisterHandler(false, "application/rss+xml", "foo/%s", "Foo handler"), "a content handler uri should be valid"); |
michael@0 | 52 | |
michael@0 | 53 | // we should only accept to register when the handler has the same host as the current page (bug 402287) |
michael@0 | 54 | is(false, testRegisterHandler(true, "foo", "http://remotehost:8888/%s", "Foo handler"), "registering a foo protocol handler with a different host should not work"); |
michael@0 | 55 | 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"); |
michael@0 | 56 | |
michael@0 | 57 | // restriction to http(s) for the uri of the handler (bug 401343) |
michael@0 | 58 | // https should work (http already tested in the generic case) |
michael@0 | 59 | is(true, testRegisterHandler(true, "foo", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with https scheme should work"); |
michael@0 | 60 | is(true, testRegisterHandler(false, "application/rss+xml", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with https scheme should work"); |
michael@0 | 61 | // ftp should not work |
michael@0 | 62 | is(false, testRegisterHandler(true, "foo", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with ftp scheme should not work"); |
michael@0 | 63 | 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"); |
michael@0 | 64 | // chrome should not work |
michael@0 | 65 | is(false, testRegisterHandler(true, "foo", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with chrome scheme should not work"); |
michael@0 | 66 | 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"); |
michael@0 | 67 | // foo should not work |
michael@0 | 68 | is(false, testRegisterHandler(true, "foo", "foo://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with foo scheme should not work"); |
michael@0 | 69 | 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"); |
michael@0 | 70 | |
michael@0 | 71 | // for security reasons, protocol handlers should never be registered for some schemes (chrome, vbscript, ...) (bug 402788) |
michael@0 | 72 | is(false, testRegisterHandler(true, "chrome", "http://mochi.test:8888/%s", "chrome handler"), "registering a chrome protocol handler should not work"); |
michael@0 | 73 | is(false, testRegisterHandler(true, "vbscript", "http://mochi.test:8888/%s", "vbscript handler"), "registering a vbscript protocol handler should not work"); |
michael@0 | 74 | is(false, testRegisterHandler(true, "javascript", "http://mochi.test:8888/%s", "javascript handler"), "registering a javascript protocol handler should not work"); |
michael@0 | 75 | is(false, testRegisterHandler(true, "moz-icon", "http://mochi.test:8888/%s", "moz-icon handler"), "registering a moz-icon protocol handler should not work"); |
michael@0 | 76 | |
michael@0 | 77 | // for security reasons, content handlers should never be registered for some types (html, ...) |
michael@0 | 78 | is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering rss content handlers should work"); |
michael@0 | 79 | is(true, testRegisterHandler(false, "application/atom+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering atom content handlers should work"); |
michael@0 | 80 | todo(false, testRegisterHandler(false, "text/html", "http://mochi.test:8888/%s", "Foo handler"), "registering html content handlers should not work"); // bug 403798 |
michael@0 | 81 | |
michael@0 | 82 | </script> |
michael@0 | 83 | </pre> |
michael@0 | 84 | </body> |
michael@0 | 85 | </html> |