11cb0ef41Sopenharmony_ci<!doctype html>
21cb0ef41Sopenharmony_ci<meta charset=utf-8>
31cb0ef41Sopenharmony_ci<title>DOMException-throwing tests</title>
41cb0ef41Sopenharmony_ci<link rel=author title="Aryeh Gregor" href=ayg@aryeh.name>
51cb0ef41Sopenharmony_ci<div id=log></div>
61cb0ef41Sopenharmony_ci<script src=/resources/testharness.js></script>
71cb0ef41Sopenharmony_ci<script src=/resources/testharnessreport.js></script>
81cb0ef41Sopenharmony_ci<script>
91cb0ef41Sopenharmony_ci/**
101cb0ef41Sopenharmony_ci * This file just picks one case where browsers are supposed to throw an
111cb0ef41Sopenharmony_ci * exception, and tests the heck out of whether it meets the spec.  In the
121cb0ef41Sopenharmony_ci * future, all these checks should be in assert_throws_dom(), but we don't want
131cb0ef41Sopenharmony_ci * every browser failing every assert_throws_dom() check until they fix every
141cb0ef41Sopenharmony_ci * single bug in their exception-throwing.
151cb0ef41Sopenharmony_ci *
161cb0ef41Sopenharmony_ci * We don't go out of our way to test everything that's already tested by
171cb0ef41Sopenharmony_ci * interfaces.html, like whether all constants are present on the object, but
181cb0ef41Sopenharmony_ci * some things are duplicated.
191cb0ef41Sopenharmony_ci */
201cb0ef41Sopenharmony_cisetup({explicit_done: true});
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_cifunction testException(exception, global, desc) {
231cb0ef41Sopenharmony_ci  test(function() {
241cb0ef41Sopenharmony_ci    assert_equals(global.Object.getPrototypeOf(exception),
251cb0ef41Sopenharmony_ci                  global.DOMException.prototype);
261cb0ef41Sopenharmony_ci  }, desc + "Object.getPrototypeOf(exception) === DOMException.prototype");
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  test(function() {
301cb0ef41Sopenharmony_ci    assert_false(exception.hasOwnProperty("name"));
311cb0ef41Sopenharmony_ci  }, desc + "exception.hasOwnProperty(\"name\")");
321cb0ef41Sopenharmony_ci  test(function() {
331cb0ef41Sopenharmony_ci    assert_false(exception.hasOwnProperty("message"));
341cb0ef41Sopenharmony_ci  }, desc + "exception.hasOwnProperty(\"message\")");
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  test(function() {
371cb0ef41Sopenharmony_ci    assert_equals(exception.name, "HierarchyRequestError");
381cb0ef41Sopenharmony_ci  }, desc + "exception.name === \"HierarchyRequestError\"");
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  test(function() {
411cb0ef41Sopenharmony_ci    assert_equals(exception.code, global.DOMException.HIERARCHY_REQUEST_ERR);
421cb0ef41Sopenharmony_ci  }, desc + "exception.code === DOMException.HIERARCHY_REQUEST_ERR");
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci  test(function() {
451cb0ef41Sopenharmony_ci    assert_equals(global.Object.prototype.toString.call(exception),
461cb0ef41Sopenharmony_ci                  "[object DOMException]");
471cb0ef41Sopenharmony_ci  }, desc + "Object.prototype.toString.call(exception) === \"[object DOMException]\"");
481cb0ef41Sopenharmony_ci}
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci// Test in current window
521cb0ef41Sopenharmony_civar exception = null;
531cb0ef41Sopenharmony_citry {
541cb0ef41Sopenharmony_ci  // This should throw a HierarchyRequestError in every browser since the
551cb0ef41Sopenharmony_ci  // Stone Age, so we're really only testing exception-throwing details.
561cb0ef41Sopenharmony_ci  document.documentElement.appendChild(document);
571cb0ef41Sopenharmony_ci} catch(e) {
581cb0ef41Sopenharmony_ci  exception = e;
591cb0ef41Sopenharmony_ci}
601cb0ef41Sopenharmony_citestException(exception, window, "");
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci// Test in iframe
631cb0ef41Sopenharmony_civar iframe = document.createElement("iframe");
641cb0ef41Sopenharmony_ciiframe.src = "about:blank";
651cb0ef41Sopenharmony_ciiframe.onload = function() {
661cb0ef41Sopenharmony_ci  var exception = null;
671cb0ef41Sopenharmony_ci  try {
681cb0ef41Sopenharmony_ci    iframe.contentDocument.documentElement.appendChild(iframe.contentDocument);
691cb0ef41Sopenharmony_ci  } catch(e) {
701cb0ef41Sopenharmony_ci    exception = e;
711cb0ef41Sopenharmony_ci  }
721cb0ef41Sopenharmony_ci  testException(exception, iframe.contentWindow, "In iframe: ");
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci  document.body.removeChild(iframe);
751cb0ef41Sopenharmony_ci  done();
761cb0ef41Sopenharmony_ci};
771cb0ef41Sopenharmony_cidocument.body.appendChild(iframe);
781cb0ef41Sopenharmony_ci</script>
79