11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Tests below are not from WPT. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ciif (!common.hasIntl) { 71cb0ef41Sopenharmony_ci // A handful of the tests fail when ICU is not included. 81cb0ef41Sopenharmony_ci common.skip('missing Intl'); 91cb0ef41Sopenharmony_ci} 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst assert = require('assert'); 121cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst tests = require( 151cb0ef41Sopenharmony_ci fixtures.path('wpt', 'url', 'resources', 'urltestdata.json') 161cb0ef41Sopenharmony_ci); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciconst originalFailures = tests.filter((test) => test.failure); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciconst typeFailures = [ 211cb0ef41Sopenharmony_ci { input: '' }, 221cb0ef41Sopenharmony_ci { input: 'test' }, 231cb0ef41Sopenharmony_ci { input: undefined }, 241cb0ef41Sopenharmony_ci { input: 0 }, 251cb0ef41Sopenharmony_ci { input: true }, 261cb0ef41Sopenharmony_ci { input: false }, 271cb0ef41Sopenharmony_ci { input: null }, 281cb0ef41Sopenharmony_ci { input: new Date() }, 291cb0ef41Sopenharmony_ci { input: new RegExp() }, 301cb0ef41Sopenharmony_ci { input: 'test', base: null }, 311cb0ef41Sopenharmony_ci { input: 'http://nodejs.org', base: null }, 321cb0ef41Sopenharmony_ci { input: () => {} }, 331cb0ef41Sopenharmony_ci]; 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// See https://github.com/w3c/web-platform-tests/pull/10955 361cb0ef41Sopenharmony_ci// > If `failure` is true, parsing `about:blank` against `base` 371cb0ef41Sopenharmony_ci// > must give failure. This tests that the logic for converting 381cb0ef41Sopenharmony_ci// > base URLs into strings properly fails the whole parsing 391cb0ef41Sopenharmony_ci// > algorithm if the base URL cannot be parsed. 401cb0ef41Sopenharmony_ciconst aboutBlankFailures = originalFailures 411cb0ef41Sopenharmony_ci .map((test) => ({ 421cb0ef41Sopenharmony_ci input: 'about:blank', 431cb0ef41Sopenharmony_ci base: test.input, 441cb0ef41Sopenharmony_ci failure: true 451cb0ef41Sopenharmony_ci })); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ciconst failureTests = originalFailures 481cb0ef41Sopenharmony_ci .concat(typeFailures) 491cb0ef41Sopenharmony_ci .concat(aboutBlankFailures); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ciconst expectedError = { code: 'ERR_INVALID_URL', name: 'TypeError' }; 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_cifor (const test of failureTests) { 541cb0ef41Sopenharmony_ci assert.throws( 551cb0ef41Sopenharmony_ci () => new URL(test.input, test.base), 561cb0ef41Sopenharmony_ci (error) => { 571cb0ef41Sopenharmony_ci assert.throws(() => { throw error; }, expectedError); 581cb0ef41Sopenharmony_ci assert.strictEqual(`${error}`, 'TypeError [ERR_INVALID_URL]: Invalid URL'); 591cb0ef41Sopenharmony_ci assert.strictEqual(error.message, 'Invalid URL'); 601cb0ef41Sopenharmony_ci return true; 611cb0ef41Sopenharmony_ci }); 621cb0ef41Sopenharmony_ci} 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ciconst additional_tests = 651cb0ef41Sopenharmony_ci require(fixtures.path('url-tests-additional.js')); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_cifor (const test of additional_tests) { 681cb0ef41Sopenharmony_ci const url = new URL(test.url); 691cb0ef41Sopenharmony_ci if (test.href) assert.strictEqual(url.href, test.href); 701cb0ef41Sopenharmony_ci if (test.origin) assert.strictEqual(url.origin, test.origin); 711cb0ef41Sopenharmony_ci if (test.protocol) assert.strictEqual(url.protocol, test.protocol); 721cb0ef41Sopenharmony_ci if (test.username) assert.strictEqual(url.username, test.username); 731cb0ef41Sopenharmony_ci if (test.password) assert.strictEqual(url.password, test.password); 741cb0ef41Sopenharmony_ci if (test.hostname) assert.strictEqual(url.hostname, test.hostname); 751cb0ef41Sopenharmony_ci if (test.host) assert.strictEqual(url.host, test.host); 761cb0ef41Sopenharmony_ci if (test.port !== undefined) assert.strictEqual(url.port, test.port); 771cb0ef41Sopenharmony_ci if (test.pathname) assert.strictEqual(url.pathname, test.pathname); 781cb0ef41Sopenharmony_ci if (test.search) assert.strictEqual(url.search, test.search); 791cb0ef41Sopenharmony_ci if (test.hash) assert.strictEqual(url.hash, test.hash); 801cb0ef41Sopenharmony_ci} 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ciassert.throws(() => { 831cb0ef41Sopenharmony_ci new URL(); 841cb0ef41Sopenharmony_ci}, { 851cb0ef41Sopenharmony_ci name: 'TypeError', 861cb0ef41Sopenharmony_ci code: 'ERR_MISSING_ARGS', 871cb0ef41Sopenharmony_ci}); 88