test_setstatusline.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  * Jeff Walden <jwalden+code@mit.edu>.
20  * Portions created by the Initial Developer are Copyright (C) 2006
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38 
39 // exercise nsIHttpResponse.setStatusLine, ensure its atomicity, and ensure the
40 // specified behavior occurs if it's not called
41 
42 var srv;
43 
44 function run_test()
45 {
46  srv = createServer();
47 
48  srv.registerPathHandler("/no/setstatusline", noSetstatusline);
49  srv.registerPathHandler("/http1_0", http1_0);
50  srv.registerPathHandler("/http1_1", http1_1);
51  srv.registerPathHandler("/invalidVersion", invalidVersion);
52  srv.registerPathHandler("/invalidStatus", invalidStatus);
53  srv.registerPathHandler("/invalidDescription", invalidDescription);
54  srv.registerPathHandler("/crazyCode", crazyCode);
55  srv.registerPathHandler("/nullVersion", nullVersion);
56 
57  srv.start(4444);
58 
60 }
61 
62 
63 /*************
64  * UTILITIES *
65  *************/
66 
67 function checkStatusLine(channel, httpMaxVer, httpMinVer, httpCode, statusText)
68 {
69  do_check_eq(channel.responseStatus, httpCode);
70  do_check_eq(channel.responseStatusText, statusText);
71 
72  var respMaj = {}, respMin = {};
73  channel.getResponseVersion(respMaj, respMin);
74  do_check_eq(respMaj.value, httpMaxVer);
75  do_check_eq(respMin.value, httpMinVer);
76 }
77 
78 
79 /*********
80  * TESTS *
81  *********/
82 
83 var tests = [];
84 var test;
85 
86 // /no/setstatusline
87 function noSetstatusline(metadata, response)
88 {
89 }
90 test = new Test("http://localhost:4444/no/setstatusline",
92 tests.push(test);
93 function startNoSetStatusLine(ch, cx)
94 {
95  checkStatusLine(ch, 1, 1, 200, "OK");
96 }
97 function stop(ch, cx, status, data)
98 {
99  do_check_true(Components.isSuccessCode(status));
100 }
101 
102 
103 // /http1_0
104 function http1_0(metadata, response)
105 {
106  response.setStatusLine("1.0", 200, "OK");
107 }
108 test = new Test("http://localhost:4444/http1_0",
110 tests.push(test);
111 function startHttp1_0(ch, cx)
112 {
113  checkStatusLine(ch, 1, 0, 200, "OK");
114 }
115 
116 
117 // /http1_1
118 function http1_1(metadata, response)
119 {
120  response.setStatusLine("1.1", 200, "OK");
121 }
122 test = new Test("http://localhost:4444/http1_1",
124 tests.push(test);
125 function startHttp1_1(ch, cx)
126 {
127  checkStatusLine(ch, 1, 1, 200, "OK");
128 }
129 
130 
131 // /invalidVersion
132 function invalidVersion(metadata, response)
133 {
134  try
135  {
136  response.setStatusLine(" 1.0", 200, "FAILED");
137  }
138  catch (e)
139  {
140  response.setHeader("Passed", "true", false);
141  }
142 }
143 test = new Test("http://localhost:4444/invalidVersion",
145 tests.push(test);
146 function startPassedTrue(ch, cx)
147 {
148  checkStatusLine(ch, 1, 1, 200, "OK");
149  do_check_eq(ch.getResponseHeader("Passed"), "true");
150 }
151 
152 
153 // /invalidStatus
154 function invalidStatus(metadata, response)
155 {
156  try
157  {
158  response.setStatusLine("1.0", 1000, "FAILED");
159  }
160  catch (e)
161  {
162  response.setHeader("Passed", "true", false);
163  }
164 }
165 test = new Test("http://localhost:4444/invalidStatus",
167 tests.push(test);
168 
169 
170 // /invalidDescription
171 function invalidDescription(metadata, response)
172 {
173  try
174  {
175  response.setStatusLine("1.0", 200, "FAILED\x01");
176  }
177  catch (e)
178  {
179  response.setHeader("Passed", "true", false);
180  }
181 }
182 test = new Test("http://localhost:4444/invalidDescription",
184 tests.push(test);
185 
186 
187 // /crazyCode
188 function crazyCode(metadata, response)
189 {
190  response.setStatusLine("1.1", 617, "Crazy");
191 }
192 test = new Test("http://localhost:4444/crazyCode",
193  null, startCrazy, stop);
194 tests.push(test);
195 function startCrazy(ch, cx)
196 {
197  checkStatusLine(ch, 1, 1, 617, "Crazy");
198 }
199 
200 
201 // /nullVersion
202 function nullVersion(metadata, response)
203 {
204  response.setStatusLine(null, 255, "NULL");
205 }
206 test = new Test("http://localhost:4444/nullVersion",
208 tests.push(test);
209 function startNullVersion(ch, cx)
210 {
211  // currently, this server implementation defaults to 1.1
212  checkStatusLine(ch, 1, 1, 255, "NULL");
213 }
function noSetstatusline(metadata, response)
do_check_eq(typeof PlacesUtils,"object")
function stop(ch, cx, status, data)
var srv
function http1_0(metadata, response)
function run_test()
function startHttp1_0(ch, cx)
function invalidDescription(metadata, response)
function startPassedTrue(ch, cx)
function runHttpTests(testArray, done)
Definition: head_utils.js:340
function nullVersion(metadata, response)
function startCrazy(ch, cx)
function createServer()
Definition: head_utils.js:53
function invalidStatus(metadata, response)
var tests
function invalidVersion(metadata, response)
var test
return null
Definition: FeedWriter.js:1143
function crazyCode(metadata, response)
function testComplete(srv)
Definition: head_utils.js:292
function Test(path, initChannel, onStartRequest, onStopRequest)
Definition: head_utils.js:322
function http1_1(metadata, response)
function checkStatusLine(channel, httpMaxVer, httpMinVer, httpCode, statusText)
function startHttp1_1(ch, cx)
function startNullVersion(ch, cx)
observe data
Definition: FeedWriter.js:1329
function startNoSetStatusLine(ch, cx)