Bug 1437806 - Enable browser_console.js in new frontend r=bgrins

Not a huge amount needed changing in this one... changed paths, removed references to bug numbers, switched to async / await and used the new method to check for messages.

MozReview-Commit-ID: 2pefVnMozXq

--HG--
extra : rebase_source : fe4b0fc52bf8a60d566314920baa75aaf8458d9d
This commit is contained in:
Michael Ratcliffe 2018-03-02 15:38:38 +00:00
parent 74e2cfaf30
commit e9b1a3f125
2 changed files with 65 additions and 124 deletions

View File

@ -3,24 +3,28 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Test the basic features of the Browser Console, bug 587757.
/* import-globals-from head.js */
// Test the basic features of the Browser Console.
"use strict";
const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
"test/test-console.html?" + Date.now();
"new-console-output/test/mochitest/test-console.html?" +
Date.now();
const TEST_FILE = "chrome://mochitests/content/browser/devtools/client/" +
"webconsole/test/test-cu-reporterror.js";
"webconsole/new-console-output/test/mochitest/" +
"test-cu-reporterror.js";
const TEST_XHR_ERROR_URI = `http://example.com/404.html?${Date.now()}`;
const TEST_IMAGE = "http://example.com/browser/devtools/client/webconsole/" +
"test/test-image.png";
"new-console-output/test/test-image.png";
const ObjectClient = require("devtools/shared/client/object-client");
add_task(function* () {
yield loadTab(TEST_URI);
add_task(async function () {
await addTab(TEST_URI);
let opened = waitForBrowserConsole();
@ -29,49 +33,53 @@ add_task(function* () {
info("wait for the browser console to open with ctrl-shift-j");
EventUtils.synthesizeKey("j", { accelKey: true, shiftKey: true }, window);
hud = yield opened;
hud = await opened;
ok(hud, "browser console opened");
yield testMessages(hud);
yield testCPOWInspection(hud);
await setFilterState(hud, {
netxhr: true
});
await testMessages(hud);
await testCPOWInspection(hud);
await resetFilters(hud);
});
function testMessages(hud) {
async function testMessages(hud) {
hud.jsterm.clearOutput(true);
expectUncaughtException();
executeSoon(() => {
foobarExceptionBug587757();
foobarException();
});
// Add a message from a chrome window.
hud.iframeWindow.console.log("bug587757a");
hud.iframeWindow.console.log("message from chrome window");
// Check Cu.reportError stack.
// Use another js script to not depend on the test file line numbers.
Services.scriptloader.loadSubScript(TEST_FILE, hud.iframeWindow);
// Bug 1348885: test that error from nuked globals do not throw
let sandbox = new Cu.Sandbox(null, {
wantComponents: false,
wantGlobalProperties: ["URL", "URLSearchParams"],
});
let error = Cu.evalInSandbox(`
new Error("1348885");
`, sandbox);
let error = Cu.evalInSandbox(`new Error("error from nuked globals");`, sandbox);
Cu.reportError(error);
Cu.nukeSandbox(sandbox);
// Add a message from a content window.
content.console.log("bug587757b");
content.console.log("message from content window");
// Test eval.
hud.jsterm.execute("document.location.href");
// Test eval frame script
hud.jsterm.execute(`
gBrowser.selectedBrowser.messageManager.loadFrameScript('data:application/javascript,console.log("framescript-message")', false);
"framescript-eval";
`);
hud.jsterm.execute(
`gBrowser.selectedBrowser.messageManager.loadFrameScript(` +
`'data:application/javascript,console.log("framescript-message")', false);` +
`"framescript-eval";`);
// Check for network requests.
let xhr = new XMLHttpRequest();
@ -88,102 +96,30 @@ function testMessages(hud) {
xhrErr.send();
// Check that Fetch requests are categorized as "XHR".
fetch(TEST_IMAGE).then(() => { console.log("fetch loaded"); });
await fetch(TEST_IMAGE);
console.log("fetch loaded");
return waitForMessages({
webconsole: hud,
messages: [
{
name: "chrome window console.log() is displayed",
text: "bug587757a",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
},
{
name: "Cu.reportError is displayed",
text: "bug1141222",
category: CATEGORY_JS,
severity: SEVERITY_ERROR,
stacktrace: [{
file: TEST_FILE,
line: 2,
}, {
file: TEST_FILE,
line: 4,
},
// Ignore the rest of the stack,
// just assert Cu.reportError call site
// and consoleOpened call
]
},
{
name: "Error from nuked global works",
text: "1348885",
category: CATEGORY_JS,
severity: SEVERITY_ERROR,
},
{
name: "content window console.log() is displayed",
text: "bug587757b",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
},
{
name: "jsterm eval result",
text: "browser.xul",
category: CATEGORY_OUTPUT,
severity: SEVERITY_LOG,
},
{
name: "jsterm eval result 2",
text: "framescript-eval",
category: CATEGORY_OUTPUT,
severity: SEVERITY_LOG,
},
{
name: "frame script message",
text: "framescript-message",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
},
{
name: "exception message",
text: "foobarExceptionBug587757",
category: CATEGORY_JS,
severity: SEVERITY_ERROR,
},
{
name: "network message",
text: "test-console.html",
category: CATEGORY_NETWORK,
severity: SEVERITY_INFO,
isXhr: true,
},
{
name: "xhr error message",
text: "404.html",
category: CATEGORY_NETWORK,
severity: SEVERITY_ERROR,
isXhr: true,
},
{
name: "network message",
text: "test-image.png",
category: CATEGORY_NETWORK,
severity: SEVERITY_INFO,
isXhr: true,
},
],
});
await checkMessageExists(hud, "message from chrome window");
await checkMessageExists(hud,
"error thrown from test-cu-reporterror.js via Cu.reportError()");
await checkMessageExists(hud, "error from nuked globals");
await checkMessageExists(hud, "message from content window");
await checkMessageExists(hud, "browser.xul");
await checkMessageExists(hud, "framescript-eval");
await checkMessageExists(hud, "framescript-message");
await checkMessageExists(hud, "foobarException");
await checkMessageExists(hud, "test-console.html");
await checkMessageExists(hud, "404.html");
await checkMessageExists(hud, "test-image.png");
}
function* testCPOWInspection(hud) {
async function testCPOWInspection(hud) {
// Directly request evaluation to get an actor for the selected browser.
// Note that this doesn't actually render a message, and instead allows us
// us to assert that inspecting an object doesn't throw in the server.
// This would be done in a mochitest-chrome suite, but that doesn't run in
// e10s, so it's harder to get ahold of a CPOW.
let cpowEval = yield hud.jsterm.requestEvaluation("gBrowser.selectedBrowser");
let cpowEval = await hud.jsterm.requestEvaluation("gBrowser.selectedBrowser");
info("Creating an ObjectClient with: " + cpowEval.result.actor);
let objectClient = new ObjectClient(hud.jsterm.hud.proxy.client, {
@ -192,7 +128,7 @@ function* testCPOWInspection(hud) {
// Before the fix for Bug 1382833, this wouldn't resolve due to a CPOW error
// in the ObjectActor.
let prototypeAndProperties = yield objectClient.getPrototypeAndProperties();
let prototypeAndProperties = await objectClient.getPrototypeAndProperties();
// Just a sanity check to make sure a valid packet came back
is(prototypeAndProperties.prototype.class, "XBL prototype JSClass",
@ -202,7 +138,7 @@ function* testCPOWInspection(hud) {
let cpow = prototypeAndProperties.ownProperties._contentWindow.value;
// But it's only a CPOW in e10s.
let e10sCheck = yield hud.jsterm.requestEvaluation(
let e10sCheck = await hud.jsterm.requestEvaluation(
"Cu.isCrossProcessWrapper(gBrowser.selectedBrowser._contentWindow)");
if (!e10sCheck.result) {
is(cpow.class, "Window", "The object is not a CPOW.");
@ -212,35 +148,40 @@ function* testCPOWInspection(hud) {
is(cpow.class, "CPOW: Window", "The CPOW grip has the right class.");
// Check that various protocol request methods work for the CPOW.
let response, slice;
let objClient = new ObjectClient(hud.jsterm.hud.proxy.client, cpow);
response = yield objClient.getPrototypeAndProperties();
let response = await objClient.getPrototypeAndProperties();
is(Reflect.ownKeys(response.ownProperties).length, 0, "No property was retrieved.");
is(response.ownSymbols.length, 0, "No symbol property was retrieved.");
is(response.prototype.type, "null", "The prototype is null.");
response = yield objClient.enumProperties({ignoreIndexedProperties: true});
slice = yield response.iterator.slice(0, response.iterator.count);
response = await objClient.enumProperties({ignoreIndexedProperties: true});
let slice = await response.iterator.slice(0, response.iterator.count);
is(Reflect.ownKeys(slice.ownProperties).length, 0, "No property was retrieved.");
response = yield objClient.enumProperties({});
slice = yield response.iterator.slice(0, response.iterator.count);
response = await objClient.enumProperties({});
slice = await response.iterator.slice(0, response.iterator.count);
is(Reflect.ownKeys(slice.ownProperties).length, 0, "No property was retrieved.");
response = yield objClient.getOwnPropertyNames();
response = await objClient.getOwnPropertyNames();
is(response.ownPropertyNames.length, 0, "No property was retrieved.");
response = yield objClient.getProperty("x");
response = await objClient.getProperty("x");
is(response.descriptor, undefined, "The property does not exist.");
response = yield objClient.enumSymbols();
slice = yield response.iterator.slice(0, response.iterator.count);
response = await objClient.enumSymbols();
slice = await response.iterator.slice(0, response.iterator.count);
is(slice.ownSymbols.length, 0, "No symbol property was retrieved.");
response = yield objClient.getPrototype();
response = await objClient.getPrototype();
is(response.prototype.type, "null", "The prototype is null.");
response = yield objClient.getDisplayString();
response = await objClient.getDisplayString();
is(response.displayString, "<cpow>", "The CPOW stringifies to <cpow>");
}
async function checkMessageExists(hud, msg) {
info(`Checking "${msg}" was logged`);
let message = await waitFor(() => findMessage(hud, msg));
ok(message, `"${msg}" was logged`);
}

View File

@ -1,4 +1,4 @@
function a() {
Cu.reportError("bug1141222");
Cu.reportError("error thrown from test-cu-reporterror.js via Cu.reportError()");
}
a();