1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function raisesWithoutArguments({ client, tab }) {
const { Target } = client;
let errorThrown = false;
try {
await Target.activateTarget();
} catch (e) {
errorThrown = true;
}
ok(errorThrown, "activateTarget raised error without an argument");
});
add_task(async function raisesWithUnknownTargetId({ client, tab }) {
const { Target } = client;
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({ client, tab }) {
const { Target, target } = client;
const currentTargetId = target.id;
const targets = await getDiscoveredTargets(Target);
const filtered_targets = targets.filter(target => {
return target.targetId == currentTargetId;
});
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.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");
}
|