1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/ccd.sjs Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +const DEBUG_all_valid = false; 1.5 +const DEBUG_all_stub = false; 1.6 + 1.7 +function handleRequest(request, response) 1.8 +{ 1.9 + // Decode the query string to know what test we're doing. 1.10 + 1.11 + // character 1: 'I' = text/css response, 'J' = text/html response 1.12 + let responseCSS = (request.queryString[0] == 'I'); 1.13 + 1.14 + // character 2: redirection type - we only care about whether we're 1.15 + // ultimately same-origin with the requesting document ('A', 'D') or 1.16 + // not ('B', 'C'). 1.17 + let sameOrigin = (request.queryString[1] == 'A' || 1.18 + request.queryString[1] == 'D'); 1.19 + 1.20 + // character 3: '1' = syntactically valid, '2' = invalid, '3' = http error 1.21 + let malformed = (request.queryString[2] == '2'); 1.22 + let httpError = (request.queryString[2] == '3'); 1.23 + 1.24 + // character 4: loaded with <link> or @import (no action required) 1.25 + 1.26 + // character 5: loading document mode: 'q' = quirks, 's' = standards 1.27 + let quirksMode = (request.queryString[4] == 'q'); 1.28 + 1.29 + // Our response contains a CSS rule that selects an element whose 1.30 + // ID is the first four characters of the query string. 1.31 + let selector = '#' + request.queryString.substring(0,4); 1.32 + 1.33 + // "Malformed" responses wrap the CSS rule in the construct 1.34 + // <html>{} ... </html> 1.35 + // This mimics what the CSS parser might see if an actual HTML 1.36 + // document were fed to it. Because CSS parsers recover from 1.37 + // errors by skipping tokens until they find something 1.38 + // recognizable, a style rule appearing where I wrote '...' above 1.39 + // will be honored! 1.40 + let leader = (malformed ? '<html>{}' : ''); 1.41 + let trailer = (malformed ? '</html>' : ''); 1.42 + 1.43 + // Standards mode documents will ignore the style sheet if it is being 1.44 + // served as text/html (regardless of its contents). Quirks mode 1.45 + // documents will ignore the style sheet if it is being served as 1.46 + // text/html _and_ it is not same-origin. Regardless, style sheets 1.47 + // are ignored if they come as the body of an HTTP error response. 1.48 + // 1.49 + // Style sheets that should be ignored paint the element red; those 1.50 + // that should be honored paint it lime. 1.51 + let color = ((responseCSS || (quirksMode && sameOrigin)) && !httpError 1.52 + ? 'lime' : 'red'); 1.53 + 1.54 + // For debugging the test itself, we have the capacity to make every style 1.55 + // sheet well-formed, or every style sheet do nothing. 1.56 + if (DEBUG_all_valid) { 1.57 + // In this mode, every test chip should turn blue. 1.58 + response.setHeader('Content-Type', 'text/css'); 1.59 + response.write(selector + '{background-color:blue}\n'); 1.60 + } else if (DEBUG_all_stub) { 1.61 + // In this mode, every test chip for a case where the true test 1.62 + // sheet would be honored, should turn red. 1.63 + response.setHeader('Content-Type', 'text/css'); 1.64 + response.write(selector + '{}\n'); 1.65 + } else { 1.66 + // Normal operation. 1.67 + if (httpError) 1.68 + response.setStatusLine(request.httpVersion, 500, 1.69 + "Internal Server Error"); 1.70 + response.setHeader('Content-Type', 1.71 + responseCSS ? 'text/css' : 'text/html'); 1.72 + response.write(leader + selector + 1.73 + '{background-color:' + color + '}' + 1.74 + trailer + '\n'); 1.75 + } 1.76 +}