test_compareURIs.js (1742B)
1 "use strict"; 2 3 function do_info(text, stack) { 4 if (!stack) { 5 stack = Components.stack.caller; 6 } 7 8 dump( 9 "TEST-INFO | " + 10 stack.filename + 11 " | [" + 12 stack.name + 13 " : " + 14 stack.lineNumber + 15 "] " + 16 text + 17 "\n" 18 ); 19 } 20 function run_test() { 21 var tests = [ 22 ["http://mozilla.org/", "http://mozilla.org/somewhere/there", true], 23 ["http://mozilla.org/", "http://www.mozilla.org/", false], 24 ["http://mozilla.org/", "http://mozilla.org:80", true], 25 ["http://mozilla.org/", "http://mozilla.org:90", false], 26 ["http://mozilla.org", "https://mozilla.org", false], 27 ["http://mozilla.org", "https://mozilla.org:80", false], 28 ["http://mozilla.org:443", "https://mozilla.org", false], 29 ["https://mozilla.org:443", "https://mozilla.org", true], 30 ["https://mozilla.org:443", "https://mozilla.org/somewhere/", true], 31 ["about:", "about:", false], 32 ["data:text/plain,text", "data:text/plain,text", false], 33 ["about:blank", "about:blank", false], 34 ["about:", "http://mozilla.org/", false], 35 ["about:", "about:config", false], 36 ["about:text/plain,text", "data:text/plain,text", false], 37 ["jar:http://mozilla.org/!/", "http://mozilla.org/", true], 38 ["view-source:http://mozilla.org/", "http://mozilla.org/", true], 39 ]; 40 41 tests.forEach(function (aTest) { 42 do_info("Comparing " + aTest[0] + " to " + aTest[1]); 43 44 var uri1 = NetUtil.newURI(aTest[0]); 45 var uri2 = NetUtil.newURI(aTest[1]); 46 47 var equal; 48 try { 49 Services.scriptSecurityManager.checkSameOriginURI( 50 uri1, 51 uri2, 52 false, 53 false 54 ); 55 equal = true; 56 } catch (e) { 57 equal = false; 58 } 59 Assert.equal(equal, aTest[2]); 60 }); 61 }