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