browser_markup_html_edit_01.js (3521B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* import-globals-from helper_outerhtml_test_runner.js */ 4 "use strict"; 5 6 // Test outerHTML edition via the markup-view 7 8 requestLongerTimeout(2); 9 10 loadHelperScript("helper_outerhtml_test_runner.js"); 11 12 const TEST_DATA = [ 13 { 14 selector: "#one", 15 oldHTML: '<div id="one">First <em>Div</em></div>', 16 newHTML: '<div id="one">First Div</div>', 17 async validate() { 18 const text = await getContentPageElementProperty("#one", "textContent"); 19 is(text, "First Div", "New div has expected text content"); 20 const num = await getNumberOfMatchingElementsInContentPage("#one em"); 21 is(num, 0, "No em remaining"); 22 }, 23 }, 24 { 25 selector: "#removedChildren", 26 oldHTML: 27 '<div id="removedChildren">removedChild ' + 28 "<i>Italic <b>Bold <u>Underline</u></b></i> Normal</div>", 29 newHTML: '<div id="removedChildren">removedChild</div>', 30 }, 31 { 32 selector: "#addedChildren", 33 oldHTML: '<div id="addedChildren">addedChildren</div>', 34 newHTML: 35 '<div id="addedChildren">addedChildren ' + 36 "<i>Italic <b>Bold <u>Underline</u></b></i> Normal</div>", 37 }, 38 { 39 selector: "#addedAttribute", 40 oldHTML: '<div id="addedAttribute">addedAttribute</div>', 41 newHTML: 42 '<div id="addedAttribute" class="important" disabled checked>' + 43 "addedAttribute</div>", 44 async validate({ pageNodeFront, selectedNodeFront }) { 45 is(pageNodeFront, selectedNodeFront, "Original element is selected"); 46 const html = await getContentPageElementProperty( 47 "#addedAttribute", 48 "outerHTML" 49 ); 50 is( 51 html, 52 '<div id="addedAttribute" class="important" disabled="" ' + 53 'checked="">addedAttribute</div>', 54 "Attributes have been added" 55 ); 56 }, 57 }, 58 { 59 selector: "#changedTag", 60 oldHTML: '<div id="changedTag">changedTag</div>', 61 newHTML: '<p id="changedTag" class="important">changedTag</p>', 62 }, 63 { 64 selector: "#siblings", 65 oldHTML: '<div id="siblings">siblings</div>', 66 newHTML: 67 '<div id="siblings-before-sibling">before sibling</div>' + 68 '<div id="siblings">siblings (updated)</div>' + 69 '<div id="siblings-after-sibling">after sibling</div>', 70 async validate({ selectedNodeFront, inspector }) { 71 const beforeSiblingFront = await getNodeFront( 72 "#siblings-before-sibling", 73 inspector 74 ); 75 is(beforeSiblingFront, selectedNodeFront, "Sibling has been selected"); 76 77 const text = await getContentPageElementProperty( 78 "#siblings", 79 "textContent" 80 ); 81 is(text, "siblings (updated)", "New div has expected text content"); 82 83 const beforeText = await getContentPageElementProperty( 84 "#siblings-before-sibling", 85 "textContent" 86 ); 87 is(beforeText, "before sibling", "Sibling has been inserted"); 88 89 const afterText = await getContentPageElementProperty( 90 "#siblings-after-sibling", 91 "textContent" 92 ); 93 is(afterText, "after sibling", "Sibling has been inserted"); 94 }, 95 }, 96 ]; 97 98 const TEST_URL = 99 "data:text/html," + 100 "<!DOCTYPE html>" + 101 "<head><meta charset='utf-8' /></head>" + 102 "<body>" + 103 TEST_DATA.map(outer => outer.oldHTML).join("\n") + 104 "</body>" + 105 "</html>"; 106 107 add_task(async function () { 108 const { inspector } = await openInspectorForURL(TEST_URL); 109 inspector.markup._frame.focus(); 110 await runEditOuterHTMLTests(TEST_DATA, inspector); 111 });