Bug 1804412 [wpt PR 37372] - Subset URL tests by file/javascript/mailto schemes,...
[gecko.git] / testing / web-platform / tests / url / url-setters-a-area.window.js
blob6a5e762cd42fe89de25bef44dcad8c537b5b9874
1 // META: script=/common/subset-tests-by-key.js
2 // META: variant=?include=file
3 // META: variant=?include=javascript
4 // META: variant=?include=mailto
5 // META: variant=?exclude=(file|javascript|mailto)
7 // Keep this file in sync with url-setters.any.js.
9 promise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…");
11 function runURLSettersTests(all_test_cases) {
12   for (var attribute_to_be_set in all_test_cases) {
13     if (attribute_to_be_set == "comment") {
14       continue;
15     }
16     var test_cases = all_test_cases[attribute_to_be_set];
17     for(var i = 0, l = test_cases.length; i < l; i++) {
18       var test_case = test_cases[i];
19       var name = "Setting <" + test_case.href + ">." + attribute_to_be_set +
20                  " = '" + test_case.new_value + "'";
21       if ("comment" in test_case) {
22         name += " " + test_case.comment;
23       }
24       const key = test_case.href.split(":")[0];
25       subsetTestByKey(key, test, function() {
26         var url = document.createElement("a");
27         url.href = test_case.href;
28         url[attribute_to_be_set] = test_case.new_value;
29         for (var attribute in test_case.expected) {
30           assert_equals(url[attribute], test_case.expected[attribute])
31         }
32       }, "<a>: " + name)
33       subsetTestByKey(key, test, function() {
34         var url = document.createElement("area");
35         url.href = test_case.href;
36         url[attribute_to_be_set] = test_case.new_value;
37         for (var attribute in test_case.expected) {
38           assert_equals(url[attribute], test_case.expected[attribute])
39         }
40       }, "<area>: " + name)
41     }
42   }