browser_inspector_keyboard-shortcuts-copy-outerhtml.js (1664B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test copy outer HTML from the keyboard/copy event 6 7 const TEST_URL = URL_ROOT + "doc_inspector_outerhtml.html"; 8 9 add_task(async function () { 10 const { inspector } = await openInspectorForURL(TEST_URL); 11 const root = inspector.markup._elt; 12 13 info("Test copy outerHTML for COMMENT node"); 14 const comment = getElementByType(inspector, Node.COMMENT_NODE); 15 await setSelectionNodeFront(comment, inspector); 16 await checkClipboard("<!-- Comment -->", root); 17 18 info("Test copy outerHTML for DOCTYPE node"); 19 const doctype = getElementByType(inspector, Node.DOCUMENT_TYPE_NODE); 20 await setSelectionNodeFront(doctype, inspector); 21 await checkClipboard("<!DOCTYPE html>", root); 22 23 info("Test copy outerHTML for ELEMENT node"); 24 await selectAndHighlightNode("div", inspector); 25 await checkClipboard("<div><p>Test copy OuterHTML</p></div>", root); 26 }); 27 28 async function setSelectionNodeFront(node, inspector) { 29 const updated = inspector.once("inspector-updated"); 30 inspector.selection.setNodeFront(node); 31 await updated; 32 } 33 34 async function checkClipboard(expectedText, node) { 35 try { 36 await waitForClipboardPromise(() => fireCopyEvent(node), expectedText); 37 ok(true, "Clipboard successfully filled with : " + expectedText); 38 } catch (e) { 39 ok( 40 false, 41 "Clipboard could not be filled with the expected text : " + expectedText 42 ); 43 } 44 } 45 46 function getElementByType(inspector, type) { 47 for (const [node] of inspector.markup._containers) { 48 if (node.nodeType === type) { 49 return node; 50 } 51 } 52 return null; 53 }