browser_markup_textcontent_display.js (3480B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test the rendering of text nodes in the markup view. 7 8 const LONG_VALUE = 9 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " + 10 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."; 11 const SCHEMA = "data:text/html;charset=UTF-8,"; 12 const TEST_URL = `${SCHEMA}<!DOCTYPE html> 13 <html> 14 <body> 15 <div id="shorttext">Short text</div> 16 <div id="longtext">${LONG_VALUE}</div> 17 <div id="shortcomment"><!--Short comment--></div> 18 <div id="longcomment"><!--${LONG_VALUE}--></div> 19 <div id="shorttext-and-node">Short text<span>Other element</span></div> 20 <div id="longtext-and-node">${LONG_VALUE}<span>Other element</span></div> 21 </body> 22 </html>`; 23 24 const TEST_DATA = [ 25 { 26 desc: "Test node containing a short text, short text nodes can be inlined.", 27 selector: "#shorttext", 28 inline: true, 29 value: "Short text", 30 }, 31 { 32 desc: "Test node containing a long text, long text nodes are not inlined.", 33 selector: "#longtext", 34 inline: false, 35 value: LONG_VALUE, 36 }, 37 { 38 desc: "Test node containing a short comment, comments are not inlined.", 39 selector: "#shortcomment", 40 inline: false, 41 value: "Short comment", 42 }, 43 { 44 desc: "Test node containing a long comment, comments are not inlined.", 45 selector: "#longcomment", 46 inline: false, 47 value: LONG_VALUE, 48 }, 49 { 50 desc: "Test node containing a short text and a span.", 51 selector: "#shorttext-and-node", 52 inline: false, 53 value: "Short text", 54 }, 55 { 56 desc: "Test node containing a long text and a span.", 57 selector: "#longtext-and-node", 58 inline: false, 59 value: LONG_VALUE, 60 }, 61 ]; 62 63 add_task(async function () { 64 const { inspector } = await openInspectorForURL(TEST_URL); 65 66 for (const data of TEST_DATA) { 67 await checkNode(inspector, data); 68 } 69 }); 70 71 async function checkNode(inspector, { desc, selector, inline, value }) { 72 info(desc); 73 74 const container = await getContainerForSelector(selector, inspector); 75 const nodeValue = await getFirstChildNodeValue(selector); 76 is(nodeValue, value, "The test node's text content is correct"); 77 78 is( 79 !!container.inlineTextChild, 80 inline, 81 "Container inlineTextChild is as expected" 82 ); 83 is( 84 !container.canExpand, 85 inline, 86 "Container canExpand property is as expected" 87 ); 88 89 let textContainer; 90 if (inline) { 91 textContainer = container.elt.querySelector("pre"); 92 ok( 93 !!textContainer, 94 "Text container is already rendered for inline text elements" 95 ); 96 ok( 97 textContainer.parentNode.previousSibling.previousSibling.classList.contains( 98 "open" 99 ), 100 "Text container is after the open tag" 101 ); 102 ok( 103 textContainer.parentNode.nextSibling.classList.contains("close"), 104 "Text container is before the close tag" 105 ); 106 } else { 107 textContainer = container.elt.querySelector("pre"); 108 ok( 109 !textContainer, 110 "Text container is not rendered for collapsed text nodes" 111 ); 112 await inspector.markup.expandNode(container.node); 113 await waitForMultipleChildrenUpdates(inspector); 114 115 textContainer = container.elt.querySelector("pre"); 116 ok( 117 !!textContainer, 118 "Text container is rendered after expanding the container" 119 ); 120 } 121 122 is(textContainer.textContent, value, "The complete text node is rendered."); 123 }