Bug 1536794 - Add test to cover /json/version endpoint and Target domain. r=ato

Depends on D24221

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-03-21 14:18:03 +00:00
Родитель 7d04b7c5e0
Коммит 4decca62c1
3 изменённых файлов: 75 добавлений и 1 удалений

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

@ -94,12 +94,15 @@ class ParentRemoteAgent {
async close() {
if (this.listening) {
try {
// Disconnect the targets first in order to ensure closing all pending
// connection first. Otherwise Httpd's stop is not going to resolve.
this.targets.clear();
await this.server.stop();
Preferences.reset(Object.keys(RecommendedPreferences));
this.tabs.stop();
this.targets.clear();
} catch (e) {
throw new Error(`Unable to stop agent: ${e.message}`, e);
}

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

@ -7,3 +7,4 @@ support-files =
[browser_cdp.js]
[browser_tabs.js]
[browser_target.js]

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

@ -0,0 +1,70 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* global getCDP */
// 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 new Error("CDP Exception:\n" + e.response + "\n");
} else {
throw e;
}
}
});
async function testCDP() {
// Start the CDP server
const RemoteAgent = Cc["@mozilla.org/remote/agent"].getService(Ci.nsISupports).wrappedJSObject;
RemoteAgent.tabs.start();
RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
// Retrieve the chrome-remote-interface library object
const CDP = await getCDP();
// Connect to the server
const {webSocketDebuggerUrl} = await CDP.Version();
is(webSocketDebuggerUrl, "ws://localhost:9222/devtools/browser", "Version endpoint refers to /devtools/browser target");
const client = await CDP({"target": webSocketDebuggerUrl});
ok(true, "CDP client has been instantiated");
const {Target} = client;
ok("Target" in client, "Target domain is available");
// Instruct the server to fire Target.targetCreated events
Target.setDiscoverTargets({ discover: true });
// Create a new target so that the test runs against a fresh new tab
const targetCreated = Target.targetCreated();
const {targetId} = await Target.createTarget();
ok(true, "Target created");
ok(!!targetId, "createTarget returns a non-empty target id");
const {targetInfo} = await targetCreated;
is(targetId, targetInfo.targetId, "createTarget and targetCreated refers to the same target id");
is(targetInfo.type, "page", "The target is a page");
const attachedToTarget = Target.attachedToTarget();
const {sessionId} = await Target.attachToTarget({ targetId });
ok(true, "Target attached");
const attachedEvent = await attachedToTarget;
ok(true, "Received Target.attachToTarget event");
is(attachedEvent.sessionId, sessionId, "attachedToTarget and attachToTarget returns the same session id");
is(attachedEvent.targetInfo.type, "page", "attachedToTarget creates a tab by default");
await client.close();
ok(true, "The client is closed");
BrowserTestUtils.removeTab(gBrowser.selectedTab);
await RemoteAgent.close();
}