1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/mochitest/test_inspector-changeattrs.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 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 gClient = null; 1.29 +var gWalker = null; 1.30 +var checkActorIDs = []; 1.31 + 1.32 +function assertOwnership() { 1.33 + assertOwnershipTrees(gWalker); 1.34 +} 1.35 + 1.36 +addTest(function setup() { 1.37 + let url = document.getElementById("inspectorContent").href; 1.38 + attachURL(url, function(err, client, tab, doc) { 1.39 + gInspectee = doc; 1.40 + let {InspectorFront} = devtools.require("devtools/server/actors/inspector"); 1.41 + let inspector = InspectorFront(client, tab); 1.42 + promiseDone(inspector.getWalker().then(walker => { 1.43 + ok(walker, "getWalker() should return an actor."); 1.44 + gClient = client; 1.45 + gWalker = walker; 1.46 + }).then(runNextTest)); 1.47 + }); 1.48 +}); 1.49 + 1.50 +addTest(function testChangeAttrs() { 1.51 + let attrNode = gInspectee.querySelector("#a"); 1.52 + let attrFront; 1.53 + promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(front => { 1.54 + attrFront = front; 1.55 + dump("attrFront is: " + attrFront + "\n"); 1.56 + // Add a few attributes. 1.57 + let list = attrFront.startModifyingAttributes(); 1.58 + list.setAttribute("data-newattr", "newvalue"); 1.59 + list.setAttribute("data-newattr2", "newvalue"); 1.60 + return list.apply(); 1.61 + }).then(() => { 1.62 + // We're only going to test that the change hit the document. 1.63 + // There are other tests that make sure changes are propagated 1.64 + // to the client. 1.65 + is(attrNode.getAttribute("data-newattr"), "newvalue", "Node should have the first new attribute"); 1.66 + is(attrNode.getAttribute("data-newattr2"), "newvalue", "Node should have the second new attribute."); 1.67 + }).then(() => { 1.68 + // Change an attribute. 1.69 + let list = attrFront.startModifyingAttributes(); 1.70 + list.setAttribute("data-newattr", "changedvalue"); 1.71 + return list.apply(); 1.72 + }).then(() => { 1.73 + is(attrNode.getAttribute("data-newattr"), "changedvalue", "Node should have the changed first value."); 1.74 + is(attrNode.getAttribute("data-newattr2"), "newvalue", "Second value should remain unchanged."); 1.75 + }).then(() => { 1.76 + let list = attrFront.startModifyingAttributes(); 1.77 + list.removeAttribute("data-newattr2"); 1.78 + return list.apply(); 1.79 + }).then(() => { 1.80 + is(attrNode.getAttribute("data-newattr"), "changedvalue", "Node should have the changed first value."); 1.81 + ok(!attrNode.hasAttribute("data-newattr2"), "Second value should be removed."); 1.82 + }).then(runNextTest)); 1.83 +}); 1.84 + 1.85 +addTest(function cleanup() { 1.86 + delete gWalker; 1.87 + delete gInspectee; 1.88 + delete gClient; 1.89 + runNextTest(); 1.90 +}); 1.91 + 1.92 + 1.93 + </script> 1.94 +</head> 1.95 +<body> 1.96 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> 1.97 +<a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a> 1.98 +<p id="display"></p> 1.99 +<div id="content" style="display: none"> 1.100 + 1.101 +</div> 1.102 +<pre id="test"> 1.103 +</pre> 1.104 +</body> 1.105 +</html>