summaryrefslogtreecommitdiffstats
path: root/toolkit/components/antitracking/test/browser/imageCacheWorker.js
blob: d11221112c3f9ea2ee65e7f052403789972cf4c5 (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
/* import-globals-from head.js */
/* import-globals-from antitracking_head.js */
/* import-globals-from browser_imageCache4.js */

AntiTracking.runTest(
  "Image cache - should load the image three times.",
  // blocking callback
  async _ => {
    // Let's load the image twice here.
    let img = document.createElement("img");
    document.body.appendChild(img);
    img.src =
      "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs";
    await new Promise(resolve => {
      img.onload = resolve;
    });
    ok(true, "Image 1 loaded");

    img = document.createElement("img");
    document.body.appendChild(img);
    img.src =
      "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs";
    await new Promise(resolve => {
      img.onload = resolve;
    });
    ok(true, "Image 2 loaded");
  },

  // non-blocking callback
  {
    runExtraTests: false,
    cookieBehavior,
    blockingByAllowList,
    expectedBlockingNotifications,
    callback: async _ => {
      // Let's load the image twice here as well.
      let img = document.createElement("img");
      document.body.appendChild(img);
      img.src =
        "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs";
      await new Promise(resolve => {
        img.onload = resolve;
      });
      ok(true, "Image 3 loaded");

      img = document.createElement("img");
      document.body.appendChild(img);
      img.src =
        "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs";
      await new Promise(resolve => {
        img.onload = resolve;
      });
      ok(true, "Image 4 loaded");
    },
  },
  null, // cleanup function
  null, // no extra prefs
  false, // no window open test
  false, // no user-interaction test
  expectedBlockingNotifications
);

// We still want to see just expected requests.
add_task(async _ => {
  await fetch(
    "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs?result"
  )
    .then(r => r.text())
    .then(text => {
      is(text, "2", "The image should be loaded correctly.");
    });

  await new Promise(resolve => {
    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>
      resolve()
    );
  });
});