1<!doctype html> 2<meta charset=utf-8> 3<title>DOMException-throwing tests</title> 4<link rel=author title="Aryeh Gregor" href=ayg@aryeh.name> 5<div id=log></div> 6<script src=/resources/testharness.js></script> 7<script src=/resources/testharnessreport.js></script> 8<script> 9/** 10 * This file just picks one case where browsers are supposed to throw an 11 * exception, and tests the heck out of whether it meets the spec. In the 12 * future, all these checks should be in assert_throws_dom(), but we don't want 13 * every browser failing every assert_throws_dom() check until they fix every 14 * single bug in their exception-throwing. 15 * 16 * We don't go out of our way to test everything that's already tested by 17 * interfaces.html, like whether all constants are present on the object, but 18 * some things are duplicated. 19 */ 20setup({explicit_done: true}); 21 22function testException(exception, global, desc) { 23 test(function() { 24 assert_equals(global.Object.getPrototypeOf(exception), 25 global.DOMException.prototype); 26 }, desc + "Object.getPrototypeOf(exception) === DOMException.prototype"); 27 28 29 test(function() { 30 assert_false(exception.hasOwnProperty("name")); 31 }, desc + "exception.hasOwnProperty(\"name\")"); 32 test(function() { 33 assert_false(exception.hasOwnProperty("message")); 34 }, desc + "exception.hasOwnProperty(\"message\")"); 35 36 test(function() { 37 assert_equals(exception.name, "HierarchyRequestError"); 38 }, desc + "exception.name === \"HierarchyRequestError\""); 39 40 test(function() { 41 assert_equals(exception.code, global.DOMException.HIERARCHY_REQUEST_ERR); 42 }, desc + "exception.code === DOMException.HIERARCHY_REQUEST_ERR"); 43 44 test(function() { 45 assert_equals(global.Object.prototype.toString.call(exception), 46 "[object DOMException]"); 47 }, desc + "Object.prototype.toString.call(exception) === \"[object DOMException]\""); 48} 49 50 51// Test in current window 52var exception = null; 53try { 54 // This should throw a HierarchyRequestError in every browser since the 55 // Stone Age, so we're really only testing exception-throwing details. 56 document.documentElement.appendChild(document); 57} catch(e) { 58 exception = e; 59} 60testException(exception, window, ""); 61 62// Test in iframe 63var iframe = document.createElement("iframe"); 64iframe.src = "about:blank"; 65iframe.onload = function() { 66 var exception = null; 67 try { 68 iframe.contentDocument.documentElement.appendChild(iframe.contentDocument); 69 } catch(e) { 70 exception = e; 71 } 72 testException(exception, iframe.contentWindow, "In iframe: "); 73 74 document.body.removeChild(iframe); 75 done(); 76}; 77document.body.appendChild(iframe); 78</script> 79