michael@0: Components.utils.import("resource://gre/modules/NetUtil.jsm"); michael@0: michael@0: function do_info(text, stack) { michael@0: if (!stack) michael@0: stack = Components.stack.caller; michael@0: michael@0: dump("TEST-INFO | " + stack.filename + " | [" + stack.name + " : " + michael@0: stack.lineNumber + "] " + text + "\n"); michael@0: } michael@0: function run_test() michael@0: { michael@0: var tests = [ michael@0: [ "http://mozilla.org/", "http://mozilla.org/somewhere/there", true ], michael@0: [ "http://mozilla.org/", "http://www.mozilla.org/", false ], michael@0: [ "http://mozilla.org/", "http://mozilla.org:80", true ], michael@0: [ "http://mozilla.org/", "http://mozilla.org:90", false ], michael@0: [ "http://mozilla.org", "https://mozilla.org", false ], michael@0: [ "http://mozilla.org", "https://mozilla.org:80", false ], michael@0: [ "http://mozilla.org:443", "https://mozilla.org", false ], michael@0: [ "https://mozilla.org:443", "https://mozilla.org", true ], michael@0: [ "https://mozilla.org:443", "https://mozilla.org/somewhere/", true ], michael@0: [ "about:", "about:", false ], michael@0: [ "data:text/plain,text", "data:text/plain,text", false ], michael@0: [ "about:blank", "about:blank", false ], michael@0: [ "about:", "http://mozilla.org/", false ], michael@0: [ "about:", "about:config", false ], michael@0: [ "about:text/plain,text", "data:text/plain,text", false ], michael@0: [ "jar:http://mozilla.org/!/", "http://mozilla.org/", true ], michael@0: [ "view-source:http://mozilla.org/", "http://mozilla.org/", true ] michael@0: ]; michael@0: michael@0: var secman = Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService(Components.interfaces.nsIScriptSecurityManager); michael@0: michael@0: tests.forEach(function(aTest) { michael@0: do_info("Comparing " + aTest[0] + " to " + aTest[1]); michael@0: michael@0: var uri1 = NetUtil.newURI(aTest[0]); michael@0: var uri2 = NetUtil.newURI(aTest[1]); michael@0: michael@0: var equal; michael@0: try { michael@0: secman.checkSameOriginURI(uri1, uri2, false); michael@0: equal = true; michael@0: } catch (e) { michael@0: equal = false michael@0: } michael@0: do_check_eq(equal, aTest[2]); michael@0: }); michael@0: }