Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
<title>Tabs executeScript bypassCache 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": ["tabs", "<all_urls>"],
19
},
20
21
async background() {
23
const URL = BASE + "file_bypass_cache.sjs";
24
25
function awaitLoad(tabId) {
26
return new Promise(resolve => {
27
browser.tabs.onUpdated.addListener(function listener(tabId_, changed, tab) {
28
if (tabId == tabId_ && changed.status == "complete" && tab.url == URL) {
29
browser.tabs.onUpdated.removeListener(listener);
30
resolve();
31
}
32
});
33
});
34
}
35
36
try {
37
let tab = await browser.tabs.create({url: URL});
38
await awaitLoad(tab.id);
39
40
await browser.tabs.reload(tab.id, {bypassCache: false});
41
await awaitLoad(tab.id);
42
43
let [textContent] = await browser.tabs.executeScript(tab.id, {code: "document.body.textContent"});
44
browser.test.assertEq("", textContent, "`textContent` should be empty when bypassCache=false");
45
46
await browser.tabs.reload(tab.id, {bypassCache: true});
47
await awaitLoad(tab.id);
48
49
[textContent] = await browser.tabs.executeScript(tab.id, {code: "document.body.textContent"});
50
51
let [pragma, cacheControl] = textContent.split(":");
52
browser.test.assertEq("no-cache", pragma, "`pragma` should be set to `no-cache` when bypassCache is true");
53
browser.test.assertEq("no-cache", cacheControl, "`cacheControl` should be set to `no-cache` when bypassCache is true");
54
55
await browser.tabs.remove(tab.id);
56
57
browser.test.notifyPass("tabs.reload_bypass_cache");
58
} catch (error) {
59
browser.test.fail(`${error} :: ${error.stack}`);
60
browser.test.notifyFail("tabs.reload_bypass_cache");
61
}
62
},
63
});
64
65
await extension.startup();
66
await extension.awaitFinish("tabs.reload_bypass_cache");
67
await extension.unload();
68
});
69
</script>
70
71
</body>
72
</html>