Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
<title>WebNavigation onCommitted Test</title>
5
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
7
<script type="text/javascript" src="head.js"></script>
8
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
9
</head>
10
<body>
11
12
<script type="text/javascript">
13
"use strict";
14
15
add_task(async function() {
16
let extension = ExtensionTestUtils.loadExtension({
17
manifest: {
18
permissions: ["webNavigation", "tabs"],
19
applications: {
20
gecko: {
21
id: "test_ext_webNavigation_onCommitted@tests.mozilla.org",
22
},
23
},
24
},
25
useAddonManager: "permanent",
26
async background() {
27
const url = "http://mochi.test:8888/";
28
const [tab, tabDetails] = await Promise.all([
29
browser.tabs.create({url}),
30
new Promise(resolve => {
31
browser.webNavigation.onCommitted.addListener(details => {
32
if (details.url === "about:blank") {
33
// skip initial about:blank
34
return;
35
}
36
resolve(details);
37
});
38
}),
39
]);
40
41
browser.test.assertEq(url, tabDetails.url, "webNavigation.onCommitted detects correct url");
42
browser.test.assertEq(tab.id, tabDetails.tabId, "webNavigation.onCommitted fire for proper tabId");
43
await browser.tabs.remove(tab.id);
44
browser.test.notifyPass("webNavigation.onCommitted");
45
},
46
});
47
48
await extension.startup();
49
await extension.awaitFinish("webNavigation.onCommitted");
50
await extension.unload();
51
});
52
</script>
53
54
</body>
55
</html>