blob: a47ce547a51f23735e302f9d49f11fc0664680f8 (
plain)
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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Check tab attach/navigation.
*/
const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html";
const TAB2_FILE = "doc_empty-tab-02.html";
const TAB2_URL = EXAMPLE_URL + TAB2_FILE;
add_task(async () => {
const tab = await addTab(TAB1_URL);
const target = await TargetFactory.forTab(tab);
await target.attach();
await testNavigate(target);
await testDetach(target);
});
function testNavigate(target) {
return new Promise(resolve => {
let gotStartPacket = false;
target.on("tabNavigated", function onTabNavigated(packet) {
is(
packet.url.split("/").pop(),
TAB2_FILE,
"Got a tab navigation notification."
);
info(JSON.stringify(packet));
if (packet.state == "start") {
ok(true, "Tab started to navigate.");
gotStartPacket = true;
} else if (gotStartPacket) {
ok(true, "Tab finished navigating.");
target.off("tabNavigated", onTabNavigated);
resolve();
}
});
BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TAB2_URL);
});
}
async function testDetach(target) {
// We can't listen for tabDetached at it is received by Target first
// and target is destroyed
const onDetached = target.once("close");
removeTab(gBrowser.selectedTab);
await onDetached;
ok(true, "Got a tab detach notification.");
}
|