Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
7 const Cu = Components.utils;
9 Cu.import('resource://gre/modules/CSPUtils.jsm');
11 var ioService = Cc["@mozilla.org/network/io-service;1"]
12 .getService(Ci.nsIIOService);
13 var self = ioService.newURI("http://test1.example.com:80", null, null);
15 function testValidSRCsHostSourceWithSchemeAndPath() {
16 var csps = [
17 "http://test1.example.com",
18 "http://test1.example.com/",
19 "http://test1.example.com/path-1",
20 "http://test1.example.com/path-1/",
21 "http://test1.example.com/path-1/path_2/",
22 "http://test1.example.com/path-1/path_2/file.js",
23 "http://test1.example.com/path-1/path_2/file_1.js",
24 "http://test1.example.com/path-1/path_2/file-2.js",
25 "http://test1.example.com/path-1/path_2/f.js",
26 "http://test1.example.com/path-1/path_2/f.oo.js"
27 ]
29 var obj;
30 var expected = "http://test1.example.com:80";
31 for (let i in csps) {
32 var src = csps[i];
33 obj = CSPSourceList.fromString(src, undefined, self);
34 dump("expected: " + expected + "\n");
35 dump("got: " + obj._sources[0] + "\n");
36 do_check_eq(1, obj._sources.length);
37 do_check_eq(obj._sources[0], expected);
38 }
39 }
41 function testValidSRCsRegularHost() {
42 var csps = [
43 "test1.example.com",
44 "test1.example.com/",
45 "test1.example.com/path-1",
46 "test1.example.com/path-1/",
47 "test1.example.com/path-1/path_2/",
48 "test1.example.com/path-1/path_2/file.js",
49 "test1.example.com/path-1/path_2/file_1.js",
50 "test1.example.com/path-1/path_2/file-2.js",
51 "test1.example.com/path-1/path_2/f.js",
52 "test1.example.com/path-1/path_2/f.oo.js"
53 ]
55 var obj;
56 var expected = "http://test1.example.com:80";
57 for (let i in csps) {
58 var src = csps[i];
59 obj = CSPSourceList.fromString(src, undefined, self);
60 do_check_eq(1, obj._sources.length);
61 do_check_eq(obj._sources[0], expected);
62 }
63 }
65 function testValidSRCsWildCardHost() {
66 var csps = [
67 "*.example.com",
68 "*.example.com/",
69 "*.example.com/path-1",
70 "*.example.com/path-1/",
71 "*.example.com/path-1/path_2/",
72 "*.example.com/path-1/path_2/file.js",
73 "*.example.com/path-1/path_2/file_1.js",
74 "*.example.com/path-1/path_2/file-2.js",
75 "*.example.com/path-1/path_2/f.js",
76 "*.example.com/path-1/path_2/f.oo.js"
77 ]
79 var obj;
80 var expected = "http://*.example.com:80";
81 for (let i in csps) {
82 var src = csps[i];
83 obj = CSPSourceList.fromString(src, undefined, self);
84 do_check_eq(1, obj._sources.length);
85 do_check_eq(obj._sources[0], expected);
86 }
87 }
89 function testValidSRCsRegularPort() {
90 var csps = [
91 "test1.example.com:80",
92 "test1.example.com:80/",
93 "test1.example.com:80/path-1",
94 "test1.example.com:80/path-1/",
95 "test1.example.com:80/path-1/path_2",
96 "test1.example.com:80/path-1/path_2/",
97 "test1.example.com:80/path-1/path_2/file.js",
98 "test1.example.com:80/path-1/path_2/f.ile.js"
99 ]
101 var obj;
102 var expected = "http://test1.example.com:80";
103 for (let i in csps) {
104 var src = csps[i];
105 obj = CSPSourceList.fromString(src, undefined, self);
106 do_check_eq(1, obj._sources.length);
107 do_check_eq(obj._sources[0], expected);
108 }
109 }
111 function testValidSRCsWildCardPort() {
112 var csps = [
113 "test1.example.com:*",
114 "test1.example.com:*/",
115 "test1.example.com:*/path-1",
116 "test1.example.com:*/path-1/",
117 "test1.example.com:*/path-1/path_2",
118 "test1.example.com:*/path-1/path_2/",
119 "test1.example.com:*/path-1/path_2/file.js",
120 "test1.example.com:*/path-1/path_2/f.ile.js"
121 ]
123 var obj;
124 var expected = "http://test1.example.com:*";
125 for (let i in csps) {
126 var src = csps[i];
127 obj = CSPSourceList.fromString(src, undefined, self);
128 do_check_eq(1, obj._sources.length);
129 do_check_eq(obj._sources[0], expected);
130 }
131 }
134 function testInvalidSRCs() {
135 var csps = [
136 "test1.example.com:88path-1/",
137 "test1.example.com:80.js",
138 "test1.example.com:*.js",
139 "test1.example.com:*."
140 ]
142 var obj;
143 var expected = [];
144 for (let i in csps) {
145 var src = csps[i];
146 obj = CSPSourceList.fromString(src, undefined, self);
147 do_check_eq(0, obj._sources.length);
148 }
149 }
151 function run_test() {
152 testValidSRCsHostSourceWithSchemeAndPath();
153 testValidSRCsRegularHost();
154 testValidSRCsWildCardHost();
155 testValidSRCsRegularPort();
156 testValidSRCsWildCardPort();
157 testInvalidSRCs();
158 do_test_finished();
159 }