netwerk/test/unit/test_compareURIs.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 Components.utils.import("resource://gre/modules/NetUtil.jsm");
michael@0 2
michael@0 3 function do_info(text, stack) {
michael@0 4 if (!stack)
michael@0 5 stack = Components.stack.caller;
michael@0 6
michael@0 7 dump("TEST-INFO | " + stack.filename + " | [" + stack.name + " : " +
michael@0 8 stack.lineNumber + "] " + text + "\n");
michael@0 9 }
michael@0 10 function run_test()
michael@0 11 {
michael@0 12 var tests = [
michael@0 13 [ "http://mozilla.org/", "http://mozilla.org/somewhere/there", true ],
michael@0 14 [ "http://mozilla.org/", "http://www.mozilla.org/", false ],
michael@0 15 [ "http://mozilla.org/", "http://mozilla.org:80", true ],
michael@0 16 [ "http://mozilla.org/", "http://mozilla.org:90", false ],
michael@0 17 [ "http://mozilla.org", "https://mozilla.org", false ],
michael@0 18 [ "http://mozilla.org", "https://mozilla.org:80", false ],
michael@0 19 [ "http://mozilla.org:443", "https://mozilla.org", false ],
michael@0 20 [ "https://mozilla.org:443", "https://mozilla.org", true ],
michael@0 21 [ "https://mozilla.org:443", "https://mozilla.org/somewhere/", true ],
michael@0 22 [ "about:", "about:", false ],
michael@0 23 [ "data:text/plain,text", "data:text/plain,text", false ],
michael@0 24 [ "about:blank", "about:blank", false ],
michael@0 25 [ "about:", "http://mozilla.org/", false ],
michael@0 26 [ "about:", "about:config", false ],
michael@0 27 [ "about:text/plain,text", "data:text/plain,text", false ],
michael@0 28 [ "jar:http://mozilla.org/!/", "http://mozilla.org/", true ],
michael@0 29 [ "view-source:http://mozilla.org/", "http://mozilla.org/", true ]
michael@0 30 ];
michael@0 31
michael@0 32 var secman = Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService(Components.interfaces.nsIScriptSecurityManager);
michael@0 33
michael@0 34 tests.forEach(function(aTest) {
michael@0 35 do_info("Comparing " + aTest[0] + " to " + aTest[1]);
michael@0 36
michael@0 37 var uri1 = NetUtil.newURI(aTest[0]);
michael@0 38 var uri2 = NetUtil.newURI(aTest[1]);
michael@0 39
michael@0 40 var equal;
michael@0 41 try {
michael@0 42 secman.checkSameOriginURI(uri1, uri2, false);
michael@0 43 equal = true;
michael@0 44 } catch (e) {
michael@0 45 equal = false
michael@0 46 }
michael@0 47 do_check_eq(equal, aTest[2]);
michael@0 48 });
michael@0 49 }

mercurial