11cb0ef41Sopenharmony_ci// META: script=/common/subset-tests-by-key.js 21cb0ef41Sopenharmony_ci// META: variant=?include=file 31cb0ef41Sopenharmony_ci// META: variant=?include=javascript 41cb0ef41Sopenharmony_ci// META: variant=?include=mailto 51cb0ef41Sopenharmony_ci// META: variant=?exclude=(file|javascript|mailto) 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// Keep this file in sync with url-setters.any.js. 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cipromise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…"); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifunction runURLSettersTests(all_test_cases) { 121cb0ef41Sopenharmony_ci for (var attribute_to_be_set in all_test_cases) { 131cb0ef41Sopenharmony_ci if (attribute_to_be_set == "comment") { 141cb0ef41Sopenharmony_ci continue; 151cb0ef41Sopenharmony_ci } 161cb0ef41Sopenharmony_ci var test_cases = all_test_cases[attribute_to_be_set]; 171cb0ef41Sopenharmony_ci for(var i = 0, l = test_cases.length; i < l; i++) { 181cb0ef41Sopenharmony_ci var test_case = test_cases[i]; 191cb0ef41Sopenharmony_ci var name = "Setting <" + test_case.href + ">." + attribute_to_be_set + 201cb0ef41Sopenharmony_ci " = '" + test_case.new_value + "'"; 211cb0ef41Sopenharmony_ci if ("comment" in test_case) { 221cb0ef41Sopenharmony_ci name += " " + test_case.comment; 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci const key = test_case.href.split(":")[0]; 251cb0ef41Sopenharmony_ci subsetTestByKey(key, test, function() { 261cb0ef41Sopenharmony_ci var url = document.createElement("a"); 271cb0ef41Sopenharmony_ci url.href = test_case.href; 281cb0ef41Sopenharmony_ci url[attribute_to_be_set] = test_case.new_value; 291cb0ef41Sopenharmony_ci for (var attribute in test_case.expected) { 301cb0ef41Sopenharmony_ci assert_equals(url[attribute], test_case.expected[attribute]) 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci }, "<a>: " + name) 331cb0ef41Sopenharmony_ci subsetTestByKey(key, test, function() { 341cb0ef41Sopenharmony_ci var url = document.createElement("area"); 351cb0ef41Sopenharmony_ci url.href = test_case.href; 361cb0ef41Sopenharmony_ci url[attribute_to_be_set] = test_case.new_value; 371cb0ef41Sopenharmony_ci for (var attribute in test_case.expected) { 381cb0ef41Sopenharmony_ci assert_equals(url[attribute], test_case.expected[attribute]) 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci }, "<area>: " + name) 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci} 44