Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / layout / style / test / ccd.sjs
blob22a4294d59c18a7581ece2bc66a00ad4147e4a28
1 const DEBUG_all_valid = false;
2 const DEBUG_all_stub = false;
4 function handleRequest(request, response) {
5   // Decode the query string to know what test we're doing.
7   // character 1: 'I' = text/css response, 'J' = text/html response
8   let responseCSS = request.queryString[0] == "I";
10   // character 2: redirection type - we only care about whether we're
11   // ultimately same-origin with the requesting document ('A', 'D') or
12   // not ('B', 'C').
13   let sameOrigin =
14     request.queryString[1] == "A" || request.queryString[1] == "D";
16   // character 3: '1' = syntactically valid, '2' = invalid, '3' = http error
17   let malformed = request.queryString[2] == "2";
18   let httpError = request.queryString[2] == "3";
20   // character 4: loaded with <link> or @import (no action required)
22   // character 5: loading document mode: 'q' = quirks, 's' = standards
23   let quirksMode = request.queryString[4] == "q";
25   // Our response contains a CSS rule that selects an element whose
26   // ID is the first four characters of the query string.
27   let selector = "#" + request.queryString.substring(0, 4);
29   // "Malformed" responses wrap the CSS rule in the construct
30   //     <html>{} ... </html>
31   // This mimics what the CSS parser might see if an actual HTML
32   // document were fed to it.  Because CSS parsers recover from
33   // errors by skipping tokens until they find something
34   // recognizable, a style rule appearing where I wrote '...' above
35   // will be honored!
36   let leader = malformed ? "<html>{}" : "";
37   let trailer = malformed ? "</html>" : "";
39   // Standards mode documents will ignore the style sheet if it is being
40   // served as text/html (regardless of its contents).  Quirks mode
41   // documents will ignore the style sheet if it is being served as
42   // text/html _and_ it is not same-origin.  Regardless, style sheets
43   // are ignored if they come as the body of an HTTP error response.
44   //
45   // Style sheets that should be ignored paint the element red; those
46   // that should be honored paint it lime.
47   let color =
48     (responseCSS || (quirksMode && sameOrigin)) && !httpError ? "lime" : "red";
50   // For debugging the test itself, we have the capacity to make every style
51   // sheet well-formed, or every style sheet do nothing.
52   if (DEBUG_all_valid) {
53     // In this mode, every test chip should turn blue.
54     response.setHeader("Content-Type", "text/css");
55     response.write(selector + "{background-color:blue}\n");
56   } else if (DEBUG_all_stub) {
57     // In this mode, every test chip for a case where the true test
58     // sheet would be honored, should turn red.
59     response.setHeader("Content-Type", "text/css");
60     response.write(selector + "{}\n");
61   } else {
62     // Normal operation.
63     if (httpError) {
64       response.setStatusLine(request.httpVersion, 500, "Internal Server Error");
65     }
66     response.setHeader("Content-Type", responseCSS ? "text/css" : "text/html");
67     response.write(
68       leader + selector + "{background-color:" + color + "}" + trailer + "\n"
69     );
70   }