summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/h1-parsing/status-code.window.js
blob: 5776cf4050f01e838c42f7e845a2e033e2604f41 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
[
  {
    input: "",
    expected: null
  },
  {
    input: "BLAH",
    expected: null
  },
  {
    input: "0 OK",
    expected: {
      status: 0,
      statusText: "OK"
    }
  },
  {
    input: "1 OK",
    expected: {
      status: 1,
      statusText: "OK"
    }
  },
  {
    input: "99 NOT OK",
    expected: {
      status: 99,
      statusText: "NOT OK"
    }
  },
  {
    input: "077 77",
    expected: {
      status: 77,
      statusText: "77"
    }
  },
  {
    input: "099 HELLO",
    expected: {
      status: 99,
      statusText: "HELLO"
    }
  },
  {
    input: "200",
    expected: {
      status: 200,
      statusText: ""
    }
  },
  {
    input: "999 DOES IT MATTER",
    expected: {
      status: 999,
      statusText: "DOES IT MATTER"
    }
  },
  {
    input: "1000 BOO",
    expected: null
  },
  {
    input: "0200 BOO",
    expected: null
  },
  {
    input: "65736 NOT 200 OR SOME SUCH",
    expected: null
  },
  {
    input: "131072 HI",
    expected: null
  },
  {
    input: "-200 TEST",
    expected: null
  },
  {
    input: "0xA",
    expected: null
  },
  {
    input: "C8",
    expected: null
  }
].forEach(({ description, input, expected }) => {
  promise_test(async t => {
    if (expected !== null) {
      const response = await fetch("resources/status-code.py?input=" + input);
      assert_equals(response.status, expected.status);
      assert_equals(response.statusText, expected.statusText);
      assert_equals(response.headers.get("header-parsing"), "is sad");
    } else {
      await promise_rejects_js(t, TypeError, fetch("resources/status-code.py?input=" + input));
    }
  }, `HTTP/1.1 ${input} ${expected === null ? "(network error)" : ""}`);
});