summaryrefslogtreecommitdiffstats
path: root/netwerk/test/httpserver/test/test_cern_meta.js
blob: b6c3047685a39aa907f75081e20d0525a2a2f2a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// exercises support for mod_cern_meta-style header/status line modification
var srv;

XPCOMUtils.defineLazyGetter(this, "PREFIX", function () {
  return "http://localhost:" + srv.identity.primaryPort;
});

XPCOMUtils.defineLazyGetter(this, "tests", function () {
  return [
    new Test(PREFIX + "/test_both.html", null, start_testBoth, null),
    new Test(
      PREFIX + "/test_ctype_override.txt",
      null,
      start_test_ctype_override_txt,
      null
    ),
    new Test(
      PREFIX + "/test_status_override.html",
      null,
      start_test_status_override_html,
      null
    ),
    new Test(
      PREFIX + "/test_status_override_nodesc.txt",
      null,
      start_test_status_override_nodesc_txt,
      null
    ),
    new Test(PREFIX + "/caret_test.txt^", null, start_caret_test_txt_, null),
  ];
});

function run_test() {
  srv = createServer();

  var cernDir = do_get_file("data/cern_meta/");
  srv.registerDirectory("/", cernDir);

  srv.start(-1);

  runHttpTests(tests, testComplete(srv));
}

// TEST DATA

function start_testBoth(ch) {
  Assert.equal(ch.responseStatus, 501);
  Assert.equal(ch.responseStatusText, "Unimplemented");

  Assert.equal(ch.getResponseHeader("Content-Type"), "text/plain");
}

function start_test_ctype_override_txt(ch) {
  Assert.equal(ch.getResponseHeader("Content-Type"), "text/html");
}

function start_test_status_override_html(ch) {
  Assert.equal(ch.responseStatus, 404);
  Assert.equal(ch.responseStatusText, "Can't Find This");
}

function start_test_status_override_nodesc_txt(ch) {
  Assert.equal(ch.responseStatus, 732);
  Assert.equal(ch.responseStatusText, "");
}

function start_caret_test_txt_(ch) {
  Assert.equal(ch.responseStatus, 500);
  Assert.equal(ch.responseStatusText, "This Isn't A Server Error");

  Assert.equal(ch.getResponseHeader("Foo-RFC"), "3092");
  Assert.equal(ch.getResponseHeader("Shaving-Cream-Atom"), "Illudium Phosdex");
}