Skip to content

Commit a9140f7

Browse files
committed
Bug 1968644 - Part 9: Add more tests for loads triggered by tracking scripts. r=valentin,anti-tracking-reviewers,emz
Differential Revision: https://phabricator.services.mozilla.com/D253346
1 parent 1092aef commit a9140f7

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

toolkit/components/antitracking/test/browser/browser.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ support-files = [
341341
"style.css^headers^",
342342
"test.font.woff",
343343
"test.font.woff^headers^",
344+
"triggerLoads.sjs",
344345
]
345346

346347
["browser_urlDecorationStripping.js"]

toolkit/components/antitracking/test/browser/browser_triggeringClassificationFlags.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,48 @@ add_task(async function test_first_party_flags_in_about_blank_iframe() {
364364

365365
BrowserTestUtils.removeTab(tab);
366366
});
367+
368+
// Test that loads from an embedded tracking script have the correct flags.
369+
add_task(async function test_embedded_tracking_script() {
370+
// Open the test page and inject the tracking iframe
371+
let tab = await BrowserTestUtils.openNewForegroundTab(
372+
gBrowser,
373+
TEST_TOP_PAGE
374+
);
375+
376+
for (const testCase of TEST_CASES) {
377+
// Skip the font face test because we don't have a definite way to determine
378+
// who triggers the load in this case.
379+
if (testCase.name === "Font") {
380+
continue;
381+
}
382+
383+
let obsPromise = observeAndCheck(
384+
testCase.url,
385+
0,
386+
Ci.nsIClassifiedChannel.CLASSIFIED_TRACKING
387+
);
388+
389+
// Inject a tracking script into the page.
390+
await SpecialPowers.spawn(
391+
tab.linkedBrowser,
392+
[
393+
TEST_3RD_PARTY_DOMAIN_HTTP +
394+
TEST_PATH +
395+
"triggerLoads.sjs?type=" +
396+
testCase.name +
397+
"&url=" +
398+
testCase.url,
399+
],
400+
async src => {
401+
let script = content.document.createElement("script");
402+
script.src = src;
403+
content.document.body.appendChild(script);
404+
}
405+
);
406+
407+
await obsPromise;
408+
}
409+
410+
BrowserTestUtils.removeTab(tab);
411+
});
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
function handleRequest(aRequest, aResponse) {
2+
aResponse.setStatusLine(aRequest.httpVersion, 200);
3+
aResponse.setHeader("Content-Type", "text/javascript", false);
4+
aResponse.setHeader("Access-Control-Allow-Origin", "*");
5+
6+
let params = new URLSearchParams(aRequest.queryString);
7+
let type = params.get("type");
8+
let url = params.get("url");
9+
10+
switch (type) {
11+
case "XHR":
12+
aResponse.write(`
13+
let xhr = new XMLHttpRequest();
14+
xhr.open("GET", "${url}");
15+
xhr.send();
16+
`);
17+
break;
18+
19+
case "Fetch":
20+
aResponse.write(`
21+
fetch("${url}");
22+
`);
23+
break;
24+
25+
case "Image":
26+
aResponse.write(`
27+
let img = document.createElement("img");
28+
img.src = "${url}";
29+
document.body.appendChild(img);
30+
`);
31+
break;
32+
33+
case "CSS":
34+
aResponse.write(`
35+
let link = document.createElement("link");
36+
link.rel = "stylesheet";
37+
link.href = "${url}";
38+
document.head.appendChild(link);
39+
`);
40+
break;
41+
42+
case "Video":
43+
aResponse.write(`
44+
let video = document.createElement("video");
45+
video.src = "${url}";
46+
document.body.appendChild(video);
47+
`);
48+
break;
49+
50+
case "Audio":
51+
aResponse.write(`
52+
let audio = document.createElement("audio");
53+
audio.src = "${url}";
54+
document.body.appendChild(audio);
55+
`);
56+
break;
57+
58+
case "Iframe":
59+
aResponse.write(`
60+
let iframe = document.createElement("iframe");
61+
iframe.src = "${url}";
62+
document.body.appendChild(iframe);
63+
`);
64+
break;
65+
66+
case "Script":
67+
aResponse.write(`
68+
let script = document.createElement("script");
69+
script.src = "${url}";
70+
document.body.appendChild(script);
71+
`);
72+
break;
73+
74+
case "WebSocket":
75+
aResponse.write(`
76+
let ws = new WebSocket(
77+
"ws://mochi.test:8888/browser/toolkit/components/antitracking/test/browser/file_ws_handshake_delay",
78+
["test"]
79+
);
80+
`);
81+
break;
82+
83+
default:
84+
throw new Error("Unsupported load type: " + aRequest.queryString);
85+
}
86+
}

0 commit comments

Comments
 (0)