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
},
20
async background() {
21
const url = "http://mochi.test:8888/";
22
const [tab, tabDetails] = await Promise.all([
23
browser.tabs.create({url}),
24
new Promise(resolve => {
25
browser.webNavigation.onCommitted.addListener(details => {
26
if (details.url === "about:blank") {
27
// skip initial about:blank
28
return;
29
}
30
resolve(details);
31
});
32
}),
33
]);
34
35
browser.test.assertEq(url, tabDetails.url, "webNavigation.onCommitted detects correct url");
36
browser.test.assertEq(tab.id, tabDetails.tabId, "webNavigation.onCommitted fire for proper tabId");
37
await browser.tabs.remove(tab.id);
38
browser.test.notifyPass("webNavigation.onCommitted");
39
},
40
});
41
42
await extension.startup();
43
await extension.awaitFinish("webNavigation.onCommitted");
44
await extension.unload();
45
});
46
</script>
47
48
</body>
49
</html>