test-case.sub.js (2391B)
1 /** 2 * @fileoverview Test case for mixed-content in web-platform-tests. 3 * @author burnik@google.com (Kristijan Burnik) 4 */ 5 6 /** 7 * MixedContentTestCase exercises all the tests for checking browser behavior 8 * when resources regarded as mixed-content are requested. A single run covers 9 * only a single scenario. 10 * @param {object} scenario A JSON describing the test arrangement and 11 * expectation(s). Refer to /mixed-content/spec.src.json for details. 12 * @param {string} description The test scenario verbose description. 13 * @param {SanityChecker} sanityChecker Instance of an object used to check the 14 * running scenario. Useful in debug mode. See ./sanity-checker.js. 15 * Run {@code ./tools/generate.py -h} for info on test generating modes. 16 * @return {object} Object wrapping the start method used to run the test. 17 */ 18 function TestCase(scenarios, sanityChecker) { 19 function runTest(scenario) { 20 sanityChecker.checkScenario(scenario, subresourceMap); 21 22 const urls = getRequestURLs(scenario.subresource, 23 scenario.origin, 24 scenario.redirection); 25 const checkResult = _ => { 26 // Send request to check if the key has been torn down. 27 return xhrRequest(urls.assertUrl) 28 .then(assertResult => { 29 // Now check if the value has been torn down. If it's still there, 30 // we have blocked the request to mixed-content. 31 assert_equals(assertResult.status, scenario.expectation, 32 "The resource request should be '" + scenario.expectation + "'."); 33 }); 34 }; 35 36 /** @type {Subresource} */ 37 const subresource = { 38 subresourceType: scenario.subresource, 39 url: urls.testUrl, 40 policyDeliveries: scenario.subresource_policy_deliveries, 41 }; 42 43 promise_test(() => { 44 return xhrRequest(urls.announceUrl) 45 // Send out the real resource request. 46 // This should tear down the key if it's not blocked. 47 .then(_ => invokeRequest(subresource, scenario.source_context_list)) 48 // We check the key state, regardless of whether the main request 49 // succeeded or failed. 50 .then(checkResult, checkResult); 51 }, scenario.test_description); 52 } // runTest 53 54 function runTests() { 55 for (const scenario of scenarios) { 56 runTest(scenario); 57 } 58 } 59 60 return {start: runTests}; 61 }