blob: abbb814ac7867a931e994aaa601bacd74c3c842d (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
"use strict";
var { WebRequest } = ChromeUtils.importESModule(
"resource://gre/modules/WebRequest.sys.mjs"
);
var { ExtensionParent } = ChromeUtils.importESModule(
"resource://gre/modules/ExtensionParent.sys.mjs"
);
const server = createHttpServer({ hosts: ["example.com"] });
server.registerDirectory("/data/", do_get_file("data"));
add_task(async function setup() {
// When WebRequest.sys.mjs is used directly instead of through ext-webRequest.js,
// ExtensionParent.apiManager is not automatically initialized. Do it here.
await ExtensionParent.apiManager.lazyInit();
});
add_task(async function test_ancestors_exist() {
let deferred = Promise.withResolvers();
function onBeforeRequest(details) {
info(`onBeforeRequest ${details.url}`);
Assert.strictEqual(
typeof details.frameAncestors,
"object",
`ancestors exists [${typeof details.frameAncestors}]`
);
deferred.resolve();
}
WebRequest.onBeforeRequest.addListener(
onBeforeRequest,
{ urls: new MatchPatternSet(["http://example.com/*"]) },
["blocking"]
);
let contentPage = await ExtensionTestUtils.loadContentPage(
"http://example.com/data/file_sample.html"
);
await deferred.promise;
await contentPage.close();
WebRequest.onBeforeRequest.removeListener(onBeforeRequest);
});
add_task(async function test_ancestors_null() {
let deferred = Promise.withResolvers();
function onBeforeRequest(details) {
info(`onBeforeRequest ${details.url}`);
Assert.strictEqual(
details.frameAncestors,
undefined,
"ancestors do not exist"
);
deferred.resolve();
}
WebRequest.onBeforeRequest.addListener(onBeforeRequest, null, ["blocking"]);
function fetch(url) {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.mozBackgroundRequest = true;
xhr.open("GET", url);
xhr.onload = () => {
resolve(xhr.responseText);
};
xhr.onerror = () => {
reject(xhr.status);
};
// use a different contextId to avoid auth cache.
xhr.setOriginAttributes({ userContextId: 1 });
xhr.send();
});
}
await fetch("http://example.com/data/file_sample.html");
await deferred.promise;
WebRequest.onBeforeRequest.removeListener(onBeforeRequest);
});
|