summaryrefslogtreecommitdiffstats
path: root/dom/url/tests/browser_download_after_revoke.js
blob: 8894e092e68eed05e28ab842f225f661354a2fe7 (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
function test() {
  waitForExplicitFinish();
  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);

  function onLoad() {
    info("Page loaded.");

    var listener = {
      onOpenWindow(aXULWindow) {
        info("Download window shown...");
        Services.wm.removeListener(listener);

        function downloadOnLoad() {
          domwindow.removeEventListener("load", downloadOnLoad, true);

          is(
            domwindow.document.location.href,
            "chrome://mozapps/content/downloads/unknownContentType.xhtml",
            "Download page appeared"
          );

          domwindow.close();
          gBrowser.removeTab(gBrowser.selectedTab);
          finish();
        }

        var domwindow = aXULWindow.docShell.domWindow;
        domwindow.addEventListener("load", downloadOnLoad, true);
      },
      onCloseWindow(aXULWindow) {},
    };

    Services.wm.addListener(listener);

    info("Creating BlobURL and clicking on a HTMLAnchorElement...");
    SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
      let blob = new content.Blob(["test"], { type: "text/plain" });
      let url = content.URL.createObjectURL(blob);

      let link = content.document.createElement("a");
      link.href = url;
      link.download = "example.txt";
      content.document.body.appendChild(link);
      link.click();

      content.URL.revokeObjectURL(url);
    });
  }

  const target = "http://example.com/browser/dom/url/tests/empty.html";
  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, target).then(
    onLoad
  );

  info("Loading download page...");
  BrowserTestUtils.loadURI(gBrowser, target);
}