1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/mochitest/test_inspector-mutations-attr.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id= 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug </title> 1.12 + 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 1.15 + <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script> 1.16 + <script type="application/javascript;version=1.8"> 1.17 +Components.utils.import("resource://gre/modules/devtools/Loader.jsm"); 1.18 +const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {}); 1.19 + 1.20 +const inspector = devtools.require("devtools/server/actors/inspector"); 1.21 + 1.22 +window.onload = function() { 1.23 + SimpleTest.waitForExplicitFinish(); 1.24 + runNextTest(); 1.25 +} 1.26 + 1.27 +var gInspectee = null; 1.28 +var gWalker = null; 1.29 +var gClient = null; 1.30 +var attrNode; 1.31 +var attrFront; 1.32 + 1.33 +addTest(function setup() { 1.34 + let url = document.getElementById("inspectorContent").href; 1.35 + attachURL(url, function(err, client, tab, doc) { 1.36 + gInspectee = doc; 1.37 + let {InspectorFront} = devtools.require("devtools/server/actors/inspector"); 1.38 + let inspector = InspectorFront(client, tab); 1.39 + promiseDone(inspector.getWalker().then(walker => { 1.40 + ok(walker, "getWalker() should return an actor."); 1.41 + gClient = client; 1.42 + gWalker = walker; 1.43 + }).then(runNextTest)); 1.44 + }); 1.45 +}); 1.46 + 1.47 +addTest(setupAttrTest); 1.48 +addTest(testAddAttribute); 1.49 +addTest(testChangeAttribute); 1.50 +addTest(testRemoveAttribute); 1.51 +addTest(setupFrameAttrTest); 1.52 +addTest(testAddAttribute); 1.53 +addTest(testChangeAttribute); 1.54 +addTest(testRemoveAttribute); 1.55 + 1.56 +function setupAttrTest() { 1.57 + attrNode = gInspectee.querySelector("#a") 1.58 + promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(node => { 1.59 + attrFront = node; 1.60 + }).then(runNextTest)); 1.61 +} 1.62 + 1.63 +function setupFrameAttrTest() { 1.64 + let frame = gInspectee.querySelector('#childFrame'); 1.65 + attrNode = frame.contentDocument.querySelector("#a"); 1.66 + 1.67 + promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => { 1.68 + return gWalker.children(childFrame); 1.69 + }).then(children => { 1.70 + let nodes = children.nodes; 1.71 + ok(nodes.length, 1, "There should be only one child of the iframe"); 1.72 + is(nodes[0].nodeType, Node.DOCUMENT_NODE, "iframe child should be a document node"); 1.73 + return gWalker.querySelector(nodes[0], "#a"); 1.74 + }).then(node => { 1.75 + attrFront = node; 1.76 + }).then(runNextTest)); 1.77 +} 1.78 + 1.79 +function testAddAttribute() { 1.80 + attrNode.setAttribute("data-newattr", "newvalue"); 1.81 + attrNode.setAttribute("data-newattr2", "newvalue"); 1.82 + gWalker.once("mutations", () => { 1.83 + is(attrFront.attributes.length, 3, "Should have id and two new attributes."); 1.84 + is(attrFront.getAttribute("data-newattr"), "newvalue", "Node front should have the first new attribute"); 1.85 + is(attrFront.getAttribute("data-newattr2"), "newvalue", "Node front should have the second new attribute."); 1.86 + runNextTest(); 1.87 + }); 1.88 +} 1.89 + 1.90 +function testChangeAttribute() { 1.91 + attrNode.setAttribute("data-newattr", "changedvalue"); 1.92 + gWalker.once("mutations", () => { 1.93 + is(attrFront.attributes.length, 3, "Should have id and two new attributes."); 1.94 + is(attrFront.getAttribute("data-newattr"), "changedvalue", "Node front should have the changed first value"); 1.95 + is(attrFront.getAttribute("data-newattr2"), "newvalue", "Second value should remain unchanged."); 1.96 + runNextTest(); 1.97 + }); 1.98 +} 1.99 + 1.100 +function testRemoveAttribute() { 1.101 + attrNode.removeAttribute("data-newattr2"); 1.102 + gWalker.once("mutations", () => { 1.103 + is(attrFront.attributes.length, 2, "Should have id and one remaining attribute."); 1.104 + is(attrFront.getAttribute("data-newattr"), "changedvalue", "Node front should still have the first value"); 1.105 + ok(!attrFront.hasAttribute("data-newattr2"), "Second value should be removed."); 1.106 + runNextTest(); 1.107 + }) 1.108 +} 1.109 + 1.110 +addTest(function cleanup() { 1.111 + delete gInspectee; 1.112 + delete gWalker; 1.113 + delete gClient; 1.114 + runNextTest(); 1.115 +}); 1.116 + 1.117 + 1.118 + </script> 1.119 +</head> 1.120 +<body> 1.121 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> 1.122 +<a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a> 1.123 +<p id="display"></p> 1.124 +<div id="content" style="display: none"> 1.125 + 1.126 +</div> 1.127 +<pre id="test"> 1.128 +</pre> 1.129 +</body> 1.130 +</html>