Bug 1537768 - Override add_task to translate cdp exception from head.js. r=remote-protocol-reviewers,ato

This allows improving all tests exceptions without requiring
any specific to be done in each tests.
I'm also moving a few imports to head.js to share the most into head.js.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-05-02 12:00:39 +00:00
parent b45bb32493
commit 6141376ca9
8 changed files with 30 additions and 106 deletions

View File

@ -3,31 +3,11 @@
"use strict";
/* global getCDP */
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
// Test very basic CDP features.
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {
try {
await testCDP();
} catch (e) {
// Display better error message with the server side stacktrace
// if an error happened on the server side:
if (e.response) {
throw RemoteAgentError.fromJSON(e.response);
} else {
throw e;
}
}
});
async function testCDP() {
add_task(async function testCDP() {
// Open a test page, to prevent debugging the random default page
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
@ -91,4 +71,4 @@ async function testCDP() {
BrowserTestUtils.removeTab(tab);
await RemoteAgent.close();
}
});

View File

@ -5,8 +5,6 @@
// Test very basic CDP features.
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {

View File

@ -3,30 +3,11 @@
"use strict";
/* global getCDP */
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
// Test the Page navigation events
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {
try {
await testCDP();
} catch (e) {
// Display better error message with the server side stacktrace
// if an error happened on the server side:
if (e.response) {
throw RemoteAgentError.fromJSON(e.response);
} else {
throw e;
}
}
});
async function testCDP() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
@ -111,4 +92,4 @@ async function testCDP() {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
await RemoteAgent.close();
}
});

View File

@ -3,30 +3,11 @@
"use strict";
/* global getCDP */
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
// Test the Runtime execution context events
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {
try {
await testCDP();
} catch (e) {
// Display better error message with the server side stacktrace
// if an error happened on the server side:
if (e.response) {
throw RemoteAgentError.fromJSON(e.response);
} else {
throw e;
}
}
});
async function testCDP() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
@ -62,7 +43,7 @@ async function testCDP() {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
await RemoteAgent.close();
}
});
async function testRuntimeEnable({ Runtime }) {
// Enable watching for new execution context

View File

@ -3,30 +3,11 @@
"use strict";
/* global getCDP */
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
// Test the Runtime execution context events
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {
try {
await testCDP();
} catch (e) {
// Display better error message with the server side stacktrace
// if an error happened on the server side:
if (e.response) {
throw RemoteAgentError.fromJSON(e.response);
} else {
throw e;
}
}
});
async function testCDP() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
@ -57,7 +38,7 @@ async function testCDP() {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
await RemoteAgent.close();
}
});
async function testRuntimeEnable({ Runtime }) {
// Enable watching for new execution context

View File

@ -5,8 +5,6 @@
// Test very basic CDP features.
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {

View File

@ -3,28 +3,9 @@
"use strict";
/* global getCDP */
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
// Test the Target domain
add_task(async function() {
try {
await testCDP();
} catch (e) {
// Display better error message with the server side stacktrace
// if an error happened on the server side:
if (e.response) {
throw RemoteAgentError.fromJSON(e.response);
} else {
throw e;
}
}
});
async function testCDP() {
// Start the CDP server
await RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
@ -88,4 +69,4 @@ async function testCDP() {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
await RemoteAgent.close();
}
});

View File

@ -3,6 +3,30 @@
"use strict";
const {RemoteAgent} = ChromeUtils.import("chrome://remote/content/RemoteAgent.jsm");
const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
/**
* Override `add_task` in order to translate chrome-remote-interface exceptions
* into something that logs better errors on stdout
*/
const original_add_task = add_task.bind(this);
this.add_task = function(test) {
original_add_task(async function() {
try {
await test();
} catch (e) {
// Display better error message with the server side stacktrace
// if an error happened on the server side:
if (e.response) {
throw RemoteAgentError.fromJSON(e.response);
} else {
throw e;
}
}
});
};
const CRI_URI = "http://example.com/browser/remote/test/browser/chrome-remote-interface.js";
/**