Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / netwerk / test / unit / test_http_headers.js
blobcb5ed4cca834173297c0484d097f96fb979c55df
1 function check_request_header(chan, name, value) {
2 var chanValue;
3 try {
4 chanValue = chan.getRequestHeader(name);
5 } catch (e) {
6 do_throw("Expected to find header '" + name + "' but didn't find it");
8 do_check_eq(chanValue, value);
11 function run_test() {
12 var ios = Components.classes["@mozilla.org/network/io-service;1"]
13 .getService(Components.interfaces.nsIIOService);
14 var chan = ios.newChannel("http://www.mozilla.org/", null, null)
15 .QueryInterface(Components.interfaces.nsIHttpChannel);
17 check_request_header(chan, "host", "www.mozilla.org");
18 check_request_header(chan, "Host", "www.mozilla.org");
20 chan.setRequestHeader("foopy", "bar", false);
21 check_request_header(chan, "foopy", "bar");
23 chan.setRequestHeader("foopy", "baz", true);
24 check_request_header(chan, "foopy", "bar, baz");
26 for (var i = 0; i < 100; ++i)
27 chan.setRequestHeader("foopy" + i, i, false);
29 for (var i = 0; i < 100; ++i)
30 check_request_header(chan, "foopy" + i, i);
32 var x = false;
33 try {
34 chan.setRequestHeader("foo:py", "baz", false);
35 } catch (e) {
36 x = true;
38 if (!x)
39 do_throw("header with colon not rejected");
41 x = false;
42 try {
43 chan.setRequestHeader("foopy", "b\naz", false);
44 } catch (e) {
45 x = true;
47 if (!x)
48 do_throw("header value with newline not rejected");
50 x = false;
51 try {
52 chan.setRequestHeader("foopy\u0080", "baz", false);
53 } catch (e) {
54 x = true;
56 if (!x)
57 do_throw("header name with non-ASCII not rejected");
59 x = false;
60 try {
61 chan.setRequestHeader("foopy", "b\u0000az", false);
62 } catch (e) {
63 x = true;
65 if (!x)
66 do_throw("header value with null-byte not rejected");