browser_markup_html_edit_04.js (2848B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that outerHTML editing keybindings work as expected and that the <svg> 7 // root element can be edited correctly. 8 9 const TEST_URL = 10 "data:image/svg+xml," + 11 '<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">' + 12 '<circle cx="50" cy="50" r="50"/>' + 13 "</svg>"; 14 15 requestLongerTimeout(2); 16 17 add_task(async function () { 18 const { inspector } = await openInspectorForURL(TEST_URL); 19 20 inspector.markup._frame.focus(); 21 22 info("Check that editing the <svg> element works like other nodes"); 23 await testDocumentElement(inspector); 24 25 info("Check (again) that editing the <svg> element works like other nodes"); 26 await testDocumentElement2(inspector); 27 }); 28 29 async function testDocumentElement(inspector) { 30 const currentDocElementOuterHTML = await SpecialPowers.spawn( 31 gBrowser.selectedBrowser, 32 [], 33 () => content.document.documentElement.outerHTML 34 ); 35 const docElementSVG = 36 '<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">' + 37 '<rect x="10" y="10" width="180" height="180"/>' + 38 "</svg>"; 39 const docElementFront = await inspector.markup.walker.documentElement(); 40 41 const onReselected = inspector.markup.once("reselectedonremoved"); 42 await inspector.markup.updateNodeOuterHTML( 43 docElementFront, 44 docElementSVG, 45 currentDocElementOuterHTML 46 ); 47 await onReselected; 48 49 is( 50 await getContentPageElementAttribute("svg", "width"), 51 "200", 52 "<svg> width has been updated" 53 ); 54 is( 55 await getContentPageElementAttribute("svg", "height"), 56 "200", 57 "<svg> height has been updated" 58 ); 59 is( 60 await getContentPageElementProperty("svg", "outerHTML"), 61 docElementSVG, 62 "<svg> markup has been updated" 63 ); 64 } 65 66 async function testDocumentElement2(inspector) { 67 const currentDocElementOuterHTML = await SpecialPowers.spawn( 68 gBrowser.selectedBrowser, 69 [], 70 () => content.document.documentElement.outerHTML 71 ); 72 const docElementSVG = 73 '<svg width="300" height="300" xmlns="http://www.w3.org/2000/svg">' + 74 '<ellipse cx="150" cy="150" rx="150" ry="100"/>' + 75 "</svg>"; 76 const docElementFront = await inspector.markup.walker.documentElement(); 77 78 const onReselected = inspector.markup.once("reselectedonremoved"); 79 inspector.markup.updateNodeOuterHTML( 80 docElementFront, 81 docElementSVG, 82 currentDocElementOuterHTML 83 ); 84 await onReselected; 85 86 is( 87 await getContentPageElementAttribute("svg", "width"), 88 "300", 89 "<svg> width has been updated" 90 ); 91 is( 92 await getContentPageElementAttribute("svg", "height"), 93 "300", 94 "<svg> height has been updated" 95 ); 96 is( 97 await getContentPageElementProperty("svg", "outerHTML"), 98 docElementSVG, 99 "<svg> markup has been updated" 100 ); 101 }