Bug 1535102 - Extract shared helper to setup remote CDP mochitests r=ato

Depends on D32538.
Not mandatory, but we have some duplicated code shared by several mochitests, maybe we could have a shared helper?

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2019-05-27 08:04:11 +00:00
Родитель 2456aa785c
Коммит 12d5dff1f5
7 изменённых файлов: 32 добавлений и 111 удалений

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

@ -56,26 +56,3 @@ add_task(async function testBringToFrontUpdatesFocusedWindow() {
function getFocusedNavigator() {
return Services.wm.getMostRecentWindow("navigator:browser");
}
async function setupTestForUri(uri) {
// Open a test page, to prevent debugging the random default page
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, uri);
// Start the CDP server
RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const client = await CDP({
target(list) {
// Ensure debugging the right target, i.e. the one for our test tab.
return list.find(target => {
return target.url == uri;
});
},
});
ok(true, "CDP client has been instantiated");
return { client, tab };
}

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

@ -11,23 +11,7 @@ const promises = new Set();
const resolutions = new Map();
add_task(async function() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
// Start the CDP server
await RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const client = await CDP({
target(list) {
// Ensure debugging the right target, i.e. the one for our test tab.
return list.find(target => target.url == TEST_URI);
},
});
ok(true, "CDP client has been instantiated");
const {client} = await setupTestForUri(TEST_URI);
const {Page} = client;

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

@ -10,26 +10,7 @@
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function testCDP() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
// Start the CDP server
RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const client = await CDP({
target(list) {
// Ensure debugging the right target, i.e. the one for our test tab.
return list.find(target => {
return target.url == TEST_URI;
});
},
});
ok(true, "CDP client has been instantiated");
const {client} = await setupTestForUri(TEST_URI);
const {Page, Runtime} = client;
const events = [];

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

@ -9,23 +9,7 @@
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
// Start the CDP server
await RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const client = await CDP({
target(list) {
// Ensure debugging the right target, i.e. the one for our test tab.
return list.find(target => target.url == TEST_URI);
},
});
ok(true, "CDP client has been instantiated");
const {client} = await setupTestForUri(TEST_URI);
const firstContext = await testRuntimeEnable(client);
const contextId = firstContext.id;

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

@ -8,23 +8,7 @@
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
// Start the CDP server
await RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const client = await CDP({
target(list) {
// Ensure debugging the right target, i.e. the one for our test tab.
return list.find(target => target.url == TEST_URI);
},
});
ok(true, "CDP client has been instantiated");
const {client} = await setupTestForUri(TEST_URI);
const firstContext = await testRuntimeEnable(client);
await testEvaluate(client, firstContext);

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

@ -8,23 +8,7 @@
const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
add_task(async function() {
// Open a test page, to prevent debugging the random default page
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
// Start the CDP server
await RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const client = await CDP({
target(list) {
// Ensure debugging the right target, i.e. the one for our test tab.
return list.find(target => target.url == TEST_URI);
},
});
ok(true, "CDP client has been instantiated");
const {client} = await setupTestForUri(TEST_URI);
const firstContext = await testRuntimeEnable(client);
const contextId = firstContext.id;

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

@ -95,3 +95,30 @@ function getTargets(CDP) {
});
});
}
/**
* Create a new tab for the provided uri and start a CDP server debugging the
* created tab.
*/
async function setupTestForUri(uri) {
// Open a test page, to prevent debugging the random default page
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, uri);
// Start the CDP server
RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const client = await CDP({
target(list) {
// Ensure debugging the right target, i.e. the one for our test tab.
return list.find(target => {
return target.url == uri;
});
},
});
ok(true, "CDP client has been instantiated");
return { client, tab };
}