1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/mochitest/test_inspector-mutations-value.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,151 @@ 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 +const testSummaryLength = 10; 1.28 +inspector.setValueSummaryLength(testSummaryLength); 1.29 +SimpleTest.registerCleanupFunction(function() { 1.30 + inspector.setValueSummaryLength(inspector.DEFAULT_VALUE_SUMMARY_LENGTH); 1.31 +}); 1.32 + 1.33 +var gInspectee = null; 1.34 +var gWalker = null; 1.35 +var gClient = null; 1.36 +var valueNode; 1.37 +var valueFront; 1.38 +var longString = "stringstringstringstringstringstringstringstringstringstringstring"; 1.39 +var truncatedLongString = longString.substring(0, testSummaryLength); 1.40 +var shortString = "str"; 1.41 +var shortString2 = "str2"; 1.42 + 1.43 +addTest(function setup() { 1.44 + let url = document.getElementById("inspectorContent").href; 1.45 + attachURL(url, function(err, client, tab, doc) { 1.46 + gInspectee = doc; 1.47 + let {InspectorFront} = devtools.require("devtools/server/actors/inspector"); 1.48 + let inspector = InspectorFront(client, tab); 1.49 + promiseDone(inspector.getWalker().then(walker => { 1.50 + ok(walker, "getWalker() should return an actor."); 1.51 + gClient = client; 1.52 + gWalker = walker; 1.53 + }).then(runNextTest)); 1.54 + }); 1.55 +}); 1.56 + 1.57 +addTest(setupValueTest); 1.58 +addTest(testKeepLongValue); 1.59 +addTest(testSetShortValue); 1.60 +addTest(testKeepShortValue); 1.61 +addTest(testSetLongValue); 1.62 +addTest(setupFrameValueTest); 1.63 +addTest(testKeepLongValue); 1.64 +addTest(testSetShortValue); 1.65 +addTest(testKeepShortValue); 1.66 +addTest(testSetLongValue); 1.67 + 1.68 +function setupValueTest() { 1.69 + valueNode = gInspectee.querySelector("#longstring").firstChild; 1.70 + promiseDone(gWalker.querySelector(gWalker.rootNode, "#longstring").then(node => { 1.71 + return gWalker.children(node); 1.72 + }).then(children => { 1.73 + valueFront = children.nodes[0]; 1.74 + }).then(runNextTest)); 1.75 +} 1.76 + 1.77 +function setupFrameValueTest() { 1.78 + let frame = gInspectee.querySelector('#childFrame'); 1.79 + valueNode = frame.contentDocument.querySelector("#longstring").firstChild; 1.80 + 1.81 + promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => { 1.82 + return gWalker.children(childFrame); 1.83 + }).then(children => { 1.84 + let nodes = children.nodes; 1.85 + ok(nodes.length, 1, "There should be only one child of the iframe"); 1.86 + is(nodes[0].nodeType, Node.DOCUMENT_NODE, "iframe child should be a document node"); 1.87 + return gWalker.querySelector(nodes[0], "#longstring"); 1.88 + }).then(node => { 1.89 + return gWalker.children(node); 1.90 + }).then(children => { 1.91 + valueFront = children.nodes[0]; 1.92 + }).then(runNextTest)); 1.93 +} 1.94 + 1.95 +function testKeepLongValue() { 1.96 + // After first setup we should have a long string in the node 1.97 + is(valueFront.shortValue.length, testSummaryLength, "After setup the test node should be truncated."); 1.98 + ok(valueFront.incompleteValue, "After setup the node value should be incomplete."); 1.99 + valueNode.nodeValue = longString; 1.100 + gWalker.once("mutations", () => { 1.101 + is(valueFront.shortValue, truncatedLongString, "Value should have changed to a truncated value"); 1.102 + ok(valueFront.incompleteValue, "Node value should stay incomplete."); 1.103 + runNextTest(); 1.104 + }); 1.105 +} 1.106 + 1.107 +function testSetShortValue() { 1.108 + valueNode.nodeValue = shortString; 1.109 + gWalker.once("mutations", () => { 1.110 + is(valueFront.shortValue, shortString, "Value should not be truncated."); 1.111 + ok(!valueFront.incompleteValue, "Value should not be incomplete."); 1.112 + runNextTest(); 1.113 + }); 1.114 +} 1.115 + 1.116 +function testKeepShortValue() { 1.117 + valueNode.nodeValue = shortString2; 1.118 + gWalker.once("mutations", () => { 1.119 + is(valueFront.shortValue, shortString2, "Value should not be truncated."); 1.120 + ok(!valueFront.incompleteValue, "Value should not be incomplete."); 1.121 + runNextTest(); 1.122 + }); 1.123 +} 1.124 + 1.125 +function testSetLongValue() { 1.126 + valueNode.nodeValue = longString; 1.127 + gWalker.once("mutations", () => { 1.128 + is(valueFront.shortValue, truncatedLongString, "Value should have changed to a truncated value"); 1.129 + ok(valueFront.incompleteValue, "Node value should stay incomplete."); 1.130 + runNextTest(); 1.131 + }); 1.132 +} 1.133 + 1.134 +addTest(function cleanup() { 1.135 + delete gInspectee; 1.136 + delete gWalker; 1.137 + delete gClient; 1.138 + runNextTest(); 1.139 +}); 1.140 + 1.141 + 1.142 + </script> 1.143 +</head> 1.144 +<body> 1.145 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> 1.146 +<a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a> 1.147 +<p id="display"></p> 1.148 +<div id="content" style="display: none"> 1.149 + 1.150 +</div> 1.151 +<pre id="test"> 1.152 +</pre> 1.153 +</body> 1.154 +</html>