test_inspector-changeattrs.html (2943B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id= 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug </title> 9 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 12 <script type="application/javascript" src="inspector-helpers.js"></script> 13 <script type="application/javascript"> 14 "use strict"; 15 16 window.onload = function() { 17 SimpleTest.waitForExplicitFinish(); 18 runNextTest(); 19 }; 20 21 let gInspectee = null; 22 let gWalker = null; 23 24 addTest(async function setup() { 25 const url = document.getElementById("inspectorContent").href; 26 const { target, doc } = await attachURL(url); 27 gInspectee = doc; 28 const inspector = await target.getFront("inspector"); 29 gWalker = inspector.walker; 30 runNextTest(); 31 }); 32 33 addTest(function testChangeAttrs() { 34 const attrNode = gInspectee.querySelector("#a"); 35 let attrFront; 36 promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(front => { 37 attrFront = front; 38 dump("attrFront is: " + attrFront + "\n"); 39 // Add a few attributes. 40 const list = attrFront.startModifyingAttributes(); 41 list.setAttribute("data-newattr", "newvalue"); 42 list.setAttribute("data-newattr2", "newvalue"); 43 return list.apply(); 44 }).then(() => { 45 // We're only going to test that the change hit the document. 46 // There are other tests that make sure changes are propagated 47 // to the client. 48 is(attrNode.getAttribute("data-newattr"), "newvalue", 49 "Node should have the first new attribute"); 50 is(attrNode.getAttribute("data-newattr2"), "newvalue", 51 "Node should have the second new attribute."); 52 }).then(() => { 53 // Change an attribute. 54 const list = attrFront.startModifyingAttributes(); 55 list.setAttribute("data-newattr", "changedvalue"); 56 return list.apply(); 57 }).then(() => { 58 is(attrNode.getAttribute("data-newattr"), "changedvalue", 59 "Node should have the changed first value."); 60 is(attrNode.getAttribute("data-newattr2"), "newvalue", 61 "Second value should remain unchanged."); 62 }).then(() => { 63 const list = attrFront.startModifyingAttributes(); 64 list.removeAttribute("data-newattr2"); 65 return list.apply(); 66 }).then(() => { 67 is(attrNode.getAttribute("data-newattr"), "changedvalue", 68 "Node should have the changed first value."); 69 ok(!attrNode.hasAttribute("data-newattr2"), "Second value should be removed."); 70 }).then(runNextTest)); 71 }); 72 73 addTest(function cleanup() { 74 gWalker = null; 75 gInspectee = null; 76 runNextTest(); 77 }); 78 </script> 79 </head> 80 <body> 81 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> 82 <a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a> 83 <p id="display"></p> 84 <div id="content" style="display: none"> 85 86 </div> 87 <pre id="test"> 88 </pre> 89 </body> 90 </html>