зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1680740 - [remote] Implement Target.getTargets. r=remote-protocol-reviewers,maja_zf
Differential Revision: https://phabricator.services.mozilla.com/D98803
This commit is contained in:
Родитель
2e689029d7
Коммит
5167e2ba69
|
@ -22,6 +22,9 @@ const { ContextualIdentityService } = ChromeUtils.import(
|
||||||
const { Domain } = ChromeUtils.import(
|
const { Domain } = ChromeUtils.import(
|
||||||
"chrome://remote/content/domains/Domain.jsm"
|
"chrome://remote/content/domains/Domain.jsm"
|
||||||
);
|
);
|
||||||
|
const { MainProcessTarget } = ChromeUtils.import(
|
||||||
|
"chrome://remote/content/targets/MainProcessTarget.jsm"
|
||||||
|
);
|
||||||
const { TabManager } = ChromeUtils.import(
|
const { TabManager } = ChromeUtils.import(
|
||||||
"chrome://remote/content/TabManager.jsm"
|
"chrome://remote/content/TabManager.jsm"
|
||||||
);
|
);
|
||||||
|
@ -60,6 +63,29 @@ class Target extends Domain {
|
||||||
ContextualIdentityService.closeContainerTabs(browserContextId);
|
ContextualIdentityService.closeContainerTabs(browserContextId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTargets() {
|
||||||
|
const { targets } = this.session.target;
|
||||||
|
|
||||||
|
const targetInfos = [];
|
||||||
|
for (const target of targets) {
|
||||||
|
if (target instanceof MainProcessTarget) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
targetInfos.push({
|
||||||
|
targetId: target.id,
|
||||||
|
type: target.type,
|
||||||
|
title: target.title,
|
||||||
|
url: target.url,
|
||||||
|
// TODO: Correctly determine if target is attached (bug 1680780)
|
||||||
|
attached: target.id == this.session.target.id,
|
||||||
|
browserContextId: target.browserContextId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { targetInfos };
|
||||||
|
}
|
||||||
|
|
||||||
setDiscoverTargets({ discover }) {
|
setDiscoverTargets({ discover }) {
|
||||||
const { targets } = this.session.target;
|
const { targets } = this.session.target;
|
||||||
if (discover) {
|
if (discover) {
|
||||||
|
|
|
@ -107,6 +107,10 @@ class TabTarget extends Target {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get title() {
|
||||||
|
return this.browsingContext.currentWindowGlobal.documentTitle;
|
||||||
|
}
|
||||||
|
|
||||||
get type() {
|
get type() {
|
||||||
return "page";
|
return "page";
|
||||||
}
|
}
|
||||||
|
@ -131,7 +135,8 @@ class TabTarget extends Target {
|
||||||
// TODO(ato): toJSON cannot be marked async )-:
|
// TODO(ato): toJSON cannot be marked async )-:
|
||||||
faviconUrl: "",
|
faviconUrl: "",
|
||||||
id: this.id,
|
id: this.id,
|
||||||
title: this.title,
|
// Bug 1680817: Fails to encode some UTF-8 characters
|
||||||
|
// title: this.title,
|
||||||
type: this.type,
|
type: this.type,
|
||||||
url: this.url,
|
url: this.url,
|
||||||
browsingContextId: this.browsingContext.id,
|
browsingContextId: this.browsingContext.id,
|
||||||
|
|
|
@ -7,12 +7,14 @@ support-files =
|
||||||
!/remote/test/browser/chrome-remote-interface.js
|
!/remote/test/browser/chrome-remote-interface.js
|
||||||
!/remote/test/browser/head.js
|
!/remote/test/browser/head.js
|
||||||
head.js
|
head.js
|
||||||
|
doc_test.html
|
||||||
|
|
||||||
[browser_activateTarget.js]
|
[browser_activateTarget.js]
|
||||||
[browser_attachToTarget.js]
|
[browser_attachToTarget.js]
|
||||||
[browser_attachedToTarget.js]
|
[browser_attachedToTarget.js]
|
||||||
[browser_browserContext.js]
|
[browser_browserContext.js]
|
||||||
[browser_closeTarget.js]
|
[browser_closeTarget.js]
|
||||||
|
[browser_getTargets.js]
|
||||||
[browser_sendMessageToTarget.js]
|
[browser_sendMessageToTarget.js]
|
||||||
skip-if = true # bug 1598468 - temporarily stop emitting event due to spamming
|
skip-if = true # bug 1598468 - temporarily stop emitting event due to spamming
|
||||||
[browser_setDiscoverTargets.js]
|
[browser_setDiscoverTargets.js]
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const PAGE_TEST =
|
||||||
|
"http://example.com/browser/remote/test/browser/target/doc_test.html";
|
||||||
|
|
||||||
|
add_task(
|
||||||
|
async function getTargetsDetails({ client }) {
|
||||||
|
const { Target, target } = client;
|
||||||
|
|
||||||
|
await loadURL(PAGE_TEST);
|
||||||
|
|
||||||
|
const { targetInfos } = await Target.getTargets();
|
||||||
|
|
||||||
|
Assert.equal(targetInfos.length, 1, "Got expected amount of targets");
|
||||||
|
|
||||||
|
const targetInfo = targetInfos[0];
|
||||||
|
is(targetInfo.id, target.id, "Got expected target id");
|
||||||
|
is(targetInfo.type, "page", "Got expected target type");
|
||||||
|
is(targetInfo.title, "Test Page", "Got expected target title");
|
||||||
|
is(targetInfo.url, PAGE_TEST, "Got expected target URL");
|
||||||
|
},
|
||||||
|
{ createTab: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
add_task(
|
||||||
|
async function getTargetsCount({ client }) {
|
||||||
|
const { Target, target } = client;
|
||||||
|
const { targetInfo: newTabTargetInfo } = await openTab(Target);
|
||||||
|
|
||||||
|
await loadURL(PAGE_TEST);
|
||||||
|
|
||||||
|
const { targetInfos } = await Target.getTargets();
|
||||||
|
|
||||||
|
Assert.equal(targetInfos.length, 2, "Got expected amount of targets");
|
||||||
|
const targetIds = targetInfos.map(info => info.id);
|
||||||
|
ok(targetIds.includes(target.id), "Got expected original target id");
|
||||||
|
ok(targetIds.includes(newTabTargetInfo.id), "Got expected new target id");
|
||||||
|
},
|
||||||
|
{ createTab: false }
|
||||||
|
);
|
|
@ -0,0 +1,8 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test Page</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
Загрузка…
Ссылка в новой задаче