blob: e77d482e14a725e95bc794e6bd4bf86e3ce4764b (
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
|
"use strict";
function setupRedirect(fromUrl, redirectUrl) {
browser.webRequest.onBeforeRequest.addListener(
() => {
console.log(`Extension redirects from ${fromUrl} to ${redirectUrl}`);
return { redirectUrl };
},
{ urls: [fromUrl] },
["blocking"]
);
}
// Intercepts all script requests from androidTest/assets/www/trackers.html.
// Scripts are executed in order of appearance in the page and block the
// page's "load" event, so the test runner can just wait for the page to
// have loaded and then check the page content to verify that the requests
// were intercepted as expected.
setupRedirect(
"http://trackertest.org/tracker.js",
"data:text/javascript,document.body.textContent='start'"
);
setupRedirect(
"https://tracking.example.com/tracker.js",
browser.runtime.getURL("web-accessible-script.js")
);
setupRedirect(
"https://itisatracker.org/tracker.js",
`data:text/javascript,document.body.textContent+=',end'`
);
// Work around bug 1300234 to ensure that the webRequest listener has been
// registered before we resume the test. API result doesn't matter, we just
// want to make a roundtrip.
var listenerReady = browser.webRequest.getSecurityInfo("").catch(() => {});
listenerReady.then(() => {
browser.runtime.sendNativeMessage("browser", "setupReadyStartTest");
});
|