Bug 1520782 - Convert console tests using chrome documents and using server references directly to browser mochitests. r=nchevobbe

These two tests were using chrome mochitest which forces the test page to be running in chrome and in parent process.
This doesn't reflect typical setup where the page runs unprivileged in content process.
Also, with the current bug, the pages running in system principal will be debugged with a special setup.
Actors will be run with modules loaded in a distinct loader in order to be executed
in a distinct compartment, distinct from the shared system principal compartment.
That a prerequisite for the Debugger API. It has to run in a distinct compartment than its debuggee.

Depends on D16826

Differential Revision: https://phabricator.services.mozilla.com/D16827

--HG--
rename : devtools/shared/webconsole/test/test_network_longstring.html => devtools/shared/webconsole/test/browser/browser_network_longstring.js
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-01-23 08:53:06 +00:00
Родитель 189029e823
Коммит afc0fa1a25
12 изменённых файлов: 606 добавлений и 487 удалений

Просмотреть файл

@ -7,6 +7,7 @@
if CONFIG['OS_TARGET'] != 'Android':
MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
# Compute where to put transpiled files into omni.ja package
# All DevTools modules are used via resource://devtools/ URI
@ -28,4 +29,4 @@ DevToolsModules(
'js-property-provider.js',
'network-helper.js',
'throttle.js',
)
)

Просмотреть файл

@ -0,0 +1,6 @@
"use strict";
module.exports = {
// Extend from the shared list of defined globals for mochitests.
"extends": "../../../../.eslintrc.mochitests.js"
};

Просмотреть файл

@ -0,0 +1,11 @@
[DEFAULT]
tags = devtools
subsuite = devtools
support-files =
head.js
data.json
data.json^headers^
network_requests_iframe.html
[browser_commands_registration.js]
[browser_network_longstring.js]

Просмотреть файл

@ -0,0 +1,181 @@
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test for Web Console commands registration.
add_task(async function() {
const tab = await addTab("data:text/html,<div id=quack></div>");
const target = await getTargetForTab(tab);
const consoleClient = target.activeConsole;
// Fetch WebConsoleCommands so that it is available for next Content Tasks
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const { WebConsoleCommands } = require("devtools/server/actors/webconsole/utils");
// Bind the symbol on this in order to make it available for next tasks
this.WebConsoleCommands = WebConsoleCommands;
});
await registerNewCommand(consoleClient);
await wrapCommand(consoleClient);
await unregisterCommand(consoleClient);
await registerAccessor(consoleClient);
await unregisterAfterOverridingTwice(consoleClient);
});
async function evaluateJSAndCheckResult(consoleClient, input, expected) {
const response = await consoleClient.evaluateJS(input);
checkObject(response, expected);
}
async function registerNewCommand(consoleClient) {
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
this.WebConsoleCommands.register("setFoo", (owner, value) => {
owner.window.foo = value;
return "ok";
});
ok(this.WebConsoleCommands.hasCommand("setFoo"),
"The command should be registered");
});
const command = "setFoo('bar')";
await evaluateJSAndCheckResult(consoleClient, command, {
from: consoleClient.actor,
input: command,
result: "ok",
});
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
is(content.top.foo, "bar", "top.foo should equal to 'bar'");
});
}
async function wrapCommand(consoleClient) {
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
const origKeys = this.WebConsoleCommands.getCommand("keys");
const newKeys = (...args) => {
const [, arg0] = args;
if (arg0 === ">o_/") {
return "bang!";
}
return origKeys(...args);
};
this.WebConsoleCommands.register("keys", newKeys);
is(this.WebConsoleCommands.getCommand("keys"), newKeys,
"the keys() command should have been replaced");
this.origKeys = origKeys;
});
await evaluateJSAndCheckResult(consoleClient, "keys('>o_/')", {
from: consoleClient.actor,
result: "bang!",
});
await evaluateJSAndCheckResult(consoleClient, "keys({foo: 'bar'})", {
from: consoleClient.actor,
result: {
class: "Array",
preview: {
items: ["foo"],
},
},
});
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
this.WebConsoleCommands.register("keys", this.origKeys);
is(this.WebConsoleCommands.getCommand("keys"), this.origKeys,
"the keys() command should be restored");
delete this.origKeys;
});
}
async function unregisterCommand(consoleClient) {
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
this.WebConsoleCommands.unregister("setFoo");
});
await evaluateJSAndCheckResult(consoleClient, "setFoo", {
from: consoleClient.actor,
input: "setFoo",
result: {
type: "undefined",
},
exceptionMessage: /setFoo is not defined/,
});
}
async function registerAccessor(consoleClient) {
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
this.WebConsoleCommands.register("$foo", {
get(owner) {
const foo = owner.window.document.getElementById("quack");
return owner.makeDebuggeeValue(foo);
},
});
});
const command = "$foo.textContent = '>o_/'";
await evaluateJSAndCheckResult(consoleClient, command, {
from: consoleClient.actor,
input: command,
result: ">o_/",
});
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
is(content.document.getElementById("quack").textContent, ">o_/",
"#foo textContent should equal to \">o_/\"");
this.WebConsoleCommands.unregister("$foo");
ok(!this.WebConsoleCommands.hasCommand("$foo"), "$foo should be unregistered");
});
}
async function unregisterAfterOverridingTwice(consoleClient) {
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
this.WebConsoleCommands.register("keys", (owner, obj) => "command 1");
});
info("checking the value of the first override");
await evaluateJSAndCheckResult(consoleClient, "keys('foo');", {
result: "command 1",
});
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
const orig = this.WebConsoleCommands.getCommand("keys");
this.WebConsoleCommands.register("keys", (owner, obj) => {
if (obj === "quack") {
return "bang!";
}
return orig(owner, obj);
});
});
info("checking the values after the second override");
await evaluateJSAndCheckResult(consoleClient, "keys({});", {
result: "command 1",
});
await evaluateJSAndCheckResult(consoleClient, "keys('quack');", {
result: "bang!",
});
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
this.WebConsoleCommands.unregister("keys");
});
info("checking the value after unregistration (should restore " +
"the original command)");
await evaluateJSAndCheckResult(consoleClient, "keys({});", {
result: {
class: "Array",
preview: {items: []},
},
});
}

Просмотреть файл

@ -0,0 +1,268 @@
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that the network actor uses the LongStringActor
const { DebuggerServer } = require("devtools/server/main");
const LONG_STRING_LENGTH = 400;
const LONG_STRING_INITIAL_LENGTH = 400;
let ORIGINAL_LONG_STRING_LENGTH, ORIGINAL_LONG_STRING_INITIAL_LENGTH;
add_task(async function() {
const tab = await addTab(URL_ROOT + "network_requests_iframe.html");
const target = await getTargetForTab(tab);
const { client } = target;
const consoleClient = target.activeConsole;
await consoleClient.startListeners(["NetworkActivity"]);
// Override the default long string settings to lower values.
// This is done from the parent process's DebuggerServer as the LongString
// actor is being created from the parent process as network requests are
// watched from the parent process.
ORIGINAL_LONG_STRING_LENGTH = DebuggerServer.LONG_STRING_LENGTH;
ORIGINAL_LONG_STRING_INITIAL_LENGTH =
DebuggerServer.LONG_STRING_INITIAL_LENGTH;
DebuggerServer.LONG_STRING_LENGTH = LONG_STRING_LENGTH;
DebuggerServer.LONG_STRING_INITIAL_LENGTH = LONG_STRING_INITIAL_LENGTH;
info("test network POST request");
const onNetworkEvent = client.addOneTimeListener("networkEvent");
const updates = [];
let netActor = null;
const onAllNetworkEventUpdateReceived = new Promise(resolve => {
const onNetworkEventUpdate = (type, packet) => {
updates.push(packet.updateType);
assertNetworkEventUpdate(netActor, packet);
if (updates.includes("responseContent") &&
updates.includes("eventTimings")) {
client.removeListener("networkEventUpdate", onNetworkEventUpdate);
resolve();
}
};
client.addListener("networkEventUpdate", onNetworkEventUpdate);
});
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
content.wrappedJSObject.testXhrPost();
});
info("Waiting for networkEvent");
const netEvent = await onNetworkEvent;
netActor = assertNetworkEvent(client, consoleClient, netEvent);
info("Waiting for all networkEventUpdate");
await onAllNetworkEventUpdateReceived;
const requestHeaders = await consoleClient.getRequestHeaders(netActor);
assertRequestHeaders(requestHeaders);
const requestCookies = await consoleClient.getRequestCookies(netActor);
assertRequestCookies(requestCookies);
const requestPostData = await consoleClient.getRequestPostData(netActor);
assertRequestPostData(requestPostData);
const responseHeaders = await consoleClient.getResponseHeaders(netActor);
assertResponseHeaders(responseHeaders);
const responseCookies = await consoleClient.getResponseCookies(netActor);
assertResponseCookies(responseCookies);
const responseContent = await consoleClient.getResponseContent(netActor);
assertResponseContent(responseContent);
const eventTimings = await consoleClient.getEventTimings(netActor);
assertEventTimings(eventTimings);
await target.destroy();
DebuggerServer.LONG_STRING_LENGTH = ORIGINAL_LONG_STRING_LENGTH;
DebuggerServer.LONG_STRING_INITIAL_LENGTH = ORIGINAL_LONG_STRING_INITIAL_LENGTH;
});
function assertNetworkEvent(client, consoleClient, packet) {
is(packet.from, consoleClient.actor, "network event actor");
info("checking the network event packet");
const netActor = packet.eventActor;
checkObject(netActor, {
actor: /[a-z]/,
startedDateTime: /^\d+\-\d+\-\d+T.+$/,
url: /data\.json/,
method: "POST",
});
return netActor.actor;
}
function assertNetworkEventUpdate(netActor, packet) {
info("received networkEventUpdate " + packet.updateType);
is(packet.from, netActor, "networkEventUpdate actor");
let expectedPacket = null;
switch (packet.updateType) {
case "requestHeaders":
case "responseHeaders":
ok(packet.headers > 0, "headers > 0");
ok(packet.headersSize > 0, "headersSize > 0");
break;
case "requestCookies":
expectedPacket = {
cookies: 3,
};
break;
case "requestPostData":
ok(packet.dataSize > 0, "dataSize > 0");
ok(!packet.discardRequestBody, "discardRequestBody");
break;
case "responseStart":
expectedPacket = {
response: {
httpVersion: /^HTTP\/\d\.\d$/,
status: "200",
statusText: "OK",
headersSize: /^\d+$/,
discardResponseBody: false,
},
};
break;
case "securityInfo":
expectedPacket = {
state: "insecure",
};
break;
case "responseCookies":
expectedPacket = {
cookies: 0,
};
break;
case "responseContent":
expectedPacket = {
mimeType: "application/json",
contentSize: /^\d+$/,
discardResponseBody: false,
};
break;
case "eventTimings":
expectedPacket = {
totalTime: /^\d+$/,
};
break;
default:
ok(false, "unknown network event update type: " +
packet.updateType);
return;
}
if (expectedPacket) {
info("checking the packet content");
checkObject(packet, expectedPacket);
}
}
function assertRequestHeaders(response) {
info("checking request headers");
ok(response.headers.length > 0, "request headers > 0");
ok(response.headersSize > 0, "request headersSize > 0");
checkHeadersOrCookies(response.headers, {
Referer: /network_requests_iframe\.html/,
Cookie: /bug768096/,
});
}
function assertRequestCookies(response) {
info("checking request cookies");
is(response.cookies.length, 3, "request cookies length");
checkHeadersOrCookies(response.cookies, {
foobar: "fooval",
omgfoo: "bug768096",
badcookie: "bug826798=st3fan",
});
}
function assertRequestPostData(response) {
info("checking request POST data");
checkObject(response, {
postData: {
text: {
type: "longString",
initial: /^Hello world! foobaz barr.+foobaz barrfo$/,
length: 563,
actor: /[a-z]/,
},
},
postDataDiscarded: false,
});
is(response.postData.text.initial.length,
LONG_STRING_INITIAL_LENGTH, "postData text initial length");
}
function assertResponseHeaders(response) {
info("checking response headers");
ok(response.headers.length > 0, "response headers > 0");
ok(response.headersSize > 0, "response headersSize > 0");
checkHeadersOrCookies(response.headers, {
"content-type": /^application\/(json|octet-stream)$/,
"content-length": /^\d+$/,
"x-very-short": "hello world",
"x-very-long": {
"type": "longString",
"length": 521,
"initial": /^Lorem ipsum.+\. Donec vitae d$/,
"actor": /[a-z]/,
},
});
}
function assertResponseCookies(response) {
info("checking response cookies");
is(response.cookies.length, 0, "response cookies length");
}
function assertResponseContent(response) {
info("checking response content");
checkObject(response, {
content: {
text: {
type: "longString",
initial: /^\{ id: "test JSON data"(.|\r|\n)+ barfoo ba$/g,
length: 1070,
actor: /[a-z]/,
},
},
contentDiscarded: false,
});
is(response.content.text.initial.length,
LONG_STRING_INITIAL_LENGTH, "content initial length");
}
function assertEventTimings(response) {
info("checking event timings");
checkObject(response, {
timings: {
blocked: /^-1|\d+$/,
dns: /^-1|\d+$/,
connect: /^-1|\d+$/,
send: /^-1|\d+$/,
wait: /^-1|\d+$/,
receive: /^-1|\d+$/,
},
totalTime: /^\d+$/,
});
}

Просмотреть файл

@ -0,0 +1,3 @@
{ id: "test JSON data", myArray: [ "foo", "bar", "baz", "biff" ],
veryLong: "foo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo bar"
}

Просмотреть файл

@ -0,0 +1,3 @@
Content-Type: application/json
x-very-long: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse a ipsum massa. Phasellus at elit dictum libero laoreet sagittis. Phasellus condimentum ultricies imperdiet. Nam eu ligula justo, ut tincidunt quam. Etiam sollicitudin, tortor sed egestas blandit, sapien sem tincidunt nulla, eu luctus libero odio quis leo. Nam elit massa, mattis quis blandit ac, facilisis vitae arcu. Donec vitae dictum neque. Proin ornare nisl at lectus commodo iaculis eget eget est. Quisque scelerisque vestibulum quam sed interdum.
x-very-short: hello world

Просмотреть файл

@ -0,0 +1,66 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* import-globals-from ../../../../client/shared/test/shared-head.js */
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
this);
async function getTargetForTab(tab) {
const target = await TargetFactory.forTab(tab);
info("Attaching to the active tab.");
await target.attach();
return target;
}
function checkObject(object, expected) {
for (const name of Object.keys(expected)) {
const expectedValue = expected[name];
const value = object[name];
checkValue(name, value, expectedValue);
}
}
function checkValue(name, value, expected) {
if (expected === null) {
is(value, null, "'" + name + "' is null");
} else if (value === null) {
ok(false, "'" + name + "' is null");
} else if (value === undefined) {
ok(false, "'" + name + "' is undefined");
} else if (typeof expected == "string" || typeof expected == "number" ||
typeof expected == "boolean") {
is(value, expected, "property '" + name + "'");
} else if (expected instanceof RegExp) {
ok(expected.test(value), name + ": " + expected + " matched " + value);
} else if (Array.isArray(expected)) {
info("checking array for property '" + name + "'");
checkObject(value, expected);
} else if (typeof expected == "object") {
info("checking object for property '" + name + "'");
checkObject(value, expected);
}
}
function checkHeadersOrCookies(array, expected) {
const foundHeaders = {};
for (const elem of array) {
if (!(elem.name in expected)) {
continue;
}
foundHeaders[elem.name] = true;
info("checking value of header " + elem.name);
checkValue(elem.name, elem.value, expected[elem.name]);
}
for (const header in expected) {
if (!(header in foundHeaders)) {
ok(false, header + " was not found");
}
}
}

Просмотреть файл

@ -0,0 +1,66 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Console HTTP test page</title>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<script type="text/javascript"><!--
"use strict";
let setAllowAllCookies = false;
function makeXhr(method, url, requestBody, callback) {
// On the first call, allow all cookies and set cookies, then resume the actual test
if (!setAllowAllCookies) {
SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0]]},
function() {
setAllowAllCookies = true;
setCookies();
makeXhrCallback(method, url, requestBody, callback);
});
} else {
makeXhrCallback(method, url, requestBody, callback);
}
}
function makeXhrCallback(method, url, requestBody, callback) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.open(method, url, true);
if (callback) {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
callback();
}
};
}
xmlhttp.send(requestBody);
}
/* exported testXhrGet */
function testXhrGet(callback) {
makeXhr("get", "data.json", null, callback);
}
/* exported testXhrPost */
function testXhrPost(callback) {
const body = "Hello world! " + "foobaz barr".repeat(50);
makeXhr("post", "data.json", body, callback);
}
function setCookies() {
document.cookie = "foobar=fooval";
document.cookie = "omgfoo=bug768096";
document.cookie = "badcookie=bug826798=st3fan";
}
</script>
</head>
<body>
<h1>Web Console HTTP Logging Testpage</h1>
<h2>This page is used to test the HTTP logging.</h2>
<form action="?" method="post">
<input name="name" type="text" value="foo bar"><br>
<input name="age" type="text" value="144"><br>
</form>
</body>
</html>

Просмотреть файл

@ -15,7 +15,6 @@ support-files =
[test_bug819670_getter_throws.html]
[test_cached_messages.html]
[test_commands_other.html]
[test_commands_registration.html]
[test_consoleapi.html]
[test_consoleapi_innerID.html]
[test_console_assert.html]
@ -34,7 +33,6 @@ support-files =
[test_jsterm_queryselector.html]
[test_network_get.html]
skip-if = verify
[test_network_longstring.html]
[test_network_post.html]
[test_network_security-hpkp.html]
[test_network_security-hsts.html]

Просмотреть файл

@ -1,191 +0,0 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for Web Console commands registration.</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for Web Console commands registration.</p>
<p id="quack"></p>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
let gState;
let tests;
let {WebConsoleCommands} = require("devtools/server/actors/webconsole/utils");
function evaluateJS(input) {
return gState.client.evaluateJS(input);
}
async function evaluateJSAndCheckResult(input, result) {
let response = await evaluateJS(input);
checkObject(response, {result});
}
function startTest()
{
removeEventListener("load", startTest);
attachConsoleToTab(["PageError"], onAttach);
}
function onAttach(aState, aResponse)
{
gState = aState;
runTests(tests, testEnd);
}
tests = [
async function registerNewCommand() {
let win;
WebConsoleCommands.register("setFoo", (owner, value) => {
owner.window.foo = value;
return "ok";
});
ok(WebConsoleCommands.hasCommand("setFoo"),
"The command should be registered");
let command = "setFoo('bar')";
let response = await evaluateJS(command);
checkObject(response, {
from: gState.actor,
input: command,
result: "ok"
});
is(top.foo, "bar", "top.foo should equal to 'bar'");
nextTest();
},
async function wrapCommand() {
let origKeys = WebConsoleCommands.getCommand("keys");
let newKeys = (...args) => {
let [owner, arg0] = args;
if (arg0 === ">o_/") {
return "bang!";
}
else {
return origKeys(...args);
}
};
WebConsoleCommands.register("keys", newKeys);
is(WebConsoleCommands.getCommand("keys"), newKeys,
"the keys() command should have been replaced");
let response = await evaluateJS("keys('>o_/')");
checkObject(response, {
from: gState.actor,
result: "bang!"
});
response = await evaluateJS("keys({foo: 'bar'})");
checkObject(response, {
from: gState.actor,
result: {
class: "Array",
preview: {
items: ["foo"]
}
}
});
WebConsoleCommands.register("keys", origKeys);
is(WebConsoleCommands.getCommand("keys"), origKeys,
"the keys() command should be restored");
nextTest();
},
async function unregisterCommand() {
WebConsoleCommands.unregister("setFoo");
let response = await evaluateJS("setFoo");
checkObject(response, {
from: gState.actor,
input: "setFoo",
result: {
type: "undefined"
},
exceptionMessage: /setFoo is not defined/
});
nextTest();
},
async function registerAccessor() {
WebConsoleCommands.register("$foo", {
get(owner) {
let foo = owner.window.frames[0].window.document.getElementById("quack");
return owner.makeDebuggeeValue(foo);
}
});
let command = "$foo.textContent = '>o_/'";
let response = await evaluateJS(command);
checkObject(response, {
from: gState.actor,
input: command,
result: ">o_/"
});
is(document.getElementById("quack").textContent, ">o_/",
"#foo textContent should equal to \">o_/\"");
WebConsoleCommands.unregister("$foo");
ok(!WebConsoleCommands.hasCommand("$foo"), "$foo should be unregistered");
nextTest();
},
async function unregisterAfterOverridingTwice() {
WebConsoleCommands.register("keys", (owner, obj) => "command 1");
info("checking the value of the first override");
await evaluateJSAndCheckResult("keys('foo');", "command 1");
let orig = WebConsoleCommands.getCommand("keys");
WebConsoleCommands.register("keys", (owner, obj) => {
if (obj === "quack")
return "bang!";
return orig(owner, obj);
});
info("checking the values after the second override");
await evaluateJSAndCheckResult("keys({});", "command 1");
await evaluateJSAndCheckResult("keys('quack');", "bang!");
WebConsoleCommands.unregister("keys");
info("checking the value after unregistration (should restore " +
"the original command)");
await evaluateJSAndCheckResult("keys({});", {
class: "Array",
preview: {items: []}
});
nextTest();
}
];
function testEnd()
{
// If this is the first run, reload the page and do it again.
// Otherwise, end the test.
delete top.foo;
closeDebugger(gState, function() {
gState = null;
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>

Просмотреть файл

@ -1,293 +0,0 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test that the network actor uses the LongStringActor</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test that the network actor uses the LongStringActor</p>
<iframe src="http://example.com/chrome/devtools/shared/webconsole/test/network_requests_iframe.html"></iframe>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
function startTest()
{
removeEventListener("load", startTest);
attachConsoleToTab(["NetworkActivity"], onAttach);
}
function onAttach(aState, aResponse)
{
info("set long string length");
window.ORIGINAL_LONG_STRING_LENGTH = DebuggerServer.LONG_STRING_LENGTH;
window.ORIGINAL_LONG_STRING_INITIAL_LENGTH =
DebuggerServer.LONG_STRING_INITIAL_LENGTH;
DebuggerServer.LONG_STRING_LENGTH = 400;
DebuggerServer.LONG_STRING_INITIAL_LENGTH = 400;
info("test network POST request");
onNetworkEvent = onNetworkEvent.bind(null, aState);
aState.dbgClient.addListener("networkEvent", onNetworkEvent);
onNetworkEventUpdate = onNetworkEventUpdate.bind(null, aState);
aState.dbgClient.addListener("networkEventUpdate", onNetworkEventUpdate);
let iframe = document.querySelector("iframe").contentWindow;
iframe.wrappedJSObject.testXhrPost();
}
function onNetworkEvent(aState, aType, aPacket)
{
is(aPacket.from, aState.actor, "network event actor");
info("checking the network event packet");
let netActor = aPacket.eventActor;
checkObject(netActor, {
actor: /[a-z]/,
startedDateTime: /^\d+\-\d+\-\d+T.+$/,
url: /data\.json/,
method: "POST",
});
aState.netActor = netActor.actor;
aState.dbgClient.removeListener("networkEvent", onNetworkEvent);
}
let updates = [];
function onNetworkEventUpdate(aState, aType, aPacket)
{
info("received networkEventUpdate " + aPacket.updateType);
is(aPacket.from, aState.netActor, "networkEventUpdate actor");
updates.push(aPacket.updateType);
let expectedPacket = null;
switch (aPacket.updateType) {
case "requestHeaders":
case "responseHeaders":
ok(aPacket.headers > 0, "headers > 0");
ok(aPacket.headersSize > 0, "headersSize > 0");
break;
case "requestCookies":
expectedPacket = {
cookies: 3,
};
break;
case "requestPostData":
ok(aPacket.dataSize > 0, "dataSize > 0");
ok(!aPacket.discardRequestBody, "discardRequestBody");
break;
case "responseStart":
expectedPacket = {
response: {
httpVersion: /^HTTP\/\d\.\d$/,
status: "200",
statusText: "OK",
headersSize: /^\d+$/,
discardResponseBody: false,
},
};
break;
case "securityInfo":
expectedPacket = {
state: "insecure",
};
break;
case "responseCookies":
expectedPacket = {
cookies: 0,
};
break;
case "responseContent":
expectedPacket = {
mimeType: "application/json",
contentSize: /^\d+$/,
discardResponseBody: false,
};
break;
case "eventTimings":
expectedPacket = {
totalTime: /^\d+$/,
};
break;
default:
ok(false, "unknown network event update type: " +
aPacket.updateType);
return;
}
if (expectedPacket) {
info("checking the packet content");
checkObject(aPacket, expectedPacket);
}
if (updates.indexOf("responseContent") > -1 &&
updates.indexOf("eventTimings") > -1) {
aState.dbgClient.removeListener("networkEventUpdate",
onNetworkEvent);
onRequestHeaders = onRequestHeaders.bind(null, aState);
aState.client.getRequestHeaders(aState.netActor,
onRequestHeaders);
}
}
function onRequestHeaders(aState, aResponse)
{
info("checking request headers");
ok(aResponse.headers.length > 0, "request headers > 0");
ok(aResponse.headersSize > 0, "request headersSize > 0");
checkHeadersOrCookies(aResponse.headers, {
Referer: /network_requests_iframe\.html/,
Cookie: /bug768096/,
});
onRequestCookies = onRequestCookies.bind(null, aState);
aState.client.getRequestCookies(aState.netActor,
onRequestCookies);
}
function onRequestCookies(aState, aResponse)
{
info("checking request cookies");
is(aResponse.cookies.length, 3, "request cookies length");
checkHeadersOrCookies(aResponse.cookies, {
foobar: "fooval",
omgfoo: "bug768096",
badcookie: "bug826798=st3fan",
});
onRequestPostData = onRequestPostData.bind(null, aState);
aState.client.getRequestPostData(aState.netActor,
onRequestPostData);
}
function onRequestPostData(aState, aResponse)
{
info("checking request POST data");
checkObject(aResponse, {
postData: {
text: {
type: "longString",
initial: /^Hello world! foobaz barr.+foobaz barrfo$/,
length: 552,
actor: /[a-z]/,
},
},
postDataDiscarded: false,
});
is(aResponse.postData.text.initial.length,
DebuggerServer.LONG_STRING_INITIAL_LENGTH, "postData text initial length");
onResponseHeaders = onResponseHeaders.bind(null, aState);
aState.client.getResponseHeaders(aState.netActor,
onResponseHeaders);
}
function onResponseHeaders(aState, aResponse)
{
info("checking response headers");
ok(aResponse.headers.length > 0, "response headers > 0");
ok(aResponse.headersSize > 0, "response headersSize > 0");
checkHeadersOrCookies(aResponse.headers, {
"content-type": /^application\/(json|octet-stream)$/,
"content-length": /^\d+$/,
"x-very-short": "hello world",
"x-very-long": {
"type": "longString",
"length": 521,
"initial": /^Lorem ipsum.+\. Donec vitae d$/,
"actor": /[a-z]/,
},
});
onResponseCookies = onResponseCookies.bind(null, aState);
aState.client.getResponseCookies(aState.netActor,
onResponseCookies);
}
function onResponseCookies(aState, aResponse)
{
info("checking response cookies");
is(aResponse.cookies.length, 0, "response cookies length");
onResponseContent = onResponseContent.bind(null, aState);
aState.client.getResponseContent(aState.netActor,
onResponseContent);
}
function onResponseContent(aState, aResponse)
{
info("checking response content");
checkObject(aResponse, {
content: {
text: {
type: "longString",
initial: /^\{ id: "test JSON data"(.|\r|\n)+ barfoo ba$/g,
length: 1070,
actor: /[a-z]/,
},
},
contentDiscarded: false,
});
is(aResponse.content.text.initial.length,
DebuggerServer.LONG_STRING_INITIAL_LENGTH, "content initial length");
onEventTimings = onEventTimings.bind(null, aState);
aState.client.getEventTimings(aState.netActor,
onEventTimings);
}
function onEventTimings(aState, aResponse)
{
info("checking event timings");
checkObject(aResponse, {
timings: {
blocked: /^-1|\d+$/,
dns: /^-1|\d+$/,
connect: /^-1|\d+$/,
send: /^-1|\d+$/,
wait: /^-1|\d+$/,
receive: /^-1|\d+$/,
},
totalTime: /^\d+$/,
});
closeDebugger(aState, function() {
DebuggerServer.LONG_STRING_LENGTH = ORIGINAL_LONG_STRING_LENGTH;
DebuggerServer.LONG_STRING_INITIAL_LENGTH = ORIGINAL_LONG_STRING_INITIAL_LENGTH;
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>