sanity-checker.js (1860B)
1 // The SanityChecker is used in debug mode to identify problems with the 2 // structure of the testsuite. In release mode it is mocked out to do nothing. 3 4 function SanityChecker() {} 5 6 SanityChecker.prototype.checkScenario = function(scenario) { 7 // Check if scenario is valid. 8 // TODO(kristijanburnik): Move to a sanity-checks.js for debug mode only. 9 test(function() { 10 11 // We extend the exsiting test_expansion_schema not to kill performance by 12 // copying. 13 var expectedFields = SPEC_JSON["test_expansion_schema"]; 14 expectedFields["referrer_policy"] = SPEC_JSON["referrer_policy_schema"]; 15 16 for (var field in expectedFields) { 17 assert_own_property(scenario, field, 18 "The scenario contains field " + field) 19 assert_in_array(scenario[field], expectedFields[field], 20 "Scenario's " + field + " is one of: " + 21 expectedFields[field].join(", ")) + "." 22 } 23 24 // Check if the protocol is matched. 25 assert_equals(scenario["source_protocol"] + ":", location.protocol, 26 "Protocol of the test page should match the scenario.") 27 28 }, "[ReferrerPolicyTestCase] The test scenario is valid."); 29 } 30 31 SanityChecker.prototype.checkSubresourceResult = function(scenario, 32 subresourceUrl, 33 result) { 34 assert_equals(Object.keys(result).length, 3); 35 assert_own_property(result, "location"); 36 assert_own_property(result, "referrer"); 37 assert_own_property(result, "headers"); 38 39 // Skip location check for scripts. 40 if (scenario.subresource == "script-tag") 41 return; 42 43 // Sanity check: location of sub-resource matches reported location. 44 assert_equals(result.location, subresourceUrl, 45 "Subresource reported location."); 46 };