test-case.sub.js (1533B)
1 // TODO(hiroshige): Document the type of `scenario`. 2 function TestCase(scenarios) { 3 function runTest(scenario) { 4 const urls = getRequestURLs(scenario.subresource, 5 scenario.origin, 6 scenario.redirection); 7 const checkResult = _ => { 8 // Send request to check if the key has been torn down. 9 return xhrRequest(urls.assertUrl) 10 .then(assertResult => { 11 // Now check if the value has been torn down. If it's still there, 12 // we have blocked the request to mixed-content. 13 assert_equals(assertResult.status, scenario.expectation, 14 "The resource request should be '" + scenario.expectation + "'."); 15 }); 16 }; 17 18 /** @type {Subresource} */ 19 const subresource = { 20 subresourceType: scenario.subresource, 21 url: urls.testUrl, 22 policyDeliveries: scenario.subresource_policy_deliveries, 23 }; 24 25 promise_test(() => { 26 return xhrRequest(urls.announceUrl) 27 // Send out the real resource request. 28 // This should tear down the key if it's not blocked. 29 .then(_ => invokeRequest(subresource, scenario.source_context_list)) 30 // We check the key state, regardless of whether the main request 31 // succeeded or failed. 32 .then(checkResult, checkResult); 33 }, scenario.test_description); 34 } // runTest 35 36 function runTests() { 37 for (const scenario of scenarios) { 38 runTest(scenario); 39 } 40 } 41 42 return {start: runTests}; 43 }