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