Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<!--
5
-->
6
<head>
7
<meta charset="utf-8">
8
<title>Test for Bug </title>
9
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
const WalkerActor = require("devtools/server/actors/inspector/walker");
17
18
window.onload = function() {
19
SimpleTest.waitForExplicitFinish();
20
runNextTest();
21
};
22
23
const testSummaryLength = 10;
24
WalkerActor.setValueSummaryLength(testSummaryLength);
25
SimpleTest.registerCleanupFunction(function() {
26
WalkerActor.setValueSummaryLength(WalkerActor.DEFAULT_VALUE_SUMMARY_LENGTH);
27
});
28
29
let gInspectee = null;
30
let gWalker = null;
31
let valueNode;
32
var valueFront;
33
var longStringFront;
34
var longString = "stringstringstringstringstringstringstringstringstringstringstring";
35
var shortString = "str";
36
var shortString2 = "str2";
37
38
addTest(async function setup() {
39
const url = document.getElementById("inspectorContent").href;
40
const { target, doc } = await attachURL(url);
41
const inspector = await target.getFront("inspector");
42
gInspectee = doc;
43
gWalker = inspector.walker;
44
runNextTest();
45
});
46
47
addTest(setupValueTest);
48
addTest(testKeepLongValue);
49
addTest(testSetShortValue);
50
addTest(testKeepShortValue);
51
addTest(testSetLongValue);
52
addTest(setupFrameValueTest);
53
addTest(testKeepLongValue);
54
addTest(testSetShortValue);
55
addTest(testKeepShortValue);
56
addTest(testSetLongValue);
57
58
function setupValueTest() {
59
valueNode = gInspectee.querySelector("#longstring").firstChild;
60
promiseDone(gWalker.querySelector(gWalker.rootNode, "#longstring").then(node => {
61
longStringFront = node;
62
return gWalker.children(node);
63
}).then(children => {
64
valueFront = children.nodes[0];
65
}).then(runNextTest));
66
}
67
68
function setupFrameValueTest() {
69
const frame = gInspectee.querySelector("#childFrame");
70
valueNode = frame.contentDocument.querySelector("#longstring").firstChild;
71
72
promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => {
73
return gWalker.children(childFrame);
74
}).then(children => {
75
const nodes = children.nodes;
76
is(nodes.length, 1, "There should be only one child of the iframe");
77
is(nodes[0].nodeType, Node.DOCUMENT_NODE, "iframe child should be a document node");
78
return gWalker.querySelector(nodes[0], "#longstring");
79
}).then(node => {
80
longStringFront = node;
81
return gWalker.children(node);
82
}).then(children => {
83
valueFront = children.nodes[0];
84
}).then(runNextTest));
85
}
86
87
function checkNodeFrontValue(front, expectedValue) {
88
return front.getNodeValue().then(longstring => {
89
return longstring.string();
90
}).then(str => {
91
is(str, expectedValue, "Node value is as expected");
92
});
93
}
94
95
function testKeepLongValue() {
96
// After first setup we should have a long string in the node
97
ok(!longStringFront.inlineTextChild, "Text node is too long to be inlined.");
98
99
valueNode.nodeValue = longString;
100
gWalker.once("mutations", (changes) => {
101
ok(!longStringFront.inlineTextChild, "Text node is too long to be inlined.");
102
ok(!changes.some(change => change.type === "inlineTextChild"),
103
"No inline text child mutation was fired.");
104
checkNodeFrontValue(valueFront, longString).then(runNextTest);
105
});
106
}
107
108
function testSetShortValue() {
109
ok(!longStringFront.inlineTextChild, "Text node is too long to be inlined.");
110
111
valueNode.nodeValue = shortString;
112
gWalker.once("mutations", (changes) => {
113
ok(!!longStringFront.inlineTextChild, "Text node is short enough to be inlined.");
114
ok(changes.some(change => change.type === "inlineTextChild"),
115
"An inlineTextChild mutation was fired.");
116
checkNodeFrontValue(valueFront, shortString).then(runNextTest);
117
});
118
}
119
120
function testKeepShortValue() {
121
ok(!!longStringFront.inlineTextChild, "Text node is short enough to be inlined.");
122
123
valueNode.nodeValue = shortString2;
124
gWalker.once("mutations", (changes) => {
125
ok(!!longStringFront.inlineTextChild, "Text node is short enough to be inlined.");
126
ok(!changes.some(change => change.type === "inlineTextChild"),
127
"No inline text child mutation was fired.");
128
checkNodeFrontValue(valueFront, shortString2).then(runNextTest);
129
});
130
}
131
132
function testSetLongValue() {
133
ok(!!longStringFront.inlineTextChild, "Text node is short enough to be inlined.");
134
135
valueNode.nodeValue = longString;
136
gWalker.once("mutations", (changes) => {
137
ok(!longStringFront.inlineTextChild, "Text node is too long to be inlined.");
138
ok(changes.some(change => change.type === "inlineTextChild"),
139
"An inlineTextChild mutation was fired.");
140
checkNodeFrontValue(valueFront, longString).then(runNextTest);
141
});
142
}
143
144
addTest(function cleanup() {
145
gInspectee = null;
146
gWalker = null;
147
runNextTest();
148
});
149
150
</script>
151
</head>
152
<body>
153
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
154
<a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
155
<p id="display"></p>
156
<div id="content" style="display: none">
157
158
</div>
159
<pre id="test">
160
</pre>
161
</body>
162
</html>