test_byte_range.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* ***** BEGIN LICENSE BLOCK *****
4  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is httpd.js code.
17  *
18  * The Initial Developer of the Original Code is
19  * Chris Double <chris.double@double.co.nz>.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */
36 
37 // checks if a byte range request and non-byte range request retrieve the
38 // correct data.
39 
40 const PREFIX = "http://localhost:4444";
41 
42 var tests =
43  [
44  new Test(PREFIX + "/range.txt",
46  new Test(PREFIX + "/range.txt",
48  new Test(PREFIX + "/range.txt",
50  new Test(PREFIX + "/range.txt",
52  new Test(PREFIX + "/range.txt",
54  new Test(PREFIX + "/range.txt",
56  new Test(PREFIX + "/range.txt",
58  new Test(PREFIX + "/range.txt",
60  new Test(PREFIX + "/range.txt",
62  new Test(PREFIX + "/range.txt",
64  new Test(PREFIX + "/range.txt",
66  new Test(PREFIX + "/empty.txt",
68  new Test(PREFIX + "/range.txt",
70  ];
71 
72 function run_test()
73 {
74  var srv = createServer();
75  var dir = do_get_file("data/ranges/");
76  srv.registerDirectory("/", dir);
77 
78  srv.start(4444);
79 
81 }
82 
83 function start_normal(ch, cx)
84 {
85  do_check_eq(ch.responseStatus, 200);
86  do_check_eq(ch.getResponseHeader("Content-Length"), "21");
87  do_check_eq(ch.getResponseHeader("Content-Type"), "text/plain");
88 }
89 
90 function stop_normal(ch, cx, status, data)
91 {
92  do_check_eq(data.length, 21);
93  do_check_eq(data[0], 0x54);
94  do_check_eq(data[20], 0x0a);
95 }
96 
97 function init_byterange(ch)
98 {
99  ch.setRequestHeader("Range", "bytes=10-", false);
100 }
101 
102 function start_byterange(ch, cx)
103 {
104  do_check_eq(ch.responseStatus, 206);
105  do_check_eq(ch.getResponseHeader("Content-Length"), "11");
106  do_check_eq(ch.getResponseHeader("Content-Type"), "text/plain");
107  do_check_eq(ch.getResponseHeader("Content-Range"), "bytes 10-20/21");
108 }
109 
110 function stop_byterange(ch, cx, status, data)
111 {
112  do_check_eq(data.length, 11);
113  do_check_eq(data[0], 0x64);
114  do_check_eq(data[10], 0x0a);
115 }
116 
117 function init_byterange2(ch)
118 {
119  ch.setRequestHeader("Range", "bytes=21-", false);
120 }
121 
122 function start_byterange2(ch, cx)
123 {
124  do_check_eq(ch.responseStatus, 416);
125 }
126 
127 function init_byterange3(ch)
128 {
129  ch.setRequestHeader("Range", "bytes=10-15", false);
130 }
131 
132 function start_byterange3(ch, cx)
133 {
134  do_check_eq(ch.responseStatus, 206);
135  do_check_eq(ch.getResponseHeader("Content-Length"), "6");
136  do_check_eq(ch.getResponseHeader("Content-Type"), "text/plain");
137  do_check_eq(ch.getResponseHeader("Content-Range"), "bytes 10-15/21");
138 }
139 
140 function stop_byterange3(ch, cx, status, data)
141 {
142  do_check_eq(data.length, 6);
143  do_check_eq(data[0], 0x64);
144  do_check_eq(data[1], 0x20);
145  do_check_eq(data[2], 0x62);
146  do_check_eq(data[3], 0x65);
147  do_check_eq(data[4], 0x20);
148  do_check_eq(data[5], 0x73);
149 }
150 
151 function init_byterange4(ch)
152 {
153  ch.setRequestHeader("Range", "xbytes=21-", false);
154 }
155 
156 function start_byterange4(ch, cx)
157 {
158  do_check_eq(ch.responseStatus, 400);
159 }
160 
161 function init_byterange5(ch)
162 {
163  ch.setRequestHeader("Range", "bytes=-5", false);
164 }
165 
166 function start_byterange5(ch, cx)
167 {
168  do_check_eq(ch.responseStatus, 206);
169 }
170 
171 function stop_byterange5(ch, cx, status, data)
172 {
173  do_check_eq(data.length, 5);
174  do_check_eq(data[0], 0x65);
175  do_check_eq(data[1], 0x65);
176  do_check_eq(data[2], 0x6e);
177  do_check_eq(data[3], 0x2e);
178  do_check_eq(data[4], 0x0a);
179 }
180 
181 function init_byterange6(ch)
182 {
183  ch.setRequestHeader("Range", "bytes=15-12", false);
184 }
185 
186 function start_byterange6(ch, cx)
187 {
188  do_check_eq(ch.responseStatus, 200);
189 }
190 
191 function stop_byterange6(ch, cx, status, data)
192 {
193  do_check_eq(data.length, 21);
194  do_check_eq(data[0], 0x54);
195  do_check_eq(data[20], 0x0a);
196 }
197 
198 function init_byterange7(ch)
199 {
200  ch.setRequestHeader("Range", "bytes=0-5", false);
201 }
202 
203 function start_byterange7(ch, cx)
204 {
205  do_check_eq(ch.responseStatus, 206);
206  do_check_eq(ch.getResponseHeader("Content-Length"), "6");
207  do_check_eq(ch.getResponseHeader("Content-Type"), "text/plain");
208  do_check_eq(ch.getResponseHeader("Content-Range"), "bytes 0-5/21");
209 }
210 
211 function stop_byterange7(ch, cx, status, data)
212 {
213  do_check_eq(data.length, 6);
214  do_check_eq(data[0], 0x54);
215  do_check_eq(data[1], 0x68);
216  do_check_eq(data[2], 0x69);
217  do_check_eq(data[3], 0x73);
218  do_check_eq(data[4], 0x20);
219  do_check_eq(data[5], 0x73);
220 }
221 
222 function init_byterange8(ch)
223 {
224  ch.setRequestHeader("Range", "bytes=20-21", false);
225 }
226 
227 function start_byterange8(ch, cx)
228 {
229  do_check_eq(ch.responseStatus, 206);
230  do_check_eq(ch.getResponseHeader("Content-Range"), "bytes 20-20/21");
231 }
232 
233 function stop_byterange8(ch, cx, status, data)
234 {
235  do_check_eq(data.length, 1);
236  do_check_eq(data[0], 0x0a);
237 }
238 
239 function init_byterange9(ch)
240 {
241  ch.setRequestHeader("Range", "bytes=020-021", false);
242 }
243 
244 function start_byterange9(ch, cx)
245 {
246  do_check_eq(ch.responseStatus, 206);
247 }
248 
249 function stop_byterange9(ch, cx, status, data)
250 {
251  do_check_eq(data.length, 1);
252  do_check_eq(data[0], 0x0a);
253 }
254 
255 function init_byterange10(ch)
256 {
257  ch.setRequestHeader("Range", "bytes=-", false);
258 }
259 
260 function start_byterange10(ch, cx)
261 {
262  do_check_eq(ch.responseStatus, 400);
263 }
264 
265 function init_byterange11(ch)
266 {
267  ch.setRequestHeader("Range", "bytes=-500", false);
268 }
269 
270 function start_byterange11(ch, cx)
271 {
272  do_check_eq(ch.responseStatus, 206);
273 }
274 
275 function stop_byterange11(ch, cx, status, data)
276 {
277  do_check_eq(data.length, 21);
278  do_check_eq(data[0], 0x54);
279  do_check_eq(data[20], 0x0a);
280 }
281 
282 function start_byterange12(ch, cx)
283 {
284  do_check_eq(ch.responseStatus, 200);
285  do_check_eq(ch.getResponseHeader("Content-Length"), "0");
286 }
287 
288 function stop_byterange12(ch, cx, status, data)
289 {
290  do_check_eq(data.length, 0);
291 }
function init_byterange7(ch)
function start_byterange10(ch, cx)
do_check_eq(typeof PlacesUtils,"object")
function start_byterange(ch, cx)
function start_byterange11(ch, cx)
function init_byterange2(ch)
function init_byterange11(ch)
function stop_byterange3(ch, cx, status, data)
function runHttpTests(testArray, done)
Definition: head_utils.js:340
function start_normal(ch, cx)
function stop_byterange(ch, cx, status, data)
function start_byterange2(ch, cx)
function start_byterange6(ch, cx)
function init_byterange10(ch)
function start_byterange12(ch, cx)
function stop_normal(ch, cx, status, data)
const PREFIX
function stop_byterange5(ch, cx, status, data)
function start_byterange4(ch, cx)
function stop_byterange12(ch, cx, status, data)
function createServer()
Definition: head_utils.js:53
function init_byterange3(ch)
function start_byterange7(ch, cx)
function stop_byterange8(ch, cx, status, data)
function init_byterange4(ch)
function stop_byterange7(ch, cx, status, data)
function start_byterange5(ch, cx)
function stop_byterange11(ch, cx, status, data)
return null
Definition: FeedWriter.js:1143
function init_byterange(ch)
function start_byterange9(ch, cx)
function testComplete(srv)
Definition: head_utils.js:292
function Test(path, initChannel, onStartRequest, onStopRequest)
Definition: head_utils.js:322
var tests
function stop_byterange9(ch, cx, status, data)
function stop_byterange6(ch, cx, status, data)
function run_test()
observe data
Definition: FeedWriter.js:1329
function start_byterange3(ch, cx)
function init_byterange6(ch)
function init_byterange5(ch)
function init_byterange9(ch)
function start_byterange8(ch, cx)
var srv
function init_byterange8(ch)