browser_chromeutils_isdomobject.js (2707B)
1 "use strict"; 2 3 add_task(async function invalidArgument() { 4 const args = [undefined, null, 42, "foo"]; 5 6 for (const argument of args) { 7 let hadException = false; 8 try { 9 ChromeUtils.isDOMObject(argument); 10 } catch (ex) { 11 hadException = true; 12 } 13 ok(hadException, "Should have got an exception!"); 14 } 15 }); 16 17 add_task(async function NoUnwrap() { 18 const args = [ 19 window.document, 20 window.document.childNodes, 21 new DocumentFragment(), 22 new Response(), 23 new URL("https://example.com"), 24 ]; 25 26 for (const argument of args) { 27 ok( 28 ChromeUtils.isDOMObject(argument, false), 29 `${ChromeUtils.getClassName( 30 argument 31 )} to be a DOM object with unwrap=false` 32 ); 33 } 34 35 ok( 36 !ChromeUtils.isDOMObject(window, false), 37 `${ChromeUtils.getClassName( 38 window 39 )} not to be a DOM object with unwrap=false` 40 ); 41 }); 42 43 add_task(async function DOMObjects() { 44 const args = [ 45 window, 46 window.document, 47 window.document.childNodes, 48 new DocumentFragment(), 49 new Response(), 50 new URL("https://example.com"), 51 ]; 52 53 for (const argument of args) { 54 ok( 55 ChromeUtils.isDOMObject(argument), 56 `${ChromeUtils.getClassName(argument)} to be a DOM object` 57 ); 58 } 59 }); 60 61 add_task(async function nonDOMObjects() { 62 const args = [new Object(), {}, []]; 63 64 for (const argument of args) { 65 ok( 66 !ChromeUtils.isDOMObject(argument), 67 `${ChromeUtils.getClassName(argument)} not to be a DOM object` 68 ); 69 } 70 }); 71 72 add_task(async function DOMObjects_contentProcess() { 73 await BrowserTestUtils.withNewTab( 74 { 75 gBrowser, 76 url: `data:text/html,<div>`, 77 }, 78 async function (browser) { 79 await SpecialPowers.spawn(browser, [], async () => { 80 const args = [ 81 content, 82 content.document, 83 content.document.querySelector("div"), 84 content.document.childNodes, 85 new content.DocumentFragment(), 86 new content.URL("https://example.com"), 87 ]; 88 89 for (const argument of args) { 90 ok( 91 ChromeUtils.isDOMObject(argument), 92 `${ChromeUtils.getClassName( 93 argument 94 )} in content to be a DOM object` 95 ); 96 } 97 98 ok( 99 !ChromeUtils.isDOMObject({}), 100 `${ChromeUtils.getClassName({})} in content not to be a DOM object` 101 ); 102 103 // unwrap=false 104 for (const argument of args) { 105 ok( 106 !ChromeUtils.isDOMObject(argument, false), 107 `${ChromeUtils.getClassName( 108 argument 109 )} in content not to be a DOM object with unwrap=false` 110 ); 111 } 112 }); 113 } 114 ); 115 });