Bug 1325988 - Fix ESLint issues in devtools/server/tests/mochitest/ r=tromey

MozReview-Commit-ID: BFaOv5i5Tun

--HG--
extra : rebase_source : 5c2b5d1867eb5b48c56725b87d71dae72a83eb34
This commit is contained in:
Fabien Casters 2017-03-13 21:15:44 +01:00
parent 33a9e6d050
commit 7b53fcdbb6
92 changed files with 1568 additions and 1454 deletions

View file

@ -134,7 +134,6 @@ devtools/server/actors/stylesheets.js
devtools/server/tests/browser/storage-*.html devtools/server/tests/browser/storage-*.html
!devtools/server/tests/browser/storage-unsecured-iframe.html !devtools/server/tests/browser/storage-unsecured-iframe.html
devtools/server/tests/browser/stylesheets-nested-iframes.html devtools/server/tests/browser/stylesheets-nested-iframes.html
devtools/server/tests/mochitest/**
devtools/server/tests/unit/** devtools/server/tests/unit/**
devtools/shared/platform/content/test/test_clipboard.html devtools/shared/platform/content/test/test_clipboard.html
devtools/shared/qrcode/tests/mochitest/test_decode.html devtools/shared/qrcode/tests/mochitest/test_decode.html

View file

@ -1 +1,4 @@
"use strict";
// eslint-disable-next-line no-debugger
debugger; debugger;

View file

@ -1,6 +1,14 @@
<head> <head>
<!-- Static (not dynamically inserted) inline script. --> <!-- Static (not dynamically inserted) inline script. -->
<script id='franz'>function franz() { debugger; }</script> <script id='franz'>
/* exported franz */
"use strict";
function franz() {
// eslint-disable-next-line no-debugger
debugger;
}
</script>
<!-- Static out-of-line script element. --> <!-- Static out-of-line script element. -->
<script id='heinrich' src='Debugger.Source.prototype.element.js'></script> <script id='heinrich' src='Debugger.Source.prototype.element.js'></script>

View file

@ -1 +1,6 @@
function heinrichFun() { franz(); } /* exported heinrichFun */
"use strict";
function heinrichFun() {
franz();
}

View file

@ -101,8 +101,10 @@
} }
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
window.onload = function() { "use strict";
window.opener.postMessage('ready', '*');
window.onload = function () {
window.opener.postMessage("ready", "*");
}; };
</script> </script>
</head> </head>

View file

@ -1,4 +1,8 @@
var Cu = Components.utils; /* exported DirectorRegistryFront, DirectorManagerFront, Task,
newConnectedDebuggerClient, purgeInstalledDirectorScripts */
"use strict";
const Cu = Components.utils;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {DebuggerClient} = require("devtools/shared/client/main"); const {DebuggerClient} = require("devtools/shared/client/main");
const {DebuggerServer} = require("devtools/server/main"); const {DebuggerServer} = require("devtools/server/main");
@ -25,12 +29,12 @@ const { Task } = require("devtools/shared/task");
**********************************/ **********************************/
function* newConnectedDebuggerClient(opts) { function* newConnectedDebuggerClient(opts) {
var transport = DebuggerServer.connectPipe(); let transport = DebuggerServer.connectPipe();
var client = new DebuggerClient(transport); let client = new DebuggerClient(transport);
yield client.connect(); yield client.connect();
var root = yield client.listTabs(); let root = yield client.listTabs();
return { return {
client: client, client: client,

View file

@ -1,5 +1,7 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
/* exported HelloActor */
"use strict";
const protocol = require("devtools/shared/protocol"); const protocol = require("devtools/shared/protocol");

View file

@ -1,18 +1,20 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Inspector Eyedropper tests</title> <title>Inspector Eyedropper tests</title>
<style> <style>
html { html {
background: black; background: black;
} }
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
window.onload = function() { "use strict";
window.opener.postMessage('ready', '*');
}; window.onload = function () {
</script> window.opener.postMessage("ready", "*");
</head> };
</body> </script>
</body> </head>
</html> </body>
</body>
</html>

View file

@ -1,3 +1,9 @@
/* exported attachURL, promiseDone, assertOwnershipTrees, checkMissing, checkAvailable,
promiseOnce, isSrcChange, isUnretained, isNewRoot, assertSrcChange, assertUnload,
assertFrameLoad, assertChildList, waitForMutation, addTest, addAsyncTest,
runNextTest */
"use strict";
var Cu = Components.utils; var Cu = Components.utils;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
@ -15,7 +21,6 @@ SimpleTest.registerCleanupFunction(function () {
Services.prefs.clearUserPref("devtools.debugger.log"); Services.prefs.clearUserPref("devtools.debugger.log");
}); });
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
@ -40,8 +45,8 @@ SimpleTest.registerCleanupFunction(function () {
* and disconnect its debugger client. * and disconnect its debugger client.
*/ */
function attachURL(url, callback) { function attachURL(url, callback) {
var win = window.open(url, "_blank"); let win = window.open(url, "_blank");
var client = null; let client = null;
let cleanup = () => { let cleanup = () => {
if (client) { if (client) {
@ -63,7 +68,8 @@ function attachURL(url, callback) {
for (let tab of response.tabs) { for (let tab of response.tabs) {
if (tab.url === url) { if (tab.url === url) {
window.removeEventListener("message", loadListener); window.removeEventListener("message", loadListener);
client.attachTab(tab.actor, function (aResponse, aTabClient) { // eslint-disable-next-line max-nested-callbacks
client.attachTab(tab.actor, function (_response, _tabClient) {
try { try {
callback(null, client, tab, win.document); callback(null, client, tab, win.document);
} catch (ex) { } catch (ex) {
@ -125,15 +131,18 @@ function serverOwnershipTree(walker) {
return { return {
root: serverOwnershipSubtree(serverWalker, serverWalker.rootDoc), root: serverOwnershipSubtree(serverWalker, serverWalker.rootDoc),
orphaned: [...serverWalker._orphaned].map(o => serverOwnershipSubtree(serverWalker, o.rawNode)), orphaned: [...serverWalker._orphaned]
retained: [...serverWalker._retainedOrphans].map(o => serverOwnershipSubtree(serverWalker, o.rawNode)) .map(o => serverOwnershipSubtree(serverWalker, o.rawNode)),
retained: [...serverWalker._retainedOrphans]
.map(o => serverOwnershipSubtree(serverWalker, o.rawNode))
}; };
} }
function clientOwnershipSubtree(node) { function clientOwnershipSubtree(node) {
return { return {
name: node.actorID, name: node.actorID,
children: sortOwnershipChildren(node.treeChildren().map(child => clientOwnershipSubtree(child))) children: sortOwnershipChildren(node.treeChildren()
.map(child => clientOwnershipSubtree(child)))
}; };
} }
@ -156,7 +165,8 @@ function ownershipTreeSize(tree) {
function assertOwnershipTrees(walker) { function assertOwnershipTrees(walker) {
let serverTree = serverOwnershipTree(walker); let serverTree = serverOwnershipTree(walker);
let clientTree = clientOwnershipTree(walker); let clientTree = clientOwnershipTree(walker);
is(JSON.stringify(clientTree, null, " "), JSON.stringify(serverTree, null, " "), "Server and client ownership trees should match."); is(JSON.stringify(clientTree, null, " "), JSON.stringify(serverTree, null, " "),
"Server and client ownership trees should match.");
return ownershipTreeSize(clientTree.root); return ownershipTreeSize(clientTree.root);
} }
@ -189,14 +199,15 @@ function checkAvailable(client, actorID) {
to: actorID, to: actorID,
type: "garbageAvailableTest", type: "garbageAvailableTest",
}, response => { }, response => {
is(response.error, "unrecognizedPacketType", "node list actor should be contactable."); is(response.error, "unrecognizedPacketType",
"node list actor should be contactable.");
deferred.resolve(undefined); deferred.resolve(undefined);
}); });
return deferred.promise; return deferred.promise;
} }
function promiseDone(promise) { function promiseDone(currentPromise) {
promise.then(null, err => { currentPromise.then(null, err => {
ok(false, "Promise failed: " + err); ok(false, "Promise failed: " + err);
if (err.stack) { if (err.stack) {
dump(err.stack); dump(err.stack);
@ -207,10 +218,6 @@ function promiseDone(promise) {
// Mutation list testing // Mutation list testing
function isSrcChange(change) {
return (change.type === "attributes" && change.attributeName === "src");
}
function assertAndStrip(mutations, message, test) { function assertAndStrip(mutations, message, test) {
let size = mutations.length; let size = mutations.length;
mutations = mutations.filter(test); mutations = mutations.filter(test);
@ -245,7 +252,8 @@ function isNewRoot(change) {
// Make sure an iframe's src attribute changed and then // Make sure an iframe's src attribute changed and then
// strip that mutation out of the list. // strip that mutation out of the list.
function assertSrcChange(mutations) { function assertSrcChange(mutations) {
return assertAndStrip(mutations, "Should have had an iframe source change.", isSrcChange); return assertAndStrip(mutations, "Should have had an iframe source change.",
isSrcChange);
} }
// Make sure there's an unload in the mutation list and strip // Make sure there's an unload in the mutation list and strip
@ -285,7 +293,6 @@ function waitForMutation(walker, test, mutations = []) {
return deferred.promise; return deferred.promise;
} }
var _tests = []; var _tests = [];
function addTest(test) { function addTest(test) {
_tests.push(test); _tests.push(test);
@ -300,7 +307,7 @@ function runNextTest() {
SimpleTest.finish(); SimpleTest.finish();
return; return;
} }
var fn = _tests.shift(); let fn = _tests.shift();
try { try {
fn(); fn();
} catch (ex) { } catch (ex) {

View file

@ -15,8 +15,10 @@
} }
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
window.onload = function() { "use strict";
window.opener.postMessage('ready', '*');
window.onload = function () {
window.opener.postMessage("ready", "*");
}; };
</script> </script>
</head> </head>
@ -49,4 +51,4 @@
<div class="💩" id="💩" 💩="💩"></div> <div class="💩" id="💩" 💩="💩"></div>
</body> </body>
</html> </html>

View file

@ -1,8 +1,10 @@
<html> <html>
<script> <script>
"use strict";
window.onload = () => { window.onload = () => {
window.opener.postMessage('ready', '*') window.opener.postMessage("ready", "*");
} };
</script> </script>
<style> <style>
.inheritable-rule { .inheritable-rule {

View file

@ -18,26 +18,27 @@
} }
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
window.onload = function() { "use strict";
window.onload = function () {
// Set up a basic shadow DOM // Set up a basic shadow DOM
var host = document.querySelector('#shadow'); let host = document.querySelector("#shadow");
if (host.createShadowRoot) { if (host.createShadowRoot) {
var root = host.createShadowRoot(); let root = host.createShadowRoot();
root.innerHTML = '<h3>Shadow <em>DOM</em></h3><select multiple></select>'; root.innerHTML = "<h3>Shadow <em>DOM</em></h3><select multiple></select>";
} }
// Put a copy of the body in an iframe to test frame traversal. // Put a copy of the body in an iframe to test frame traversal.
var body = document.querySelector("body"); let body = document.querySelector("body");
var data = "data:text/html,<html>" + body.outerHTML + "<html>"; let data = "data:text/html,<html>" + body.outerHTML + "<html>";
var iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.setAttribute("id", "childFrame"); iframe.setAttribute("id", "childFrame");
iframe.onload = function() { iframe.onload = function () {
window.opener.postMessage('ready', '*') window.opener.postMessage("ready", "*");
}; };
iframe.src = data; iframe.src = data;
body.appendChild(iframe); body.appendChild(iframe);
} };
</script> </script>
</head> </head>
<body style="background-color:white"> <body style="background-color:white">

View file

@ -2,8 +2,10 @@
<head> <head>
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
window.onload = function() { "use strict";
window.opener.postMessage('ready', '*');
window.onload = function () {
window.opener.postMessage("ready", "*");
}; };
</script> </script>
</body> </body>

View file

@ -7,6 +7,8 @@
<img class="small" src="small-image.gif"> <img class="small" src="small-image.gif">
<img class="data" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAJklEQVRIie3NMREAAAgAoe9fWls4eAzMVM0xoVAoFAqFQqFQ+C9chp4NHvu+4Q4AAAAASUVORK5CYII="> <img class="data" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAJklEQVRIie3NMREAAAgAoe9fWls4eAzMVM0xoVAoFAqFQqFQ+C9chp4NHvu+4Q4AAAAASUVORK5CYII=">
<script> <script>
"use strict";
window.onload = () => { window.onload = () => {
var canvas = document.querySelector("canvas"), ctx = canvas.getContext("2d"); var canvas = document.querySelector("canvas"), ctx = canvas.getContext("2d");
canvas.width = 1000; canvas.width = 1000;
@ -14,8 +16,8 @@
ctx.fillStyle = "red"; ctx.fillStyle = "red";
ctx.fillRect(0, 0, 1000, 2000); ctx.fillRect(0, 0, 1000, 2000);
window.opener.postMessage('ready', '*') window.opener.postMessage("ready", "*");
} };
</script> </script>
</body> </body>
</html> </html>

View file

@ -1,14 +1,16 @@
var Cu = Components.utils; /* exported Task, startServerAndGetSelectedTabMemory, destroyServerAndFinish,
var Cc = Components.classes; waitForTime, waitUntil */
var Ci = Components.interfaces; "use strict";
var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); const Cu = Components.utils;
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
const Services = require("Services");
const { Task } = require("devtools/shared/task"); const { Task } = require("devtools/shared/task");
var Services = require("Services"); const { DebuggerClient } = require("devtools/shared/client/main");
var { DebuggerClient } = require("devtools/shared/client/main"); const { DebuggerServer } = require("devtools/server/main");
var { DebuggerServer } = require("devtools/server/main");
var { MemoryFront } = require("devtools/shared/fronts/memory"); const { MemoryFront } = require("devtools/shared/fronts/memory");
// Always log packets when running tests. // Always log packets when running tests.
Services.prefs.setBoolPref("devtools.debugger.log", true); Services.prefs.setBoolPref("devtools.debugger.log", true);
@ -19,13 +21,13 @@ SimpleTest.registerCleanupFunction(function () {
function startServerAndGetSelectedTabMemory() { function startServerAndGetSelectedTabMemory() {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
var client = new DebuggerClient(DebuggerServer.connectPipe()); let client = new DebuggerClient(DebuggerServer.connectPipe());
return client.connect() return client.connect()
.then(() => client.listTabs()) .then(() => client.listTabs())
.then(response => { .then(response => {
var form = response.tabs[response.selected]; let form = response.tabs[response.selected];
var memory = MemoryFront(client, form, response); let memory = MemoryFront(client, form, response);
return { memory, client }; return { memory, client };
}); });
@ -48,5 +50,6 @@ function waitUntil(predicate) {
if (predicate()) { if (predicate()) {
return Promise.resolve(true); return Promise.resolve(true);
} }
return new Promise(resolve => setTimeout(() => waitUntil(predicate).then(() => resolve(true)), 10)); return new Promise(resolve => setTimeout(() => waitUntil(predicate)
.then(() => resolve(true)), 10));
} }

View file

@ -1,8 +1,10 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<script> <script>
var xhr = new XMLHttpRequest; "use strict";
var xhr = new XMLHttpRequest();
xhr.timeout = 1742; xhr.timeout = 1742;
xhr.expando = 'Expando!'; xhr.expando = "Expando!";
</script> </script>
</html> </html>

View file

@ -1,6 +1,8 @@
"use strict";
const {Cc, Ci} = require("chrome"); const {Cc, Ci} = require("chrome");
const cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]. const cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
getService(Ci.nsIMessageListenerManager); .getService(Ci.nsIMessageListenerManager);
const { DebuggerServer } = require("devtools/server/main"); const { DebuggerServer } = require("devtools/server/main");
exports.setupChild = function (a, b, c) { exports.setupChild = function (a, b, c) {

View file

@ -1,3 +1,5 @@
"use strict";
var {Ci} = require("chrome"); var {Ci} = require("chrome");
var Services = require("Services"); var Services = require("Services");

View file

@ -14,6 +14,7 @@ Debugger.Script.prototype.global should return innerize globals, not WindowProxi
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
Components.utils.import("resource://gre/modules/jsdebugger.jsm"); Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this); addDebuggerToGlobal(this);
@ -21,27 +22,26 @@ addDebuggerToGlobal(this);
window.onload = function () { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.src = "data:text/html,<script>function glorp() { }<\/script>"; iframe.src = "data:text/html,<script>function glorp() { }<\/script>";
iframe.onload = firstOnLoadHandler; iframe.onload = firstOnLoadHandler;
document.body.appendChild(iframe); document.body.appendChild(iframe);
function firstOnLoadHandler() { function firstOnLoadHandler() {
var dbg = new Debugger; let dbg = new Debugger();
var iframeDO = dbg.addDebuggee(iframe.contentWindow); let iframeDO = dbg.addDebuggee(iframe.contentWindow);
// For sanity: check that the debuggee global is the inner window, // For sanity: check that the debuggee global is the inner window,
// and that the outer window gets a distinct D.O. // and that the outer window gets a distinct D.O.
var iframeWindowProxyDO = iframeDO.makeDebuggeeValue(iframe.contentWindow); let iframeWindowProxyDO = iframeDO.makeDebuggeeValue(iframe.contentWindow);
ok(iframeDO !== iframeWindowProxyDO); ok(iframeDO !== iframeWindowProxyDO);
// The real test: Debugger.Script.prototype.global returns inner windows. // The real test: Debugger.Script.prototype.global returns inner windows.
ok(iframeDO.getOwnPropertyDescriptor('glorp').value.script.global === iframeDO); ok(iframeDO.getOwnPropertyDescriptor("glorp").value.script.global === iframeDO);
SimpleTest.finish(); SimpleTest.finish();
} }
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -15,6 +15,7 @@ element to which code is attached (if any), and how.
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
Components.utils.import("resource://gre/modules/jsdebugger.jsm"); Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this); addDebuggerToGlobal(this);
@ -22,65 +23,65 @@ addDebuggerToGlobal(this);
window.onload = function () { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var log = ''; let log = "";
var doc, dieter, ulrich, isolde, albrecht; let doc, dieter, ulrich, isolde, albrecht;
var dbg, iframeDO, DOFor; let dbg, iframeDO, DOFor;
// Create an iframe to debug. // Create an iframe to debug.
// We can't use a data: URL here, because we want to test script elements // We can't use a data: URL here, because we want to test script elements
// that refer to the JavaScript via 'src' attributes, and data: documents // that refer to the JavaScript via 'src' attributes, and data: documents
// can't refer to those. So we use a separate HTML document. // can't refer to those. So we use a separate HTML document.
var iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.src = "Debugger.Source.prototype.element.html"; iframe.src = "Debugger.Source.prototype.element.html";
iframe.onload = onLoadHandler; iframe.onload = onLoadHandler;
document.body.appendChild(iframe); document.body.appendChild(iframe);
function onLoadHandler() { function onLoadHandler() {
log += 'l'; log += "l";
// Now that the iframe's window has been created, we can add // Now that the iframe's window has been created, we can add
// it as a debuggee. // it as a debuggee.
dbg = new Debugger; dbg = new Debugger();
dbg.onDebuggerStatement = franzDebuggerHandler; dbg.onDebuggerStatement = franzDebuggerHandler;
iframeDO = dbg.addDebuggee(iframe.contentWindow); iframeDO = dbg.addDebuggee(iframe.contentWindow);
DOFor = iframeDO.makeDebuggeeValue.bind(iframeDO); DOFor = iframeDO.makeDebuggeeValue.bind(iframeDO);
// Send a click event to heidi. // Send a click event to heidi.
doc = iframe.contentWindow.document; doc = iframe.contentWindow.document;
doc.getElementById('heidi').dispatchEvent(new Event('click')); doc.getElementById("heidi").dispatchEvent(new Event("click"));
} }
function franzDebuggerHandler(frame) { function franzDebuggerHandler(frame) {
log += 'f'; log += "f";
// The top stack frame should be franz, belonging to the script element. // The top stack frame should be franz, belonging to the script element.
ok(frame.callee.displayName === 'franz', 'top frame is franz'); ok(frame.callee.displayName === "franz", "top frame is franz");
ok(frame.script.source.element === DOFor(doc.getElementById('franz')), ok(frame.script.source.element === DOFor(doc.getElementById("franz")),
'top frame source belongs to element franz'); "top frame source belongs to element franz");
ok(frame.script.source.elementAttributeName === undefined, ok(frame.script.source.elementAttributeName === undefined,
"top frame source doesn't belong to an attribute"); "top frame source doesn't belong to an attribute");
// The second stack frame should belong to heinrich. // The second stack frame should belong to heinrich.
ok(frame.older.script.source.element === DOFor(doc.getElementById('heinrich')), ok(frame.older.script.source.element === DOFor(doc.getElementById("heinrich")),
"second frame source belongs to element heinrich"); "second frame source belongs to element heinrich");
ok(frame.older.script.source.elementAttributeName === undefined, ok(frame.older.script.source.elementAttributeName === undefined,
"second frame source doesn't belong to an attribute"); "second frame source doesn't belong to an attribute");
// The next stack frame should belong to heidi's onclick handler. // The next stack frame should belong to heidi's onclick handler.
ok(frame.older.older.script.source.element === DOFor(doc.getElementById('heidi')), ok(frame.older.older.script.source.element === DOFor(doc.getElementById("heidi")),
'third frame source belongs to element heidi'); "third frame source belongs to element heidi");
ok(frame.older.older.script.source.elementAttributeName === 'onclick', ok(frame.older.older.script.source.elementAttributeName === "onclick",
"third frame source belongs to 'onclick' attribute"); "third frame source belongs to 'onclick' attribute");
// Try a dynamically inserted inline script element. // Try a dynamically inserted inline script element.
ulrich = doc.createElement('script'); ulrich = doc.createElement("script");
ulrich.text = 'debugger;' ulrich.text = "debugger;";
dbg.onDebuggerStatement = ulrichDebuggerHandler; dbg.onDebuggerStatement = ulrichDebuggerHandler;
doc.body.appendChild(ulrich); doc.body.appendChild(ulrich);
} }
function ulrichDebuggerHandler(frame) { function ulrichDebuggerHandler(frame) {
log += 'u'; log += "u";
// The top frame should be ulrich's text. // The top frame should be ulrich's text.
ok(frame.script.source.element === DOFor(ulrich), ok(frame.script.source.element === DOFor(ulrich),
@ -89,23 +90,23 @@ window.onload = function () {
"top frame is not on an attribute of ulrich"); "top frame is not on an attribute of ulrich");
// Try a dynamically inserted out-of-line script element. // Try a dynamically inserted out-of-line script element.
isolde = doc.createElement('script'); isolde = doc.createElement("script");
isolde.setAttribute('src', 'Debugger.Source.prototype.element-2.js'); isolde.setAttribute("src", "Debugger.Source.prototype.element-2.js");
isolde.setAttribute('id', 'idolde, my dear'); isolde.setAttribute("id", "idolde, my dear");
dbg.onDebuggerStatement = isoldeDebuggerHandler; dbg.onDebuggerStatement = isoldeDebuggerHandler;
doc.body.appendChild(isolde); doc.body.appendChild(isolde);
} }
function isoldeDebuggerHandler(frame) { function isoldeDebuggerHandler(frame) {
log += 'i'; log += "i";
// The top frame should belong to isolde. // The top frame should belong to isolde.
ok(frame.script.source.element === DOFor(isolde), ok(frame.script.source.element === DOFor(isolde),
"top frame belongs to isolde"); "top frame belongs to isolde");
info("frame.script.source.element is: " + uneval(frame.script.source.element)); info("frame.script.source.element is: " + uneval(frame.script.source.element));
if (typeof frame.script.source.element.unsafeDereference() == 'object') { if (typeof frame.script.source.element.unsafeDereference() == "object") {
info(" toString: " + frame.script.source.element.unsafeDereference()); info(" toString: " + frame.script.source.element.unsafeDereference());
info(" id: " + frame.script.source.element.unsafeDereference().id); info(" id: " + frame.script.source.element.unsafeDereference().id);
} }
ok(frame.script.source.elementAttributeName === undefined, ok(frame.script.source.elementAttributeName === undefined,
@ -114,20 +115,20 @@ window.onload = function () {
uneval(frame.script.source.elementAttributeName)); uneval(frame.script.source.elementAttributeName));
// Try a dynamically created div element with a handler. // Try a dynamically created div element with a handler.
dieter = doc.createElement('div'); dieter = doc.createElement("div");
dieter.setAttribute('id', 'dieter'); dieter.setAttribute("id", "dieter");
dieter.setAttribute('ondrag', 'debugger;'); dieter.setAttribute("ondrag", "debugger;");
dbg.onDebuggerStatement = dieterDebuggerHandler; dbg.onDebuggerStatement = dieterDebuggerHandler;
dieter.dispatchEvent(new Event('drag')); dieter.dispatchEvent(new Event("drag"));
} }
function dieterDebuggerHandler(frame) { function dieterDebuggerHandler(frame) {
log += 'd'; log += "d";
// The top frame should belong to dieter's ondrag handler. // The top frame should belong to dieter's ondrag handler.
ok(frame.script.source.element === DOFor(dieter), ok(frame.script.source.element === DOFor(dieter),
"second event's handler belongs to dieter"); "second event's handler belongs to dieter");
ok(frame.script.source.elementAttributeName === 'ondrag', ok(frame.script.source.elementAttributeName === "ondrag",
"second event's handler is on dieter's 'ondrag' element"); "second event's handler is on dieter's 'ondrag' element");
// Try sending an 'onresize' event to the window. // Try sending an 'onresize' event to the window.
@ -139,43 +140,42 @@ window.onload = function () {
// won't affect propagation. Then, the content event only runs its // won't affect propagation. Then, the content event only runs its
// 'debugger' statement when the event is cancelable. It's a kludge. // 'debugger' statement when the event is cancelable. It's a kludge.
dbg.onDebuggerStatement = resizeDebuggerHandler; dbg.onDebuggerStatement = resizeDebuggerHandler;
iframe.contentWindow.dispatchEvent(new Event('resize', { cancelable: true })); iframe.contentWindow.dispatchEvent(new Event("resize", { cancelable: true }));
} }
function resizeDebuggerHandler(frame) { function resizeDebuggerHandler(frame) {
log += 'e'; log += "e";
// The top frame should belong to the body's 'onresize' handler, even // The top frame should belong to the body's 'onresize' handler, even
// though we sent the message to the window and it was handled. // though we sent the message to the window and it was handled.
ok(frame.script.source.element === DOFor(doc.body), ok(frame.script.source.element === DOFor(doc.body),
"onresize event handler belongs to body element"); "onresize event handler belongs to body element");
ok(frame.script.source.elementAttributeName === 'onresize', ok(frame.script.source.elementAttributeName === "onresize",
"onresize event handler is on body element's 'onresize' attribute"); "onresize event handler is on body element's 'onresize' attribute");
// In SVG, the event and the attribute that holds that event's handler // In SVG, the event and the attribute that holds that event's handler
// have different names. Debugger.Source.prototype.elementAttributeName // have different names. Debugger.Source.prototype.elementAttributeName
// should report (as one might infer) the attribute name, not the event // should report (as one might infer) the attribute name, not the event
// name. // name.
albrecht = doc.createElementNS('http://www.w3.org/2000/svg', 'svg'); albrecht = doc.createElementNS("http://www.w3.org/2000/svg", "svg");
albrecht.setAttribute('onload', 'debugger;'); albrecht.setAttribute("onload", "debugger;");
dbg.onDebuggerStatement = SVGLoadHandler; dbg.onDebuggerStatement = SVGLoadHandler;
albrecht.dispatchEvent(new Event("SVGLoad")); albrecht.dispatchEvent(new Event("SVGLoad"));
} }
function SVGLoadHandler(frame) { function SVGLoadHandler(frame) {
log += 's'; log += "s";
// The top frame's source should be on albrecht's 'onload' attribute. // The top frame's source should be on albrecht's 'onload' attribute.
ok(frame.script.source.element === DOFor(albrecht), ok(frame.script.source.element === DOFor(albrecht),
"SVGLoad event handler belongs to albrecht"); "SVGLoad event handler belongs to albrecht");
ok(frame.script.source.elementAttributeName === 'onload', ok(frame.script.source.elementAttributeName === "onload",
"SVGLoad event handler is on albrecht's 'onload' attribute"); "SVGLoad event handler is on albrecht's 'onload' attribute");
ok(log === 'lfuides', "all tests actually ran"); ok(log === "lfuides", "all tests actually ran");
SimpleTest.finish(); SimpleTest.finish();
} }
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -15,6 +15,7 @@ behave when 'eval' is called with no scripted frames active at all.
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
Components.utils.import("resource://gre/modules/jsdebugger.jsm"); Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this); addDebuggerToGlobal(this);
@ -22,10 +23,10 @@ addDebuggerToGlobal(this);
window.onload = function () { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var dbg, iframeDO, doc, script2DO; let dbg, iframeDO, doc, script2DO;
// Create an iframe to debug. // Create an iframe to debug.
var iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.src = "data:text/html,<div>Hi!</div>"; iframe.src = "data:text/html,<div>Hi!</div>";
iframe.onload = onLoadHandler; iframe.onload = onLoadHandler;
document.body.appendChild(iframe); document.body.appendChild(iframe);
@ -33,11 +34,11 @@ window.onload = function () {
function onLoadHandler() { function onLoadHandler() {
// Now that the iframe's window has been created, we can add // Now that the iframe's window has been created, we can add
// it as a debuggee. // it as a debuggee.
dbg = new Debugger; dbg = new Debugger();
iframeDO = dbg.addDebuggee(iframe.contentWindow); iframeDO = dbg.addDebuggee(iframe.contentWindow);
doc = iframe.contentWindow.document; doc = iframe.contentWindow.document;
var script = doc.createElement('script'); let script = doc.createElement("script");
script.text = "setTimeout(eval.bind(null, 'debugger;'), 0);"; script.text = "setTimeout(eval.bind(null, 'debugger;'), 0);";
dbg.onDebuggerStatement = timerHandler; dbg.onDebuggerStatement = timerHandler;
doc.body.appendChild(script); doc.body.appendChild(script);
@ -46,7 +47,7 @@ window.onload = function () {
function timerHandler(frame) { function timerHandler(frame) {
// The top stack frame's source should have an undefined // The top stack frame's source should have an undefined
// introduction script and introduction offset. // introduction script and introduction offset.
var source = frame.script.source; let source = frame.script.source;
ok(source.introductionScript === undefined, ok(source.introductionScript === undefined,
"setTimeout eval introductionScript is undefined"); "setTimeout eval introductionScript is undefined");
ok(source.introductionOffset === undefined, ok(source.introductionOffset === undefined,
@ -55,7 +56,7 @@ window.onload = function () {
// Check that the above isn't just some quirk of iframes, or the // Check that the above isn't just some quirk of iframes, or the
// browser milieu destroying information: an eval script should indeed // browser milieu destroying information: an eval script should indeed
// have proper introduction information. // have proper introduction information.
var script2 = doc.createElement('script'); let script2 = doc.createElement("script");
script2.text = "eval('debugger;');"; script2.text = "eval('debugger;');";
script2DO = iframeDO.makeDebuggeeValue(script2); script2DO = iframeDO.makeDebuggeeValue(script2);
dbg.onDebuggerStatement = evalHandler; dbg.onDebuggerStatement = evalHandler;
@ -65,10 +66,10 @@ window.onload = function () {
function evalHandler(frame) { function evalHandler(frame) {
// The top stack frame's source should be introduced by the script that // The top stack frame's source should be introduced by the script that
// called eval. // called eval.
var source = frame.script.source; let source = frame.script.source;
var frame2 = frame.older; let frame2 = frame.older;
ok(source.introductionType === 'eval', ok(source.introductionType === "eval",
"top frame's source was introduced by 'eval'"); "top frame's source was introduced by 'eval'");
ok(source.introductionScript === frame2.script, ok(source.introductionScript === frame2.script,
"eval frame's introduction script is the older frame's script"); "eval frame's introduction script is the older frame's script");
@ -81,7 +82,7 @@ window.onload = function () {
// information. (In the future, we certainly could point at the call // information. (In the future, we certainly could point at the call
// that inserted the script element into the document; if that happens, // that inserted the script element into the document; if that happens,
// we can update this test.) // we can update this test.)
ok(frame2.script.source.introductionType === 'scriptElement', ok(frame2.script.source.introductionType === "scriptElement",
"older frame has no introduction type"); "older frame has no introduction type");
ok(frame2.script.source.introductionScript === undefined, ok(frame2.script.source.introductionScript === undefined,
"older frame has no introduction script"); "older frame has no introduction script");
@ -90,7 +91,7 @@ window.onload = function () {
SimpleTest.finish(); SimpleTest.finish();
} }
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -16,13 +16,14 @@ JavaScrip appearing in an inline event handler attribute.
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
Components.utils.import("resource://gre/modules/jsdebugger.jsm"); Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this); addDebuggerToGlobal(this);
var dbg; let dbg;
var iframeDO, doc; let iframeDO, doc;
var Tootles, TootlesDO; let Tootles, TootlesDO;
window.onload = function () { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
@ -31,7 +32,7 @@ window.onload = function () {
addTest(function setup() { addTest(function setup() {
// Create an iframe to debug. // Create an iframe to debug.
var iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.src = "data:text/html," + iframe.src = "data:text/html," +
"<div id='Tootles' onclick='debugger;'>I'm a DIV!</div>" + "<div id='Tootles' onclick='debugger;'>I'm a DIV!</div>" +
"<script id='Auddie'>function auddie() { debugger; }<\/script>"; "<script id='Auddie'>function auddie() { debugger; }<\/script>";
@ -41,88 +42,84 @@ addTest(function setup() {
function onLoadHandler() { function onLoadHandler() {
// Now that the iframe's window has been created, we can add // Now that the iframe's window has been created, we can add
// it as a debuggee. // it as a debuggee.
dbg = new Debugger; dbg = new Debugger();
iframeDO = dbg.addDebuggee(iframe.contentWindow); iframeDO = dbg.addDebuggee(iframe.contentWindow);
doc = iframe.contentWindow.document; doc = iframe.contentWindow.document;
Tootles = doc.getElementById('Tootles'); Tootles = doc.getElementById("Tootles");
TootlesDO = iframeDO.makeDebuggeeValue(Tootles); TootlesDO = iframeDO.makeDebuggeeValue(Tootles);
runNextTest(); runNextTest();
} }
}); });
// Check the introduction type of in-markup event handler code. // Check the introduction type of in-markup event handler code.
// Send a click event to Tootles, whose handler has a 'debugger' statement, // Send a click event to Tootles, whose handler has a 'debugger' statement,
// and check that script's introduction type. // and check that script's introduction type.
addTest(function ClickOnTootles() { addTest(function ClickOnTootles() {
dbg.onDebuggerStatement = TootlesClickDebugger; dbg.onDebuggerStatement = TootlesClickDebugger;
Tootles.dispatchEvent(new Event('click')); Tootles.dispatchEvent(new Event("click"));
function TootlesClickDebugger(frame) { function TootlesClickDebugger(frame) {
// some sanity checks // some sanity checks
ok(frame.script.source.element === TootlesDO, ok(frame.script.source.element === TootlesDO,
"top frame source belongs to element 'Tootles'"); "top frame source belongs to element 'Tootles'");
is(frame.script.source.elementAttributeName, 'onclick', is(frame.script.source.elementAttributeName, "onclick",
"top frame source belongs to 'onclick' attribute"); "top frame source belongs to 'onclick' attribute");
// And, the actual point of this test: // And, the actual point of this test:
is(frame.script.source.introductionType, 'eventHandler', is(frame.script.source.introductionType, "eventHandler",
"top frame source's introductionType is 'eventHandler'"); "top frame source's introductionType is 'eventHandler'");
runNextTest(); runNextTest();
} }
}); });
// Check the introduction type of dynamically added event handler code. // Check the introduction type of dynamically added event handler code.
// Add a drag event handler to Tootles as a string, and then send // Add a drag event handler to Tootles as a string, and then send
// Tootles a drag event. // Tootles a drag event.
addTest(function DragTootles() { addTest(function DragTootles() {
dbg.onDebuggerStatement = TootlesDragDebugger; dbg.onDebuggerStatement = TootlesDragDebugger;
Tootles.setAttribute('ondrag', 'debugger;'); Tootles.setAttribute("ondrag", "debugger;");
Tootles.dispatchEvent(new Event('drag')); Tootles.dispatchEvent(new Event("drag"));
function TootlesDragDebugger(frame) { function TootlesDragDebugger(frame) {
// sanity checks // sanity checks
ok(frame.script.source.element === TootlesDO, ok(frame.script.source.element === TootlesDO,
"top frame source belongs to element 'Tootles'"); "top frame source belongs to element 'Tootles'");
is(frame.script.source.elementAttributeName, 'ondrag', is(frame.script.source.elementAttributeName, "ondrag",
"top frame source belongs to 'ondrag' attribute"); "top frame source belongs to 'ondrag' attribute");
// And, the actual point of this test: // And, the actual point of this test:
is(frame.script.source.introductionType, 'eventHandler', is(frame.script.source.introductionType, "eventHandler",
"top frame source's introductionType is 'eventHandler'"); "top frame source's introductionType is 'eventHandler'");
runNextTest(); runNextTest();
} }
}); });
// Check the introduction type of an in-markup script element. // Check the introduction type of an in-markup script element.
addTest(function checkAuddie() { addTest(function checkAuddie() {
var fnDO = iframeDO.getOwnPropertyDescriptor('auddie').value; let fnDO = iframeDO.getOwnPropertyDescriptor("auddie").value;
var AuddieDO = iframeDO.makeDebuggeeValue(doc.getElementById('Auddie')); let AuddieDO = iframeDO.makeDebuggeeValue(doc.getElementById("Auddie"));
is(fnDO.class, 'Function', is(fnDO.class, "Function",
"Script element 'Auddie' defined function 'auddie'."); "Script element 'Auddie' defined function 'auddie'.");
ok(fnDO.script.source.element === AuddieDO, ok(fnDO.script.source.element === AuddieDO,
"Function auddie's script belongs to script element 'Auddie'"); "Function auddie's script belongs to script element 'Auddie'");
is(fnDO.script.source.elementAttributeName, undefined, is(fnDO.script.source.elementAttributeName, undefined,
"Function auddie's script doesn't belong to any attribute of 'Auddie'"); "Function auddie's script doesn't belong to any attribute of 'Auddie'");
is(fnDO.script.source.introductionType, 'scriptElement', is(fnDO.script.source.introductionType, "scriptElement",
"Function auddie's script's source was introduced by a script element"); "Function auddie's script's source was introduced by a script element");
runNextTest(); runNextTest();
}); });
// Check the introduction type of a dynamically inserted script element. // Check the introduction type of a dynamically inserted script element.
addTest(function InsertRover() { addTest(function InsertRover() {
dbg.onDebuggerStatement = RoverDebugger; dbg.onDebuggerStatement = RoverDebugger;
var rover = doc.createElement('script'); let rover = doc.createElement("script");
var roverDO = iframeDO.makeDebuggeeValue(rover); let roverDO = iframeDO.makeDebuggeeValue(rover);
rover.text = 'debugger;'; rover.text = "debugger;";
doc.body.appendChild(rover); doc.body.appendChild(rover);
function RoverDebugger(frame) { function RoverDebugger(frame) {
@ -133,17 +130,16 @@ addTest(function InsertRover() {
"Rover script doesn't belong to an attribute of Rover"); "Rover script doesn't belong to an attribute of Rover");
// Check the introduction type. // Check the introduction type.
ok(frame.script.source.introductionType === 'scriptElement', ok(frame.script.source.introductionType === "scriptElement",
"Rover script's introduction type is 'scriptElement'"); "Rover script's introduction type is 'scriptElement'");
runNextTest(); runNextTest();
} }
}); });
// Create a XUL document with a script element, and check its introduction type. // Create a XUL document with a script element, and check its introduction type.
addTest(function XULDocumentScript() { addTest(function XULDocumentScript() {
var xulFrame = document.createElement('iframe'); let xulFrame = document.createElement("iframe");
xulFrame.src = "data:application/vnd.mozilla.xul+xml;charset=utf-8," + xulFrame.src = "data:application/vnd.mozilla.xul+xml;charset=utf-8," +
"<?xml version=\"1.0\"?>" + "<?xml version=\"1.0\"?>" +
"<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>" + "<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>" +
@ -155,12 +151,10 @@ addTest(function XULDocumentScript() {
function xulLoaded() { function xulLoaded() {
info("Loaded XUL document"); info("Loaded XUL document");
var xulFrameDO = dbg.addDebuggee(xulFrame.contentWindow); let xulFrameDO = dbg.addDebuggee(xulFrame.contentWindow);
var xulDoc = xulFrame.contentWindow.document; let xulFnDO = xulFrameDO.getOwnPropertyDescriptor("xulScriptFunc").value;
var xulieDO = xulFrameDO.makeDebuggeeValue(xulDoc.getElementById('xulie')); is(typeof xulFnDO, "object", "XUL script element defined 'xulScriptFunc'");
var xulFnDO = xulFrameDO.getOwnPropertyDescriptor('xulScriptFunc').value; is(xulFnDO.class, "Function",
is(typeof xulFnDO, 'object', "XUL script element defined 'xulScriptFunc'");
is(xulFnDO.class, 'Function',
"XUL global 'xulScriptFunc' is indeed a function"); "XUL global 'xulScriptFunc' is indeed a function");
// A XUL document's script elements' code gets shared amongst all // A XUL document's script elements' code gets shared amongst all
@ -169,12 +163,11 @@ addTest(function XULDocumentScript() {
is(xulFnDO.script.source.element, undefined, is(xulFnDO.script.source.element, undefined,
"XUL script code should not be attributed to any individual element"); "XUL script code should not be attributed to any individual element");
is(xulFnDO.script.source.introductionType, 'scriptElement', is(xulFnDO.script.source.introductionType, "scriptElement",
"xulScriptFunc's introduction type is 'scriptElement'"); "xulScriptFunc's introduction type is 'scriptElement'");
runNextTest(); runNextTest();
} }
}); });
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -11,67 +11,65 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1247243
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { "use strict";
const Ci = Components.interfaces;
window.onload = function () {
const {AnimationsFront} = require("devtools/shared/fronts/animation"); const {AnimationsFront} = require("devtools/shared/fronts/animation");
const {InspectorFront} = require("devtools/shared/fronts/inspector"); const {InspectorFront} = require("devtools/shared/fronts/inspector");
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
let gWalker = null; let gWalker = null;
let gClient = null;
let animationsFront = null; let animationsFront = null;
addTest(function setup() { addTest(function setup() {
info ("Setting up inspector and animation actors."); info("Setting up inspector and animation actors.");
let url = document.getElementById("animationContent").href; let url = document.getElementById("animationContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
animationsFront = new AnimationsFront(client, tab); animationsFront = new AnimationsFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
}); });
addAsyncTest(function* testActorLifetime() { addAsyncTest(function* testActorLifetime() {
info("Testing animated node actor");
info ("Testing animated node actor");
let animatedNodeActor = yield gWalker.querySelector(gWalker.rootNode, let animatedNodeActor = yield gWalker.querySelector(gWalker.rootNode,
".animated"); ".animated");
yield animationsFront.getAnimationPlayersForNode(animatedNodeActor); yield animationsFront.getAnimationPlayersForNode(animatedNodeActor);
let animationsActor = DebuggerServer._searchAllConnectionsForActor(animationsFront.actorID); let animationsActor = DebuggerServer
._searchAllConnectionsForActor(animationsFront.actorID);
is(animationsActor.actors.length, 1, is(animationsActor.actors.length, 1,
"AnimationActor have 1 AnimationPlayerActors"); "AnimationActor have 1 AnimationPlayerActors");
info ("Testing AnimationPlayerActors release"); info("Testing AnimationPlayerActors release");
let stillNodeActor = yield gWalker.querySelector(gWalker.rootNode, let stillNodeActor = yield gWalker.querySelector(gWalker.rootNode,
".still"); ".still");
yield animationsFront.getAnimationPlayersForNode(stillNodeActor); yield animationsFront.getAnimationPlayersForNode(stillNodeActor);
is(animationsActor.actors.length, 0, is(animationsActor.actors.length, 0,
"AnimationActor does not have any AnimationPlayerActors anymore"); "AnimationActor does not have any AnimationPlayerActors anymore");
info ("Testing multi animated node actor"); info("Testing multi animated node actor");
let multiNodeActor = yield gWalker.querySelector(gWalker.rootNode, let multiNodeActor = yield gWalker.querySelector(gWalker.rootNode,
".multi"); ".multi");
yield animationsFront.getAnimationPlayersForNode(multiNodeActor); yield animationsFront.getAnimationPlayersForNode(multiNodeActor);
is(animationsActor.actors.length, 2, is(animationsActor.actors.length, 2,
"AnimationActor has now 2 AnimationPlayerActors"); "AnimationActor has now 2 AnimationPlayerActors");
info ("Testing single animated node actor"); info("Testing single animated node actor");
yield animationsFront.getAnimationPlayersForNode(animatedNodeActor); yield animationsFront.getAnimationPlayersForNode(animatedNodeActor);
is(animationsActor.actors.length, 1, is(animationsActor.actors.length, 1,
"AnimationActor has only one AnimationPlayerActors"); "AnimationActor has only one AnimationPlayerActors");
info ("Testing AnimationPlayerActors release again"); info("Testing AnimationPlayerActors release again");
yield animationsFront.getAnimationPlayersForNode(stillNodeActor); yield animationsFront.getAnimationPlayersForNode(stillNodeActor);
is(animationsActor.actors.length, 0, is(animationsActor.actors.length, 0,
"AnimationActor does not have any AnimationPlayerActors anymore"); "AnimationActor does not have any AnimationPlayerActors anymore");
@ -79,7 +77,6 @@ window.onload = function() {
runNextTest(); runNextTest();
}); });
runNextTest(); runNextTest();
}; };
</script> </script>

View file

@ -1,4 +1,4 @@
<SDOCTYPv HTM.> <!DOCTYPE HTML>
<html> <html>
<!-- <!--
Bug 966991 - Test DebuggerServer.connectToChild Bug 966991 - Test DebuggerServer.connectToChild
@ -12,16 +12,16 @@ Bug 966991 - Test DebuggerServer.connectToChild
<body> <body>
<pre id="test"> <pre id="test">
<script type="application/javascript"> <script type="application/javascript">
"use strict";
let Cu = Components.utils; let Cu = Components.utils;
let Cc = Components.classes;
let Ci = Components.interfaces; let Ci = Components.interfaces;
let { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); let { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
let { DebuggerClient } = require("devtools/shared/client/main"); let { DebuggerClient } = require("devtools/shared/client/main");
let { DebuggerServer } = require("devtools/server/main"); let { DebuggerServer } = require("devtools/server/main");
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ SpecialPowers.pushPrefEnv({
@ -31,7 +31,7 @@ window.onload = function() {
["dom.mozBrowserFramesEnabled", true] ["dom.mozBrowserFramesEnabled", true]
] ]
}, runTests); }, runTests);
} };
function runTests() { function runTests() {
// Create a minimal iframe with a message manager // Create a minimal iframe with a message manager
@ -44,14 +44,18 @@ function runTests() {
// Register a test actor in the child process so that we can know if and when // Register a test actor in the child process so that we can know if and when
// this fake actor is destroyed. // this fake actor is destroyed.
mm.loadFrameScript("data:text/javascript,new " + function FrameScriptScope() { mm.loadFrameScript("data:text/javascript,new " + function FrameScriptScope() {
/* eslint-disable no-shadow */
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
const { DebuggerServer } = require("devtools/server/main"); const { DebuggerServer } = require("devtools/server/main");
/* eslint-enable no-shadow */
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
} }
function TestActor() {dump("instanciate test actor\n");} function TestActor() {
dump("instanciate test actor\n");
}
TestActor.prototype = { TestActor.prototype = {
actorPrefix: "test", actorPrefix: "test",
@ -59,7 +63,7 @@ function runTests() {
sendAsyncMessage("test-actor-destroyed", null); sendAsyncMessage("test-actor-destroyed", null);
}, },
hello: function () { hello: function () {
return {msg:"world"}; return {msg: "world"};
} }
}; };
TestActor.prototype.requestTypes = { TestActor.prototype.requestTypes = {
@ -90,7 +94,6 @@ function runTests() {
to: actor.testActor, to: actor.testActor,
type: "hello", type: "hello",
}, function (response) { }, function (response) {
// Then close the client. That should end up cleaning our test actor // Then close the client. That should end up cleaning our test actor
client.close(); client.close();
@ -113,7 +116,8 @@ function runTests() {
let client = new DebuggerClient(transport); let client = new DebuggerClient(transport);
DebuggerServer.connectToChild(conn, iframe).then(actor => { DebuggerServer.connectToChild(conn, iframe).then(actor => {
ok(actor.testActor, "Got a test actor for the second connection"); ok(actor.testActor, "Got a test actor for the second connection");
isnot(actor.testActor, firstActor, "We get different actor instances between two connections"); isnot(actor.testActor, firstActor,
"We get different actor instances between two connections");
client.close(cleanup); client.close(cleanup);
}); });
@ -122,12 +126,11 @@ function runTests() {
function cleanup() { function cleanup() {
DebuggerServer.destroy(); DebuggerServer.destroy();
iframe.remove(); iframe.remove();
SimpleTest.finish() SimpleTest.finish();
} }
firstClient(); firstClient();
} }
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -12,70 +12,89 @@ Bug 898485 - [app manager] Implement an abstract connection manager
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var Cu = Components.utils; const Cu = Components.utils;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {DebuggerServer} = require("devtools/server/main"); const {DebuggerServer} = require("devtools/server/main");
var Services = require("Services"); const Services = require("Services");
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
} }
var {ConnectionManager, Connection} = require("devtools/shared/client/connection-manager"); const {
ConnectionManager,
Connection
} = require("devtools/shared/client/connection-manager");
var orgCount = ConnectionManager.connections.length; let orgCount = ConnectionManager.connections.length;
ConnectionManager.once("new", (event, c) => { ConnectionManager.once("new", (event, c) => {
is(ConnectionManager.connections[orgCount], c, "new event fired, with correct connection"); is(ConnectionManager.connections[orgCount], c,
"new event fired, with correct connection");
}); });
var c1 = ConnectionManager.createConnection(); let c1 = ConnectionManager.createConnection();
var c2 = ConnectionManager.createConnection(); let c2 = ConnectionManager.createConnection();
is(ConnectionManager.connections[orgCount], c1, "Connection 1 registered"); is(ConnectionManager.connections[orgCount], c1, "Connection 1 registered");
is(ConnectionManager.connections[orgCount + 1], c2, "Connection 2 registered"); is(ConnectionManager.connections[orgCount + 1], c2, "Connection 2 registered");
c1.once(Connection.Events.DESTROYED, function() { c1.once(Connection.Events.DESTROYED, function () {
is(ConnectionManager.connections.length, orgCount + 1, "Connection 1 destroyed"); is(ConnectionManager.connections.length, orgCount + 1, "Connection 1 destroyed");
var c = c2; let c = c2;
var eventsRef = "connecting connected disconnecting disconnected host-changed disconnected timeout destroyed"; let eventsRef = "connecting connected disconnecting disconnected host-changed"
var events = []; + " disconnected timeout destroyed";
let events = [];
var s = Connection.Status; let s = Connection.Status;
is(c.status, s.DISCONNECTED, "disconnected"); is(c.status, s.DISCONNECTED, "disconnected");
c.once(Connection.Events.CONNECTING, function(e) { events.push(e); is(c.status, s.CONNECTING, "connecting"); }); c.once(Connection.Events.CONNECTING, function (e) {
c.once(Connection.Events.CONNECTED, function(e) { events.push(e); is(c.status, s.CONNECTED, "connected"); c.disconnect()}); events.push(e);
c.once(Connection.Events.DISCONNECTING, function(e) { events.push(e); is(c.status, s.DISCONNECTING, "disconnecting"); }); is(c.status, s.CONNECTING, "connecting");
c.once(Connection.Events.DISCONNECTED, function(e) { events.push(e); is(c.status, s.DISCONNECTED, "disconnected"); testError()}); });
c.once(Connection.Events.DESTROYED, function(e) { events.push(e); is(c.status, s.DESTROYED, "destroyed"); finish()});
c.once(Connection.Events.CONNECTED, function (e) {
events.push(e);
is(c.status, s.CONNECTED, "connected");
c.disconnect();
});
c.once(Connection.Events.DISCONNECTING, function (e) {
events.push(e);
is(c.status, s.DISCONNECTING, "disconnecting");
});
c.once(Connection.Events.DISCONNECTED, function (e) {
events.push(e);
is(c.status, s.DISCONNECTED, "disconnected");
testError();
});
c.once(Connection.Events.DESTROYED, function (e) {
events.push(e);
is(c.status, s.DESTROYED, "destroyed");
finish();
});
c.connect(); c.connect();
function testStore() {
c.store.on("set", function(e,path) {
if (path.join(".") == "device.width") {
is(c.store.object.device.width, window.screen.width, "Store is fed with valid data");
c.disconnect();
}
});
}
function testError() { function testError() {
c.once(Connection.Events.DISCONNECTED, function(e) { c.once(Connection.Events.DISCONNECTED, function (e) {
events.push(e); events.push(e);
testKeepConnecting(); testKeepConnecting();
}); });
c.once(Connection.Events.HOST_CHANGED, function(e) { c.once(Connection.Events.HOST_CHANGED, function (e) {
events.push(e); events.push(e);
c.connect(); c.connect();
}); });
@ -86,16 +105,17 @@ window.onload = function() {
function testKeepConnecting() { function testKeepConnecting() {
// ensure that keepConnecting keep trying connecting // ensure that keepConnecting keep trying connecting
// until the connection attempts timeout // until the connection attempts timeout
var originalTimeout = Services.prefs.getIntPref("devtools.debugger.remote-timeout"); let prefRemoteTimeout = "devtools.debugger.remote-timeout";
let originalTimeout = Services.prefs.getIntPref(prefRemoteTimeout);
Services.prefs.setIntPref("devtools.debugger.remote-timeout", 1000); Services.prefs.setIntPref("devtools.debugger.remote-timeout", 1000);
c.once("timeout", function (e) { c.once("timeout", function (e) {
events.push(e); events.push(e);
Services.prefs.setIntPref("devtools.debugger.remote-timeout", originalTimeout); Services.prefs.setIntPref(prefRemoteTimeout, originalTimeout);
ConnectionManager.destroyConnection(c); ConnectionManager.destroyConnection(c);
}); });
c.keepConnecting = true; c.keepConnecting = true;
var port = ConnectionManager.getFreeTCPPort(); let port = ConnectionManager.getFreeTCPPort();
ok(parseInt(port), "Free TCP port looks like a port number"); ok(parseInt(port, 10), "Free TCP port looks like a port number");
c.port = port; c.port = port;
c.host = "locahost"; c.host = "locahost";
c.connect(); c.connect();
@ -106,13 +126,10 @@ window.onload = function() {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish(); SimpleTest.finish();
} }
}); });
ConnectionManager.destroyConnection(c1); ConnectionManager.destroyConnection(c1);
};
}
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -25,14 +25,15 @@ Test that css-logic handles media-queries correctly
<body> <body>
<div></div> <div></div>
<script type="application/javascript"> <script type="application/javascript">
"use strict";
window.onload = function() { window.onload = function () {
var { classes: Cc, utils: Cu, interfaces: Ci } = Components; const { classes: Cc, utils: Cu, interfaces: Ci } = Components;
const DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"] const DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(Ci.inIDOMUtils); .getService(Ci.inIDOMUtils);
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var Services = require("Services"); const Services = require("Services");
const {CssLogic} = require("devtools/server/css-logic"); const {CssLogic} = require("devtools/server/css-logic");
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
@ -55,8 +56,7 @@ Test that css-logic handles media-queries correctly
"rule.source gives correct output for rule 2"); "rule.source gives correct output for rule 2");
SimpleTest.finish(); SimpleTest.finish();
} };
</script> </script>
</body> </body>
</html> </html>

View file

@ -10,9 +10,10 @@ Test that css-logic calculates CSS specificity properly
</head> </head>
<body style="background:blue;"> <body style="background:blue;">
<script type="application/javascript"> <script type="application/javascript">
"use strict";
window.onload = function() { window.onload = function () {
var {utils: Cu, classes: Cc, interfaces: Ci} = Components; const {utils: Cu, classes: Cc, interfaces: Ci} = Components;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {CssLogic, CssSelector} = require("devtools/server/css-logic"); const {CssLogic, CssSelector} = require("devtools/server/css-logic");
@ -58,7 +59,7 @@ Test that css-logic calculates CSS specificity properly
let cssRule = cssSheet.domSheet.cssRules[0]; let cssRule = cssSheet.domSheet.cssRules[0];
let selectors = CssLogic.getSelectors(cssRule); let selectors = CssLogic.getSelectors(cssRule);
info("Iterating over the test selectors") info("Iterating over the test selectors");
for (let i = 0; i < selectors.length; i++) { for (let i = 0; i < selectors.length; i++) {
let selectorText = selectors[i]; let selectorText = selectors[i];
info("Testing selector " + selectorText); info("Testing selector " + selectorText);
@ -66,7 +67,7 @@ Test that css-logic calculates CSS specificity properly
let selector = new CssSelector(cssRule, selectorText, i); let selector = new CssSelector(cssRule, selectorText, i);
let expected = getExpectedSpecificity(selectorText); let expected = getExpectedSpecificity(selectorText);
let specificity = DOMUtils.getSpecificity(selector.cssRule, let specificity = DOMUtils.getSpecificity(selector.cssRule,
selector.selectorIndex) selector.selectorIndex);
is(specificity, expected, is(specificity, expected,
'Selector "' + selectorText + '" has a specificity of ' + expected); 'Selector "' + selectorText + '" has a specificity of ' + expected);
} }
@ -77,8 +78,7 @@ Test that css-logic calculates CSS specificity properly
"Element styles have specificity of 0x01000000 (16777216)."); "Element styles have specificity of 0x01000000 (16777216).");
SimpleTest.finish(); SimpleTest.finish();
} };
</script> </script>
</body> </body>
</html> </html>

View file

@ -11,49 +11,51 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
"use strict";
const {CssLogic} = require("devtools/server/css-logic"); const {CssLogic} = require("devtools/server/css-logic");
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
addTest(function getComputedStyle() { addTest(function getComputedStyle() {
let node = document.querySelector("#computed-style"); let node = document.querySelector("#computed-style");
is (CssLogic.getComputedStyle(node).getPropertyValue("width"), is(CssLogic.getComputedStyle(node).getPropertyValue("width"),
"50px", "Computed style on a normal node works (width)"); "50px", "Computed style on a normal node works (width)");
is (CssLogic.getComputedStyle(node).getPropertyValue("height"), is(CssLogic.getComputedStyle(node).getPropertyValue("height"),
"10px", "Computed style on a normal node works (height)"); "10px", "Computed style on a normal node works (height)");
let firstChild = new _documentWalker(node, window).firstChild(); let firstChild = new _documentWalker(node, window).firstChild();
is (CssLogic.getComputedStyle(firstChild).getPropertyValue("content"), is(CssLogic.getComputedStyle(firstChild).getPropertyValue("content"),
"\"before\"", "Computed style on a ::before node works (content)"); "\"before\"", "Computed style on a ::before node works (content)");
let lastChild = new _documentWalker(node, window).lastChild(); let lastChild = new _documentWalker(node, window).lastChild();
is (CssLogic.getComputedStyle(lastChild).getPropertyValue("content"), is(CssLogic.getComputedStyle(lastChild).getPropertyValue("content"),
"\"after\"", "Computed style on a ::after node works (content)"); "\"after\"", "Computed style on a ::after node works (content)");
runNextTest(); runNextTest();
}); });
addTest(function getBindingElementAndPseudo() { addTest(function getBindingElementAndPseudo() {
let node = document.querySelector("#computed-style"); let node = document.querySelector("#computed-style");
var {bindingElement, pseudo} = CssLogic.getBindingElementAndPseudo(node); let {bindingElement, pseudo} = CssLogic.getBindingElementAndPseudo(node);
is (bindingElement, node, is(bindingElement, node,
"Binding element is the node itself for a normal node"); "Binding element is the node itself for a normal node");
ok (!pseudo, "Pseudo is null for a normal node"); ok(!pseudo, "Pseudo is null for a normal node");
let firstChild = new _documentWalker(node, window).firstChild(); let firstChild = new _documentWalker(node, window).firstChild();
var {bindingElement, pseudo} = CssLogic.getBindingElementAndPseudo(firstChild); ({ bindingElement, pseudo } = CssLogic.getBindingElementAndPseudo(firstChild));
is (bindingElement, node, is(bindingElement, node,
"Binding element is the parent for a pseudo node"); "Binding element is the parent for a pseudo node");
is (pseudo, ":before", "Pseudo is correct for a ::before node"); is(pseudo, ":before", "Pseudo is correct for a ::before node");
let lastChild = new _documentWalker(node, window).lastChild(); let lastChild = new _documentWalker(node, window).lastChild();
var {bindingElement, pseudo} = CssLogic.getBindingElementAndPseudo(lastChild); ({ bindingElement, pseudo } = CssLogic.getBindingElementAndPseudo(lastChild));
is (bindingElement, node, is(bindingElement, node,
"Binding element is the parent for a pseudo node"); "Binding element is the parent for a pseudo node");
is (pseudo, ":after", "Pseudo is correct for a ::after node"); is(pseudo, ":after", "Pseudo is correct for a ::after node");
runNextTest(); runNextTest();
}); });

View file

@ -10,19 +10,21 @@ Bug 1265798 - Replace inIDOMUtils.cssPropertyIsShorthand
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { "use strict";
window.onload = function () {
const { initCssProperties, getCssProperties } = const { initCssProperties, getCssProperties } =
require("devtools/shared/fronts/css-properties"); require("devtools/shared/fronts/css-properties");
function promiseAttachUrl (url) { function promiseAttachUrl(url) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
if (err) { if (err) {
return reject(err); return reject(err);
} }
resolve({client, tab, doc}); return resolve({client, tab, doc});
}); });
}) });
} }
function toSortedString(array) { function toSortedString(array) {
@ -63,7 +65,7 @@ window.onload = function() {
is(cssProperties, cssPropertiesA, is(cssProperties, cssPropertiesA,
"Multiple calls with the same toolbox returns the same object."); "Multiple calls with the same toolbox returns the same object.");
isnot(cssProperties, cssPropertiesB, isnot(cssProperties, cssPropertiesB,
"Multiple calls with the different toolboxes return different "+ "Multiple calls with the different toolboxes return different " +
" objects."); " objects.");
ok(cssProperties.isKnown("border"), ok(cssProperties.isKnown("border"),
@ -81,13 +83,13 @@ window.onload = function() {
ok(!cssProperties.isKnown("--foo bar"), ok(!cssProperties.isKnown("--foo bar"),
"A CSS variable with spaces fails"); "A CSS variable with spaces fails");
is(toSortedString(cssProperties.getValues('margin')), is(toSortedString(cssProperties.getValues("margin")),
toSortedString(["auto","calc","inherit","initial","unset"]), toSortedString(["auto", "calc", "inherit", "initial", "unset"]),
"Can get values for the CSS margin."); "Can get values for the CSS margin.");
is(cssProperties.getValues('foobar').length, 0, is(cssProperties.getValues("foobar").length, 0,
"Unknown values return an empty array."); "Unknown values return an empty array.");
const bgColorValues = cssProperties.getValues('background-color'); const bgColorValues = cssProperties.getValues("background-color");
ok(bgColorValues.includes("blanchedalmond"), ok(bgColorValues.includes("blanchedalmond"),
"A property with color values includes blanchedalmond."); "A property with color values includes blanchedalmond.");
ok(bgColorValues.includes("papayawhip"), ok(bgColorValues.includes("papayawhip"),
@ -111,7 +113,7 @@ window.onload = function() {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
</script> </script>
</head> </head>
<body> <body>

View file

@ -12,37 +12,38 @@ Bug 895360 - [app manager] Device meta data actor
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
window.onload = function() { window.onload = function () {
var Cu = Components.utils; const Cu = Components.utils;
var Cc = Components.classes; const Cc = Components.classes;
var Ci = Components.interfaces; const Ci = Components.interfaces;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {DebuggerClient} = require("devtools/shared/client/main"); const {DebuggerClient} = require("devtools/shared/client/main");
var {DebuggerServer} = require("devtools/server/main"); const {DebuggerServer} = require("devtools/server/main");
var Services = require("Services"); const Services = require("Services");
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var {getDeviceFront} = require("devtools/shared/fronts/device"); const {getDeviceFront} = require("devtools/shared/fronts/device");
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
} }
var client = new DebuggerClient(DebuggerServer.connectPipe()); let client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() { client.connect().then(function onConnect() {
client.listTabs(function onListTabs(aResponse) { client.listTabs(function onListTabs(response) {
var d = getDeviceFront(client, aResponse); let d = getDeviceFront(client, response);
var desc; let desc;
var appInfo = Services.appinfo; let appInfo = Services.appinfo;
var utils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils); let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
let localDesc = {
var localDesc = {
appid: appInfo.ID, appid: appInfo.ID,
vendor: appInfo.vendor, vendor: appInfo.vendor,
name: appInfo.name, name: appInfo.name,
@ -53,38 +54,38 @@ window.onload = function() {
geckobuildid: appInfo.platformBuildID, geckobuildid: appInfo.platformBuildID,
geckoversion: appInfo.platformVersion, geckoversion: appInfo.platformVersion,
useragent: window.navigator.userAgent, useragent: window.navigator.userAgent,
locale: Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry).getSelectedLocale("global"), locale: Cc["@mozilla.org/chrome/chrome-registry;1"]
.getService(Ci.nsIXULChromeRegistry).getSelectedLocale("global"),
os: appInfo.OS, os: appInfo.OS,
processor: appInfo.XPCOMABI.split("-")[0], processor: appInfo.XPCOMABI.split("-")[0],
compiler: appInfo.XPCOMABI.split("-")[1], compiler: appInfo.XPCOMABI.split("-")[1],
dpi: utils.displayDPI, dpi: utils.displayDPI,
width: window.screen.width, width: window.screen.width,
height: window.screen.height height: window.screen.height
} };
function checkValues() { function checkValues() {
for (var key in localDesc) { for (let key in localDesc) {
is(desc[key], localDesc[key], "valid field (" + key + ")"); is(desc[key], localDesc[key], "valid field (" + key + ")");
} }
var currProfD = Services.dirsvc.get("ProfD", Ci.nsIFile); let currProfD = Services.dirsvc.get("ProfD", Ci.nsIFile);
var profileDir = currProfD.path; let profileDir = currProfD.path;
ok(profileDir.indexOf(desc.profile.length > 0 && desc.profile) != -1, "valid profile name"); ok(profileDir.indexOf(desc.profile.length > 0 && desc.profile) != -1,
"valid profile name");
client.close().then(() => { client.close().then(() => {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish() SimpleTest.finish();
}); });
} }
d.getDescription().then(function (v) {
d.getDescription().then((v) => desc = v) desc = v;
.then(checkValues); }).then(checkValues);
}); });
}); });
};
}
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -14,43 +14,45 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<pre id="test"> <pre id="test">
<script type="application/javascript" src="./director-helpers.js"></script> <script type="application/javascript" src="./director-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const WAIT_EVENT_TIMEOUT = 3000; "use strict";
window.onload = function() { window.onload = function () {
Task.spawn(function* () { Task.spawn(function* () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var tests = [ let tests = [
runDirectorRegistryActorTest runDirectorRegistryActorTest
].map((testCase) => { ].map((testCase) => {
return function* () { return function* () {
setup(); setup();
yield testCase().then(null, (e) => { yield testCase().then(null, (e) => {
console.error("Exception during testCase run", e); console.error("Exception during testCase run", e);
ok(false, "Exception during testCase run: " + [e, e.fileName, e.lineNumber].join("\n\t")); ok(false, "Exception during testCase run: "
+ [e, e.fileName, e.lineNumber].join("\n\t"));
}); });
teardown(); teardown();
}; };
}); });
for (var test of tests) { for (let test of tests) {
yield test(); yield test();
} }
}).then( }).then(
function success() { function success() {
SimpleTest.finish() SimpleTest.finish();
}, },
function error(e) { function error(e) {
console.error("Exception during testCase run", e); console.error("Exception during testCase run", e);
ok(false, "Exception during testCase run: " + [e, e.fileName, e.lineNumber].join("\n\t")); ok(false, "Exception during testCase run: "
+ [e, e.fileName, e.lineNumber].join("\n\t"));
SimpleTest.finish(); SimpleTest.finish();
} }
); );
}; };
var targetWin = null; let targetWin = null;
function setup() { function setup() {
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
@ -70,30 +72,26 @@ function teardown() {
} }
} }
/***********************************
* test cases
**********************************/
function runDirectorRegistryActorTest() { function runDirectorRegistryActorTest() {
let testDirectorScriptOptions = { let testDirectorScriptOptions = {
scriptCode: "(" + (function() { scriptCode: "(" + (function () {
module.exports = function({port}) { module.exports = function ({port}) {
port.onmessage = function(evt) { port.onmessage = function (evt) {
// echo messages // echo messages
evt.target.postMessage(evt.data); evt.target.postMessage(evt.data);
}; };
}; };
}).toString() + ")();", }).toString() + ")();",
scriptOptions: {} scriptOptions: {}
} };
return Task.spawn(function* () { return Task.spawn(function* () {
let { client, root } = yield newConnectedDebuggerClient(); let { client, root } = yield newConnectedDebuggerClient();
var directorRegistryClient = new DirectorRegistryFront(client, root); let directorRegistryClient = new DirectorRegistryFront(client, root);
let installed = yield directorRegistryClient.install("testDirectorScript", testDirectorScriptOptions); let installed = yield directorRegistryClient.install("testDirectorScript",
testDirectorScriptOptions);
is(installed, true, "DirectorManager.install returns true"); is(installed, true, "DirectorManager.install returns true");
let list = yield directorRegistryClient.list(); let list = yield directorRegistryClient.list();
@ -106,8 +104,6 @@ function runDirectorRegistryActorTest() {
yield client.close(); yield client.close();
}); });
} }
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -14,24 +14,27 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<pre id="test"> <pre id="test">
<script type="application/javascript" src="./director-helpers.js"></script> <script type="application/javascript" src="./director-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { "use strict";
window.onload = function () {
Task.spawn(function* () { Task.spawn(function* () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var tests = [ let tests = [
runPropagateDirectorScriptsToChildTest, runPropagateDirectorScriptsToChildTest,
].map((testCase) => { ].map((testCase) => {
return function* () { return function* () {
setup(); setup();
yield testCase().then(null, (e) => { yield testCase().then(null, (e) => {
ok(false, "Exception during testCase run: " + [e, e.fileName, e.lineNumber].join("\n\t")); ok(false, "Exception during testCase run: "
+ [e, e.fileName, e.lineNumber].join("\n\t"));
}); });
teardown(); teardown();
}; };
}); });
for (var test of tests) { for (let test of tests) {
yield test(); yield test();
} }
@ -43,7 +46,7 @@ function setup() {
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(() => true); DebuggerServer.init(() => true);
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function () {
DebuggerServer.destroy(); DebuggerServer.destroy();
}); });
} }
@ -54,10 +57,6 @@ function teardown() {
DebuggerServer.destroy(); DebuggerServer.destroy();
} }
/***********************************
* test cases
**********************************/
function runPropagateDirectorScriptsToChildTest() { function runPropagateDirectorScriptsToChildTest() {
let iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.mozbrowser = true; iframe.mozbrowser = true;
@ -65,9 +64,9 @@ function runPropagateDirectorScriptsToChildTest() {
document.body.appendChild(iframe); document.body.appendChild(iframe);
return Task.spawn(function* () { return Task.spawn(function* () {
var { client, root, transport } = yield newConnectedDebuggerClient(); let { client, root, transport } = yield newConnectedDebuggerClient();
var directorRegistryClient = new DirectorRegistryFront(client, root); let directorRegistryClient = new DirectorRegistryFront(client, root);
// install a director script // install a director script
yield directorRegistryClient.install("testPropagatedDirectorScript", { yield directorRegistryClient.install("testPropagatedDirectorScript", {
@ -75,19 +74,19 @@ function runPropagateDirectorScriptsToChildTest() {
scriptOptions: {} scriptOptions: {}
}); });
var conn = transport._serverConnection; let conn = transport._serverConnection;
var childActor = yield DebuggerServer.connectToChild(conn, iframe); let childActor = yield DebuggerServer.connectToChild(conn, iframe);
ok(typeof childActor.directorManagerActor !== "undefined", ok(typeof childActor.directorManagerActor !== "undefined",
"childActor.directorActor should be defined"); "childActor.directorActor should be defined");
var childDirectorManagerClient = new DirectorManagerFront(client, childActor); let childDirectorManagerClient = new DirectorManagerFront(client, childActor);
var directorScriptList = yield childDirectorManagerClient.list(); let directorScriptList = yield childDirectorManagerClient.list();
ok(directorScriptList.installed.length === 1 && ok(directorScriptList.installed.length === 1 &&
directorScriptList.installed[0] === "testPropagatedDirectorScript", directorScriptList.installed[0] === "testPropagatedDirectorScript",
"director scripts propagated correctly") "director scripts propagated correctly");
yield client.close(); yield client.close();
}); });

View file

@ -16,6 +16,7 @@ object.
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
Components.utils.import("resource://gre/modules/jsdebugger.jsm"); Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this); addDebuggerToGlobal(this);
@ -23,46 +24,49 @@ addDebuggerToGlobal(this);
window.onload = function () { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.src = "data:text/html,<script>var me = 'page 1';<\/script>"; iframe.src = "data:text/html,<script>var me = 'page 1';<\/script>";
iframe.onload = firstOnLoadHandler; iframe.onload = firstOnLoadHandler;
document.body.appendChild(iframe); document.body.appendChild(iframe);
function firstOnLoadHandler() { function firstOnLoadHandler() {
var dbg = new Debugger; let dbg = new Debugger();
var page1DO = dbg.addDebuggee(iframe.contentWindow); let page1DO = dbg.addDebuggee(iframe.contentWindow);
iframe.src = "data:text/html,<script>var me = 'page 2';<\/script>"; iframe.src = "data:text/html,<script>var me = 'page 2';<\/script>";
iframe.onload = function () { iframe.onload = function () {
var page2DO = dbg.addDebuggee(iframe.contentWindow); let page2DO = dbg.addDebuggee(iframe.contentWindow);
ok(page1DO !== page2DO, "the two pages' globals get distinct D.O's"); ok(page1DO !== page2DO, "the two pages' globals get distinct D.O's");
ok(page1DO.unsafeDereference() === page2DO.unsafeDereference(), ok(page1DO.unsafeDereference() === page2DO.unsafeDereference(),
"unwrapping page1DO and page2DO outerizes both, yielding the same outer window"); "unwrapping page1DO and page2DO outerizes both, yielding the same outer window");
is(page1DO.executeInGlobal('me').return, 'page 1', "page1DO continues to refer to original page"); is(page1DO.executeInGlobal("me").return,
is(page2DO.executeInGlobal('me').return, 'page 2', "page2DO refers to current page"); "page 1", "page1DO continues to refer to original page");
is(page2DO.executeInGlobal("me").return, "page 2",
"page2DO refers to current page");
is(page1DO.executeInGlobal('this === window').return, true, is(page1DO.executeInGlobal("this === window").return, true,
"page 1: Debugger.Object.prototype.executeInGlobal should outerize 'this'"); "page 1: Debugger.Object.prototype.executeInGlobal should outerize 'this'");
is(page1DO.executeInGlobalWithBindings('this === window', {x:2}).return, true, is(page1DO.executeInGlobalWithBindings("this === window", {x: 2}).return, true,
"page 1: Debugger.Object.prototype.executeInGlobal should outerize 'this'"); "page 1: Debugger.Object.prototype.executeInGlobal should outerize 'this'");
is(page2DO.executeInGlobal('this === window').return, true, is(page2DO.executeInGlobal("this === window").return, true,
"page 2: Debugger.Object.prototype.executeInGlobal should outerize 'this'"); "page 2: Debugger.Object.prototype.executeInGlobal should outerize 'this'");
is(page2DO.executeInGlobalWithBindings('this === window', {x:2}).return, true, is(page2DO.executeInGlobalWithBindings("this === window", {x: 2}).return, true,
"page 2: Debugger.Object.prototype.executeInGlobal should outerize 'this'"); "page 2: Debugger.Object.prototype.executeInGlobal should outerize 'this'");
// Debugger doesn't let one use outer windows as globals. You have to innerize. // Debugger doesn't let one use outer windows as globals. You have to innerize.
var outerDO = page1DO.makeDebuggeeValue(page1DO.unsafeDereference()); let outerDO = page1DO.makeDebuggeeValue(page1DO.unsafeDereference());
ok(outerDO !== page1DO, "outer window gets its own D.O, distinct from page 1's global"); ok(outerDO !== page1DO,
ok(outerDO !== page2DO, "outer window gets its own D.O, distinct from page 2's global"); "outer window gets its own D.O, distinct from page 1's global");
SimpleTest.doesThrow(function () { outerDO.executeInGlobal('me'); }, ok(outerDO !== page2DO,
"outer window gets its own D.O, distinct from page 2's global");
SimpleTest.doesThrow(() => outerDO.executeInGlobal("me"),
"outer window D.Os can't be used as globals"); "outer window D.Os can't be used as globals");
SimpleTest.finish(); SimpleTest.finish();
} };
} }
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -12,30 +12,29 @@ Bug 1007200 - Create a framerate actor
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
window.onload = function() { window.onload = function () {
var Cu = Components.utils; const Cu = Components.utils;
var Cc = Components.classes;
var Ci = Components.interfaces;
var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
var Services = require("Services"); const Services = require("Services");
var { DebuggerClient } = require("devtools/shared/client/main"); const { DebuggerClient } = require("devtools/shared/client/main");
var { DebuggerServer } = require("devtools/server/main"); const { DebuggerServer } = require("devtools/server/main");
// Always log packets when running tests. // Always log packets when running tests.
Services.prefs.setBoolPref("devtools.debugger.log", true); Services.prefs.setBoolPref("devtools.debugger.log", true);
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function () {
Services.prefs.clearUserPref("devtools.debugger.log"); Services.prefs.clearUserPref("devtools.debugger.log");
}); });
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var {FramerateFront} = require("devtools/shared/fronts/framerate"); const { FramerateFront } = require("devtools/shared/fronts/framerate");
function plotFPS(ticks, interval = 100, clamp = 60) { function plotFPS(ticks, interval = 100, clamp = 60) {
var timeline = []; let timeline = [];
var totalTicks = ticks.length; let totalTicks = ticks.length;
// If the refresh driver didn't get a chance to tick before the // If the refresh driver didn't get a chance to tick before the
// recording was stopped, assume framerate was 0. // recording was stopped, assume framerate was 0.
@ -45,19 +44,19 @@ window.onload = function() {
return timeline; return timeline;
} }
var frameCount = 0; let frameCount = 0;
var prevTime = ticks[0]; let prevTime = ticks[0];
for (var i = 1; i < totalTicks; i++) { for (let i = 1; i < totalTicks; i++) {
var currTime = ticks[i]; let currTime = ticks[i];
frameCount++; frameCount++;
var elapsedTime = currTime - prevTime; let elapsedTime = currTime - prevTime;
if (elapsedTime < interval) { if (elapsedTime < interval) {
continue; continue;
} }
var framerate = Math.min(1000 / (elapsedTime / frameCount), clamp); let framerate = Math.min(1000 / (elapsedTime / frameCount), clamp);
timeline.push({ delta: prevTime, value: framerate }); timeline.push({ delta: prevTime, value: framerate });
timeline.push({ delta: currTime, value: framerate }); timeline.push({ delta: currTime, value: framerate });
@ -66,20 +65,21 @@ window.onload = function() {
} }
return timeline; return timeline;
}; }
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
} }
var client = new DebuggerClient(DebuggerServer.connectPipe()); let client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() { client.connect().then(function onConnect() {
client.listTabs(function onListTabs(aResponse) { client.listTabs(function onListTabs(response) {
var form = aResponse.tabs[aResponse.selected]; let form = response.tabs[response.selected];
var front = FramerateFront(client, form); let front = FramerateFront(client, form);
window.setTimeout(() => { window.setTimeout(() => {
/* eslint-disable max-nested-callbacks */
front.startRecording().then(() => { front.startRecording().then(() => {
window.setTimeout(() => { window.setTimeout(() => {
front.stopRecording().then(rawData => { front.stopRecording().then(rawData => {
@ -87,6 +87,7 @@ window.onload = function() {
}); });
}, 1000); }, 1000);
}); });
/* eslint-enable max-nested-callbacks */
}, 1000); }, 1000);
}); });
}); });
@ -94,15 +95,15 @@ window.onload = function() {
function onRecordingStopped(front, rawData) { function onRecordingStopped(front, rawData) {
ok(rawData, "There should be a recording available."); ok(rawData, "There should be a recording available.");
var timeline = plotFPS(rawData); let timeline = plotFPS(rawData);
ok(timeline.length >= 2, ok(timeline.length >= 2,
"There should be at least one measurement available, with two entries."); "There should be at least one measurement available, with two entries.");
var prevTimeStart = timeline[0].delta; let prevTimeStart = timeline[0].delta;
for (var i = 0; i < timeline.length; i += 2) { for (let i = 0; i < timeline.length; i += 2) {
var currTimeStart = timeline[i].delta; let currTimeStart = timeline[i].delta;
var currTimeEnd = timeline[i + 1].delta; let currTimeEnd = timeline[i + 1].delta;
info("Testing delta: " + currTimeStart + " vs. " + currTimeEnd); info("Testing delta: " + currTimeStart + " vs. " + currTimeEnd);
ok(currTimeStart < currTimeEnd, ok(currTimeStart < currTimeEnd,
@ -113,28 +114,24 @@ window.onload = function() {
prevTimeStart = currTimeEnd; prevTimeStart = currTimeEnd;
} }
var prevFramerateValue = -1; for (let i = 0; i < timeline.length; i += 2) {
let currFramerateStart = timeline[i].value;
for (var i = 0; i < timeline.length; i += 2) { let currFramerateEnd = timeline[i + 1].value;
var currFramerateStart = timeline[i].value;
var currFramerateEnd = timeline[i + 1].value;
info("Testing framerate: " + currFramerateStart); info("Testing framerate: " + currFramerateStart);
is(currFramerateStart, currFramerateEnd, is(currFramerateStart, currFramerateEnd,
"The start and end framerate values should be equal."); "The start and end framerate values should be equal.");
is(typeof currFramerateStart, "number", "All values should be numbers."); is(typeof currFramerateStart, "number", "All values should be numbers.");
ok(currFramerateStart <= 60, "All values were correctly clamped.") ok(currFramerateStart <= 60, "All values were correctly clamped.");
prevFramerateValue = currFramerateStart;
} }
client.close().then(() => { client.close().then(() => {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish() SimpleTest.finish();
}); });
} }
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -12,30 +12,29 @@ Bug 1007200 - Create a framerate actor
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
window.onload = function() { window.onload = function () {
var Cu = Components.utils; const Cu = Components.utils;
var Cc = Components.classes;
var Ci = Components.interfaces;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {DebuggerClient} = require("devtools/shared/client/main"); const {DebuggerClient} = require("devtools/shared/client/main");
var {DebuggerServer} = require("devtools/server/main"); const {DebuggerServer} = require("devtools/server/main");
var Services = require("Services"); const Services = require("Services");
// Always log packets when running tests. // Always log packets when running tests.
Services.prefs.setBoolPref("devtools.debugger.log", true); Services.prefs.setBoolPref("devtools.debugger.log", true);
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function () {
Services.prefs.clearUserPref("devtools.debugger.log"); Services.prefs.clearUserPref("devtools.debugger.log");
}); });
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var {FramerateFront} = require("devtools/shared/fronts/framerate"); const {FramerateFront} = require("devtools/shared/fronts/framerate");
function plotFPS(ticks, interval = 100, clamp = 60) { function plotFPS(ticks, interval = 100, clamp = 60) {
var timeline = []; let timeline = [];
var totalTicks = ticks.length; let totalTicks = ticks.length;
// If the refresh driver didn't get a chance to tick before the // If the refresh driver didn't get a chance to tick before the
// recording was stopped, assume framerate was 0. // recording was stopped, assume framerate was 0.
@ -45,19 +44,19 @@ window.onload = function() {
return timeline; return timeline;
} }
var frameCount = 0; let frameCount = 0;
var prevTime = ticks[0]; let prevTime = ticks[0];
for (var i = 1; i < totalTicks; i++) { for (let i = 1; i < totalTicks; i++) {
var currTime = ticks[i]; let currTime = ticks[i];
frameCount++; frameCount++;
var elapsedTime = currTime - prevTime; let elapsedTime = currTime - prevTime;
if (elapsedTime < interval) { if (elapsedTime < interval) {
continue; continue;
} }
var framerate = Math.min(1000 / (elapsedTime / frameCount), clamp); let framerate = Math.min(1000 / (elapsedTime / frameCount), clamp);
timeline.push({ delta: prevTime, value: framerate }); timeline.push({ delta: prevTime, value: framerate });
timeline.push({ delta: currTime, value: framerate }); timeline.push({ delta: currTime, value: framerate });
@ -66,24 +65,24 @@ window.onload = function() {
} }
return timeline; return timeline;
}; }
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
} }
var client = new DebuggerClient(DebuggerServer.connectPipe()); let client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() { client.connect().then(function onConnect() {
client.listTabs(function onListTabs(aResponse) { client.listTabs(function onListTabs(response) {
var form = aResponse.tabs[aResponse.selected]; let form = response.tabs[response.selected];
var front = FramerateFront(client, form); let front = FramerateFront(client, form);
front.stopRecording().then(rawData => { front.stopRecording().then(rawData => {
ok(rawData, "There should be a recording available."); ok(rawData, "There should be a recording available.");
is(rawData.length, 0, "...but it should be empty."); is(rawData.length, 0, "...but it should be empty.");
var timeline = plotFPS(rawData); let timeline = plotFPS(rawData);
is(timeline.length, 2, is(timeline.length, 2,
"There should be one measurement plotted, with two entries."); "There should be one measurement plotted, with two entries.");
@ -99,14 +98,15 @@ window.onload = function() {
is(timeline[1].value, 0, is(timeline[1].value, 0,
"The last framerate value should be 0."); "The last framerate value should be 0.");
// eslint-disable-next-line max-nested-callbacks
client.close().then(() => { client.close().then(() => {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish() SimpleTest.finish();
}); });
}); });
}); });
}); });
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -12,47 +12,48 @@ Bug 1023018 - Tests whether or not the framerate actor can handle time ranges.
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
window.onload = function() { window.onload = function () {
var Cu = Components.utils; const Cu = Components.utils;
var Cc = Components.classes;
var Ci = Components.interfaces;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {DebuggerClient} = require("devtools/shared/client/main"); const {DebuggerClient} = require("devtools/shared/client/main");
var {DebuggerServer} = require("devtools/server/main"); const {DebuggerServer} = require("devtools/server/main");
var Services = require("Services"); const Services = require("Services");
// Always log packets when running tests. // Always log packets when running tests.
Services.prefs.setBoolPref("devtools.debugger.log", true); Services.prefs.setBoolPref("devtools.debugger.log", true);
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function () {
Services.prefs.clearUserPref("devtools.debugger.log"); Services.prefs.clearUserPref("devtools.debugger.log");
}); });
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var {FramerateFront} = require("devtools/shared/fronts/framerate"); const {FramerateFront} = require("devtools/shared/fronts/framerate");
var START_TICK = 2000; const START_TICK = 2000;
var STOP_TICK = 3000; const STOP_TICK = 3000;
var TOTAL_TIME = 5000; const TOTAL_TIME = 5000;
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
} }
var client = new DebuggerClient(DebuggerServer.connectPipe()); let client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() { client.connect().then(function onConnect() {
client.listTabs(function onListTabs(aResponse) { client.listTabs(function onListTabs(response) {
var form = aResponse.tabs[aResponse.selected]; let form = response.tabs[response.selected];
var front = FramerateFront(client, form); let front = FramerateFront(client, form);
front.startRecording().then(() => { front.startRecording().then(() => {
/* eslint-disable max-nested-callbacks */
window.setTimeout(() => { window.setTimeout(() => {
front.stopRecording(START_TICK, STOP_TICK).then(rawData => { front.stopRecording(START_TICK, STOP_TICK).then(rawData => {
onRecordingStopped(front, rawData); onRecordingStopped(front, rawData);
}); });
}, TOTAL_TIME); }, TOTAL_TIME);
/* eslint-enable max-nested-callbacks */
}); });
}); });
}); });
@ -65,17 +66,17 @@ window.onload = function() {
ok(!rawData.find(e => e > STOP_TICK), ok(!rawData.find(e => e > STOP_TICK),
"There should be no tick after 3000ms."); "There should be no tick after 3000ms.");
for (var tick of rawData) { for (let tick of rawData) {
info("Testing tick: " + tick); info("Testing tick: " + tick);
is(typeof tick, "number", "All values should be numbers."); is(typeof tick, "number", "All values should be numbers.");
} }
client.close().then(() => { client.close().then(() => {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish() SimpleTest.finish();
}); });
} }
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -13,26 +13,28 @@ Bug 1023018 - Tests if the framerate actor keeps recording after navigations.
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var {FramerateFront} = require("devtools/shared/fronts/framerate"); const {FramerateFront} = require("devtools/shared/fronts/framerate");
var {TargetFactory} = require("devtools/client/framework/target"); const {TargetFactory} = require("devtools/client/framework/target");
var url = document.getElementById("testContent").href; let url = document.getElementById("testContent").href;
attachURL(url, onTab); attachURL(url, onTab);
function onTab(_, client, form, contentDoc) { function onTab(_, client, form, contentDoc) {
var contentWin = contentDoc.defaultView; let contentWin = contentDoc.defaultView;
var chromeWin = Services.wm.getMostRecentWindow("navigator:browser"); let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
var selectedTab = chromeWin.gBrowser.selectedTab; let selectedTab = chromeWin.gBrowser.selectedTab;
var target = TargetFactory.forTab(selectedTab); let target = TargetFactory.forTab(selectedTab);
var front = FramerateFront(client, form); let front = FramerateFront(client, form);
front.startRecording().then(() => { front.startRecording().then(() => {
window.setTimeout(() => { window.setTimeout(() => {
front.getPendingTicks().then(firstBatch => { front.getPendingTicks().then(firstBatch => {
/* eslint-disable max-nested-callbacks */
target.once("will-navigate", () => { target.once("will-navigate", () => {
window.setTimeout(() => { window.setTimeout(() => {
front.stopRecording().then(secondBatch => { front.stopRecording().then(secondBatch => {
@ -40,6 +42,7 @@ window.onload = function() {
}); });
}, 1000); }, 1000);
}); });
/* eslint-enable max-nested-callbacks */
contentWin.location.reload(); contentWin.location.reload();
}); });
}, 1000); }, 1000);
@ -50,7 +53,7 @@ window.onload = function() {
ok(firstBatch, "There should be a first batch recording available."); ok(firstBatch, "There should be a first batch recording available.");
ok(secondBatch, "There should be a second batch recording available."); ok(secondBatch, "There should be a second batch recording available.");
var diff = secondBatch.length - firstBatch.length; let diff = secondBatch.length - firstBatch.length;
info("Difference in ticks: " + diff); info("Difference in ticks: " + diff);
ok(diff > 0, "More ticks should be recorded in the second batch."); ok(diff > 0, "More ticks should be recorded in the second batch.");
@ -61,10 +64,10 @@ window.onload = function() {
client.close().then(() => { client.close().then(() => {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish() SimpleTest.finish();
}); });
} }
} };
</script> </script>
</pre> </pre>
<a id="testContent" target="_blank" href="inspector_getImageData.html">Test Document</a> <a id="testContent" target="_blank" href="inspector_getImageData.html">Test Document</a>

View file

@ -12,37 +12,37 @@ Bug 1034648 - Tests whether a framerate recording can be cancelled.
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
window.onload = function() { window.onload = function () {
var Cu = Components.utils; let Cu = Components.utils;
var Cc = Components.classes;
var Ci = Components.interfaces;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {DebuggerClient} = require("devtools/shared/client/main"); const {DebuggerClient} = require("devtools/shared/client/main");
var {DebuggerServer} = require("devtools/server/main"); const {DebuggerServer} = require("devtools/server/main");
var Services = require("Services"); const Services = require("Services");
// Always log packets when running tests. // Always log packets when running tests.
Services.prefs.setBoolPref("devtools.debugger.log", true); Services.prefs.setBoolPref("devtools.debugger.log", true);
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function () {
Services.prefs.clearUserPref("devtools.debugger.log"); Services.prefs.clearUserPref("devtools.debugger.log");
}); });
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var {FramerateFront} = require("devtools/shared/fronts/framerate"); const {FramerateFront} = require("devtools/shared/fronts/framerate");
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
var client = new DebuggerClient(DebuggerServer.connectPipe()); let client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() { client.connect().then(function onConnect() {
client.listTabs(function onListTabs(aResponse) { client.listTabs(function onListTabs(response) {
var form = aResponse.tabs[aResponse.selected]; let form = response.tabs[response.selected];
var front = FramerateFront(client, form); let front = FramerateFront(client, form);
front.startRecording().then(() => { front.startRecording().then(() => {
/* eslint-disable max-nested-callbacks */
window.setTimeout(() => { window.setTimeout(() => {
front.cancelRecording().then(() => { front.cancelRecording().then(() => {
window.setTimeout(() => { window.setTimeout(() => {
@ -60,17 +60,18 @@ window.onload = function() {
client.close().then(() => { client.close().then(() => {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish() SimpleTest.finish();
}); });
}); });
}); });
}, 1000); }, 1000);
}); });
}, 1000); }, 1000);
/* eslint-enable max-nested-callbacks */
}); });
}); });
}); });
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -13,34 +13,33 @@ Bug 1171489 - Tests if the framerate actor does not record timestamps from multi
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var {FramerateFront} = require("devtools/shared/fronts/framerate"); const {FramerateFront} = require("devtools/shared/fronts/framerate");
var {TargetFactory} = require("devtools/client/framework/target");
var url = document.getElementById("testContent").href; let url = document.getElementById("testContent").href;
attachURL(url, onTab); attachURL(url, onTab);
function onTab(_, client, form, contentDoc) { function onTab(_, client, form, contentDoc) {
var contentWin = contentDoc.defaultView; let contentWin = contentDoc.defaultView;
var chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
var selectedTab = chromeWin.gBrowser.selectedTab;
var target = TargetFactory.forTab(selectedTab); let front = FramerateFront(client, form);
var front = FramerateFront(client, form);
front.startRecording().then(() => { front.startRecording().then(() => {
window.setTimeout(() => { window.setTimeout(() => {
// Wait for the iframe to be loaded again // Wait for the iframe to be loaded again
window.addEventListener("message", function loaded (event) { window.addEventListener("message", function loaded(event) {
if (event.data === "ready") { if (event.data === "ready") {
window.removeEventListener("message", loaded); window.removeEventListener("message", loaded);
/* eslint-disable max-nested-callbacks */
window.setTimeout(() => { window.setTimeout(() => {
front.stopRecording().then(ticks => { front.stopRecording().then(ticks => {
onRecordingStopped(client, ticks); onRecordingStopped(client, ticks);
}); });
}, 1000); }, 1000);
/* eslint-enable max-nested-callbacks */
} }
}); });
contentWin.location.reload(); contentWin.location.reload();
@ -49,13 +48,13 @@ window.onload = function() {
} }
function onRecordingStopped(client, ticks) { function onRecordingStopped(client, ticks) {
var diffs = []; let diffs = [];
info(`Got ${ticks.length} ticks.`); info(`Got ${ticks.length} ticks.`);
for (var i = 1; i < ticks.length; i++) { for (let i = 1; i < ticks.length; i++) {
var prev = ticks[i - 1]; let prev = ticks[i - 1];
var curr = ticks[i]; let curr = ticks[i];
diffs.push(curr - prev); diffs.push(curr - prev);
info(curr + " - " + (curr - prev)); info(curr + " - " + (curr - prev));
} }
@ -64,17 +63,19 @@ window.onload = function() {
// when we get ticks from other frames they're usually at diffs of < 1. Sometimes // when we get ticks from other frames they're usually at diffs of < 1. Sometimes
// ticks can still be less than 16ms even on one frame (usually following a very slow // ticks can still be less than 16ms even on one frame (usually following a very slow
// frame), so use a low number (2) to be our threshold // frame), so use a low number (2) to be our threshold
var THRESHOLD = 2; let THRESHOLD = 2;
ok(ticks.length >= 20, "we should have atleast 20 ticks over the course of two seconds."); ok(ticks.length >= 20,
var belowThreshold = diffs.filter(v => v <= THRESHOLD); "we should have atleast 20 ticks over the course of two seconds.");
ok(belowThreshold.length <= 10, "we should have very few frames less than the threshold"); let belowThreshold = diffs.filter(v => v <= THRESHOLD);
ok(belowThreshold.length <= 10,
"we should have very few frames less than the threshold");
client.close().then(() => { client.close().then(() => {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish() SimpleTest.finish();
}); });
} }
} };
</script> </script>
</pre> </pre>
<a id="testContent" target="_blank" href="inspector-traversal-data.html">Test Document</a> <a id="testContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>

View file

@ -12,17 +12,16 @@ Bug 1060093 - Test DebuggerServer.getProcess
<body> <body>
<pre id="test"> <pre id="test">
<script type="application/javascript"> <script type="application/javascript">
"use strict";
let Cu = Components.utils; let Cu = Components.utils;
let Cc = Components.classes;
let Ci = Components.interfaces;
let {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); let {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
let {DebuggerClient} = require("devtools/shared/client/main"); let {DebuggerClient} = require("devtools/shared/client/main");
let {DebuggerServer} = require("devtools/server/main"); let {DebuggerServer} = require("devtools/server/main");
let Services = require("Services"); let Services = require("Services");
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ SpecialPowers.pushPrefEnv({
@ -35,7 +34,7 @@ window.onload = function() {
["dom.ipc.processCount", 10], ["dom.ipc.processCount", 10],
] ]
}, runTests); }, runTests);
} };
function runTests() { function runTests() {
// Instantiate a minimal server // Instantiate a minimal server
@ -81,13 +80,13 @@ function runTests() {
function getProcess() { function getProcess() {
client.mainRoot.listProcesses(response => { client.mainRoot.listProcesses(response => {
ok(response.processes.length >= 2, "Got at least the parent process and one child"); ok(response.processes.length >= 2, "Got at least the parent process and one child");
is(response.processes.length, processCount+1 , "Got one additional process on the second call to listProcesses"); is(response.processes.length, processCount + 1,
"Got one additional process on the second call to listProcesses");
// Connect to the first content processe available // Connect to the first content processe available
let content = response.processes.filter(p => (!p.parent))[0]; let content = response.processes.filter(p => (!p.parent))[0];
client.getProcess(content.id).then(response => { client.getProcess(content.id).then(({form: actor}) => {
let actor = response.form;
ok(actor.consoleActor, "Got the console actor"); ok(actor.consoleActor, "Got the console actor");
ok(actor.chromeDebugger, "Got the thread actor"); ok(actor.chromeDebugger, "Got the thread actor");
@ -96,8 +95,8 @@ function runTests() {
to: actor.consoleActor, to: actor.consoleActor,
type: "evaluateJS", type: "evaluateJS",
text: "var a = 42; a" text: "var a = 42; a"
}, function (response) { }, function ({result}) {
ok(response.result, 42, "console.eval worked"); ok(result, 42, "console.eval worked");
getProcessAgain(actor, content.id); getProcessAgain(actor, content.id);
}); });
@ -118,7 +117,7 @@ function runTests() {
function processScript() { function processScript() {
let listener = function () { let listener = function () {
Services.obs.removeObserver(listener, "sdk:loader:destroy", false); Services.obs.removeObserver(listener, "sdk:loader:destroy");
sendAsyncMessage("test:getProcess-destroy", null); sendAsyncMessage("test:getProcess-destroy", null);
}; };
Services.obs.addObserver(listener, "sdk:loader:destroy", false); Services.obs.addObserver(listener, "sdk:loader:destroy", false);
@ -127,10 +126,10 @@ function runTests() {
function closeClient() { function closeClient() {
let onLoaderDestroyed = new Promise(done => { let onLoaderDestroyed = new Promise(done => {
let processListener = function () { let processListener = function () {
Services.ppmm.removeMessageListener("test:getProcess-destroy", processListener) Services.ppmm.removeMessageListener("test:getProcess-destroy", processListener);
done(); done();
}; };
Services.ppmm.addMessageListener("test:getProcess-destroy", processListener) Services.ppmm.addMessageListener("test:getProcess-destroy", processListener);
}); });
let script = "data:,(" + processScript + ")()"; let script = "data:,(" + processScript + ")()";
Services.ppmm.loadProcessScript(script, true); Services.ppmm.loadProcessScript(script, true);
@ -147,7 +146,7 @@ function runTests() {
function cleanup() { function cleanup() {
DebuggerServer.destroy(); DebuggerServer.destroy();
iframe.remove(); iframe.remove();
SimpleTest.finish() SimpleTest.finish();
} }
connect(); connect();

View file

@ -11,7 +11,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=777674
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { "use strict";
window.onload = function () {
const {InspectorFront} = const {InspectorFront} =
require("devtools/shared/fronts/inspector"); require("devtools/shared/fronts/inspector");
const {_documentWalker} = const {_documentWalker} =
@ -26,51 +28,50 @@ window.onload = function() {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
let gWalker = null; let gWalker = null;
let gClient = null; let gInspectee = null;
addTest(function setup() { addTest(function setup() {
info ("Setting up inspector and walker actors."); info("Setting up inspector and walker actors.");
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
}); });
addAsyncTest(function* testXBLAnonymousInHTMLDocument() { addAsyncTest(function* testXBLAnonymousInHTMLDocument() {
info ("Testing XBL anonymous in an HTML document."); info("Testing XBL anonymous in an HTML document.");
let rawToolbarbutton = gInspectee.createElementNS(XUL_NS, "toolbarbutton"); let rawToolbarbutton = gInspectee.createElementNS(XUL_NS, "toolbarbutton");
gInspectee.documentElement.appendChild(rawToolbarbutton); gInspectee.documentElement.appendChild(rawToolbarbutton);
let toolbarbutton = yield gWalker.querySelector(gWalker.rootNode, "toolbarbutton"); let toolbarbutton = yield gWalker.querySelector(gWalker.rootNode, "toolbarbutton");
let children = yield gWalker.children(toolbarbutton); let children = yield gWalker.children(toolbarbutton);
is (toolbarbutton.numChildren, 0, "XBL content is not visible in HTML doc"); is(toolbarbutton.numChildren, 0, "XBL content is not visible in HTML doc");
is (children.nodes.length, 0, "XBL content is not returned in HTML doc"); is(children.nodes.length, 0, "XBL content is not returned in HTML doc");
runNextTest(); runNextTest();
}); });
addAsyncTest(function* testNativeAnonymous() { addAsyncTest(function* testNativeAnonymous() {
info ("Testing native anonymous content with walker."); info("Testing native anonymous content with walker.");
let select = yield gWalker.querySelector(gWalker.rootNode, "select"); let select = yield gWalker.querySelector(gWalker.rootNode, "select");
let children = yield gWalker.children(select); let children = yield gWalker.children(select);
is (select.numChildren, 2, "No native anon content for form control"); is(select.numChildren, 2, "No native anon content for form control");
is (children.nodes.length, 2, "No native anon content for form control"); is(children.nodes.length, 2, "No native anon content for form control");
runNextTest(); runNextTest();
}); });
addAsyncTest(function* testNativeAnonymousStartingNode() { addAsyncTest(function* testNativeAnonymousStartingNode() {
info ("Tests attaching an element that a walker can't see."); info("Tests attaching an element that a walker can't see.");
let serverWalker = DebuggerServer._searchAllConnectionsForActor(gWalker.actorID); let serverWalker = DebuggerServer._searchAllConnectionsForActor(gWalker.actorID);
let docwalker = new _documentWalker( let docwalker = new _documentWalker(
@ -78,108 +79,109 @@ window.onload = function() {
gInspectee.defaultView, gInspectee.defaultView,
nodeFilterConstants.SHOW_ALL, nodeFilterConstants.SHOW_ALL,
() => { () => {
return nodeFilterConstants.FILTER_ACCEPT return nodeFilterConstants.FILTER_ACCEPT;
} }
); );
let scrollbar = docwalker.lastChild(); let scrollbar = docwalker.lastChild();
is (scrollbar.tagName, "scrollbar", "An anonymous child has been fetched"); is(scrollbar.tagName, "scrollbar", "An anonymous child has been fetched");
let node = yield serverWalker.attachElement(scrollbar); let node = yield serverWalker.attachElement(scrollbar);
ok (node, "A response has arrived"); ok(node, "A response has arrived");
ok (node.node, "A node is in the response"); ok(node.node, "A node is in the response");
is (node.node.rawNode.tagName, "SELECT", is(node.node.rawNode.tagName, "SELECT",
"The node has changed to a parent that the walker recognizes"); "The node has changed to a parent that the walker recognizes");
runNextTest(); runNextTest();
}); });
addAsyncTest(function* testPseudoElements() { addAsyncTest(function* testPseudoElements() {
info ("Testing pseudo elements with walker."); info("Testing pseudo elements with walker.");
// Markup looks like: <div><::before /><span /><::after /></div> // Markup looks like: <div><::before /><span /><::after /></div>
let pseudo = yield gWalker.querySelector(gWalker.rootNode, "#pseudo"); let pseudo = yield gWalker.querySelector(gWalker.rootNode, "#pseudo");
let children = yield gWalker.children(pseudo); let children = yield gWalker.children(pseudo);
is (pseudo.numChildren, 1, "::before/::after are not counted if there is a child"); is(pseudo.numChildren, 1, "::before/::after are not counted if there is a child");
is (children.nodes.length, 3, "Correct number of children"); is(children.nodes.length, 3, "Correct number of children");
let before = children.nodes[0]; let before = children.nodes[0];
ok (before.isAnonymous, "Child is anonymous"); ok(before.isAnonymous, "Child is anonymous");
ok (!before._form.isXBLAnonymous, "Child is not XBL anonymous"); ok(!before._form.isXBLAnonymous, "Child is not XBL anonymous");
ok (!before._form.isShadowAnonymous, "Child is not shadow anonymous"); ok(!before._form.isShadowAnonymous, "Child is not shadow anonymous");
ok (before._form.isNativeAnonymous, "Child is native anonymous"); ok(before._form.isNativeAnonymous, "Child is native anonymous");
let span = children.nodes[1]; let span = children.nodes[1];
ok (!span.isAnonymous, "Child is not anonymous"); ok(!span.isAnonymous, "Child is not anonymous");
let after = children.nodes[2]; let after = children.nodes[2];
ok (after.isAnonymous, "Child is anonymous"); ok(after.isAnonymous, "Child is anonymous");
ok (!after._form.isXBLAnonymous, "Child is not XBL anonymous"); ok(!after._form.isXBLAnonymous, "Child is not XBL anonymous");
ok (!after._form.isShadowAnonymous, "Child is not shadow anonymous"); ok(!after._form.isShadowAnonymous, "Child is not shadow anonymous");
ok (after._form.isNativeAnonymous, "Child is native anonymous"); ok(after._form.isNativeAnonymous, "Child is native anonymous");
runNextTest(); runNextTest();
}); });
addAsyncTest(function* testEmptyWithPseudo() { addAsyncTest(function* testEmptyWithPseudo() {
info ("Testing elements with no childrent, except for pseudos."); info("Testing elements with no childrent, except for pseudos.");
info ("Checking an element whose only child is a pseudo element"); info("Checking an element whose only child is a pseudo element");
let pseudo = yield gWalker.querySelector(gWalker.rootNode, "#pseudo-empty"); let pseudo = yield gWalker.querySelector(gWalker.rootNode, "#pseudo-empty");
let children = yield gWalker.children(pseudo); let children = yield gWalker.children(pseudo);
is (pseudo.numChildren, 1, "::before/::after are is counted if there are no other children"); is(pseudo.numChildren, 1,
is (children.nodes.length, 1, "Correct number of children"); "::before/::after are is counted if there are no other children");
is(children.nodes.length, 1, "Correct number of children");
let before = children.nodes[0]; let before = children.nodes[0];
ok (before.isAnonymous, "Child is anonymous"); ok(before.isAnonymous, "Child is anonymous");
ok (!before._form.isXBLAnonymous, "Child is not XBL anonymous"); ok(!before._form.isXBLAnonymous, "Child is not XBL anonymous");
ok (!before._form.isShadowAnonymous, "Child is not shadow anonymous"); ok(!before._form.isShadowAnonymous, "Child is not shadow anonymous");
ok (before._form.isNativeAnonymous, "Child is native anonymous"); ok(before._form.isNativeAnonymous, "Child is native anonymous");
runNextTest(); runNextTest();
}); });
addAsyncTest(function* testShadowAnonymous() { addAsyncTest(function* testShadowAnonymous() {
info ("Testing shadow DOM content."); info("Testing shadow DOM content.");
let shadow = yield gWalker.querySelector(gWalker.rootNode, "#shadow"); let shadow = yield gWalker.querySelector(gWalker.rootNode, "#shadow");
let children = yield gWalker.children(shadow); let children = yield gWalker.children(shadow);
is (shadow.numChildren, 3, "Children of the shadow root are counted"); is(shadow.numChildren, 3, "Children of the shadow root are counted");
is (children.nodes.length, 3, "Children returned from walker"); is(children.nodes.length, 3, "Children returned from walker");
let before = children.nodes[0]; let before = children.nodes[0];
ok (before.isAnonymous, "Child is anonymous"); ok(before.isAnonymous, "Child is anonymous");
ok (!before._form.isXBLAnonymous, "Child is not XBL anonymous"); ok(!before._form.isXBLAnonymous, "Child is not XBL anonymous");
ok (!before._form.isShadowAnonymous, "Child is not shadow anonymous"); ok(!before._form.isShadowAnonymous, "Child is not shadow anonymous");
ok (before._form.isNativeAnonymous, "Child is native anonymous"); ok(before._form.isNativeAnonymous, "Child is native anonymous");
// <h3>Shadow <em>DOM</em></h3> // <h3>Shadow <em>DOM</em></h3>
let shadowChild1 = children.nodes[1]; let shadowChild1 = children.nodes[1];
ok (shadowChild1.isAnonymous, "Child is anonymous"); ok(shadowChild1.isAnonymous, "Child is anonymous");
ok (!shadowChild1._form.isXBLAnonymous, "Child is not XBL anonymous"); ok(!shadowChild1._form.isXBLAnonymous, "Child is not XBL anonymous");
ok (shadowChild1._form.isShadowAnonymous, "Child is shadow anonymous"); ok(shadowChild1._form.isShadowAnonymous, "Child is shadow anonymous");
ok (!shadowChild1._form.isNativeAnonymous, "Child is not native anonymous"); ok(!shadowChild1._form.isNativeAnonymous, "Child is not native anonymous");
let shadowSubChildren = yield gWalker.children(children.nodes[1]); let shadowSubChildren = yield gWalker.children(children.nodes[1]);
is (shadowChild1.numChildren, 2, "Subchildren of the shadow root are counted"); is(shadowChild1.numChildren, 2, "Subchildren of the shadow root are counted");
is (shadowSubChildren.nodes.length, 2, "Subchildren are returned from walker"); is(shadowSubChildren.nodes.length, 2, "Subchildren are returned from walker");
// <em>DOM</em> // <em>DOM</em>
let shadowSubChild = children.nodes[1]; let shadowSubChild = children.nodes[1];
ok (shadowSubChild.isAnonymous, "Child is anonymous"); ok(shadowSubChild.isAnonymous, "Child is anonymous");
ok (!shadowSubChild._form.isXBLAnonymous, "Child is not XBL anonymous"); ok(!shadowSubChild._form.isXBLAnonymous, "Child is not XBL anonymous");
ok (shadowSubChild._form.isShadowAnonymous, "Child is shadow anonymous"); ok(shadowSubChild._form.isShadowAnonymous, "Child is shadow anonymous");
ok (!shadowSubChild._form.isNativeAnonymous, "Child is not native anonymous"); ok(!shadowSubChild._form.isNativeAnonymous, "Child is not native anonymous");
// <select multiple></select> // <select multiple></select>
let shadowChild2 = children.nodes[2]; let shadowChild2 = children.nodes[2];
ok (shadowChild2.isAnonymous, "Child is anonymous"); ok(shadowChild2.isAnonymous, "Child is anonymous");
ok (!shadowChild2._form.isXBLAnonymous, "Child is not XBL anonymous"); ok(!shadowChild2._form.isXBLAnonymous, "Child is not XBL anonymous");
ok (shadowChild2._form.isShadowAnonymous, "Child is shadow anonymous"); ok(shadowChild2._form.isShadowAnonymous, "Child is shadow anonymous");
ok (!shadowChild2._form.isNativeAnonymous, "Child is not native anonymous"); ok(!shadowChild2._form.isNativeAnonymous, "Child is not native anonymous");
runNextTest(); runNextTest();
}); });

View file

@ -11,31 +11,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gClient = null; let gWalker = null;
var gWalker = null;
var checkActorIDs = [];
function assertOwnership() {
assertOwnershipTrees(gWalker);
}
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -56,34 +49,36 @@ addTest(function testChangeAttrs() {
// We're only going to test that the change hit the document. // We're only going to test that the change hit the document.
// There are other tests that make sure changes are propagated // There are other tests that make sure changes are propagated
// to the client. // to the client.
is(attrNode.getAttribute("data-newattr"), "newvalue", "Node should have the first new attribute"); is(attrNode.getAttribute("data-newattr"), "newvalue",
is(attrNode.getAttribute("data-newattr2"), "newvalue", "Node should have the second new attribute."); "Node should have the first new attribute");
is(attrNode.getAttribute("data-newattr2"), "newvalue",
"Node should have the second new attribute.");
}).then(() => { }).then(() => {
// Change an attribute. // Change an attribute.
let list = attrFront.startModifyingAttributes(); let list = attrFront.startModifyingAttributes();
list.setAttribute("data-newattr", "changedvalue"); list.setAttribute("data-newattr", "changedvalue");
return list.apply(); return list.apply();
}).then(() => { }).then(() => {
is(attrNode.getAttribute("data-newattr"), "changedvalue", "Node should have the changed first value."); is(attrNode.getAttribute("data-newattr"), "changedvalue",
is(attrNode.getAttribute("data-newattr2"), "newvalue", "Second value should remain unchanged."); "Node should have the changed first value.");
is(attrNode.getAttribute("data-newattr2"), "newvalue",
"Second value should remain unchanged.");
}).then(() => { }).then(() => {
let list = attrFront.startModifyingAttributes(); let list = attrFront.startModifyingAttributes();
list.removeAttribute("data-newattr2"); list.removeAttribute("data-newattr2");
return list.apply(); return list.apply();
}).then(() => { }).then(() => {
is(attrNode.getAttribute("data-newattr"), "changedvalue", "Node should have the changed first value."); is(attrNode.getAttribute("data-newattr"), "changedvalue",
"Node should have the changed first value.");
ok(!attrNode.hasAttribute("data-newattr2"), "Second value should be removed."); ok(!attrNode.hasAttribute("data-newattr2"), "Second value should be removed.");
}).then(runNextTest)); }).then(runNextTest));
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gInspectee; gInspectee = null;
delete gClient;
runNextTest(); runNextTest();
}); });
</script> </script>
</head> </head>
<body> <body>

View file

@ -11,31 +11,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const Ci = Components.interfaces; "use strict";
const inspector = require("devtools/shared/fronts/inspector");
window.onload = function() { const Ci = Components.interfaces;
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gClient = null; let gWalker = null;
var gWalker = null;
function assertOwnership() {
assertOwnershipTrees(gWalker);
}
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -60,13 +55,10 @@ addTest(function testChangeValue() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gInspectee; gInspectee = null;
delete gClient;
runNextTest(); runNextTest();
}); });
</script> </script>
</head> </head>
<body> <body>

View file

@ -11,20 +11,21 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1121528
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker, gDoc; let gWalker = null;
let gDoc = null;
addAsyncTest(function*() { addAsyncTest(function* () {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
let def = promise.defer(); let def = promise.defer();
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
def.resolve({client, tab, doc}); def.resolve({client, tab, doc});
}); });
let {client, tab, doc} = yield def.promise; let {client, tab, doc} = yield def.promise;
@ -37,7 +38,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.parents(nodeFront) before the load completes shouldn't fail"); "walker.parents(nodeFront) before the load completes shouldn't fail");
@ -51,7 +52,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.children(nodeFront) before the load completes shouldn't fail"); "walker.children(nodeFront) before the load completes shouldn't fail");
@ -65,7 +66,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.siblings(nodeFront) before the load completes shouldn't fail"); "walker.siblings(nodeFront) before the load completes shouldn't fail");
@ -79,7 +80,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.nextSibling(nodeFront) before the load completes shouldn't fail"); "walker.nextSibling(nodeFront) before the load completes shouldn't fail");
@ -93,7 +94,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.previousSibling(nodeFront) before the load completes shouldn't fail"); "walker.previousSibling(nodeFront) before the load completes shouldn't fail");
@ -107,7 +108,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.addPseudoClassLock(nodeFront) before the load completes " + "walker.addPseudoClassLock(nodeFront) before the load completes " +
"shouldn't fail"); "shouldn't fail");
@ -122,7 +123,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.removePseudoClassLock(nodeFront) before the load completes " + "walker.removePseudoClassLock(nodeFront) before the load completes " +
"shouldn't fail"); "shouldn't fail");
@ -137,7 +138,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.clearPseudoClassLocks(nodeFront) before the load completes " + "walker.clearPseudoClassLocks(nodeFront) before the load completes " +
"shouldn't fail"); "shouldn't fail");
@ -152,7 +153,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.innerHTML(nodeFront) before the load completes shouldn't fail"); "walker.innerHTML(nodeFront) before the load completes shouldn't fail");
@ -166,7 +167,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.setInnerHTML(nodeFront) before the load completes shouldn't fail"); "walker.setInnerHTML(nodeFront) before the load completes shouldn't fail");
@ -180,7 +181,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.outerHTML(nodeFront) before the load completes shouldn't fail"); "walker.outerHTML(nodeFront) before the load completes shouldn't fail");
@ -194,7 +195,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.setOuterHTML(nodeFront) before the load completes shouldn't fail"); "walker.setOuterHTML(nodeFront) before the load completes shouldn't fail");
@ -208,7 +209,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.insertAdjacentHTML(nodeFront) before the load completes shouldn't " + "walker.insertAdjacentHTML(nodeFront) before the load completes shouldn't " +
"fail"); "fail");
@ -224,7 +225,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.removeNode(nodeFront) before the load completes should throw"); "walker.removeNode(nodeFront) before the load completes should throw");
@ -243,7 +244,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.removeNodes([nodeFront]) before the load completes should throw"); "walker.removeNodes([nodeFront]) before the load completes should throw");
@ -264,7 +265,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.insertBefore(nodeFront, parent, null) before the load completes " + "walker.insertBefore(nodeFront, parent, null) before the load completes " +
"shouldn't fail"); "shouldn't fail");
@ -280,7 +281,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.insertBefore(nodeFront, parent, sibling) before the load completes " + "walker.insertBefore(nodeFront, parent, sibling) before the load completes " +
"shouldn't fail"); "shouldn't fail");
@ -297,7 +298,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.editTagName(nodeFront) before the load completes shouldn't fail"); "walker.editTagName(nodeFront) before the load completes shouldn't fail");
@ -311,7 +312,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.hideNode(nodeFront) before the load completes shouldn't fail"); "walker.hideNode(nodeFront) before the load completes shouldn't fail");
@ -325,7 +326,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.unhideNode(nodeFront) before the load completes shouldn't fail"); "walker.unhideNode(nodeFront) before the load completes shouldn't fail");
@ -339,7 +340,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.releaseNode(nodeFront) before the load completes shouldn't fail"); "walker.releaseNode(nodeFront) before the load completes shouldn't fail");
@ -353,7 +354,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
info("Getting a nodeFront, reloading the page, and calling " + info("Getting a nodeFront, reloading the page, and calling " +
"walker.querySelector(nodeFront) before the load completes shouldn't fail"); "walker.querySelector(nodeFront) before the load completes shouldn't fail");
@ -368,7 +369,8 @@ addAsyncTest(function*() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
gWalker = gDoc = null; gWalker = null;
gDoc = null;
runNextTest(); runNextTest();
}); });
</script> </script>

View file

@ -11,30 +11,22 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1208864
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gWalker = null;
var gClient = null;
var gWalker = null;
function assertOwnership() {
assertOwnershipTrees(gWalker);
}
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -55,9 +47,7 @@ addTest(Task.async(function* testDuplicateNode() {
})); }));
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gInspectee;
delete gClient;
runNextTest(); runNextTest();
}); });
</script> </script>

View file

@ -11,25 +11,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gClient = null; let gInspectee = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -56,8 +55,8 @@ addTest(function testRearrange() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gClient; gInspectee = null;
runNextTest(); runNextTest();
}); });

View file

@ -11,29 +11,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
"use strict";
const inspector = require("devtools/server/actors/inspector"); const inspector = require("devtools/server/actors/inspector");
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gClient = null; let gInspectee = null;
function assertOwnership() {
return assertOwnershipTrees(gWalker);
}
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspectorFront = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspectorFront.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -47,9 +44,11 @@ addAsyncTest(function* testRearrange() {
// Move nodeA to the end of the list. // Move nodeA to the end of the list.
yield gWalker.insertBefore(nodeA, longlist, null); yield gWalker.insertBefore(nodeA, longlist, null);
ok(!gInspectee.querySelector("#a").nextSibling, "a should now be at the end of the list."); ok(!gInspectee.querySelector("#a").nextSibling,
"a should now be at the end of the list.");
children = yield gWalker.children(longlist); children = yield gWalker.children(longlist);
is(nodeA, children.nodes[children.nodes.length - 1], "a should now be the last returned child."); is(nodeA, children.nodes[children.nodes.length - 1],
"a should now be the last returned child.");
// Now move it to the middle of the list. // Now move it to the middle of the list.
let nextNode = children.nodes[13]; let nextNode = children.nodes[13];
@ -99,8 +98,8 @@ addAsyncTest(function* testInsertInvalidInput() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gClient; gInspectee = null;
runNextTest(); runNextTest();
}); });

View file

@ -11,28 +11,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gWalker = null; let gWalker = null;
var gClient = null; let attrNode;
var attrNode; let attrFront;
var attrFront;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -50,14 +48,14 @@ addTest(testRemoveAttribute);
addTest(testQueuedMutations); addTest(testQueuedMutations);
function setupAttrTest() { function setupAttrTest() {
attrNode = gInspectee.querySelector("#a") attrNode = gInspectee.querySelector("#a");
promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(node => { promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(node => {
attrFront = node; attrFront = node;
}).then(runNextTest)); }).then(runNextTest));
} }
function setupFrameAttrTest() { function setupFrameAttrTest() {
let frame = gInspectee.querySelector('#childFrame'); let frame = gInspectee.querySelector("#childFrame");
attrNode = frame.contentDocument.querySelector("#a"); attrNode = frame.contentDocument.querySelector("#a");
promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => { promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => {
@ -77,8 +75,10 @@ function testAddAttribute() {
attrNode.setAttribute("data-newattr2", "newvalue"); attrNode.setAttribute("data-newattr2", "newvalue");
gWalker.once("mutations", () => { gWalker.once("mutations", () => {
is(attrFront.attributes.length, 3, "Should have id and two new attributes."); is(attrFront.attributes.length, 3, "Should have id and two new attributes.");
is(attrFront.getAttribute("data-newattr"), "newvalue", "Node front should have the first new attribute"); is(attrFront.getAttribute("data-newattr"), "newvalue",
is(attrFront.getAttribute("data-newattr2"), "newvalue", "Node front should have the second new attribute."); "Node front should have the first new attribute");
is(attrFront.getAttribute("data-newattr2"), "newvalue",
"Node front should have the second new attribute.");
runNextTest(); runNextTest();
}); });
} }
@ -88,10 +88,13 @@ function testChangeAttribute() {
attrNode.setAttribute("data-newattr", "changedvalue2"); attrNode.setAttribute("data-newattr", "changedvalue2");
attrNode.setAttribute("data-newattr", "changedvalue3"); attrNode.setAttribute("data-newattr", "changedvalue3");
gWalker.once("mutations", mutations => { gWalker.once("mutations", mutations => {
is(mutations.length, 1, "Only one mutation is sent for multiple queued attribute changes"); is(mutations.length, 1,
"Only one mutation is sent for multiple queued attribute changes");
is(attrFront.attributes.length, 3, "Should have id and two new attributes."); is(attrFront.attributes.length, 3, "Should have id and two new attributes.");
is(attrFront.getAttribute("data-newattr"), "changedvalue3", "Node front should have the changed first value"); is(attrFront.getAttribute("data-newattr"), "changedvalue3",
is(attrFront.getAttribute("data-newattr2"), "newvalue", "Second value should remain unchanged."); "Node front should have the changed first value");
is(attrFront.getAttribute("data-newattr2"), "newvalue",
"Second value should remain unchanged.");
runNextTest(); runNextTest();
}); });
} }
@ -100,10 +103,11 @@ function testRemoveAttribute() {
attrNode.removeAttribute("data-newattr2"); attrNode.removeAttribute("data-newattr2");
gWalker.once("mutations", () => { gWalker.once("mutations", () => {
is(attrFront.attributes.length, 2, "Should have id and one remaining attribute."); is(attrFront.attributes.length, 2, "Should have id and one remaining attribute.");
is(attrFront.getAttribute("data-newattr"), "changedvalue3", "Node front should still have the first value"); is(attrFront.getAttribute("data-newattr"), "changedvalue3",
"Node front should still have the first value");
ok(!attrFront.hasAttribute("data-newattr2"), "Second value should be removed."); ok(!attrFront.hasAttribute("data-newattr2"), "Second value should be removed.");
runNextTest(); runNextTest();
}) });
} }
function testQueuedMutations() { function testQueuedMutations() {
@ -115,7 +119,7 @@ function testQueuedMutations() {
attrNode.setAttribute("data-newattr", "2"); attrNode.setAttribute("data-newattr", "2");
attrNode.removeAttribute("data-newattr"); attrNode.removeAttribute("data-newattr");
for (var i = 0; i <= 1000; i++) { for (let i = 0; i <= 1000; i++) {
attrNode.setAttribute("data-newattr2", i); attrNode.setAttribute("data-newattr2", i);
} }
@ -132,26 +136,27 @@ function testQueuedMutations() {
attrNode.removeAttribute("data-newattr4"); attrNode.removeAttribute("data-newattr4");
gWalker.once("mutations", mutations => { gWalker.once("mutations", mutations => {
is(mutations.length, 4, "Only one mutation each is sent for multiple queued attribute changes"); is(mutations.length, 4,
is(attrFront.attributes.length, 3, "Should have id, data-newattr2, and data-newattr3."); "Only one mutation each is sent for multiple queued attribute changes");
is(attrFront.attributes.length, 3,
"Should have id, data-newattr2, and data-newattr3.");
is(attrFront.getAttribute("data-newattr2"), "1000", "Node front should still have the correct value"); is(attrFront.getAttribute("data-newattr2"), "1000",
is(attrFront.getAttribute("data-newattr3"), "3", "Node front should still have the correct value"); "Node front should still have the correct value");
is(attrFront.getAttribute("data-newattr3"), "3",
"Node front should still have the correct value");
ok(!attrFront.hasAttribute("data-newattr"), "Attribute value should be removed."); ok(!attrFront.hasAttribute("data-newattr"), "Attribute value should be removed.");
ok(!attrFront.hasAttribute("data-newattr4"), "Attribute value should be removed."); ok(!attrFront.hasAttribute("data-newattr4"), "Attribute value should be removed.");
runNextTest(); runNextTest();
}) });
} }
addTest(function cleanup() { addTest(function cleanup() {
delete gInspectee; gInspectee = null;
delete gWalker; gWalker = null;
delete gClient;
runNextTest(); runNextTest();
}); });
</script> </script>
</head> </head>
<body> <body>

View file

@ -11,26 +11,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gWalker = null; let gWalker = null;
var gClient = null; let gCleanupConnection = null;
var gCleanupConnection = null;
function setup(callback) { function setup(callback) {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
gCleanupConnection = attachURL(url, function(err, client, tab, doc) { gCleanupConnection = attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
gClient = client;
gWalker = walker; gWalker = walker;
}).then(callback)); }).then(callback));
}); });
@ -38,7 +36,6 @@ function setup(callback) {
function teardown() { function teardown() {
gWalker = null; gWalker = null;
gClient = null;
gInspectee = null; gInspectee = null;
if (gCleanupConnection) { if (gCleanupConnection) {
gCleanupConnection(); gCleanupConnection();
@ -47,7 +44,7 @@ function teardown() {
} }
function assertOwnership() { function assertOwnership() {
let num = assertOwnershipTrees(gWalker); return assertOwnershipTrees(gWalker);
} }
function setParent(nodeSelector, newParentSelector) { function setParent(nodeSelector, newParentSelector) {
@ -83,7 +80,7 @@ function doMoves(moves) {
var gDummySerial = 0; var gDummySerial = 0;
function mutationTest(testSpec) { function mutationTest(testSpec) {
return function() { return function () {
setup(() => { setup(() => {
promiseDone(loadSelectors(testSpec.load || ["html"]).then(() => { promiseDone(loadSelectors(testSpec.load || ["html"]).then(() => {
gWalker.autoCleanup = !!testSpec.autoCleanup; gWalker.autoCleanup = !!testSpec.autoCleanup;
@ -99,6 +96,7 @@ function mutationTest(testSpec) {
gWalker.once("mutations", (mutations) => { gWalker.once("mutations", (mutations) => {
// Filter out our dummy mutation. // Filter out our dummy mutation.
// eslint-disable-next-line max-nested-callbacks
mutations = mutations.filter(change => { mutations = mutations.filter(change => {
if (change.type == "attributes" && if (change.type == "attributes" &&
change.attributeName == "data-dummy") { change.attributeName == "data-dummy") {
@ -114,14 +112,14 @@ function mutationTest(testSpec) {
runNextTest(); runNextTest();
}); });
})); }));
}) });
} };
} }
// Verify that our dummy mutation works. // Verify that our dummy mutation works.
addTest(mutationTest({ addTest(mutationTest({
autoCleanup: false, autoCleanup: false,
postCheck: function(mutations) { postCheck: function (mutations) {
is(mutations.length, 0, "Dummy mutation is filtered out."); is(mutations.length, 0, "Dummy mutation is filtered out.");
} }
})); }));
@ -134,17 +132,18 @@ addTest(mutationTest({
moves: [ moves: [
["#a", "#longlist"] ["#a", "#longlist"]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
let remove = mutations[0]; let remove = mutations[0];
is(remove.type, "childList", "First mutation should be a childList.") is(remove.type, "childList", "First mutation should be a childList.");
ok(remove.removed.length > 0, "First mutation should be a removal.") ok(remove.removed.length > 0, "First mutation should be a removal.");
let add = mutations[1]; let add = mutations[1];
is(add.type, "childList", "Second mutation should be a childList removal.") is(add.type, "childList", "Second mutation should be a childList removal.");
ok(add.added.length > 0, "Second mutation should be an addition.") ok(add.added.length > 0, "Second mutation should be an addition.");
let a = add.added[0]; let a = add.added[0];
is(a.id, "a", "Added node should be #a"); is(a.id, "a", "Added node should be #a");
is(a.parentNode(), remove.target, "Should still be a child of longlist."); is(a.parentNode(), remove.target, "Should still be a child of longlist.");
is(remove.target, add.target, "First and second mutations should be against the same node."); is(remove.target, add.target,
"First and second mutations should be against the same node.");
} }
})); }));
@ -155,13 +154,13 @@ addTest(mutationTest({
moves: [ moves: [
["#a", "#longlist-sibling"] ["#a", "#longlist-sibling"]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
let remove = mutations[0]; let remove = mutations[0];
is(remove.type, "childList", "First mutation should be a childList.") is(remove.type, "childList", "First mutation should be a childList.");
ok(remove.removed.length > 0, "First mutation should be a removal.") ok(remove.removed.length > 0, "First mutation should be a removal.");
let add = mutations[1]; let add = mutations[1];
is(add.type, "childList", "Second mutation should be a childList removal.") is(add.type, "childList", "Second mutation should be a childList removal.");
ok(add.added.length > 0, "Second mutation should be an addition.") ok(add.added.length > 0, "Second mutation should be an addition.");
let a = add.added[0]; let a = add.added[0];
is(a.id, "a", "Added node should be #a"); is(a.id, "a", "Added node should be #a");
is(a.parentNode(), add.target, "Should still be a child of longlist."); is(a.parentNode(), add.target, "Should still be a child of longlist.");
@ -177,7 +176,7 @@ addTest(mutationTest({
moves: [ moves: [
["#longlist-sibling", "#longlist"] ["#longlist-sibling", "#longlist"]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
is(mutations.length, 2, "Should generate two mutations"); is(mutations.length, 2, "Should generate two mutations");
is(mutations[0].type, "childList", "Should be childList mutations."); is(mutations[0].type, "childList", "Should be childList mutations.");
is(mutations[0].added.length, 0, "Should have no adds."); is(mutations[0].added.length, 0, "Should have no adds.");
@ -196,7 +195,7 @@ addTest(mutationTest({
moves: [ moves: [
["#longlist-sibling-firstchild", "#longlist"] ["#longlist-sibling-firstchild", "#longlist"]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
is(mutations.length, 1, "Should generate two mutations"); is(mutations.length, 1, "Should generate two mutations");
is(mutations[0].type, "childList", "Should be childList mutations."); is(mutations[0].type, "childList", "Should be childList mutations.");
is(mutations[0].added.length, 0, "Should have no adds."); is(mutations[0].added.length, 0, "Should have no adds.");
@ -211,7 +210,7 @@ addTest(mutationTest({
moves: [ moves: [
["#longlist-sibling", "#longlist"] ["#longlist-sibling", "#longlist"]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
is(mutations.length, 0, "Should generate no mutations."); is(mutations.length, 0, "Should generate no mutations.");
} }
})); }));
@ -223,14 +222,15 @@ addTest(mutationTest({
moves: [ moves: [
["#longlist", null] ["#longlist", null]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
is(mutations.length, 1, "Should generate one mutation."); is(mutations.length, 1, "Should generate one mutation.");
let change = mutations[0]; let change = mutations[0];
is(change.type, "childList", "Should be a childList."); is(change.type, "childList", "Should be a childList.");
is(change.removed.length, 1, "Should have removed a child."); is(change.removed.length, 1, "Should have removed a child.");
let ownership = clientOwnershipTree(gWalker); let ownership = clientOwnershipTree(gWalker);
is(ownership.orphaned.length, 1, "Should have one orphaned subtree."); is(ownership.orphaned.length, 1, "Should have one orphaned subtree.");
is(ownershipTreeSize(ownership.orphaned[0]), 1 + 26 + 26, "Should have orphaned longlist, and 26 children, and 26 singleTextChilds"); is(ownershipTreeSize(ownership.orphaned[0]), 1 + 26 + 26,
"Should have orphaned longlist, and 26 children, and 26 singleTextChilds");
} }
})); }));
@ -241,7 +241,7 @@ addTest(mutationTest({
moves: [ moves: [
["#longlist", null] ["#longlist", null]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
is(mutations.length, 1, "Should generate one mutation."); is(mutations.length, 1, "Should generate one mutation.");
let change = mutations[0]; let change = mutations[0];
is(change.type, "childList", "Should be a childList."); is(change.type, "childList", "Should be a childList.");
@ -258,25 +258,27 @@ addTest(mutationTest({
moves: [ moves: [
["#longlist", "#longlist-sibling"] ["#longlist", "#longlist-sibling"]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
is(mutations.length, 1, "Should generate one mutation."); is(mutations.length, 1, "Should generate one mutation.");
let change = mutations[0]; let change = mutations[0];
is(change.type, "childList", "Should be a childList."); is(change.type, "childList", "Should be a childList.");
is(change.removed.length, 1, "Should have removed a child."); is(change.removed.length, 1, "Should have removed a child.");
let ownership = clientOwnershipTree(gWalker); let ownership = clientOwnershipTree(gWalker);
is(ownership.orphaned.length, 1, "Should have one orphaned subtree."); is(ownership.orphaned.length, 1, "Should have one orphaned subtree.");
is(ownershipTreeSize(ownership.orphaned[0]), 1 + 26 + 26, "Should have orphaned longlist, 26 children, and 26 singleTextChilds."); is(ownershipTreeSize(ownership.orphaned[0]), 1 + 26 + 26,
"Should have orphaned longlist, 26 children, and 26 singleTextChilds.");
} }
})); }));
// Orphan a node by moving it into the tree but out of our visible subtree, and clean it up. // Orphan a node by moving it into the tree but out of our visible subtree,
// and clean it up.
addTest(mutationTest({ addTest(mutationTest({
autoCleanup: true, autoCleanup: true,
load: ["#longlist div"], load: ["#longlist div"],
moves: [ moves: [
["#longlist", "#longlist-sibling"] ["#longlist", "#longlist-sibling"]
], ],
postCheck: function(mutations) { postCheck: function (mutations) {
is(mutations.length, 1, "Should generate one mutation."); is(mutations.length, 1, "Should generate one mutation.");
let change = mutations[0]; let change = mutations[0];
is(change.type, "childList", "Should be a childList."); is(change.type, "childList", "Should be a childList.");
@ -286,15 +288,11 @@ addTest(mutationTest({
} }
})); }));
addTest(function cleanup() { addTest(function cleanup() {
delete gInspectee; gInspectee = null;
delete gWalker; gWalker = null;
delete gClient;
runNextTest(); runNextTest();
}); });
</script> </script>
</head> </head>
<body> <body>

View file

@ -10,9 +10,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1157469
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
"use strict";
window.onload = function() { window.onload = function () {
const Cu = Components.utils; const Cu = Components.utils;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {InspectorFront} = require("devtools/shared/fronts/inspector"); const {InspectorFront} = require("devtools/shared/fronts/inspector");
@ -30,11 +30,11 @@ window.onload = function() {
let eventFront2; let eventFront2;
addAsyncTest(function* setup() { addAsyncTest(function* setup() {
info ("Setting up inspector and walker actors."); info("Setting up inspector and walker actors.");
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
yield new Promise(resolve => { yield new Promise(resolve => {
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
inspectee = doc; inspectee = doc;
inspector = InspectorFront(client, tab); inspector = InspectorFront(client, tab);
resolve(); resolve();
@ -48,8 +48,8 @@ window.onload = function() {
}); });
addAsyncTest(function* setupEventTest() { addAsyncTest(function* setupEventTest() {
eventNode1 = inspectee.querySelector("#a") eventNode1 = inspectee.querySelector("#a");
eventNode2 = inspectee.querySelector("#b") eventNode2 = inspectee.querySelector("#b");
eventFront1 = yield walker.querySelector(walker.rootNode, "#a"); eventFront1 = yield walker.querySelector(walker.rootNode, "#a");
eventFront2 = yield walker.querySelector(walker.rootNode, "#b"); eventFront2 = yield walker.querySelector(walker.rootNode, "#b");
@ -67,7 +67,8 @@ window.onload = function() {
is(mutations.length, 1, "one mutation expected"); is(mutations.length, 1, "one mutation expected");
is(mutations[0].target, eventFront1, "mutation targets eventFront1"); is(mutations[0].target, eventFront1, "mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events"); is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, true, "mutation target should have event listeners"); is(mutations[0].hasEventListeners, true,
"mutation target should have event listeners");
is(eventFront1.hasEventListeners, true, "eventFront1 should have event listeners"); is(eventFront1.hasEventListeners, true, "eventFront1 should have event listeners");
info("remove event listener on a single node"); info("remove event listener on a single node");
@ -77,10 +78,12 @@ window.onload = function() {
is(mutations.length, 1, "one mutation expected"); is(mutations.length, 1, "one mutation expected");
is(mutations[0].target, eventFront1, "mutation targets eventFront1"); is(mutations[0].target, eventFront1, "mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events"); is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, false, "mutation target should have no event listeners"); is(mutations[0].hasEventListeners, false,
is(eventFront1.hasEventListeners, false, "eventFront1 should have no event listeners"); "mutation target should have no event listeners");
is(eventFront1.hasEventListeners, false,
"eventFront1 should have no event listeners");
info("perform several event listener changes on a single node") info("perform several event listener changes on a single node");
eventNode1.addEventListener("click", eventListener1); eventNode1.addEventListener("click", eventListener1);
eventNode1.addEventListener("click", eventListener2); eventNode1.addEventListener("click", eventListener2);
eventNode1.removeEventListener("click", eventListener1); eventNode1.removeEventListener("click", eventListener1);
@ -90,7 +93,8 @@ window.onload = function() {
is(mutations.length, 1, "one mutation expected"); is(mutations.length, 1, "one mutation expected");
is(mutations[0].target, eventFront1, "mutation targets eventFront1"); is(mutations[0].target, eventFront1, "mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events"); is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, false, "no event listener expected on mutation target"); is(mutations[0].hasEventListeners, false,
"no event listener expected on mutation target");
is(eventFront1.hasEventListeners, false, "no event listener expected on node"); is(eventFront1.hasEventListeners, false, "no event listener expected on node");
runNextTest(); runNextTest();
@ -108,12 +112,14 @@ window.onload = function() {
// first mutation // first mutation
is(mutations[0].target, eventFront1, "first mutation targets eventFront1"); is(mutations[0].target, eventFront1, "first mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events"); is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, true, "mutation target should have event listeners"); is(mutations[0].hasEventListeners, true,
"mutation target should have event listeners");
is(eventFront1.hasEventListeners, true, "eventFront1 should have event listeners"); is(eventFront1.hasEventListeners, true, "eventFront1 should have event listeners");
// second mutation // second mutation
is(mutations[1].target, eventFront2, "second mutation targets eventFront2"); is(mutations[1].target, eventFront2, "second mutation targets eventFront2");
is(mutations[1].type, "events", "mutation type is events"); is(mutations[1].type, "events", "mutation type is events");
is(mutations[1].hasEventListeners, true, "mutation target should have event listeners"); is(mutations[1].hasEventListeners, true,
"mutation target should have event listeners");
is(eventFront2.hasEventListeners, true, "eventFront1 should have event listeners"); is(eventFront2.hasEventListeners, true, "eventFront1 should have event listeners");
info("remove event listeners on both nodes"); info("remove event listeners on both nodes");
@ -125,13 +131,17 @@ window.onload = function() {
// first mutation // first mutation
is(mutations[0].target, eventFront1, "first mutation targets eventFront1"); is(mutations[0].target, eventFront1, "first mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events"); is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, false, "mutation target should have no event listeners"); is(mutations[0].hasEventListeners, false,
is(eventFront1.hasEventListeners, false, "eventFront2 should have no event listeners"); "mutation target should have no event listeners");
is(eventFront1.hasEventListeners, false,
"eventFront2 should have no event listeners");
// second mutation // second mutation
is(mutations[1].target, eventFront2, "second mutation targets eventFront2"); is(mutations[1].target, eventFront2, "second mutation targets eventFront2");
is(mutations[1].type, "events", "mutation type is events"); is(mutations[1].type, "events", "mutation type is events");
is(mutations[1].hasEventListeners, false, "mutation target should have no event listeners"); is(mutations[1].hasEventListeners, false,
is(eventFront2.hasEventListeners, false, "eventFront2 should have no event listeners"); "mutation target should have no event listeners");
is(eventFront2.hasEventListeners, false,
"eventFront2 should have no event listeners");
runNextTest(); runNextTest();
}); });
@ -142,7 +152,7 @@ window.onload = function() {
info("try to remove an event listener not previously added"); info("try to remove an event listener not previously added");
eventNode1.removeEventListener("click", eventListener1); eventNode1.removeEventListener("click", eventListener1);
info("set any attribute on the node to trigger a mutation") info("set any attribute on the node to trigger a mutation");
eventNode1.setAttribute("data-attr", "somevalue"); eventNode1.setAttribute("data-attr", "somevalue");
let mutations = yield waitForMutations(); let mutations = yield waitForMutations();
@ -153,9 +163,11 @@ window.onload = function() {
}); });
function checkNodesHaveNoEventListener() { function checkNodesHaveNoEventListener() {
is(eventFront1.hasEventListeners, false, "eventFront1 hasEventListeners should be false"); is(eventFront1.hasEventListeners, false,
is(eventFront2.hasEventListeners, false, "eventFront2 hasEventListeners should be false"); "eventFront1 hasEventListeners should be false");
}; is(eventFront2.hasEventListeners, false,
"eventFront2 hasEventListeners should be false");
}
function waitForMutations() { function waitForMutations() {
return new Promise(resolve => { return new Promise(resolve => {
@ -166,8 +178,7 @@ window.onload = function() {
} }
runNextTest(); runNextTest();
} };
</script> </script>
</head> </head>
<body> <body>

View file

@ -11,23 +11,21 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gWalker = null; let gWalker = null;
var gClient = null; let gClient = null;
var gChildFrame = null; let gCleanupConnection = null;
var gChildDocument = null;
var gCleanupConnection = null;
function setup(callback) { function setup(callback) {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
gCleanupConnection = attachURL(url, function(err, client, tab, doc) { gCleanupConnection = attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
@ -42,7 +40,6 @@ function teardown() {
gWalker = null; gWalker = null;
gClient = null; gClient = null;
gInspectee = null; gInspectee = null;
gChildFrame = null;
if (gCleanupConnection) { if (gCleanupConnection) {
gCleanupConnection(); gCleanupConnection();
gCleanupConnection = null; gCleanupConnection = null;
@ -55,8 +52,8 @@ function assertOwnership() {
function loadChildSelector(selector) { function loadChildSelector(selector) {
return gWalker.querySelector(gWalker.rootNode, "#childFrame").then(frame => { return gWalker.querySelector(gWalker.rootNode, "#childFrame").then(frame => {
ok(frame.numChildren > 0, "Child frame should consider its loaded document as a child."); ok(frame.numChildren > 0,
gChildFrame = frame; "Child frame should consider its loaded document as a child.");
return gWalker.children(frame); return gWalker.children(frame);
}).then(children => { }).then(children => {
return gWalker.querySelectorAll(children.nodes[0], selector); return gWalker.querySelectorAll(children.nodes[0], selector);
@ -76,7 +73,6 @@ function getUnloadedDoc(mutations) {
addTest(function loadNewChild() { addTest(function loadNewChild() {
setup(() => { setup(() => {
let beforeUnloadSize = 0;
// Load a bunch of fronts for actors inside the child frame. // Load a bunch of fronts for actors inside the child frame.
promiseDone(loadChildSelector("#longlist div").then(() => { promiseDone(loadChildSelector("#longlist div").then(() => {
let childFrame = gInspectee.querySelector("#childFrame"); let childFrame = gInspectee.querySelector("#childFrame");
@ -102,7 +98,6 @@ addTest(function loadNewChild() {
addTest(function loadNewChildTwice() { addTest(function loadNewChildTwice() {
setup(() => { setup(() => {
let beforeUnloadSize = 0;
// Load a bunch of fronts for actors inside the child frame. // Load a bunch of fronts for actors inside the child frame.
promiseDone(loadChildSelector("#longlist div").then(() => { promiseDone(loadChildSelector("#longlist div").then(() => {
let childFrame = gInspectee.querySelector("#childFrame"); let childFrame = gInspectee.querySelector("#childFrame");
@ -130,10 +125,8 @@ addTest(function loadNewChildTwice() {
}); });
}); });
addTest(function loadNewChildTwiceAndCareAboutIt() { addTest(function loadNewChildTwiceAndCareAboutIt() {
setup(() => { setup(() => {
let beforeUnloadSize = 0;
// Load a bunch of fronts for actors inside the child frame. // Load a bunch of fronts for actors inside the child frame.
promiseDone(loadChildSelector("#longlist div").then(() => { promiseDone(loadChildSelector("#longlist div").then(() => {
let childFrame = gInspectee.querySelector("#childFrame"); let childFrame = gInspectee.querySelector("#childFrame");
@ -168,7 +161,6 @@ addTest(function loadNewChildTwiceAndCareAboutIt() {
addTest(function testBack() { addTest(function testBack() {
setup(() => { setup(() => {
let beforeUnloadSize = 0;
// Load a bunch of fronts for actors inside the child frame. // Load a bunch of fronts for actors inside the child frame.
promiseDone(loadChildSelector("#longlist div").then(() => { promiseDone(loadChildSelector("#longlist div").then(() => {
let childFrame = gInspectee.querySelector("#childFrame"); let childFrame = gInspectee.querySelector("#childFrame");
@ -178,7 +170,8 @@ addTest(function testBack() {
// Read the new child // Read the new child
return loadChildSelector("#longlist div"); return loadChildSelector("#longlist div");
}).then(() => { }).then(() => {
// Now use history.back to change the source, and expect the same results as loadNewChild. // Now use history.back to change the source,
// and expect the same results as loadNewChild.
let childFrame = gInspectee.querySelector("#childFrame"); let childFrame = gInspectee.querySelector("#childFrame");
childFrame.contentWindow.history.back(); childFrame.contentWindow.history.back();
return waitForMutation(gWalker, isChildList); return waitForMutation(gWalker, isChildList);

View file

@ -11,39 +11,38 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
"use strict";
const inspector = require("devtools/server/actors/inspector"); const inspector = require("devtools/server/actors/inspector");
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
const testSummaryLength = 10; const testSummaryLength = 10;
inspector.setValueSummaryLength(testSummaryLength); inspector.setValueSummaryLength(testSummaryLength);
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function () {
inspector.setValueSummaryLength(inspector.DEFAULT_VALUE_SUMMARY_LENGTH); inspector.setValueSummaryLength(inspector.DEFAULT_VALUE_SUMMARY_LENGTH);
}); });
var gInspectee = null; let gInspectee = null;
var gWalker = null; let gWalker = null;
var gClient = null; let valueNode;
var valueNode;
var valueFront; var valueFront;
var longStringFront; var longStringFront;
var longString = "stringstringstringstringstringstringstringstringstringstringstring"; var longString = "stringstringstringstringstringstringstringstringstringstringstring";
var truncatedLongString = longString.substring(0, testSummaryLength);
var shortString = "str"; var shortString = "str";
var shortString2 = "str2"; var shortString2 = "str2";
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspectorFront = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspectorFront.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -71,7 +70,7 @@ function setupValueTest() {
} }
function setupFrameValueTest() { function setupFrameValueTest() {
let frame = gInspectee.querySelector('#childFrame'); let frame = gInspectee.querySelector("#childFrame");
valueNode = frame.contentDocument.querySelector("#longstring").firstChild; valueNode = frame.contentDocument.querySelector("#longstring").firstChild;
promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => { promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => {
@ -94,7 +93,7 @@ function checkNodeFrontValue(front, expectedValue) {
return longstring.string(); return longstring.string();
}).then(str => { }).then(str => {
is(str, expectedValue, "Node value is as expected"); is(str, expectedValue, "Node value is as expected");
}) });
} }
function testKeepLongValue() { function testKeepLongValue() {
@ -147,9 +146,8 @@ function testSetLongValue() {
} }
addTest(function cleanup() { addTest(function cleanup() {
delete gInspectee; gInspectee = null;
delete gWalker; gWalker = null;
delete gClient;
runNextTest(); runNextTest();
}); });

View file

@ -1,101 +1,99 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<!-- <!--
Test that the inspector actor has the pickColorFromPage and cancelPickColorFromPage Test that the inspector actor has the pickColorFromPage and cancelPickColorFromPage
methods and that when a color is picked the color-picked event is emitted and that when methods and that when a color is picked the color-picked event is emitted and that when
the eyedropper is dimissed, the color-pick-canceled event is emitted. the eyedropper is dimissed, the color-pick-canceled event is emitted.
https://bugzilla.mozilla.org/show_bug.cgi?id=1262439 https://bugzilla.mozilla.org/show_bug.cgi?id=1262439
--> -->
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Test for Bug 1262439</title> <title>Test for Bug 1262439</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { "use strict";
const Cu = Components.utils;
Cu.import("resource://devtools/shared/Loader.jsm"); window.onload = function () {
const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); const {InspectorFront} = require("devtools/shared/fronts/inspector");
const {InspectorFront} = devtools.require("devtools/shared/fronts/inspector");
const {console} = Cu.import("resource://gre/modules/Console.jsm", {}); SimpleTest.waitForExplicitFinish();
SimpleTest.waitForExplicitFinish(); let win = null;
let inspector = null;
let win = null;
let inspector = null; addAsyncTest(function* () {
info("Setting up inspector actor");
addAsyncTest(function*() {
info("Setting up inspector actor"); let url = document.getElementById("inspectorContent").href;
let url = document.getElementById("inspectorContent").href; yield new Promise(resolve => {
attachURL(url, function (err, client, tab, doc) {
yield new Promise(resolve => { win = doc.defaultView;
attachURL(url, function(err, client, tab, doc) { inspector = InspectorFront(client, tab);
win = doc.defaultView; resolve();
inspector = InspectorFront(client, tab); });
resolve(); });
});
}); runNextTest();
});
runNextTest();
}); addAsyncTest(function* () {
info("Start picking a color from the page");
addAsyncTest(function*() { yield inspector.pickColorFromPage();
info("Start picking a color from the page");
yield inspector.pickColorFromPage(); info("Click in the page and make sure a color-picked event is received");
let onColorPicked = waitForEvent("color-picked");
info("Click in the page and make sure a color-picked event is received"); win.document.body.click();
let onColorPicked = waitForEvent("color-picked"); let color = yield onColorPicked;
win.document.body.click();
let color = yield onColorPicked; is(color, "#000000", "The color-picked event was received with the right color");
is(color, "#000000", "The color-picked event was received with the right color"); runNextTest();
});
runNextTest();
}); addAsyncTest(function* () {
info("Start picking a color from the page");
addAsyncTest(function*() { yield inspector.pickColorFromPage();
info("Start picking a color from the page");
yield inspector.pickColorFromPage(); info("Use the escape key to dismiss the eyedropper");
let onPickCanceled = waitForEvent("color-pick-canceled");
info("Use the escape key to dismiss the eyedropper");
let onPickCanceled = waitForEvent("color-pick-canceled"); let keyboardEvent = win.document.createEvent("KeyboardEvent");
keyboardEvent.initKeyEvent("keydown", true, true, win, false, false,
let keyboardEvent = win.document.createEvent("KeyboardEvent"); false, false, 27, 0);
keyboardEvent.initKeyEvent("keydown", true, true, win, false, false, win.document.dispatchEvent(keyboardEvent);
false, false, 27, 0);
win.document.dispatchEvent(keyboardEvent); yield onPickCanceled;
ok(true, "The color-pick-canceled event was received");
yield onPickCanceled;
ok(true, "The color-pick-canceled event was received"); runNextTest();
});
runNextTest();
}); addAsyncTest(function* () {
info("Start picking a color from the page");
addAsyncTest(function*() { yield inspector.pickColorFromPage();
info("Start picking a color from the page");
yield inspector.pickColorFromPage(); info("And cancel the color picking");
yield inspector.cancelPickColorFromPage();
info("And cancel the color picking");
yield inspector.cancelPickColorFromPage(); runNextTest();
});
runNextTest();
}); function waitForEvent(name) {
return new Promise(resolve => inspector.once(name, resolve));
function waitForEvent(name) { }
return new Promise(resolve => inspector.once(name, resolve));
} runNextTest();
};
runNextTest(); </script>
}; </head>
</script> <body>
</head> <a id="inspectorContent" target="_blank" href="inspector-eyedropper.html">Test Document</a>
<body> <p id="display"></p>
<a id="inspectorContent" target="_blank" href="inspector-eyedropper.html">Test Document</a> <div id="content" style="display: none"></div>
<p id="display"></p> <pre id="test">
<div id="content" style="display: none"></div> </pre>
<pre id="test"> </body>
</pre> </html>
</body>
</html>

View file

@ -11,30 +11,29 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
const DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"].
getService(Components.interfaces.inIDOMUtils);
const KNOWN_PSEUDOCLASSES = [':hover', ':active', ':focus'] const DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
.getService(Components.interfaces.inIDOMUtils);
window.onload = function() { const KNOWN_PSEUDOCLASSES = [":hover", ":active", ":focus"];
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gWalker = null; let gWalker = null;
var gClient = null; let gCleanupConnection = null;
var gCleanupConnection = null;
function setup(callback) { function setup(callback) {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
gCleanupConnection = attachURL(url, function(err, client, tab, doc) { gCleanupConnection = attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
gClient = client;
gWalker = walker; gWalker = walker;
}).then(callback)); }).then(callback));
}); });
@ -42,7 +41,6 @@ function setup(callback) {
function teardown() { function teardown() {
gWalker = null; gWalker = null;
gClient = null;
gInspectee = null; gInspectee = null;
if (gCleanupConnection) { if (gCleanupConnection) {
gCleanupConnection(); gCleanupConnection();
@ -53,10 +51,13 @@ function teardown() {
function checkChange(change, expectation) { function checkChange(change, expectation) {
is(change.type, "pseudoClassLock", "Expect a pseudoclass lock change."); is(change.type, "pseudoClassLock", "Expect a pseudoclass lock change.");
let target = change.target; let target = change.target;
if (expectation.id) if (expectation.id) {
is(target.id, expectation.id, "Expect a change on node id " + expectation.id); is(target.id, expectation.id, "Expect a change on node id " + expectation.id);
if (expectation.nodeName) }
is(target.nodeName, expectation.nodeName, "Expect a change on node name " + expectation.nodeName); if (expectation.nodeName) {
is(target.nodeName, expectation.nodeName,
"Expect a change on node name " + expectation.nodeName);
}
is(target.pseudoClassLocks.length, expectation.pseudos.length, is(target.pseudoClassLocks.length, expectation.pseudos.length,
"Expect " + expectation.pseudos.length + " pseudoclass locks."); "Expect " + expectation.pseudos.length + " pseudoclass locks.");
@ -74,7 +75,8 @@ function checkChange(change, expectation) {
for (let pseudo of KNOWN_PSEUDOCLASSES) { for (let pseudo of KNOWN_PSEUDOCLASSES) {
if (!expectation.pseudos.some(expected => pseudo === expected)) { if (!expectation.pseudos.some(expected => pseudo === expected)) {
ok(!target.hasPseudoClassLock(pseudo), "Don't expect lock: " + pseudo); ok(!target.hasPseudoClassLock(pseudo), "Don't expect lock: " + pseudo);
ok(!DOMUtils.hasPseudoClassLock(target.rawNode(), pseudo), "Don't expect lock in dom: " + pseudo); ok(!DOMUtils.hasPseudoClassLock(target.rawNode(), pseudo),
"Don't expect lock in dom: " + pseudo);
} }
} }
} }
@ -82,7 +84,7 @@ function checkChange(change, expectation) {
function checkMutations(mutations, expectations) { function checkMutations(mutations, expectations) {
is(mutations.length, expectations.length, "Should get the right number of mutations."); is(mutations.length, expectations.length, "Should get the right number of mutations.");
for (let i = 0; i < mutations.length; i++) { for (let i = 0; i < mutations.length; i++) {
checkChange(mutations[i] , expectations[i]); checkChange(mutations[i], expectations[i]);
} }
} }
@ -94,7 +96,7 @@ addTest(function testPseudoClassLock() {
return promiseDone(gWalker.querySelector(gWalker.rootNode, "#b").then(front => { return promiseDone(gWalker.querySelector(gWalker.rootNode, "#b").then(front => {
nodeFront = front; nodeFront = front;
// Lock the pseudoclass alone, no parents. // Lock the pseudoclass alone, no parents.
gWalker.addPseudoClassLock(nodeFront, ':active'); gWalker.addPseudoClassLock(nodeFront, ":active");
// Expect a single pseudoClassLock mutation. // Expect a single pseudoClassLock mutation.
return promiseOnce(gWalker, "mutations"); return promiseOnce(gWalker, "mutations");
}).then(mutations => { }).then(mutations => {
@ -107,50 +109,50 @@ addTest(function testPseudoClassLock() {
}); });
}).then(() => { }).then(() => {
// Now add :hover, this time with parents. // Now add :hover, this time with parents.
gWalker.addPseudoClassLock(nodeFront, ':hover', {parents: true}); gWalker.addPseudoClassLock(nodeFront, ":hover", {parents: true});
return promiseOnce(gWalker, "mutations"); return promiseOnce(gWalker, "mutations");
}).then(mutations => { }).then(mutations => {
let expectedMutations = [{ let expectedMutations = [{
id: 'b', id: "b",
nodeName: 'DIV', nodeName: "DIV",
pseudos: [':hover', ':active'], pseudos: [":hover", ":active"],
}, },
{ {
id: 'longlist', id: "longlist",
nodeName: 'DIV', nodeName: "DIV",
pseudos: [':hover'] pseudos: [":hover"]
}, },
{ {
nodeName: 'BODY', nodeName: "BODY",
pseudos: [':hover'] pseudos: [":hover"]
}, },
{ {
nodeName: 'HTML', nodeName: "HTML",
pseudos: [':hover'] pseudos: [":hover"]
}]; }];
checkMutations(mutations, expectedMutations); checkMutations(mutations, expectedMutations);
}).then(() => { }).then(() => {
// Now remove the :hover on all parents // Now remove the :hover on all parents
gWalker.removePseudoClassLock(nodeFront, ':hover', {parents: true}); gWalker.removePseudoClassLock(nodeFront, ":hover", {parents: true});
return promiseOnce(gWalker, "mutations"); return promiseOnce(gWalker, "mutations");
}).then(mutations => { }).then(mutations => {
let expectedMutations = [{ let expectedMutations = [{
id: 'b', id: "b",
nodeName: 'DIV', nodeName: "DIV",
// Should still have :active on the original node. // Should still have :active on the original node.
pseudos: [':active'] pseudos: [":active"]
}, },
{ {
id: 'longlist', id: "longlist",
nodeName: 'DIV', nodeName: "DIV",
pseudos: [] pseudos: []
}, },
{ {
nodeName: 'BODY', nodeName: "BODY",
pseudos: [] pseudos: []
}, },
{ {
nodeName: 'HTML', nodeName: "HTML",
pseudos: [] pseudos: []
}]; }];
checkMutations(mutations, expectedMutations); checkMutations(mutations, expectedMutations);
@ -170,7 +172,8 @@ addTest(function testPseudoClassLock() {
// Now shut down the walker and make sure that clears up the remaining lock. // Now shut down the walker and make sure that clears up the remaining lock.
return gWalker.release(); return gWalker.release();
}).then(() => { }).then(() => {
ok(!DOMUtils.hasPseudoClassLock(contentNode, ':active'), "Pseudoclass should have been removed during destruction."); ok(!DOMUtils.hasPseudoClassLock(contentNode, ":active"),
"Pseudoclass should have been removed during destruction.");
teardown(); teardown();
}).then(runNextTest)); }).then(runNextTest));
}); });

View file

@ -11,15 +11,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gClient = null; let gClient = null;
function assertOwnership() { function assertOwnership() {
return assertOwnershipTrees(gWalker); return assertOwnershipTrees(gWalker);
@ -27,7 +27,7 @@ function assertOwnership() {
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
@ -45,7 +45,8 @@ addTest(function testReleaseSubtree() {
promiseDone(gWalker.querySelectorAll(gWalker.rootNode, "#longlist div").then(list => { promiseDone(gWalker.querySelectorAll(gWalker.rootNode, "#longlist div").then(list => {
// Make sure we have the 26 children of longlist in our ownership tree. // Make sure we have the 26 children of longlist in our ownership tree.
is(list.length, 26, "Expect 26 div children."); is(list.length, 26, "Expect 26 div children.");
// Make sure we've read in all those children and incorporated them in our ownership tree. // Make sure we've read in all those children and incorporated them
// in our ownership tree.
return list.items(); return list.items();
}).then((items)=> { }).then((items)=> {
originalOwnershipSize = assertOwnership(); originalOwnershipSize = assertOwnership();
@ -69,7 +70,8 @@ addTest(function testReleaseSubtree() {
longlist = node.actorID; longlist = node.actorID;
return gWalker.releaseNode(node); return gWalker.releaseNode(node);
}).then(() => { }).then(() => {
// Our ownership size should now be 53 fewer (we forgot about #longlist + 26 children + 26 singleTextChild nodes) // Our ownership size should now be 53 fewer
// (we forgot about #longlist + 26 children + 26 singleTextChild nodes)
let newOwnershipSize = assertOwnership(); let newOwnershipSize = assertOwnership();
is(newOwnershipSize, originalOwnershipSize - 53, is(newOwnershipSize, originalOwnershipSize - 53,
"Ownership tree should be lower"); "Ownership tree should be lower");
@ -81,12 +83,10 @@ addTest(function testReleaseSubtree() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gClient; gClient = null;
runNextTest(); runNextTest();
}); });
</script> </script>
</head> </head>
<body> <body>

View file

@ -11,26 +11,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gClient = null; let gWalker = null;
var gWalker = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
return inspector.getWalker(); return inspector.getWalker();
}).then(walker => { }).then(walker => {
@ -41,7 +39,6 @@ addTest(function setup() {
}); });
addTest(function testReload() { addTest(function testReload() {
let nodeFront;
let oldRootID = gWalker.rootNode.actorID; let oldRootID = gWalker.rootNode.actorID;
// Load a node to populate the tree a bit. // Load a node to populate the tree a bit.
promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(front => { promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(front => {
@ -58,13 +55,10 @@ addTest(function testReload() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gInspectee; gInspectee = null;
delete gClient;
runNextTest(); runNextTest();
}); });
</script> </script>
</head> </head>
<body> <body>

View file

@ -11,15 +11,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gClient = null; let gClient = null;
let gInspectee = null;
function assertOwnership() { function assertOwnership() {
return assertOwnershipTrees(gWalker); return assertOwnershipTrees(gWalker);
@ -33,7 +34,7 @@ function ignoreNode(node) {
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
@ -80,8 +81,10 @@ addTest(function testRemoveSubtree() {
is(originalOwnershipSize, 56, "Correct number of items in ownership tree"); is(originalOwnershipSize, 56, "Correct number of items in ownership tree");
return gWalker.removeNode(longlist); return gWalker.removeNode(longlist);
}).then(siblings => { }).then(siblings => {
is(siblings.previousSibling.rawNode(), previousSibling, "Should have returned the previous sibling."); is(siblings.previousSibling.rawNode(), previousSibling,
is(siblings.nextSibling.rawNode(), nextSibling, "Should have returned the next sibling."); "Should have returned the previous sibling.");
is(siblings.nextSibling.rawNode(), nextSibling,
"Should have returned the next sibling.");
return waitForMutation(gWalker, isChildList); return waitForMutation(gWalker, isChildList);
}).then(() => { }).then(() => {
// Our ownership size should now be 51 fewer (we forgot about #longlist + 26 // Our ownership size should now be 51 fewer (we forgot about #longlist + 26
@ -96,12 +99,11 @@ addTest(function testRemoveSubtree() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gClient; gClient = null;
gInspectee = null;
runNextTest(); runNextTest();
}); });
</script> </script>
</head> </head>
<body> <body>

View file

@ -11,12 +11,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1222409
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { "use strict";
window.onload = function () {
const Cu = Components.utils; const Cu = Components.utils;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const promise = require("promise"); const promise = require("promise");
const {InspectorFront} = require("devtools/shared/fronts/inspector"); const {InspectorFront} = require("devtools/shared/fronts/inspector");
const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
@ -24,12 +25,13 @@ window.onload = function() {
let inspector = null; let inspector = null;
addAsyncTest(function* setup() { addAsyncTest(function* setup() {
info ("Setting up inspector and walker actors."); info("Setting up inspector and walker actors.");
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
// eslint-disable-next-line new-cap
yield new promise(resolve => { yield new promise(resolve => {
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
win = doc.defaultView; win = doc.defaultView;
inspector = InspectorFront(client, tab); inspector = InspectorFront(client, tab);
resolve(); resolve();
@ -39,7 +41,7 @@ window.onload = function() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
let walker = yield inspector.getWalker(); let walker = yield inspector.getWalker();
// We can't receive events from the walker if we haven't first executed a // We can't receive events from the walker if we haven't first executed a
@ -47,6 +49,7 @@ window.onload = function() {
yield walker.querySelector(walker.rootNode, "img"); yield walker.querySelector(walker.rootNode, "img");
let {outerWidth, outerHeight} = win; let {outerWidth, outerHeight} = win;
// eslint-disable-next-line new-cap
let onResize = new promise(resolve => { let onResize = new promise(resolve => {
walker.once("resize", () => { walker.once("resize", () => {
resolve(); resolve();

View file

@ -11,19 +11,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=921102
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspector; let gInspector;
var gDoc; let gDoc;
addTest(function() { addTest(function () {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gDoc = doc; gDoc = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
gInspector = InspectorFront(client, tab); gInspector = InspectorFront(client, tab);
@ -31,7 +31,7 @@ addTest(function() {
}); });
}); });
addTest(function() { addTest(function () {
info("Resolve a relative URL without providing a context node"); info("Resolve a relative URL without providing a context node");
gInspector.resolveRelativeURL("test.png?id=4#wow").then(url => { gInspector.resolveRelativeURL("test.png?id=4#wow").then(url => {
is(url, "chrome://mochitests/content/chrome/devtools/server/tests/" + is(url, "chrome://mochitests/content/chrome/devtools/server/tests/" +
@ -40,16 +40,16 @@ addTest(function() {
}); });
}); });
addTest(function() { addTest(function () {
info("Resolve an absolute URL without providing a context node"); info("Resolve an absolute URL without providing a context node");
gInspector.resolveRelativeURL("chrome://mochitests/content/chrome/" + gInspector.resolveRelativeURL("chrome://mochitests/content/chrome/" +
"devtools/server/").then(url => { "devtools/server/").then(url => {
is(url, "chrome://mochitests/content/chrome/devtools/server/"); is(url, "chrome://mochitests/content/chrome/devtools/server/");
runNextTest(); runNextTest();
}); });
}); });
addTest(function() { addTest(function () {
info("Resolve a relative URL providing a context node"); info("Resolve a relative URL providing a context node");
let node = gDoc.querySelector(".big-horizontal"); let node = gDoc.querySelector(".big-horizontal");
gInspector.resolveRelativeURL("test.png?id=4#wow", node).then(url => { gInspector.resolveRelativeURL("test.png?id=4#wow", node).then(url => {
@ -59,18 +59,19 @@ addTest(function() {
}); });
}); });
addTest(function() { addTest(function () {
info("Resolve an absolute URL providing a context node"); info("Resolve an absolute URL providing a context node");
let node = gDoc.querySelector(".big-horizontal"); let node = gDoc.querySelector(".big-horizontal");
gInspector.resolveRelativeURL("chrome://mochitests/content/chrome/" + gInspector.resolveRelativeURL("chrome://mochitests/content/chrome/" +
"devtools/server/", node).then(url => { "devtools/server/", node).then(url => {
is(url, "chrome://mochitests/content/chrome/devtools/server/"); is(url, "chrome://mochitests/content/chrome/devtools/server/");
runNextTest(); runNextTest();
}); });
}); });
addTest(function() { addTest(function () {
gInspector = gDoc = null; gInspector = null;
gDoc = null;
runNextTest(); runNextTest();
}); });
</script> </script>

View file

@ -11,16 +11,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gClient = null; let gInspectee = null;
var gInspectee = null;
function assertOwnership() { function assertOwnership() {
return assertOwnershipTrees(gWalker); return assertOwnershipTrees(gWalker);
@ -28,13 +27,12 @@ function assertOwnership() {
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -50,7 +48,6 @@ addTest(function setup() {
addTest(function testRetain() { addTest(function testRetain() {
let originalOwnershipSize = 0; let originalOwnershipSize = 0;
let bodyFront = null; let bodyFront = null;
let frameFront = null;
let childListFront = null; let childListFront = null;
// Get the toplevel body element and retain it. // Get the toplevel body element and retain it.
promiseDone(gWalker.querySelector(gWalker.rootNode, "body").then(front => { promiseDone(gWalker.querySelector(gWalker.rootNode, "body").then(front => {
@ -60,7 +57,6 @@ addTest(function testRetain() {
// Get an element in the child frame and retain it. // Get an element in the child frame and retain it.
return gWalker.querySelector(gWalker.rootNode, "#childFrame"); return gWalker.querySelector(gWalker.rootNode, "#childFrame");
}).then(frame => { }).then(frame => {
frameFront = frame;
return gWalker.children(frame, { maxNodes: 1 }).then(children => { return gWalker.children(frame, { maxNodes: 1 }).then(children => {
return children.nodes[0]; return children.nodes[0];
}); });
@ -75,7 +71,6 @@ addTest(function testRetain() {
// OK, try releasing the parent of the first retained. // OK, try releasing the parent of the first retained.
return gWalker.releaseNode(bodyFront.parentNode()); return gWalker.releaseNode(bodyFront.parentNode());
}).then(() => { }).then(() => {
let size = assertOwnership();
let clientTree = clientOwnershipTree(gWalker); let clientTree = clientOwnershipTree(gWalker);
// That request should have freed the parent of the first retained // That request should have freed the parent of the first retained
@ -84,26 +79,25 @@ addTest(function testRetain() {
originalOwnershipSize, originalOwnershipSize,
"Should have only lost one item overall."); "Should have only lost one item overall.");
is(gWalker._retainedOrphans.size, 1, "Should have retained one orphan"); is(gWalker._retainedOrphans.size, 1, "Should have retained one orphan");
ok(gWalker._retainedOrphans.has(bodyFront), "Should have retained the expected node."); ok(gWalker._retainedOrphans.has(bodyFront),
"Should have retained the expected node.");
}).then(() => { }).then(() => {
// Unretain the body, which should promote the childListFront to a retained orphan. // Unretain the body, which should promote the childListFront to a retained orphan.
return gWalker.unretainNode(bodyFront); return gWalker.unretainNode(bodyFront);
}).then(() => { }).then(() => {
assertOwnership(); assertOwnership();
let clientTree = clientOwnershipTree(gWalker);
is(gWalker._retainedOrphans.size, 1, "Should still only have one retained orphan."); is(gWalker._retainedOrphans.size, 1, "Should still only have one retained orphan.");
ok(!gWalker._retainedOrphans.has(bodyFront), "Should have dropped the body node.") ok(!gWalker._retainedOrphans.has(bodyFront), "Should have dropped the body node.");
ok(gWalker._retainedOrphans.has(childListFront), "Should have retained the child node.") ok(gWalker._retainedOrphans.has(childListFront),
"Should have retained the child node.");
}).then(() => { }).then(() => {
// Change the source of the iframe, which should kill the retained orphan. // Change the source of the iframe, which should kill the retained orphan.
gInspectee.querySelector("#childFrame").src = "data:text/html,<html>new child</html>"; gInspectee.querySelector("#childFrame").src = "data:text/html,<html>new child</html>";
return waitForMutation(gWalker, isUnretained); return waitForMutation(gWalker, isUnretained);
}).then(mutations => { }).then(mutations => {
assertOwnership(); assertOwnership();
let clientTree = clientOwnershipTree(gWalker);
is(gWalker._retainedOrphans.size, 0, "Should have no more retained orphans."); is(gWalker._retainedOrphans.size, 0, "Should have no more retained orphans.");
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -123,14 +117,12 @@ addTest(function testWinRace() {
]); ]);
}).then(() => { }).then(() => {
assertOwnership(); assertOwnership();
let clientTree = clientOwnershipTree(gWalker);
is(gWalker._retainedOrphans.size, 1, "Should have a retained orphan."); is(gWalker._retainedOrphans.size, 1, "Should have a retained orphan.");
ok(gWalker._retainedOrphans.has(front), "Should have retained our expected node."); ok(gWalker._retainedOrphans.has(front), "Should have retained our expected node.");
return gWalker.unretainNode(front); return gWalker.unretainNode(front);
}).then(() => { }).then(() => {
// Make sure we're clear for the next test. // Make sure we're clear for the next test.
assertOwnership(); assertOwnership();
let clientTree = clientOwnershipTree(gWalker);
is(gWalker._retainedOrphans.size, 0, "Should have no more retained orphans."); is(gWalker._retainedOrphans.size, 0, "Should have no more retained orphans.");
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -149,19 +141,18 @@ addTest(function testLoseRace() {
// Verify that we have an outstanding request (no good way to tell that it's a // Verify that we have an outstanding request (no good way to tell that it's a
// getMutations request, but there's nothing else it would be). // getMutations request, but there's nothing else it would be).
is(gWalker._requests.length, 1, "Should have an outstanding request."); is(gWalker._requests.length, 1, "Should have an outstanding request.");
return gWalker.retainNode(front) return gWalker.retainNode(front);
}).then(() => { ok(false, "Request should not have succeeded!"); }, }).then(() => ok(false, "Request should not have succeeded!"),
(err) => { (err) => {
ok(err, "noSuchActor", "Should have lost the race."); ok(err, "noSuchActor", "Should have lost the race.");
let clientTree = clientOwnershipTree(gWalker); is(gWalker._retainedOrphans.size, 0, "Should have no more retained orphans.");
is(gWalker._retainedOrphans.size, 0, "Should have no more retained orphans."); // Don't re-throw the error.
// Don't re-throw the error. }).then(runNextTest));
}).then(runNextTest));
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gClient; gInspectee = null;
runNextTest(); runNextTest();
}); });

View file

@ -11,30 +11,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=901250
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gClient = null; let gWalker = null;
var gWalker = null;
function assertOwnership() {
assertOwnershipTrees(gWalker);
}
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -67,9 +61,8 @@ addTest(Task.async(function* testScrollIntoView() {
})); }));
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gInspectee; gInspectee = null;
delete gClient;
runNextTest(); runNextTest();
}); });
</script> </script>

View file

@ -10,17 +10,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=835896
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { "use strict";
window.onload = function () {
const Cu = Components.utils; const Cu = Components.utils;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const promise = require("promise"); const promise = require("promise");
const {InspectorFront} = require("devtools/shared/fronts/inspector"); const {InspectorFront} = require("devtools/shared/fronts/inspector");
const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
let walkerFront = null; let walkerFront = null;
let inspectee = null;
let inspector = null; let inspector = null;
// WalkerFront specific tests. These aren't to excercise search // WalkerFront specific tests. These aren't to excercise search
@ -29,13 +29,13 @@ window.onload = function() {
// See also test_inspector-search.html // See also test_inspector-search.html
addAsyncTest(function* setup() { addAsyncTest(function* setup() {
info ("Setting up inspector and walker actors."); info("Setting up inspector and walker actors.");
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
// eslint-disable-next-line new-cap
yield new promise(resolve => { yield new promise(resolve => {
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
inspectee = doc;
inspector = InspectorFront(client, tab); inspector = InspectorFront(client, tab);
resolve(); resolve();
}); });
@ -48,7 +48,7 @@ window.onload = function() {
}); });
addAsyncTest(function* testWalkerFrontDefaults() { addAsyncTest(function* testWalkerFrontDefaults() {
info ("Testing search API using WalkerFront."); info("Testing search API using WalkerFront.");
let nodes = yield walkerFront.querySelectorAll(walkerFront.rootNode, "h2"); let nodes = yield walkerFront.querySelectorAll(walkerFront.rootNode, "h2");
let fronts = yield nodes.items(); let fronts = yield nodes.items();
@ -77,7 +77,7 @@ window.onload = function() {
}); });
addAsyncTest(function* testMultipleSearches() { addAsyncTest(function* testMultipleSearches() {
info ("Testing search API using WalkerFront (reverse=false)"); info("Testing search API using WalkerFront (reverse=false)");
let nodes = yield walkerFront.querySelectorAll(walkerFront.rootNode, "h2"); let nodes = yield walkerFront.querySelectorAll(walkerFront.rootNode, "h2");
let fronts = yield nodes.items(); let fronts = yield nodes.items();
@ -119,7 +119,7 @@ window.onload = function() {
}); });
addAsyncTest(function* testMultipleSearchesReverse() { addAsyncTest(function* testMultipleSearchesReverse() {
info ("Testing search API using WalkerFront (reverse=true)"); info("Testing search API using WalkerFront (reverse=true)");
let nodes = yield walkerFront.querySelectorAll(walkerFront.rootNode, "h2"); let nodes = yield walkerFront.querySelectorAll(walkerFront.rootNode, "h2");
let fronts = yield nodes.items(); let fronts = yield nodes.items();
@ -168,9 +168,8 @@ window.onload = function() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function* testBackwardsCompat() { addAsyncTest(function* testBackwardsCompat() {
info ("Simulating a server that doesn't have the new search functionality."); info("Simulating a server that doesn't have the new search functionality.");
walkerFront.traits.textSearch = false; walkerFront.traits.textSearch = false;
let front = yield walkerFront.querySelector(walkerFront.rootNode, "h1"); let front = yield walkerFront.querySelector(walkerFront.rootNode, "h1");

View file

@ -10,14 +10,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=835896
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { "use strict";
window.onload = function () {
const Cu = Components.utils; const Cu = Components.utils;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const promise = require("promise"); const promise = require("promise");
const {InspectorFront} = require("devtools/shared/fronts/inspector"); const {InspectorFront} = require("devtools/shared/fronts/inspector");
const {WalkerSearch, WalkerIndex} = const {WalkerSearch, WalkerIndex} =
require("devtools/server/actors/utils/walker-search"); require("devtools/server/actors/utils/walker-search");
const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
@ -31,12 +32,13 @@ window.onload = function() {
// See also test_inspector-search-front.html. // See also test_inspector-search-front.html.
addAsyncTest(function* setup() { addAsyncTest(function* setup() {
info ("Setting up inspector and walker actors."); info("Setting up inspector and walker actors.");
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
// eslint-disable-next-line new-cap
yield new promise(resolve => { yield new promise(resolve => {
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
inspectee = doc; inspectee = doc;
inspector = InspectorFront(client, tab); inspector = InspectorFront(client, tab);
resolve(); resolve();
@ -56,7 +58,7 @@ window.onload = function() {
}); });
addAsyncTest(function* testIndexExists() { addAsyncTest(function* testIndexExists() {
info ("Testing basic index APIs exist."); info("Testing basic index APIs exist.");
let index = new WalkerIndex(walkerActor); let index = new WalkerIndex(walkerActor);
ok(index.data.size > 0, "public index is filled after getting"); ok(index.data.size > 0, "public index is filled after getting");
@ -70,7 +72,7 @@ window.onload = function() {
}); });
addAsyncTest(function* testSearchExists() { addAsyncTest(function* testSearchExists() {
info ("Testing basic search APIs exist."); info("Testing basic search APIs exist.");
ok(walkerSearch, "walker search exists on the WalkerActor"); ok(walkerSearch, "walker search exists on the WalkerActor");
ok(walkerSearch.search, "walker search has `search` method"); ok(walkerSearch.search, "walker search has `search` method");
@ -88,8 +90,8 @@ window.onload = function() {
}); });
addAsyncTest(function* testEmptySearch() { addAsyncTest(function* testEmptySearch() {
info ("Testing search with an empty query."); info("Testing search with an empty query.");
results = walkerSearch.search(""); let results = walkerSearch.search("");
is(results.length, 0, "No results when searching for ''"); is(results.length, 0, "No results when searching for ''");
results = walkerSearch.search(null); results = walkerSearch.search(null);
@ -165,7 +167,7 @@ window.onload = function() {
{node: inspectee.querySelector("h1 + p > strong").childNodes[0], type: "text"}, {node: inspectee.querySelector("h1 + p > strong").childNodes[0], type: "text"},
] ]
}, },
] ];
for (let {desc, search, expected} of testData) { for (let {desc, search, expected} of testData) {
info("Running test: " + desc); info("Running test: " + desc);
@ -178,7 +180,7 @@ window.onload = function() {
}); });
addAsyncTest(function* testPseudoElements() { addAsyncTest(function* testPseudoElements() {
info ("Testing ::before and ::after element matching"); info("Testing ::before and ::after element matching");
let beforeElt = new _documentWalker(inspectee.querySelector("#pseudo"), let beforeElt = new _documentWalker(inspectee.querySelector("#pseudo"),
inspectee.defaultView).firstChild(); inspectee.defaultView).firstChild();
@ -218,7 +220,7 @@ window.onload = function() {
}); });
addAsyncTest(function* testSearchMutationChangeResults() { addAsyncTest(function* testSearchMutationChangeResults() {
info ("Testing search before and after a mutation."); info("Testing search before and after a mutation.");
let expected = [ let expected = [
{node: inspectee.querySelectorAll("h3")[0], type: "tag"}, {node: inspectee.querySelectorAll("h3")[0], type: "tag"},
{node: inspectee.querySelectorAll("h3")[1], type: "tag"}, {node: inspectee.querySelectorAll("h3")[1], type: "tag"},
@ -238,6 +240,7 @@ window.onload = function() {
expected[2] expected[2]
], "Results are updated after removal"); ], "Results are updated after removal");
// eslint-disable-next-line new-cap
yield new promise(resolve => { yield new promise(resolve => {
info("Waiting for a mutation to happen"); info("Waiting for a mutation to happen");
let observer = new inspectee.defaultView.MutationObserver(() => { let observer = new inspectee.defaultView.MutationObserver(() => {
@ -254,6 +257,7 @@ window.onload = function() {
expected[2] expected[2]
], "Results are updated after addition"); ], "Results are updated after addition");
// eslint-disable-next-line new-cap
yield new promise(resolve => { yield new promise(resolve => {
info("Waiting for a mutation to happen"); info("Waiting for a mutation to happen");
let observer = new inspectee.defaultView.MutationObserver(() => { let observer = new inspectee.defaultView.MutationObserver(() => {
@ -274,6 +278,7 @@ window.onload = function() {
runNextTest(); runNextTest();
function mutateDocumentAndWaitForMutation(mutationFn) { function mutateDocumentAndWaitForMutation(mutationFn) {
// eslint-disable-next-line new-cap
return new promise(resolve => { return new promise(resolve => {
info("Listening to markup mutation on the inspectee"); info("Listening to markup mutation on the inspectee");
let observer = new inspectee.defaultView.MutationObserver(resolve); let observer = new inspectee.defaultView.MutationObserver(resolve);

View file

@ -11,24 +11,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/server/actors/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspectee = null; let gInspectee = null;
var gClient = null; let gClient = null;
var gWalker = null; let gWalker = null;
var checkActorIDs = []; let checkActorIDs = [];
function assertOwnership() { function assertOwnership() {
assertOwnershipTrees(gWalker); assertOwnershipTrees(gWalker);
} }
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
@ -44,7 +44,8 @@ addTest(function testWalkerRoot() {
// Make sure that refetching the root document of the walker returns the same // Make sure that refetching the root document of the walker returns the same
// actor as the getWalker returned. // actor as the getWalker returned.
promiseDone(gWalker.document().then(root => { promiseDone(gWalker.document().then(root => {
ok(root === gWalker.rootNode, "Re-fetching the document node should match the root document node."); ok(root === gWalker.rootNode,
"Re-fetching the document node should match the root document node.");
checkActorIDs.push(root.actorID); checkActorIDs.push(root.actorID);
assertOwnership(); assertOwnership();
}).then(runNextTest)); }).then(runNextTest));
@ -121,11 +122,12 @@ addTest(function testQuerySelectors() {
is(nodes[0], firstNode, "First node should be reused."); is(nodes[0], firstNode, "First node should be reused.");
ok(nodes[0]._parent, "Parent node should be set."); ok(nodes[0]._parent, "Parent node should be set.");
ok(nodes[0]._next || nodes[0]._prev, "Siblings should be set."); ok(nodes[0]._next || nodes[0]._prev, "Siblings should be set.");
ok(nodes[25]._next || nodes[25]._prev, "Siblings of " + nodes[25] + " should be set."); ok(nodes[25]._next || nodes[25]._prev,
"Siblings of " + nodes[25] + " should be set.");
assertOwnership(); assertOwnership();
return nodeList.items(-1); return nodeList.items(-1);
}).then(nodes => { }).then(nodes => {
is(nodes.length, 1, "Expect 1 node") is(nodes.length, 1, "Expect 1 node");
is(nodes[0].id, "z", "Expect it to be the last node."); is(nodes[0].id, "z", "Expect it to be the last node.");
checkActorIDs.push(nodes[0].actorID); checkActorIDs.push(nodes[0].actorID);
// Save the node list ID so we can ensure it was destroyed. // Save the node list ID so we can ensure it was destroyed.
@ -142,17 +144,19 @@ addTest(function testQuerySelectors() {
// Helper to check the response of requests that return hasFirst/hasLast/nodes // Helper to check the response of requests that return hasFirst/hasLast/nodes
// node lists (like `children` and `siblings`) // node lists (like `children` and `siblings`)
function nodeArrayChecker(first, last, ids) { function nodeArrayChecker(first, last, ids) {
return function(response) { return function (response) {
is(response.hasFirst, first, "Should " + (first ? "" : "not ") + " have the first node."); is(response.hasFirst, first,
"Should " + (first ? "" : "not ") + " have the first node.");
is(response.hasLast, last, "Should " + (last ? "" : "not ") + " have the last node."); is(response.hasLast, last, "Should " + (last ? "" : "not ") + " have the last node.");
is(response.nodes.length, ids.length, "Should have " + ids.length + " children listed."); is(response.nodes.length, ids.length,
let responseIds = ''; "Should have " + ids.length + " children listed.");
for (node of response.nodes) { let responseIds = "";
for (let node of response.nodes) {
responseIds += node.id; responseIds += node.id;
} }
is(responseIds, ids, "Correct nodes were returned."); is(responseIds, ids, "Correct nodes were returned.");
assertOwnership(); assertOwnership();
} };
} }
addTest(function testNoChildren() { addTest(function testNoChildren() {
@ -163,8 +167,8 @@ addTest(function testNoChildren() {
}); });
addTest(function testLongListTraversal() { addTest(function testLongListTraversal() {
var longList; let longList;
var allChildren; let allChildren;
promiseDone(gWalker.querySelector(gWalker.rootNode, "#longlist").then(node => { promiseDone(gWalker.querySelector(gWalker.rootNode, "#longlist").then(node => {
longList = node; longList = node;
// First call with no options, expect all children. // First call with no options, expect all children.
@ -177,36 +181,37 @@ addTest(function testLongListTraversal() {
}).then(() => { }).then(() => {
// maxNodes should limit us to the first 5 nodes. // maxNodes should limit us to the first 5 nodes.
assertOwnership(); assertOwnership();
return gWalker.children(longList, { maxNodes: 5 }).then(nodeArrayChecker(true, false, 'abcde')); return gWalker.children(longList, { maxNodes: 5 })
.then(nodeArrayChecker(true, false, "abcde"));
}).then(() => { }).then(() => {
assertOwnership(); assertOwnership();
// maxNodes with the second item centered should still give us the first 5 nodes. // maxNodes with the second item centered should still give us the first 5 nodes.
return gWalker.children(longList, { maxNodes: 5, center: allChildren[1] }).then( return gWalker.children(longList, { maxNodes: 5, center: allChildren[1] }).then(
nodeArrayChecker(true, false, 'abcde') nodeArrayChecker(true, false, "abcde")
); );
}).then(() => { }).then(() => {
// maxNodes with a center in the middle of the list should put that item in the middle // maxNodes with a center in the middle of the list should put that item in the middle
let center = allChildren[13]; let center = allChildren[13];
is(center.id, 'n', "Make sure I know how to count letters."); is(center.id, "n", "Make sure I know how to count letters.");
return gWalker.children(longList, { maxNodes: 5, center: center }).then( return gWalker.children(longList, { maxNodes: 5, center: center }).then(
nodeArrayChecker(false, false, 'lmnop') nodeArrayChecker(false, false, "lmnop")
); );
}).then(() => { }).then(() => {
// maxNodes with the second-to-last item centered should give us the last 5 nodes. // maxNodes with the second-to-last item centered should give us the last 5 nodes.
return gWalker.children(longList, { maxNodes: 5, center: allChildren[24] }).then( return gWalker.children(longList, { maxNodes: 5, center: allChildren[24] }).then(
nodeArrayChecker(false, true, 'vwxyz') nodeArrayChecker(false, true, "vwxyz")
); );
}).then(() => { }).then(() => {
// maxNodes with a start in the middle should start at that node and fetch 5 // maxNodes with a start in the middle should start at that node and fetch 5
let start = allChildren[13]; let start = allChildren[13];
is(start.id, 'n', "Make sure I know how to count letters.") is(start.id, "n", "Make sure I know how to count letters.");
return gWalker.children(longList, { maxNodes: 5, start: start }).then( return gWalker.children(longList, { maxNodes: 5, start: start }).then(
nodeArrayChecker(false, false, 'nopqr') nodeArrayChecker(false, false, "nopqr")
); );
}).then(() => { }).then(() => {
// maxNodes near the end should only return what's left // maxNodes near the end should only return what's left
return gWalker.children(longList, { maxNodes: 5, start: allChildren[24] }).then( return gWalker.children(longList, { maxNodes: 5, start: allChildren[24] }).then(
nodeArrayChecker(false, true, 'yz') nodeArrayChecker(false, true, "yz")
); );
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -221,7 +226,8 @@ addTest(function testObjectNodeChildren() {
addTest(function testSiblings() { addTest(function testSiblings() {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(a => { promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(a => {
return gWalker.siblings(a, { maxNodes: 5, center: a }).then(nodeArrayChecker(true, false, "abcde")); return gWalker.siblings(a, { maxNodes: 5, center: a })
.then(nodeArrayChecker(true, false, "abcde"));
}).then(() => { }).then(() => {
return gWalker.siblings(gWalker.rootNode).then(response => { return gWalker.siblings(gWalker.rootNode).then(response => {
ok(response.hasFirst && response.hasLast, "Has first and last."); ok(response.hasFirst && response.hasLast, "Has first and last.");
@ -255,7 +261,6 @@ addTest(function testPreviousSibling() {
}).then(runNextTest)); }).then(runNextTest));
}); });
addTest(function testFrameTraversal() { addTest(function testFrameTraversal() {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => { promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => {
return gWalker.children(childFrame); return gWalker.children(childFrame);
@ -268,7 +273,8 @@ addTest(function testFrameTraversal() {
return gWalker.parents(childDocumentZ); return gWalker.parents(childDocumentZ);
}).then(parents => { }).then(parents => {
// Expected set of parent tag names for this item: // Expected set of parent tag names for this item:
let expectedParents = ['DIV', 'BODY', 'HTML', '#document', 'IFRAME', 'BODY', 'HTML', '#document']; let expectedParents = ["DIV", "BODY", "HTML", "#document", "IFRAME", "BODY", "HTML",
"#document"];
for (let parent of parents) { for (let parent of parents) {
let expected = expectedParents.shift(); let expected = expectedParents.shift();
is(parent.nodeName, expected, "Got expected parent"); is(parent.nodeName, expected, "Got expected parent");
@ -278,8 +284,10 @@ addTest(function testFrameTraversal() {
addTest(function testLongValue() { addTest(function testLongValue() {
const testSummaryLength = 10; const testSummaryLength = 10;
const inspector = require("devtools/server/actors/inspector");
inspector.setValueSummaryLength(testSummaryLength); inspector.setValueSummaryLength(testSummaryLength);
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function () {
inspector.setValueSummaryLength(inspector.DEFAULT_VALUE_SUMMARY_LENGTH); inspector.setValueSummaryLength(inspector.DEFAULT_VALUE_SUMMARY_LENGTH);
}); });
@ -298,7 +306,8 @@ addTest(function testLongValue() {
}).then(value => { }).then(value => {
return value.string(); return value.string();
}).then(valueStr => { }).then(valueStr => {
is(valueStr, longstringText, "Full node value should match the string from the document."); is(valueStr, longstringText,
"Full node value should match the string from the document.");
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -318,7 +327,8 @@ addTest(function testShortValue() {
}).then(value => { }).then(value => {
return value.string(); return value.string();
}).then(valueStr => { }).then(valueStr => {
is(valueStr, shortstringText, "Full node value should match the string from the document."); is(valueStr, shortstringText,
"Full node value should match the string from the document.");
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -327,18 +337,16 @@ addTest(function testReleaseWalker() {
promiseDone(gWalker.release().then(() => { promiseDone(gWalker.release().then(() => {
let promises = Array.from(checkActorIDs, (id) => checkMissing(gClient, id)); let promises = Array.from(checkActorIDs, (id) => checkMissing(gClient, id));
return promise.all(promises) return promise.all(promises);
}).then(runNextTest)); }).then(runNextTest));
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
delete gInspectee; gInspectee = null;
delete gClient; gClient = null;
runNextTest(); runNextTest();
}); });
</script> </script>
</head> </head>
<body> <body>

View file

@ -17,10 +17,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1192536
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
"use strict";
const flags = require("devtools/shared/flags"); const flags = require("devtools/shared/flags");
const wasTesting = flags.testing; const wasTesting = flags.testing;
SimpleTest.registerCleanupFunction(() => flags.testing = wasTesting); SimpleTest.registerCleanupFunction(function () {
flags.testing = wasTesting;
});
const PATH = "http://mochi.test:8888/chrome/devtools/server/tests/mochitest/"; const PATH = "http://mochi.test:8888/chrome/devtools/server/tests/mochitest/";
const BASE_IMAGE = PATH + "inspector-delay-image-response.sjs"; const BASE_IMAGE = PATH + "inspector-delay-image-response.sjs";
@ -28,23 +31,24 @@ const DELAYED_IMAGE = BASE_IMAGE + "?delay=300";
const TIMEOUT_IMAGE = BASE_IMAGE + "?delay=50000"; const TIMEOUT_IMAGE = BASE_IMAGE + "?delay=50000";
const NONEXISTENT_IMAGE = PATH + "this-does-not-exist.png"; const NONEXISTENT_IMAGE = PATH + "this-does-not-exist.png";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gImg = null; let gImg = null;
var gNodeFront = null; let gNodeFront = null;
var gWalker = null; let gWalker = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
gWalker = walker; gWalker = walker;
// eslint-disable-next-line max-nested-callbacks
return walker.querySelector(gWalker.rootNode, "img.custom").then(img => { return walker.querySelector(gWalker.rootNode, "img.custom").then(img => {
gNodeFront = img; gNodeFront = img;
gImg = doc.querySelector("img.custom"); gImg = doc.querySelector("img.custom");
@ -93,9 +97,9 @@ addTest(function testDelayedImage() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gImg; gImg = null;
delete gNodeFront gNodeFront = null;
delete gWalker; gWalker = null;
runNextTest(); runNextTest();
}); });

View file

@ -11,18 +11,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=932937
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
@ -45,6 +45,7 @@ addTest(function testLargeImage() {
is(imageData.size.naturalHeight, 3000, "Natural width of the image correct"); is(imageData.size.naturalHeight, 3000, "Natural width of the image correct");
ok(imageData.size.resized, "Image was resized"); ok(imageData.size.resized, "Image was resized");
// eslint-disable-next-line max-nested-callbacks
imageData.data.string().then(str => { imageData.data.string().then(str => {
ok(str, "We have an image data string!"); ok(str, "We have an image data string!");
testResizing(imageData, str); testResizing(imageData, str);
@ -66,6 +67,7 @@ addTest(function testLargeCanvas() {
is(imageData.size.naturalHeight, 2000, "Natural width of the image correct"); is(imageData.size.naturalHeight, 2000, "Natural width of the image correct");
ok(imageData.size.resized, "Image was resized"); ok(imageData.size.resized, "Image was resized");
// eslint-disable-next-line max-nested-callbacks
imageData.data.string().then(str => { imageData.data.string().then(str => {
ok(str, "We have an image data string!"); ok(str, "We have an image data string!");
testResizing(imageData, str); testResizing(imageData, str);
@ -87,6 +89,7 @@ addTest(function testSmallImage() {
is(imageData.size.naturalHeight, 240, "Natural width of the image correct"); is(imageData.size.naturalHeight, 240, "Natural width of the image correct");
ok(!imageData.size.resized, "Image was NOT resized"); ok(!imageData.size.resized, "Image was NOT resized");
// eslint-disable-next-line max-nested-callbacks
imageData.data.string().then(str => { imageData.data.string().then(str => {
ok(str, "We have an image data string!"); ok(str, "We have an image data string!");
testResizing(imageData, str); testResizing(imageData, str);
@ -108,6 +111,7 @@ addTest(function testDataImage() {
is(imageData.size.naturalHeight, 28, "Natural width of the image correct"); is(imageData.size.naturalHeight, 28, "Natural width of the image correct");
ok(imageData.size.resized, "Image was resized"); ok(imageData.size.resized, "Image was resized");
// eslint-disable-next-line max-nested-callbacks
imageData.data.string().then(str => { imageData.data.string().then(str => {
ok(str, "We have an image data string!"); ok(str, "We have an image data string!");
testResizing(imageData, str); testResizing(imageData, str);
@ -123,7 +127,7 @@ addTest(function testNonImgOrCanvasElements() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gWalker; gWalker = null;
runNextTest(); runNextTest();
}); });

View file

@ -16,10 +16,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1192536
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
"use strict";
const flags = require("devtools/shared/flags"); const flags = require("devtools/shared/flags");
const wasTesting = flags.testing; const wasTesting = flags.testing;
SimpleTest.registerCleanupFunction(() => flags.testing = wasTesting); SimpleTest.registerCleanupFunction(function () {
flags.testing = wasTesting;
});
const PATH = "http://mochi.test:8888/chrome/devtools/server/tests/mochitest/"; const PATH = "http://mochi.test:8888/chrome/devtools/server/tests/mochitest/";
const BASE_IMAGE = PATH + "inspector-delay-image-response.sjs"; const BASE_IMAGE = PATH + "inspector-delay-image-response.sjs";
@ -27,16 +30,16 @@ const DELAYED_IMAGE = BASE_IMAGE + "?delay=300";
const TIMEOUT_IMAGE = BASE_IMAGE + "?delay=50000"; const TIMEOUT_IMAGE = BASE_IMAGE + "?delay=50000";
const NONEXISTENT_IMAGE = PATH + "this-does-not-exist.png"; const NONEXISTENT_IMAGE = PATH + "this-does-not-exist.png";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gInspector = null; let gInspector = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
gInspector = InspectorFront(client, tab); gInspector = InspectorFront(client, tab);
runNextTest(); runNextTest();
@ -73,7 +76,7 @@ addTest(function testNormalImage() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gInspector; gInspector = null;
runNextTest(); runNextTest();
}); });

View file

@ -11,18 +11,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1155653
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker; let gWalker;
addTest(function() { addTest(function () {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
@ -32,7 +32,7 @@ addTest(function() {
}); });
}); });
addTest(function() { addTest(function () {
info("Try to get a NodeFront from an invalid actorID"); info("Try to get a NodeFront from an invalid actorID");
gWalker.getNodeFromActor("invalid", ["node"]).then(node => { gWalker.getNodeFromActor("invalid", ["node"]).then(node => {
ok(!node, "The node returned is null"); ok(!node, "The node returned is null");
@ -40,7 +40,7 @@ addTest(function() {
}); });
}); });
addTest(function() { addTest(function () {
info("Try to get a NodeFront from a valid actorID but invalid path"); info("Try to get a NodeFront from a valid actorID but invalid path");
gWalker.getNodeFromActor(gWalker.actorID, ["invalid", "path"]).then(node => { gWalker.getNodeFromActor(gWalker.actorID, ["invalid", "path"]).then(node => {
ok(!node, "The node returned is null"); ok(!node, "The node returned is null");
@ -48,7 +48,7 @@ addTest(function() {
}); });
}); });
addTest(function() { addTest(function () {
info("Try to get a NodeFront from a valid actorID and valid path"); info("Try to get a NodeFront from a valid actorID and valid path");
gWalker.getNodeFromActor(gWalker.actorID, ["rootDoc"]).then(rootDocNode => { gWalker.getNodeFromActor(gWalker.actorID, ["rootDoc"]).then(rootDocNode => {
ok(rootDocNode, "A node was returned"); ok(rootDocNode, "A node was returned");
@ -57,19 +57,19 @@ addTest(function() {
}); });
}); });
addTest(function() { addTest(function () {
info("Try to get a NodeFront from a valid actorID and valid complex path"); info("Try to get a NodeFront from a valid actorID and valid complex path");
gWalker.getNodeFromActor(gWalker.actorID, gWalker.getNodeFromActor(gWalker.actorID,
["tabActor", "window", "document", "body"]).then(bodyNode => { ["tabActor", "window", "document", "body"]).then(bodyNode => {
ok(bodyNode, "A node was returned"); ok(bodyNode, "A node was returned");
gWalker.querySelector(gWalker.rootNode, "body").then(node => { gWalker.querySelector(gWalker.rootNode, "body").then(node => {
is(bodyNode, node, "The body node was returned"); is(bodyNode, node, "The body node was returned");
runNextTest(); runNextTest();
});
}); });
});
}); });
addTest(function() { addTest(function () {
gWalker = null; gWalker = null;
runNextTest(); runNextTest();
}); });

View file

@ -15,6 +15,7 @@ Debugger.prototype.makeGlobalObjectReference should dereference WindowProxy
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
Components.utils.import("resource://gre/modules/jsdebugger.jsm"); Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this); addDebuggerToGlobal(this);
@ -22,23 +23,27 @@ addDebuggerToGlobal(this);
window.onload = function () { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.src = "data:text/html,<html>The word 'smorgasbord', spoken by an adorably plump child, symbolizing prosperity</html>"; iframe.src = "data:text/html,<html>The word 'smorgasbord'," +
" spoken by an adorably plump child, symbolizing prosperity</html>";
iframe.onload = iframeOnLoad; iframe.onload = iframeOnLoad;
document.body.appendChild(iframe); document.body.appendChild(iframe);
function iframeOnLoad() { function iframeOnLoad() {
var dbg = new Debugger; let dbg = new Debugger();
var g1o = iframe.contentWindow; // 'o' for 'outer window' // 'o' for 'outer window'
let g1o = iframe.contentWindow;
ok(!dbg.hasDebuggee(g1o), "iframe is not initially a debuggee"); ok(!dbg.hasDebuggee(g1o), "iframe is not initially a debuggee");
// Like addDebuggee, makeGlobalObjectReference innerizes. // Like addDebuggee, makeGlobalObjectReference innerizes.
// 'i' stands for 'inner window'. // 'i' stands for 'inner window'.
// 'DO' stands for 'Debugger.Object'. // 'DO' stands for 'Debugger.Object'.
var g1iDO = dbg.makeGlobalObjectReference(g1o); let g1iDO = dbg.makeGlobalObjectReference(g1o);
ok(!dbg.hasDebuggee(g1o), "makeGlobalObjectReference does not add g1 as debuggee, designated via outer"); ok(!dbg.hasDebuggee(g1o),
ok(!dbg.hasDebuggee(g1iDO), "makeGlobalObjectReference does not add g1 as debuggee, designated via D.O "); "makeGlobalObjectReference does not add g1 as debuggee, designated via outer");
ok(!dbg.hasDebuggee(g1iDO),
"makeGlobalObjectReference does not add g1 as debuggee, designated via D.O ");
// Wrapping an object automatically outerizes it, so dereferencing an // Wrapping an object automatically outerizes it, so dereferencing an
// inner object D.O gets you an outer object. // inner object D.O gets you an outer object.
@ -47,28 +52,32 @@ window.onload = function () {
ok(g1iDO.unsafeDereference() === g1o, "g1iDO has the right referent"); ok(g1iDO.unsafeDereference() === g1o, "g1iDO has the right referent");
// However, Debugger.Objects do distinguish inner and outer windows. // However, Debugger.Objects do distinguish inner and outer windows.
var g1oDO = g1iDO.makeDebuggeeValue(g1o); let g1oDO = g1iDO.makeDebuggeeValue(g1o);
ok(g1iDO !== g1oDO, "makeDebuggeeValue doesn't innerize"); ok(g1iDO !== g1oDO, "makeDebuggeeValue doesn't innerize");
ok(g1iDO.unsafeDereference() === g1oDO.unsafeDereference(), ok(g1iDO.unsafeDereference() === g1oDO.unsafeDereference(),
"unsafeDereference() outerizes, so inner and outer window D.Os both dereference to outer"); "unsafeDereference() outerizes," +
" so inner and outer window D.Os both dereference to outer");
ok(dbg.addDebuggee(g1o) === g1iDO, "addDebuggee returns the inner window's D.O"); ok(dbg.addDebuggee(g1o) === g1iDO, "addDebuggee returns the inner window's D.O");
ok(dbg.hasDebuggee(g1o), "addDebuggee adds the correct global"); ok(dbg.hasDebuggee(g1o), "addDebuggee adds the correct global");
ok(dbg.hasDebuggee(g1iDO), "hasDebuggee can take a D.O referring to the inner window"); ok(dbg.hasDebuggee(g1iDO),
ok(dbg.hasDebuggee(g1oDO), "hasDebuggee can take a D.O referring to the outer window"); "hasDebuggee can take a D.O referring to the inner window");
ok(dbg.hasDebuggee(g1oDO),
"hasDebuggee can take a D.O referring to the outer window");
var iframe2 = document.createElement("iframe"); let iframe2 = document.createElement("iframe");
iframe2.src = "data:text/html,<html>Her retrospection, in hindsight, was prescient.</html>"; iframe2.src = "data:text/html,<html>Her retrospection," +
" in hindsight, was prescient.</html>";
iframe2.onload = iframe2OnLoad; iframe2.onload = iframe2OnLoad;
document.body.appendChild(iframe2); document.body.appendChild(iframe2);
function iframe2OnLoad() { function iframe2OnLoad() {
// makeGlobalObjectReference dereferences CCWs. // makeGlobalObjectReference dereferences CCWs.
var g2o = iframe2.contentWindow; let g2o = iframe2.contentWindow;
g2o.g1o = g1o; g2o.g1o = g1o;
var g2iDO = dbg.addDebuggee(g2o); let g2iDO = dbg.addDebuggee(g2o);
var g2g1oDO = g2iDO.getOwnPropertyDescriptor('g1o').value; let g2g1oDO = g2iDO.getOwnPropertyDescriptor("g1o").value;
ok(g2g1oDO !== g1oDO, "g2's cross-compartment wrapper for g1o gets its own D.O"); ok(g2g1oDO !== g1oDO, "g2's cross-compartment wrapper for g1o gets its own D.O");
ok(g2g1oDO.unwrap() === g1oDO, ok(g2g1oDO.unwrap() === g1oDO,
"unwrapping g2's cross-compartment wrapper for g1o gets the right D.O"); "unwrapping g2's cross-compartment wrapper for g1o gets the right D.O");
@ -78,7 +87,7 @@ window.onload = function () {
SimpleTest.finish(); SimpleTest.finish();
} }
} }
} };
</script> </script>
</pre> </pre>

View file

@ -13,12 +13,14 @@ Bug 923275 - Add a memory monitor widget to the developer toolbar
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
var measurement = yield memory.measure(); let measurement = yield memory.measure();
ok(measurement.total > 0, "total memory is valid"); ok(measurement.total > 0, "total memory is valid");
ok(measurement.domSize > 0, "domSize is valid"); ok(measurement.domSize > 0, "domSize is valid");
ok(measurement.styleSize > 0, "styleSize is valid"); ok(measurement.styleSize > 0, "styleSize is valid");

View file

@ -13,11 +13,13 @@ Bug 1067491 - Test recording allocations.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
yield memory.startRecordingAllocations(); yield memory.startRecordingAllocations();
@ -25,18 +27,22 @@ window.onload = function() {
// Allocate some objects. // Allocate some objects.
var alloc1, alloc2, alloc3; let alloc1, alloc2, alloc3;
/* eslint-disable max-nested-callbacks */
(function outer() { (function outer() {
(function middle() { (function middle() {
(function inner() { (function inner() {
alloc1 = {}; alloc1.line = Error().lineNumber; alloc1 = {}; alloc1.line = Error().lineNumber;
alloc2 = []; alloc2.line = Error().lineNumber; alloc2 = []; alloc2.line = Error().lineNumber;
alloc3 = new function() {}; alloc3.line = Error().lineNumber; // eslint-disable-next-line new-parens
alloc3 = new function () {}; alloc3.line = Error().lineNumber;
}()); }());
}()); }());
}()); }());
/* eslint-enable max-nested-callbacks */
var response = yield memory.getAllocations(); let response = yield memory.getAllocations();
yield memory.stopRecordingAllocations(); yield memory.stopRecordingAllocations();
ok(true, "Can stop recording allocations"); ok(true, "Can stop recording allocations");
@ -45,7 +51,7 @@ window.onload = function() {
// allocations that occurred in our test case above. // allocations that occurred in our test case above.
function isTestAllocation(alloc) { function isTestAllocation(alloc) {
var frame = response.frames[alloc]; let frame = response.frames[alloc];
return frame return frame
&& frame.functionDisplayName === "inner" && frame.functionDisplayName === "inner"
&& (frame.line === alloc1.line && (frame.line === alloc1.line
@ -53,7 +59,7 @@ window.onload = function() {
|| frame.line === alloc3.line); || frame.line === alloc3.line);
} }
var testAllocations = response.allocations.filter(isTestAllocation); let testAllocations = response.allocations.filter(isTestAllocation);
ok(testAllocations.length >= 3, ok(testAllocations.length >= 3,
"Should find our 3 test allocations (plus some allocations for the error " "Should find our 3 test allocations (plus some allocations for the error "
+ "objects used to get line numbers)"); + "objects used to get line numbers)");
@ -63,19 +69,19 @@ window.onload = function() {
// line we expected (rather than a bunch on the first line and none on the // line we expected (rather than a bunch on the first line and none on the
// others, etc). // others, etc).
var expectedLines = new Set([alloc1.line, alloc2.line, alloc3.line]); let expectedLines = new Set([alloc1.line, alloc2.line, alloc3.line]);
for (var alloc of testAllocations) { for (let alloc of testAllocations) {
var innerFrame = response.frames[alloc]; let innerFrame = response.frames[alloc];
ok(innerFrame, "Should get the inner frame"); ok(innerFrame, "Should get the inner frame");
is(innerFrame.functionDisplayName, "inner"); is(innerFrame.functionDisplayName, "inner");
expectedLines.delete(innerFrame.line); expectedLines.delete(innerFrame.line);
var middleFrame = response.frames[innerFrame.parent]; let middleFrame = response.frames[innerFrame.parent];
ok(middleFrame, "Should get the middle frame"); ok(middleFrame, "Should get the middle frame");
is(middleFrame.functionDisplayName, "middle"); is(middleFrame.functionDisplayName, "middle");
var outerFrame = response.frames[middleFrame.parent]; let outerFrame = response.frames[middleFrame.parent];
ok(outerFrame, "Should get the outer frame"); ok(outerFrame, "Should get the outer frame");
is(outerFrame.functionDisplayName, "outer"); is(outerFrame.functionDisplayName, "outer");

View file

@ -13,27 +13,29 @@ Bug 1132764 - Test controlling the maximum allocations log length over the RDP.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
var allocs = []; let allocs = [];
var eventsFired = 0; let eventsFired = 0;
var intervalId = null; let intervalId = null;
function onAlloc () { function onAlloc() {
eventsFired++; eventsFired++;
} }
function startAllocating () { function startAllocating() {
intervalId = setInterval(() => { intervalId = setInterval(() => {
for (var i = 100000; --i;) { for (let i = 100000; --i;) {
allocs.push(new Object()); allocs.push(new Object());
} }
}, 1); }, 1);
} }
function stopAllocating () { function stopAllocating() {
clearInterval(intervalId); clearInterval(intervalId);
} }
@ -44,14 +46,15 @@ window.onload = function() {
}); });
yield waitUntil(() => eventsFired > 5); yield waitUntil(() => eventsFired > 5);
ok(eventsFired > 5, "Some allocation events fired without allocating much via auto drain"); ok(eventsFired > 5,
"Some allocation events fired without allocating much via auto drain");
yield memory.stopRecordingAllocations(); yield memory.stopRecordingAllocations();
// Set a really high auto drain timer so we can test if // Set a really high auto drain timer so we can test if
// it fires on GC // it fires on GC
eventsFired = 0; eventsFired = 0;
var startTime = performance.now(); let startTime = performance.now();
var drainTimer = 1000000; let drainTimer = 1000000;
yield memory.startRecordingAllocations({ yield memory.startRecordingAllocations({
drainAllocationsTimeout: drainTimer drainAllocationsTimeout: drainTimer
}); });
@ -62,7 +65,8 @@ window.onload = function() {
return eventsFired > 1; return eventsFired > 1;
}); });
stopAllocating(); stopAllocating();
ok(performance.now() - drainTimer < startTime, "Allocation events fired on GC before timer"); ok(performance.now() - drainTimer < startTime,
"Allocation events fired on GC before timer");
yield memory.stopRecordingAllocations(); yield memory.stopRecordingAllocations();
memory.off("allocations", onAlloc); memory.off("allocations", onAlloc);

View file

@ -13,11 +13,13 @@ Bug 1067491 - Test that frames keep the same index while we are recording.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
yield memory.startRecordingAllocations(); yield memory.startRecordingAllocations();
@ -26,18 +28,18 @@ window.onload = function() {
// allocating directly in the generator), but with getAllocations() calls in // allocating directly in the generator), but with getAllocations() calls in
// between. // between.
var allocs = []; let allocs = [];
function allocator() { function allocator() {
allocs.push({}); allocs.push({});
} }
setTimeout(allocator, 1); setTimeout(allocator, 1);
yield waitForTime(2); yield waitForTime(2);
var first = yield memory.getAllocations(); let first = yield memory.getAllocations();
setTimeout(allocator, 1); setTimeout(allocator, 1);
yield waitForTime(2); yield waitForTime(2);
var second = yield memory.getAllocations(); let second = yield memory.getAllocations();
yield memory.stopRecordingAllocations(); yield memory.stopRecordingAllocations();
@ -48,7 +50,6 @@ window.onload = function() {
// but before the second. // but before the second.
function assertSameFrame(a, b) { function assertSameFrame(a, b) {
info("Checking frames at index " + i + ":");
info(" First frame = " + JSON.stringify(a, null, 4)); info(" First frame = " + JSON.stringify(a, null, 4));
info(" Second frame = " + JSON.stringify(b, null, 4)); info(" Second frame = " + JSON.stringify(b, null, 4));
@ -64,7 +65,8 @@ window.onload = function() {
is(a.parent, b.parent); is(a.parent, b.parent);
} }
for (var i = 0; i < first.frames.length; i++) { for (let i = 0; i < first.frames.length; i++) {
info("Checking frames at index " + i + ":");
assertSameFrame(first.frames[i], second.frames[i]); assertSameFrame(first.frames[i], second.frames[i]);
} }

View file

@ -13,27 +13,29 @@ Bug 1068171 - Test controlling the memory actor's allocation sampling probabilit
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
var allocs = []; let allocs = [];
function allocator() { function allocator() {
for (var i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
allocs.push({}); allocs.push({});
} }
} }
var testProbability = Task.async(function* (p, expected) { let testProbability = Task.async(function* (p, expected) {
info("probability = " + p); info("probability = " + p);
yield memory.startRecordingAllocations({ yield memory.startRecordingAllocations({
probability: p probability: p
}); });
allocator(); allocator();
var response = yield memory.getAllocations(); let response = yield memory.getAllocations();
yield memory.stopRecordingAllocations(); yield memory.stopRecordingAllocations();
return response.allocations.length; return response.allocations.length;
}); });

View file

@ -13,24 +13,27 @@ Bug 1068144 - Test getting the timestamps for allocations.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
var allocs = []; let allocs = [];
function allocator() { function allocator() {
allocs.push(new Object); allocs.push(new Object());
} }
// Using setTimeout results in wildly varying delays that make it hard to // Using setTimeout results in wildly varying delays that make it hard to
// test our timestamps and results in intermittent failures. Instead, we // test our timestamps and results in intermittent failures. Instead, we
// actually spin an empty loop for a whole millisecond. // actually spin an empty loop for a whole millisecond.
function actuallyWaitOneWholeMillisecond() { function actuallyWaitOneWholeMillisecond() {
var start = window.performance.now(); let start = window.performance.now();
while (window.performance.now() - start < 1.000) ; // eslint-disable-next-line curly
while (window.performance.now() - start < 1.000);
} }
yield memory.startRecordingAllocations(); yield memory.startRecordingAllocations();
@ -41,36 +44,39 @@ window.onload = function() {
actuallyWaitOneWholeMillisecond(); actuallyWaitOneWholeMillisecond();
allocator(); allocator();
var response = yield memory.getAllocations(); let response = yield memory.getAllocations();
yield memory.stopRecordingAllocations(); yield memory.stopRecordingAllocations();
ok(response.allocationsTimestamps, "The response should have timestamps."); ok(response.allocationsTimestamps, "The response should have timestamps.");
is(response.allocationsTimestamps.length, response.allocations.length, is(response.allocationsTimestamps.length, response.allocations.length,
"There should be a timestamp for every allocation."); "There should be a timestamp for every allocation.");
var allocatorIndices = response.allocations let allocatorIndices = response.allocations
.map(function (a, idx) { .map(function (a, idx) {
var frame = response.frames[a]; let frame = response.frames[a];
if (frame && frame.functionDisplayName === "allocator") { if (frame && frame.functionDisplayName === "allocator") {
return idx; return idx;
} }
return null;
}) })
.filter(function (idx) { .filter(function (idx) {
return idx !== undefined; return idx !== null;
}); });
is(allocatorIndices.length, 3, "Should have our 3 allocations from the `allocator` timeouts."); is(allocatorIndices.length, 3,
"Should have our 3 allocations from the `allocator` timeouts.");
var lastTimestamp; let lastTimestamp;
for (var i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
var timestamp = response.allocationsTimestamps[allocatorIndices[i]]; let timestamp = response.allocationsTimestamps[allocatorIndices[i]];
info("timestamp", timestamp); info("timestamp", timestamp);
ok(timestamp, "We should have a timestamp for the `allocator` allocation."); ok(timestamp, "We should have a timestamp for the `allocator` allocation.");
if (lastTimestamp) { if (lastTimestamp) {
var delta = timestamp - lastTimestamp; let delta = timestamp - lastTimestamp;
info("delta since last timestamp", delta); info("delta since last timestamp", delta);
ok(delta >= 1 /* ms */, // ms
ok(delta >= 1,
"The timestamp should be about 1 ms after the last timestamp."); "The timestamp should be about 1 ms after the last timestamp.");
} }

View file

@ -13,16 +13,18 @@ Bug 1132764 - Test controlling the maximum allocations log length over the RDP.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
var allocs = []; let allocs = [];
function allocator() { function allocator() {
allocs.push(new Object); allocs.push(new Object());
} }
yield memory.startRecordingAllocations({ yield memory.startRecordingAllocations({
@ -33,7 +35,7 @@ window.onload = function() {
allocator(); allocator();
allocator(); allocator();
var response = yield memory.getAllocations(); let response = yield memory.getAllocations();
yield memory.stopRecordingAllocations(); yield memory.stopRecordingAllocations();
is(response.allocations.length, 1, is(response.allocations.length, 1,

View file

@ -13,16 +13,18 @@ Bug 1192335 - Test getting the byte sizes for allocations.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
var allocs = []; let allocs = [];
function allocator() { function allocator() {
allocs.push(new Object); allocs.push(new Object());
} }
yield memory.startRecordingAllocations(); yield memory.startRecordingAllocations();
@ -31,7 +33,7 @@ window.onload = function() {
allocator(); allocator();
allocator(); allocator();
var response = yield memory.getAllocations(); let response = yield memory.getAllocations();
yield memory.stopRecordingAllocations(); yield memory.stopRecordingAllocations();
ok(response.allocationSizes, "The response should have bytesizes."); ok(response.allocationSizes, "The response should have bytesizes.");
@ -39,14 +41,15 @@ window.onload = function() {
"There should be a bytesize for every allocation."); "There should be a bytesize for every allocation.");
ok(response.allocationSizes.length >= 3, ok(response.allocationSizes.length >= 3,
"There are atleast 3 allocations."); "There are atleast 3 allocations.");
ok(response.allocationSizes.every(isPositiveNumber), "every bytesize is a positive number"); ok(response.allocationSizes.every(isPositiveNumber),
"every bytesize is a positive number");
yield memory.detach(); yield memory.detach();
destroyServerAndFinish(client); destroyServerAndFinish(client);
}); });
}; };
function isPositiveNumber (n) { function isPositiveNumber(n) {
return typeof n === "number" && n > 0; return typeof n === "number" && n > 0;
} }
</script> </script>

View file

@ -13,16 +13,18 @@ Bug 960671 - Test attaching and detaching from a memory actor.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
ok(true, "Shouldn't have gotten an error attaching."); ok(true, "Shouldn't have gotten an error attaching.");
yield memory.detach(); yield memory.detach();
ok(true, "Shouldn't have gotten an error detaching."); ok(true, "Shouldn't have gotten an error detaching.");
destroyServerAndFinish(client); destroyServerAndFinish(client);
}); });
}; };
</script> </script>

View file

@ -13,17 +13,18 @@ Bug 960671 - Test attaching and detaching while in the wrong state.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
var e = null; let e = null;
try { try {
yield memory.detach(); yield memory.detach();
} } catch (ee) {
catch (ee) {
e = ee; e = ee;
} }
ok(e, "Should have hit the wrongState error"); ok(e, "Should have hit the wrongState error");
@ -33,8 +34,7 @@ window.onload = function() {
e = null; e = null;
try { try {
yield memory.attach(); yield memory.attach();
} } catch (ee) {
catch (ee) {
e = ee; e = ee;
} }
ok(e, "Should have hit the wrongState error"); ok(e, "Should have hit the wrongState error");

View file

@ -13,14 +13,16 @@ Bug 1067491 - Test taking a census over the RDP.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
var census = yield memory.takeCensus(); let census = yield memory.takeCensus();
is(typeof census, "object"); is(typeof census, "object");
yield memory.detach(); yield memory.detach();

View file

@ -13,27 +13,31 @@ Bug 1067491 - Test forcing a gc.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
let beforeGC, afterGC;
do { do {
var objects = []; let objects = [];
for (var i = 0; i < 1000; i++) { for (let i = 0; i < 1000; i++) {
var o = {}; let o = {};
o[Math.random()] = 1; o[Math.random()] = 1;
objects.push(o); objects.push(o);
} }
objects = null; objects = null;
var { total: beforeGC } = yield memory.measure(); yield { total: beforeGC } = memory.measure();
yield memory.forceGarbageCollection(); yield memory.forceGarbageCollection();
var { total: afterGC } = yield memory.measure();
} while(beforeGC < afterGC); yield { total: afterGC } = memory.measure();
} while (beforeGC < afterGC);
ok(true, "The amount of memory after GC should eventually decrease"); ok(true, "The amount of memory after GC should eventually decrease");

View file

@ -13,16 +13,18 @@ Bug 1137527 - Test receiving GC events from the memory actor.
<pre id="test"> <pre id="test">
<script src="memory-helpers.js" type="application/javascript"></script> <script src="memory-helpers.js" type="application/javascript"></script>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var event = require("sdk/event/core"); let event = require("sdk/event/core");
Task.spawn(function* () { Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory(); let { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach(); yield memory.attach();
var gotGcEvent = new Promise(resolve => { let gotGcEvent = new Promise(resolve => {
event.on(memory, "garbage-collection", gcData => { event.on(memory, "garbage-collection", gcData => {
ok(gcData, "Got GC data"); ok(gcData, "Got GC data");
resolve(); resolve();

View file

@ -12,46 +12,45 @@ Bug 943251 - Allow accessing about:config from WebIDE
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
function runTests() { function runTests() {
var Cu = Components.utils; let Cu = Components.utils;
var Cc = Components.classes; let Ci = Components.interfaces;
var Ci = Components.interfaces;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); let {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {DebuggerClient} = require("devtools/shared/client/main"); let {DebuggerClient} = require("devtools/shared/client/main");
var {DebuggerServer} = require("devtools/server/main"); let {DebuggerServer} = require("devtools/server/main");
var Services = require("Services"); let Services = require("Services");
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var {getPreferenceFront} = require("devtools/shared/fronts/preference"); let {getPreferenceFront} = require("devtools/shared/fronts/preference");
DebuggerServer.init(); DebuggerServer.init();
DebuggerServer.addBrowserActors(); DebuggerServer.addBrowserActors();
var client = new DebuggerClient(DebuggerServer.connectPipe()); let client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() { client.connect().then(function onConnect() {
client.listTabs(function onListTabs(aResponse) { client.listTabs(function onListTabs(response) {
var p = getPreferenceFront(client, aResponse); let p = getPreferenceFront(client, response);
var prefs = {}; let prefs = {};
var localPref = { let localPref = {
boolPref: true, boolPref: true,
intPref: 0x1234, intPref: 0x1234,
charPref: "Hello World", charPref: "Hello World",
}; };
function checkValues() { function checkValues() {
is(prefs.boolPref, localPref.boolPref, "read/write bool pref"); is(prefs.boolPref, localPref.boolPref, "read/write bool pref");
is(prefs.intPref, localPref.intPref, "read/write int pref"); is(prefs.intPref, localPref.intPref, "read/write int pref");
is(prefs.charPref, localPref.charPref, "read/write string pref"); is(prefs.charPref, localPref.charPref, "read/write string pref");
["test.all.bool", "test.all.int", "test.all.string"].forEach(function(key) { ["test.all.bool", "test.all.int", "test.all.string"].forEach(function (key) {
var expectedValue; let expectedValue;
switch(Services.prefs.getPrefType(key)) { switch (Services.prefs.getPrefType(key)) {
case Ci.nsIPrefBranch.PREF_STRING: case Ci.nsIPrefBranch.PREF_STRING:
expectedValue = Services.prefs.getCharPref(key); expectedValue = Services.prefs.getCharPref(key);
break; break;
@ -66,37 +65,43 @@ function runTests() {
break; break;
} }
is(prefs.allPrefs[key].value, expectedValue, "valid preference value (" + key + ")"); is(prefs.allPrefs[key].value, expectedValue,
is(prefs.allPrefs[key].hasUserValue, Services.prefs.prefHasUserValue(key), "valid hasUserValue (" + key + ")"); "valid preference value (" + key + ")");
is(prefs.allPrefs[key].hasUserValue, Services.prefs.prefHasUserValue(key),
"valid hasUserValue (" + key + ")");
}); });
["test.bool", "test.int", "test.string"].forEach(function(key) { ["test.bool", "test.int", "test.string"].forEach(function (key) {
ok(!prefs.allPrefs.hasOwnProperty(key), "expect no pref (" + key + ")"); ok(!prefs.allPrefs.hasOwnProperty(key), "expect no pref (" + key + ")");
is(Services.prefs.getPrefType(key), Ci.nsIPrefBranch.PREF_INVALID, "pref (" + key + ") is clear"); is(Services.prefs.getPrefType(key), Ci.nsIPrefBranch.PREF_INVALID,
"pref (" + key + ") is clear");
}); });
client.close().then(() => { client.close().then(() => {
DebuggerServer.destroy(); DebuggerServer.destroy();
SimpleTest.finish() SimpleTest.finish();
}); });
} }
function updatePrefsProperty(key) {
return function (value) {
prefs[key] = value;
};
}
p.getAllPrefs().then((json) => prefs["allPrefs"] = json) p.getAllPrefs().then(updatePrefsProperty("allPrefs"))
.then(() => p.setBoolPref("test.bool", localPref.boolPref)) .then(() => p.setBoolPref("test.bool", localPref.boolPref))
.then(() => p.setIntPref("test.int", localPref.intPref)) .then(() => p.setIntPref("test.int", localPref.intPref))
.then(() => p.setCharPref("test.string", localPref.charPref)) .then(() => p.setCharPref("test.string", localPref.charPref))
.then(() => p.getBoolPref("test.bool")).then((value) => prefs["boolPref"] = value) .then(() => p.getBoolPref("test.bool")).then(updatePrefsProperty("boolPref"))
.then(() => p.getIntPref("test.int")).then((value) => prefs["intPref"] = value) .then(() => p.getIntPref("test.int")).then(updatePrefsProperty("intPref"))
.then(() => p.getCharPref("test.string")).then((value) => prefs["charPref"] = value) .then(() => p.getCharPref("test.string")).then(updatePrefsProperty("charPref"))
.then(() => p.clearUserPref("test.bool")) .then(() => p.clearUserPref("test.bool"))
.then(() => p.clearUserPref("test.int")) .then(() => p.clearUserPref("test.int"))
.then(() => p.clearUserPref("test.string")) .then(() => p.clearUserPref("test.string"))
.then(checkValues); .then(checkValues);
}); });
}); });
} }
window.onload = function () { window.onload = function () {
@ -108,7 +113,7 @@ window.onload = function () {
["test.all.string", "allizom"], ["test.all.string", "allizom"],
] ]
}, runTests); }, runTests);
} };
</script> </script>
</pre> </pre>
</body> </body>

View file

@ -12,6 +12,7 @@ Bug 1181100 - Test DebuggerServerConnection.setupInParent and DebuggerServer.set
<body> <body>
<pre id="test"> <pre id="test">
<script type="application/javascript"> <script type="application/javascript">
"use strict";
let Cu = Components.utils; let Cu = Components.utils;
let Cc = Components.classes; let Cc = Components.classes;
@ -22,7 +23,7 @@ let {DebuggerClient} = require("devtools/shared/client/main");
let {DebuggerServer} = require("devtools/server/main"); let {DebuggerServer} = require("devtools/server/main");
let Services = require("Services"); let Services = require("Services");
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ SpecialPowers.pushPrefEnv({
@ -32,7 +33,7 @@ window.onload = function() {
["dom.mozBrowserFramesEnabled", true] ["dom.mozBrowserFramesEnabled", true]
] ]
}, runTests); }, runTests);
} };
function runTests() { function runTests() {
// Create a minimal iframe with a message manager // Create a minimal iframe with a message manager
@ -40,8 +41,6 @@ function runTests() {
iframe.mozbrowser = true; iframe.mozbrowser = true;
document.body.appendChild(iframe); document.body.appendChild(iframe);
let mm = iframe.frameLoader.messageManager;
// Instantiate a minimal server // Instantiate a minimal server
if (!DebuggerServer.initialized) { if (!DebuggerServer.initialized) {
DebuggerServer.init(); DebuggerServer.init();
@ -76,7 +75,7 @@ function runTests() {
// Wait also for a reponse from setupInParent called from setup-in-child.js // Wait also for a reponse from setupInParent called from setup-in-child.js
let onParent = (_, topic, args) => { let onParent = (_, topic, args) => {
Services.obs.removeObserver(onParent, "test:setupParent", false); Services.obs.removeObserver(onParent, "test:setupParent");
args = JSON.parse(args); args = JSON.parse(args);
is(args[0], true, "Got `mm` argument, a message manager"); is(args[0], true, "Got `mm` argument, a message manager");
@ -99,10 +98,9 @@ function runTests() {
client.close().then(function () { client.close().then(function () {
DebuggerServer.destroy(); DebuggerServer.destroy();
iframe.remove(); iframe.remove();
SimpleTest.finish() SimpleTest.finish();
}); });
} }
} }
</script> </script>
</pre> </pre>

View file

@ -11,25 +11,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/server/actors/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gStyles = null; let gStyles = null;
var gClient = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
return inspector.getPageStyle(); return inspector.getPageStyle();
}).then(styles => { }).then(styles => {
@ -50,23 +48,28 @@ addTest(function inheritedUserStyles() {
is(applied[1].inherited.id, "uninheritable-rule-inheritable-style", is(applied[1].inherited.id, "uninheritable-rule-inheritable-style",
"Entry 1 should be inherited from the parent"); "Entry 1 should be inherited from the parent");
is(applied[1].rule.type, 100, "Entry 1 should be an element style"); is(applied[1].rule.type, 100, "Entry 1 should be an element style");
is(applied[1].rule.cssText, "color: red;", "Entry 1 should have the expected cssText"); is(applied[1].rule.cssText, "color: red;",
"Entry 1 should have the expected cssText");
is(applied[2].inherited.id, "inheritable-rule-inheritable-style", is(applied[2].inherited.id, "inheritable-rule-inheritable-style",
"Entry 2 should be inherited from the parent's parent"); "Entry 2 should be inherited from the parent's parent");
is(applied[2].rule.type, 100, "Entry 2 should be an element style"); is(applied[2].rule.type, 100, "Entry 2 should be an element style");
is(applied[2].rule.cssText, "color: blue;", "Entry 2 should have the expected cssText"); is(applied[2].rule.cssText, "color: blue;",
"Entry 2 should have the expected cssText");
is(applied[3].inherited.id, "inheritable-rule-inheritable-style", is(applied[3].inherited.id, "inheritable-rule-inheritable-style",
"Entry 3 should be inherited from the parent's parent"); "Entry 3 should be inherited from the parent's parent");
is(applied[3].rule.type, 1, "Entry 3 should be a rule style"); is(applied[3].rule.type, 1, "Entry 3 should be a rule style");
is(applied[3].rule.cssText, "font-size: 15px;", "Entry 3 should have the expected cssText"); is(applied[3].rule.cssText, "font-size: 15px;",
ok(!applied[3].matchedSelectors, "Shouldn't get matchedSelectors with this request."); "Entry 3 should have the expected cssText");
ok(!applied[3].matchedSelectors,
"Shouldn't get matchedSelectors with this request.");
is(applied[4].inherited.id, "inheritable-rule-uninheritable-style", is(applied[4].inherited.id, "inheritable-rule-uninheritable-style",
"Entry 4 should be inherited from the parent's parent"); "Entry 4 should be inherited from the parent's parent");
is(applied[4].rule.type, 1, "Entry 4 should be an rule style"); is(applied[4].rule.type, 1, "Entry 4 should be an rule style");
is(applied[4].rule.cssText, "font-size: 15px;", "Entry 4 should have the expected cssText"); is(applied[4].rule.cssText, "font-size: 15px;",
"Entry 4 should have the expected cssText");
ok(!applied[4].matchedSelectors, "Shouldn't get matchedSelectors with this request."); ok(!applied[4].matchedSelectors, "Shouldn't get matchedSelectors with this request.");
is(applied.length, 5, "Should have 5 rules."); is(applied.length, 5, "Should have 5 rules.");
@ -106,8 +109,10 @@ addTest(function matchedSelectors() {
inherited: true, filter: "user", matchedSelectors: true inherited: true, filter: "user", matchedSelectors: true
}); });
}).then(applied => { }).then(applied => {
is(applied[3].matchedSelectors[0], ".inheritable-rule", "Entry 3 should have a matched selector"); is(applied[3].matchedSelectors[0], ".inheritable-rule",
is(applied[4].matchedSelectors[0], ".inheritable-rule", "Entry 4 should have a matched selector"); "Entry 3 should have a matched selector");
is(applied[4].matchedSelectors[0], ".inheritable-rule",
"Entry 4 should have a matched selector");
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -124,9 +129,8 @@ addTest(function testMediaQuery() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gStyles; gStyles = null;
delete gWalker; gWalker = null;
delete gClient;
runNextTest(); runNextTest();
}); });

View file

@ -11,26 +11,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/server/actors/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gStyles = null; let gStyles = null;
var gClient = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
return inspector.getPageStyle(); return inspector.getPageStyle();
}).then(styles => { }).then(styles => {
@ -40,87 +37,87 @@ addTest(function setup() {
}); });
addTest(function testComputed() { addTest(function testComputed() {
let localNode = gInspectee.querySelector("#computed-test-node"); promiseDone(
let elementStyle = null; gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => { return gStyles.getComputed(node, {});
return gStyles.getComputed(node, {}); }).then(computed => {
}).then(computed => { // Test a smattering of properties that include some system-defined
// Test a smattering of properties that include some system-defined // props, some props that were defined in this node's stylesheet,
// props, some props that were defined in this node's stylesheet, // and some default props.
// and some default props. is(computed["white-space"].value, "normal", "Default value should appear");
is(computed["white-space"].value, "normal", "Default value should appear"); is(computed.display.value, "block", "System stylesheet item should appear");
is(computed["display"].value, "block", "System stylesheet item should appear"); is(computed.cursor.value, "crosshair", "Included stylesheet rule should appear");
is(computed["cursor"].value, "crosshair", "Included stylesheet rule should appear"); is(computed.color.value, "rgb(255, 0, 0)",
is(computed["color"].value, "rgb(255, 0, 0)", "Inherited style attribute should appear"); "Inherited style attribute should appear");
is(computed["font-size"].value, "15px", "Inherited inline rule should appear"); is(computed["font-size"].value, "15px", "Inherited inline rule should appear");
// We didn't request markMatched, so these shouldn't be set // We didn't request markMatched, so these shouldn't be set
ok(!computed["cursor"].matched, "Didn't ask for matched, shouldn't get it"); ok(!computed.cursor.matched, "Didn't ask for matched, shouldn't get it");
ok(!computed["color"].matched, "Didn't ask for matched, shouldn't get it"); ok(!computed.color.matched, "Didn't ask for matched, shouldn't get it");
ok(!computed["font-size"].matched, "Didn't ask for matched, shouldn't get it"); ok(!computed["font-size"].matched, "Didn't ask for matched, shouldn't get it");
}).then(runNextTest)); }).then(runNextTest)
);
}); });
addTest(function testComputedUserMatched() { addTest(function testComputedUserMatched() {
let localNode = gInspectee.querySelector("#computed-test-node"); promiseDone(
let elementStyle = null; gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => { return gStyles.getComputed(node, { filter: "user", markMatched: true });
return gStyles.getComputed(node, { filter: "user", markMatched: true }); }).then(computed => {
}).then(computed => { ok(!computed["white-space"].matched, "Default style shouldn't match");
ok(!computed["white-space"].matched, "Default style shouldn't match"); ok(!computed.display.matched, "Only user styles should match");
ok(!computed["display"].matched, "Only user styles should match"); ok(computed.cursor.matched, "Asked for matched, should get it");
ok(computed["cursor"].matched, "Asked for matched, should get it"); ok(computed.color.matched, "Asked for matched, should get it");
ok(computed["color"].matched, "Asked for matched, should get it"); ok(computed["font-size"].matched, "Asked for matched, should get it");
ok(computed["font-size"].matched, "Asked for matched, should get it"); }).then(runNextTest)
}).then(runNextTest)); );
}); });
addTest(function testComputedSystemMatched() { addTest(function testComputedSystemMatched() {
let localNode = gInspectee.querySelector("#computed-test-node"); promiseDone(
let elementStyle = null; gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => { return gStyles.getComputed(node, { filter: "ua", markMatched: true });
return gStyles.getComputed(node, { filter: "ua", markMatched: true }); }).then(computed => {
}).then(computed => { ok(!computed["white-space"].matched, "Default style shouldn't match");
ok(!computed["white-space"].matched, "Default style shouldn't match"); ok(computed.display.matched, "System stylesheets should match");
ok(computed["display"].matched, "System stylesheets should match"); ok(computed.cursor.matched, "Asked for matched, should get it");
ok(computed["cursor"].matched, "Asked for matched, should get it"); ok(computed.color.matched, "Asked for matched, should get it");
ok(computed["color"].matched, "Asked for matched, should get it"); ok(computed["font-size"].matched, "Asked for matched, should get it");
ok(computed["font-size"].matched, "Asked for matched, should get it"); }).then(runNextTest)
}).then(runNextTest)); );
}); });
addTest(function testComputedUserOnlyMatched() { addTest(function testComputedUserOnlyMatched() {
let localNode = gInspectee.querySelector("#computed-test-node"); promiseDone(
let elementStyle = null; gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => { return gStyles.getComputed(node, { filter: "user", onlyMatched: true });
return gStyles.getComputed(node, { filter: "user", onlyMatched: true }); }).then(computed => {
}).then(computed => { ok(!("white-space" in computed), "Default style shouldn't exist");
ok(!("white-space" in computed), "Default style shouldn't exist"); ok(!("display" in computed), "System stylesheets shouldn't exist");
ok(!("display" in computed), "System stylesheets shouldn't exist"); ok(("cursor" in computed), "User items should exist.");
ok(("cursor" in computed), "User items should exist."); ok(("color" in computed), "User items should exist.");
ok(("color" in computed), "User items should exist."); ok(("font-size" in computed), "User items should exist.");
ok(("font-size" in computed), "User items should exist."); }).then(runNextTest)
}).then(runNextTest)); );
}); });
addTest(function testComputedSystemOnlyMatched() { addTest(function testComputedSystemOnlyMatched() {
let localNode = gInspectee.querySelector("#computed-test-node"); promiseDone(
let elementStyle = null; gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => { return gStyles.getComputed(node, { filter: "ua", onlyMatched: true });
return gStyles.getComputed(node, { filter: "ua", onlyMatched: true }); }).then(computed => {
}).then(computed => { ok(!("white-space" in computed), "Default style shouldn't exist");
ok(!("white-space" in computed), "Default style shouldn't exist"); ok(("display" in computed), "System stylesheets should exist");
ok(("display" in computed), "System stylesheets should exist"); ok(("cursor" in computed), "User items should exist.");
ok(("cursor" in computed), "User items should exist."); ok(("color" in computed), "User items should exist.");
ok(("color" in computed), "User items should exist."); ok(("font-size" in computed), "User items should exist.");
ok(("font-size" in computed), "User items should exist."); }).then(runNextTest)
}).then(runNextTest)); );
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gStyles; gStyles = null;
delete gWalker; gWalker = null;
delete gClient;
runNextTest(); runNextTest();
}); });

View file

@ -9,7 +9,7 @@
<script type="application/javascript"> <script type="application/javascript">
"use strict"; "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
}; };
@ -17,9 +17,9 @@ window.onload = function() {
let gWalker = null; let gWalker = null;
let gStyles = null; let gStyles = null;
addTest(function() { addTest(function () {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
@ -32,12 +32,12 @@ addTest(function() {
}); });
}); });
addTest(function() { addTest(function () {
ok(gStyles.getLayout, "The PageStyleActor has a getLayout method"); ok(gStyles.getLayout, "The PageStyleActor has a getLayout method");
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
let node = yield gWalker.querySelector(gWalker.rootNode, "#layout-element"); let node = yield gWalker.querySelector(gWalker.rootNode, "#layout-element");
let layout = yield gStyles.getLayout(node, {}); let layout = yield gStyles.getLayout(node, {});
@ -55,7 +55,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
let node = yield gWalker.querySelector(gWalker.rootNode, "#layout-element"); let node = yield gWalker.querySelector(gWalker.rootNode, "#layout-element");
let layout = yield gStyles.getLayout(node, {}); let layout = yield gStyles.getLayout(node, {});
@ -79,7 +79,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addAsyncTest(function*() { addAsyncTest(function* () {
let node = yield gWalker.querySelector(gWalker.rootNode, let node = yield gWalker.querySelector(gWalker.rootNode,
"#layout-auto-margin-element"); "#layout-auto-margin-element");
@ -98,7 +98,7 @@ addAsyncTest(function*() {
runNextTest(); runNextTest();
}); });
addTest(function() { addTest(function () {
gStyles = gWalker = null; gStyles = gWalker = null;
runNextTest(); runNextTest();
}); });

View file

@ -11,27 +11,27 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/server/actors/inspector"); "use strict";
const CssLogic = require("devtools/shared/inspector/css-logic"); const CssLogic = require("devtools/shared/inspector/css-logic");
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gStyles = null; let gStyles = null;
var gClient = null; let gInspectee = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
return inspector.getPageStyle(); return inspector.getPageStyle();
}).then(styles => { }).then(styles => {
@ -47,17 +47,22 @@ addTest(function testMatchedStyles() {
is(matched[0].sourceText, "this.style", "First match comes from the element style"); is(matched[0].sourceText, "this.style", "First match comes from the element style");
is(matched[0].selector, "@element.style", "Element style has a special selector"); is(matched[0].selector, "@element.style", "Element style has a special selector");
is(matched[0].value, "10px", "First match has the expected value"); is(matched[0].value, "10px", "First match has the expected value");
is(matched[0].status, CssLogic.STATUS.BEST, "First match is the best match") is(matched[0].status, CssLogic.STATUS.BEST, "First match is the best match");
is(matched[0].rule.type, 100, "First match is an element style"); is(matched[0].rule.type, 100, "First match is an element style");
is(matched[0].rule.href, gInspectee.defaultView.location.href, "Node style comes from this document") is(matched[0].rule.href, gInspectee.defaultView.location.href,
"Node style comes from this document");
is(matched[1].sourceText, ".inheritable-rule", "Second match comes from a rule"); is(matched[1].sourceText, ".inheritable-rule", "Second match comes from a rule");
is(matched[1].selector, ".inheritable-rule", "Second style has a selector"); is(matched[1].selector, ".inheritable-rule", "Second style has a selector");
is(matched[1].value, "15px", "Second match has the expected value"); is(matched[1].value, "15px", "Second match has the expected value");
is(matched[1].status, CssLogic.STATUS.PARENT_MATCH, "Second match is from the parent") is(matched[1].status, CssLogic.STATUS.PARENT_MATCH,
is(matched[1].rule.parentStyleSheet.href, null, "Inline stylesheet shouldn't have an href"); "Second match is from the parent");
is(matched[1].rule.parentStyleSheet.nodeHref, gInspectee.defaultView.location.href, "Inline stylesheet's nodeHref should match the current document"); is(matched[1].rule.parentStyleSheet.href, null,
ok(!matched[1].rule.parentStyleSheet.system, "Inline stylesheet shouldn't be a system stylesheet."); "Inline stylesheet shouldn't have an href");
is(matched[1].rule.parentStyleSheet.nodeHref, gInspectee.defaultView.location.href,
"Inline stylesheet's nodeHref should match the current document");
ok(!matched[1].rule.parentStyleSheet.system,
"Inline stylesheet shouldn't be a system stylesheet.");
}).then(runNextTest)); }).then(runNextTest));
}); });
@ -77,9 +82,9 @@ addTest(function testSystemStyles() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gStyles; gStyles = null;
delete gWalker; gWalker = null;
delete gClient; gInspectee = null;
runNextTest(); runNextTest();
}); });

View file

@ -11,26 +11,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/server/actors/inspector"); "use strict";
const {isCssPropertyKnown} = require("devtools/server/actors/css-properties"); const {isCssPropertyKnown} = require("devtools/server/actors/css-properties");
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; var gWalker = null;
var gStyles = null; var gStyles = null;
var gClient = null; var gInspectee = null;
addAsyncTest(function* setup() { addAsyncTest(function* setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
let inspector; let inspector;
yield new Promise(resolve => { yield new Promise(resolve => {
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
gInspectee = doc; gInspectee = doc;
gClient = client;
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
inspector = InspectorFront(client, tab); inspector = InspectorFront(client, tab);
resolve(); resolve();
@ -95,9 +95,9 @@ function* removeProperty(rule, index, name) {
} }
addTest(function cleanup() { addTest(function cleanup() {
delete gStyles; gStyles = null;
delete gWalker; gWalker = null;
delete gClient; gInspectee = null;
runNextTest(); runNextTest();
}); });

View file

@ -12,25 +12,23 @@ Bug 921191 - allow inspection/editing of SVG elements' CSS properties
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="inspector-helpers.js"></script> <script type="application/javascript" src="inspector-helpers.js"></script>
<script type="application/javascript"> <script type="application/javascript">
const inspector = require("devtools/server/actors/inspector"); "use strict";
window.onload = function() { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
runNextTest(); runNextTest();
} };
var gWalker = null; let gWalker = null;
var gStyles = null; let gStyles = null;
var gClient = null;
addTest(function setup() { addTest(function setup() {
let url = document.getElementById("inspectorContent").href; let url = document.getElementById("inspectorContent").href;
attachURL(url, function(err, client, tab, doc) { attachURL(url, function (err, client, tab, doc) {
let {InspectorFront} = require("devtools/shared/fronts/inspector"); let {InspectorFront} = require("devtools/shared/fronts/inspector");
let inspector = InspectorFront(client, tab); let inspector = InspectorFront(client, tab);
promiseDone(inspector.getWalker().then(walker => { promiseDone(inspector.getWalker().then(walker => {
ok(walker, "getWalker() should return an actor."); ok(walker, "getWalker() should return an actor.");
gClient = client;
gWalker = walker; gWalker = walker;
return inspector.getPageStyle(); return inspector.getPageStyle();
}).then(styles => { }).then(styles => {
@ -49,9 +47,8 @@ addTest(function inheritedUserStyles() {
}); });
addTest(function cleanup() { addTest(function cleanup() {
delete gStyles; gStyles = null;
delete gWalker; gWalker = null;
delete gClient;
runNextTest(); runNextTest();
}); });

View file

@ -16,6 +16,7 @@ xray wrapper.
<body> <body>
<pre id="test"> <pre id="test">
<script> <script>
"use strict";
Components.utils.import("resource://gre/modules/jsdebugger.jsm"); Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this); addDebuggerToGlobal(this);
@ -23,28 +24,28 @@ addDebuggerToGlobal(this);
window.onload = function () { window.onload = function () {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
iframe.src = "http://mochi.test:8888/chrome/devtools/server/tests/mochitest/nonchrome_unsafeDereference.html"; iframe.src = "http://mochi.test:8888/chrome/devtools/server/tests/mochitest/nonchrome_unsafeDereference.html";
iframe.onload = function () { iframe.onload = function () {
var dbg = new Debugger; let dbg = new Debugger();
var contentDO = dbg.addDebuggee(iframe.contentWindow); let contentDO = dbg.addDebuggee(iframe.contentWindow);
var xhrDesc = contentDO.getOwnPropertyDescriptor('xhr'); let xhrDesc = contentDO.getOwnPropertyDescriptor("xhr");
isnot(xhrDesc, undefined, "xhr should be visible as property of content global"); isnot(xhrDesc, undefined, "xhr should be visible as property of content global");
isnot(xhrDesc.value, undefined, "xhr should have a value"); isnot(xhrDesc.value, undefined, "xhr should have a value");
var xhr = xhrDesc.value.unsafeDereference(); let xhr = xhrDesc.value.unsafeDereference();
is(typeof xhr, "object", "we should be able to deference xhr's value's D.O"); is(typeof xhr, "object", "we should be able to deference xhr's value's D.O");
is(xhr.timeout, 1742, "chrome should see the xhr's 'timeout' property"); is(xhr.timeout, 1742, "chrome should see the xhr's 'timeout' property");
is(xhr.expando, undefined, "chrome should not see the xhr's 'expando' property"); is(xhr.expando, undefined, "chrome should not see the xhr's 'expando' property");
SimpleTest.finish(); SimpleTest.finish();
} };
document.body.appendChild(iframe); document.body.appendChild(iframe);
} };
</script> </script>
</pre> </pre>

View file

@ -9,7 +9,9 @@
</head> </head>
<body> <body>
<script> <script>
window.onload = function() { "use strict";
window.onload = function () {
const { Constructor: CC, utils: Cu } = Components; const { Constructor: CC, utils: Cu } = Components;
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
const { Task } = require("devtools/shared/task"); const { Task } = require("devtools/shared/task");
@ -76,7 +78,7 @@ window.onload = function() {
client.close(); client.close();
yield closed; yield closed;
}); });
} };
</script> </script>
</body> </body>
</html> </html>