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 { test, assert_equals } = require('../common/wpt').harness;
131cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// TODO(joyeecheung): we should submit these to the upstream
161cb0ef41Sopenharmony_ciconst additionalTestCases =
171cb0ef41Sopenharmony_ci  require(fixtures.path('url-setter-tests-additional.js'));
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci{
201cb0ef41Sopenharmony_ci  for (const attributeToBeSet in additionalTestCases) {
211cb0ef41Sopenharmony_ci    if (attributeToBeSet === 'comment') {
221cb0ef41Sopenharmony_ci      continue;
231cb0ef41Sopenharmony_ci    }
241cb0ef41Sopenharmony_ci    const testCases = additionalTestCases[attributeToBeSet];
251cb0ef41Sopenharmony_ci    for (const testCase of testCases) {
261cb0ef41Sopenharmony_ci      let name = `Setting <${testCase.href}>.${attributeToBeSet}` +
271cb0ef41Sopenharmony_ci                 ` = "${testCase.new_value}"`;
281cb0ef41Sopenharmony_ci      if ('comment' in testCase) {
291cb0ef41Sopenharmony_ci        name += ` ${testCase.comment}`;
301cb0ef41Sopenharmony_ci      }
311cb0ef41Sopenharmony_ci      test(function() {
321cb0ef41Sopenharmony_ci        const url = new URL(testCase.href);
331cb0ef41Sopenharmony_ci        url[attributeToBeSet] = testCase.new_value;
341cb0ef41Sopenharmony_ci        for (const attribute in testCase.expected) {
351cb0ef41Sopenharmony_ci          assert_equals(url[attribute], testCase.expected[attribute]);
361cb0ef41Sopenharmony_ci        }
371cb0ef41Sopenharmony_ci      }, `URL: ${name}`);
381cb0ef41Sopenharmony_ci    }
391cb0ef41Sopenharmony_ci  }
401cb0ef41Sopenharmony_ci}
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci{
431cb0ef41Sopenharmony_ci  const url = new URL('http://example.com/');
441cb0ef41Sopenharmony_ci  const obj = {
451cb0ef41Sopenharmony_ci    toString() { throw new Error('toString'); },
461cb0ef41Sopenharmony_ci    valueOf() { throw new Error('valueOf'); }
471cb0ef41Sopenharmony_ci  };
481cb0ef41Sopenharmony_ci  const sym = Symbol();
491cb0ef41Sopenharmony_ci  const props = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(url));
501cb0ef41Sopenharmony_ci  for (const [name, { set }] of Object.entries(props)) {
511cb0ef41Sopenharmony_ci    if (set) {
521cb0ef41Sopenharmony_ci      assert.throws(() => url[name] = obj,
531cb0ef41Sopenharmony_ci                    /^Error: toString$/,
541cb0ef41Sopenharmony_ci                    `url.${name} = { toString() { throw ... } }`);
551cb0ef41Sopenharmony_ci      assert.throws(() => url[name] = sym,
561cb0ef41Sopenharmony_ci                    /^TypeError: Cannot convert a Symbol value to a string$/,
571cb0ef41Sopenharmony_ci                    `url.${name} = ${String(sym)}`);
581cb0ef41Sopenharmony_ci    }
591cb0ef41Sopenharmony_ci  }
601cb0ef41Sopenharmony_ci}
61