1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* exported Cr, CC, NetUtil, errorCount, initTestDevToolsServer,
writeTestTempFile, socket_transport, local_transport, really_long
*/
var CC = Components.Constructor;
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
const { NetUtil } = require("resource://gre/modules/NetUtil.jsm");
const Services = require("Services");
// We do not want to log packets by default, because in some tests,
// we can be sending large amounts of data. The test harness has
// trouble dealing with logging all the data, and we end up with
// intermittent time outs (e.g. bug 775924).
// Services.prefs.setBoolPref("devtools.debugger.log", true);
// Services.prefs.setBoolPref("devtools.debugger.log.verbose", true);
// Enable remote debugging for the relevant tests.
Services.prefs.setBoolPref("devtools.debugger.remote-enabled", true);
const {
ActorRegistry,
} = require("devtools/server/actors/utils/actor-registry");
const { DevToolsServer } = require("devtools/server/devtools-server");
const { DevToolsClient } = require("devtools/client/devtools-client");
const { SocketListener } = require("devtools/shared/security/socket");
// Convert an nsIScriptError 'logLevel' value into an appropriate string.
function scriptErrorLogLevel(message) {
switch (message.logLevel) {
case Ci.nsIConsoleMessage.info:
return "info";
case Ci.nsIConsoleMessage.warn:
return "warning";
default:
Assert.equal(message.logLevel, Ci.nsIConsoleMessage.error);
return "error";
}
}
// Register a console listener, so console messages don't just disappear
// into the ether.
var errorCount = 0;
var listener = {
observe: function(message) {
errorCount++;
let string = "";
try {
// If we've been given an nsIScriptError, then we can print out
// something nicely formatted, for tools like Emacs to pick up.
message.QueryInterface(Ci.nsIScriptError);
dump(
message.sourceName +
":" +
message.lineNumber +
": " +
scriptErrorLogLevel(message) +
": " +
message.errorMessage +
"\n"
);
string = message.errorMessage;
} catch (x) {
// Be a little paranoid with message, as the whole goal here is to lose
// no information.
try {
string = message.message;
} catch (e) {
string = "<error converting error message to string>";
}
}
// Make sure we exit all nested event loops so that the test can finish.
while (DevToolsServer.xpcInspector.eventLoopNestLevel > 0) {
DevToolsServer.xpcInspector.exitNestedEventLoop();
}
do_throw("head_dbg.js got console message: " + string + "\n");
},
};
Services.console.registerListener(listener);
/**
* Initialize the testing devtools server.
*/
function initTestDevToolsServer() {
ActorRegistry.registerModule("devtools/server/actors/thread", {
prefix: "script",
constructor: "ScriptActor",
type: { global: true, target: true },
});
const { createRootActor } = require("xpcshell-test/testactors");
DevToolsServer.setRootActor(createRootActor);
// Allow incoming connections.
DevToolsServer.init();
}
/**
* Wrapper around do_get_file to prefix files with the name of current test to
* avoid collisions when running in parallel.
*/
function getTestTempFile(fileName, allowMissing) {
let thisTest = _TEST_FILE.toString().replace(/\\/g, "/");
thisTest = thisTest.substring(thisTest.lastIndexOf("/") + 1);
thisTest = thisTest.replace(/\..*$/, "");
return do_get_file(fileName + "-" + thisTest, allowMissing);
}
function writeTestTempFile(fileName, content) {
const file = getTestTempFile(fileName, true);
const stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(
Ci.nsIFileOutputStream
);
stream.init(file, -1, -1, 0);
try {
do {
const numWritten = stream.write(content, content.length);
content = content.slice(numWritten);
} while (content.length > 0);
} finally {
stream.close();
}
}
/** * Transport Factories ***/
var socket_transport = async function() {
if (!DevToolsServer.listeningSockets) {
const AuthenticatorType = DevToolsServer.Authenticators.get("PROMPT");
const authenticator = new AuthenticatorType.Server();
authenticator.allowConnection = () => {
return DevToolsServer.AuthenticationResult.ALLOW;
};
const socketOptions = {
authenticator,
portOrPath: -1,
};
const debuggerListener = new SocketListener(DevToolsServer, socketOptions);
await debuggerListener.open();
}
const port = DevToolsServer._listeners[0].port;
info("DevTools server port is " + port);
return DevToolsClient.socketConnect({ host: "127.0.0.1", port });
};
function local_transport() {
return Promise.resolve(DevToolsServer.connectPipe());
}
/** * Sample Data ***/
var gReallyLong;
function really_long() {
if (gReallyLong) {
return gReallyLong;
}
let ret = "0123456789";
for (let i = 0; i < 18; i++) {
ret += ret;
}
gReallyLong = ret;
return ret;
}
|