var BASE_URL = 'example.com/tests/dom/base/test/bug704320.sjs'; function createTestUrl(schemeFrom, schemeTo, policy, action, type) { return schemeTo + '://' + BASE_URL + '?' + 'action=' + action + '&' + 'scheme=' + schemeFrom + '-to-' + schemeTo + '&' + 'policy=' + policy + '&' + 'type=' + type; } function create2ndLevelIframeUrl(schemeFrom, schemeTo, policy, type) { return schemeFrom + '://' + BASE_URL + '?' + 'action=create-2nd-level-iframe&' + 'scheme-from=' + schemeFrom + '&' + 'scheme-to=' + schemeTo + '&' + 'policy=' + policy + '&' + 'type=' + type; } // Creates the following test cases for the specified scheme and referrer // policy combination: // // @import // font-face // bg-url // \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ '; } function createIframedFormTest(schemeFrom, schemeTo, policy) { var actionUrl = schemeTo + '://' + BASE_URL; return '\n\ \n\ \n\ \n\ \n\ \n\
\n\ \n\ \n\ \n\ \n\
\n\ \n\ \n\ '; } function createIframedWindowLocationTest(schemeFrom, schemeTo, policy) { var url = createTestUrl( schemeFrom, schemeTo, policy, 'test', 'window.location'); return '\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ '; } function createPolicyTest(policy, optionalEarlierPolicy) { var metaReferrerPolicyString = ''; if (optionalEarlierPolicy && optionalEarlierPolicy != '') { metaReferrerPolicyString += '\n'; } metaReferrerPolicyString += ''; return '\n\ \n\ \n\ '+metaReferrerPolicyString+'\n\ \n\ \n\ \n\ \n\ \n\ \n\ '; } function handleRequest(request, response) { var sharedKey = 'bug704320.sjs'; var params = request.queryString.split('&'); var action = params[0].split('=')[1]; if (action === 'create-1st-level-iframe') { // ?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=origin var schemeFrom = params[1].split('=')[1]; var schemeTo = params[2].split('=')[1]; var policy = params[3].split('=')[1]; var optionalEarlierPolicy = ''; if (params[4]) { optionalEarlierPolicy = params[4].split('=')[1]; } response.setHeader('Content-Type', 'text/html; charset=utf-8', false); response.setHeader('Cache-Control', 'no-cache', false); response.write(createTest(schemeFrom, schemeTo, policy, optionalEarlierPolicy)); } else if (action === 'create-2nd-level-iframe') { // ?action=create-2nd-level-iframe&scheme-from=http&scheme-to=https&policy=origin&type=form" var schemeFrom = params[1].split('=')[1]; var schemeTo = params[2].split('=')[1]; var policy = params[3].split('=')[1]; var type = params[4].split('=')[1]; response.setHeader('Content-Type', 'text/html; charset=utf-8', false); response.setHeader('Cache-Control', 'no-cache', false); if (type === 'form') { response.write(createIframedFormTest(schemeFrom, schemeTo, policy)); } else if (type === 'window.location') { response.write(createIframedWindowLocationTest( schemeFrom, schemeTo, policy)); } } else if (action === 'test') { // ?action=test&scheme=http-to-https&policy=origin&type=img var scheme = params[1].split('=')[1]; var policy = params[2].split('=')[1]; var type = params[3].split('=')[1]; var result = getSharedState(sharedKey); if (result === '') { result = {}; } else { result = JSON.parse(result); } if (!result[type]) { result[type] = {}; } if (!result[type][scheme]) { result[type][scheme] = {}; } if (request.hasHeader('Referer')) { result[type][scheme][policy] = request.getHeader('Referer'); } else { result[type][scheme][policy] = ''; } setSharedState(sharedKey, JSON.stringify(result)); if (type === 'link') { var loc = 'https://example.com/tests/dom/base/test/file_bug704320_redirect.html'; response.setStatusLine('1.1', 302, 'Found'); response.setHeader('Location', loc, false); } if (type === 'window.open') { response.setHeader('Cache-Control', 'no-cache', false); response.setHeader('Content-Type', 'text/html', false); response.write(''); } } else if (action === 'get-test-results') { // ?action=get-result response.setHeader('Cache-Control', 'no-cache', false); response.setHeader('Content-Type', 'text/plain', false); response.write(getSharedState(sharedKey)); } else if (action === 'generate-policy-test') { // ?action=generate-policy-test&policy=b64-encoded-string response.setHeader('Cache-Control', 'no-cache', false); response.setHeader('Content-Type', 'text/html', false); var policy = unescape(params[1].split('=')[1]); var optionalEarlierPolicy = ''; if (params[2]) { optionalEarlierPolicy = params[2].split('=')[1]; } response.write(createPolicyTest(policy, optionalEarlierPolicy)); } }