netwerk/test/unit/test_compareURIs.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_compareURIs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +Components.utils.import("resource://gre/modules/NetUtil.jsm");
     1.5 +
     1.6 +function do_info(text, stack) {
     1.7 +  if (!stack)
     1.8 +    stack = Components.stack.caller;
     1.9 +
    1.10 +  dump("TEST-INFO | " + stack.filename + " | [" + stack.name + " : " +
    1.11 +       stack.lineNumber + "] " + text + "\n");
    1.12 +}
    1.13 +function run_test()
    1.14 +{
    1.15 +    var tests = [
    1.16 +	[ "http://mozilla.org/", "http://mozilla.org/somewhere/there", true ],
    1.17 +	[ "http://mozilla.org/", "http://www.mozilla.org/", false ],
    1.18 +	[ "http://mozilla.org/", "http://mozilla.org:80", true ],
    1.19 +	[ "http://mozilla.org/", "http://mozilla.org:90", false ],
    1.20 +	[ "http://mozilla.org", "https://mozilla.org", false ],
    1.21 +	[ "http://mozilla.org", "https://mozilla.org:80", false ],	
    1.22 +	[ "http://mozilla.org:443", "https://mozilla.org", false ],
    1.23 +	[ "https://mozilla.org:443", "https://mozilla.org", true ],
    1.24 +	[ "https://mozilla.org:443", "https://mozilla.org/somewhere/", true ],
    1.25 +	[ "about:", "about:", false ],
    1.26 +	[ "data:text/plain,text", "data:text/plain,text", false ],
    1.27 +	[ "about:blank", "about:blank", false ],
    1.28 +	[ "about:", "http://mozilla.org/", false ],
    1.29 +	[ "about:", "about:config", false ],
    1.30 +	[ "about:text/plain,text", "data:text/plain,text", false ],
    1.31 +	[ "jar:http://mozilla.org/!/", "http://mozilla.org/", true ],
    1.32 +	[ "view-source:http://mozilla.org/", "http://mozilla.org/", true ]
    1.33 +    ];
    1.34 +
    1.35 +    var secman = Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService(Components.interfaces.nsIScriptSecurityManager);
    1.36 +
    1.37 +    tests.forEach(function(aTest) {
    1.38 +        do_info("Comparing " + aTest[0] + " to " + aTest[1]);
    1.39 +
    1.40 +	var uri1 = NetUtil.newURI(aTest[0]);
    1.41 +	var uri2 = NetUtil.newURI(aTest[1]);
    1.42 +
    1.43 +	var equal;
    1.44 +	try {
    1.45 +	    secman.checkSameOriginURI(uri1, uri2, false);
    1.46 +	    equal = true;
    1.47 +	} catch (e) {
    1.48 +	    equal = false
    1.49 +	}
    1.50 +	do_check_eq(equal, aTest[2]);
    1.51 +    });
    1.52 +}

mercurial