layout/style/test/ccd.sjs

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial