1'use strict'; 2 3const common = require('../common'); 4if (!common.hasIntl) { 5 // A handful of the tests fail when ICU is not included. 6 common.skip('missing Intl'); 7} 8 9const { test, assert_equals } = require('../common/wpt').harness; 10const fixtures = require('../common/fixtures'); 11 12const request = { 13 response: require(fixtures.path( 14 'wpt', 'url', 'resources', 'setters_tests.json' 15 )) 16}; 17 18// The following tests are copied from WPT. Modifications to them should be 19// upstreamed first. 20// Refs: https://github.com/w3c/web-platform-tests/blob/8791bed/url/url-setters.html 21// License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html 22 23/* eslint-disable */ 24function startURLSettersTests() { 25// var setup = async_test("Loading data…") 26// setup.step(function() { 27// var request = new XMLHttpRequest() 28// request.open("GET", "setters_tests.json") 29// request.send() 30// request.responseType = "json" 31// request.onload = setup.step_func(function() { 32 runURLSettersTests(request.response) 33// setup.done() 34// }) 35// }) 36} 37 38function runURLSettersTests(all_test_cases) { 39 for (var attribute_to_be_set in all_test_cases) { 40 if (attribute_to_be_set == "comment") { 41 continue; 42 } 43 var test_cases = all_test_cases[attribute_to_be_set]; 44 for(var i = 0, l = test_cases.length; i < l; i++) { 45 var test_case = test_cases[i]; 46 var name = `Setting <${test_case.href}>.${attribute_to_be_set}` + 47 ` = '${test_case.new_value}'`; 48 if ("comment" in test_case) { 49 name += ` ${test_case.comment}`; 50 } 51 test(function() { 52 var url = new URL(test_case.href); 53 url[attribute_to_be_set] = test_case.new_value; 54 for (var attribute in test_case.expected) { 55 assert_equals(url[attribute], test_case.expected[attribute]) 56 } 57 }, `URL: ${name}`); 58 // test(function() { 59 // var url = document.createElement("a"); 60 // url.href = test_case.href; 61 // url[attribute_to_be_set] = test_case.new_value; 62 // for (var attribute in test_case.expected) { 63 // assert_equals(url[attribute], test_case.expected[attribute]) 64 // } 65 // }, "<a>: " + name) 66 // test(function() { 67 // var url = document.createElement("area"); 68 // url.href = test_case.href; 69 // url[attribute_to_be_set] = test_case.new_value; 70 // for (var attribute in test_case.expected) { 71 // assert_equals(url[attribute], test_case.expected[attribute]) 72 // } 73 // }, "<area>: " + name) 74 } 75 } 76} 77 78startURLSettersTests() 79/* eslint-enable */ 80