mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1592643 - [remote] Implement Target.activateTarget. r=remote-protocol-reviewers,maja_zf,ato
Differential Revision: https://phabricator.services.mozilla.com/D52001 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
e19b0aa009
commit
976bcc1e77
@ -18,6 +18,9 @@ const { TabManager } = ChromeUtils.import(
|
||||
const { TabSession } = ChromeUtils.import(
|
||||
"chrome://remote/content/sessions/TabSession.jsm"
|
||||
);
|
||||
const { WindowManager } = ChromeUtils.import(
|
||||
"chrome://remote/content/WindowManager.jsm"
|
||||
);
|
||||
|
||||
let sessionIds = 1;
|
||||
let browserContextIds = 1;
|
||||
@ -103,6 +106,19 @@ class Target extends Domain {
|
||||
TabManager.removeTab(target.tab);
|
||||
}
|
||||
|
||||
async activateTarget({ targetId }) {
|
||||
const { targets, window } = this.session.target;
|
||||
const target = targets.getById(targetId);
|
||||
|
||||
if (!target) {
|
||||
throw new Error(`Unable to find target with id '${targetId}'`);
|
||||
}
|
||||
|
||||
// Focus the window, and select the corresponding tab
|
||||
await WindowManager.focus(window);
|
||||
TabManager.selectTab(target.tab);
|
||||
}
|
||||
|
||||
attachToTarget({ targetId }) {
|
||||
const { targets } = this.session.target;
|
||||
const target = targets.getById(targetId);
|
||||
|
@ -5,6 +5,7 @@ prefs = remote.enabled=true
|
||||
support-files =
|
||||
head.js
|
||||
|
||||
[browser_activateTarget.js]
|
||||
[browser_attachToTarget.js]
|
||||
[browser_attachedToTarget.js]
|
||||
[browser_browserContext.js]
|
||||
|
77
remote/test/browser/target/browser_activateTarget.js
Normal file
77
remote/test/browser/target/browser_activateTarget.js
Normal file
@ -0,0 +1,77 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(async function raisesWithoutArguments({ Target }, _, tab) {
|
||||
await getDiscoveredTargets(Target);
|
||||
|
||||
let errorThrown = false;
|
||||
try {
|
||||
await Target.activateTarget();
|
||||
} catch (e) {
|
||||
errorThrown = true;
|
||||
}
|
||||
ok(errorThrown, "activateTarget raised error without an argument");
|
||||
});
|
||||
|
||||
add_task(async function raisesWithUnknownTargetId({ Target }, _, tab) {
|
||||
await getDiscoveredTargets(Target);
|
||||
|
||||
let errorThrown = false;
|
||||
try {
|
||||
await Target.activateTarget({ targetId: "-1" });
|
||||
} catch (e) {
|
||||
errorThrown = true;
|
||||
}
|
||||
ok(errorThrown, "activateTarget raised error with unkown target id");
|
||||
});
|
||||
|
||||
add_task(async function selectTabInOtherWindow({ Target }, _, tab) {
|
||||
const targets = await getDiscoveredTargets(Target);
|
||||
const filtered_targets = targets.filter(target => {
|
||||
return target.targetInfo.targetId == tab.linkedBrowser.browsingContext.id;
|
||||
});
|
||||
is(filtered_targets.length, 1, "The current target has been found");
|
||||
const initialTarget = filtered_targets[0];
|
||||
|
||||
is(tab.ownerGlobal, getFocusedNavigator(), "Initial window is focused");
|
||||
|
||||
// open some more tabs in the initial window
|
||||
await openTab(Target);
|
||||
await openTab(Target);
|
||||
const lastTabFirstWindow = await openTab(Target);
|
||||
is(
|
||||
gBrowser.selectedTab,
|
||||
lastTabFirstWindow.newTab,
|
||||
"Last openend tab in initial window is the selected tab"
|
||||
);
|
||||
|
||||
const { newWindow } = await openWindow(Target);
|
||||
|
||||
const lastTabSecondWindow = await openTab(Target);
|
||||
is(
|
||||
gBrowser.selectedTab,
|
||||
lastTabSecondWindow.newTab,
|
||||
"Last openend tab in new window is the selected tab"
|
||||
);
|
||||
|
||||
try {
|
||||
is(newWindow, getFocusedNavigator(), "The new window is focused");
|
||||
await Target.activateTarget({
|
||||
targetId: initialTarget.targetInfo.targetId,
|
||||
});
|
||||
is(
|
||||
tab.ownerGlobal,
|
||||
getFocusedNavigator(),
|
||||
"Initial window is focused again"
|
||||
);
|
||||
is(gBrowser.selectedTab, tab, "Selected tab is the initial tab again");
|
||||
} finally {
|
||||
await BrowserTestUtils.closeWindow(newWindow);
|
||||
}
|
||||
});
|
||||
|
||||
function getFocusedNavigator() {
|
||||
return Services.wm.getMostRecentWindow("navigator:browser");
|
||||
}
|
@ -41,3 +41,15 @@ async function openTab(Target) {
|
||||
|
||||
return { targetInfo, newTab };
|
||||
}
|
||||
|
||||
async function openWindow(Target) {
|
||||
info("Create a new window and wait for the target to be created");
|
||||
|
||||
const targetCreated = Target.targetCreated();
|
||||
const newWindow = await BrowserTestUtils.openNewBrowserWindow();
|
||||
const newTab = newWindow.gBrowser.selectedTab;
|
||||
const { targetInfo } = await targetCreated;
|
||||
is(targetInfo.type, "page");
|
||||
|
||||
return { targetInfo, newWindow, newTab };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user