Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
<title>Tabs lastAccessed 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 testLastAccessed() {
16
let past = Date.now();
17
18
window.open("https://example.com/?1");
19
window.open("https://example.com/?2");
20
21
let extension = ExtensionTestUtils.loadExtension({
22
manifest: {
23
permissions: ["tabs"],
24
},
25
async background() {
26
browser.test.onMessage.addListener(async function(msg, past) {
27
if (msg !== "past") {
28
return;
29
}
30
31
let [tab1] = await browser.tabs.query({url: "https://example.com/?1"});
32
let [tab2] = await browser.tabs.query({url: "https://example.com/?2"});
33
34
browser.test.assertTrue(tab1 && tab2, "Expected tabs were found");
35
36
let now = Date.now();
37
38
browser.test.assertTrue(typeof tab1.lastAccessed == "number",
39
"tab1 lastAccessed should be a number");
40
41
browser.test.assertTrue(typeof tab2.lastAccessed == "number",
42
"tab2 lastAccessed should be a number");
43
44
browser.test.assertTrue(past <= tab1.lastAccessed &&
45
tab1.lastAccessed <= tab2.lastAccessed &&
46
tab2.lastAccessed <= now,
47
"lastAccessed timestamps are recent and in the right order");
48
49
await browser.tabs.remove([tab1.id, tab2.id]);
50
51
browser.test.notifyPass("tabs.lastAccessed");
52
});
53
},
54
});
55
56
await extension.startup();
57
await extension.sendMessage("past", past);
58
await extension.awaitFinish("tabs.lastAccessed");
59
await extension.unload();
60
});
61
</script>
62
63
</body>