summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_reload_deleted_file.js
blob: 2051dbfac7c1d504bb37f0cd92af67c4c469d1a5 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */

const uuidGenerator = Services.uuid;

const DUMMY_FILE = "dummy_page.html";

// Test for bug 1327942.
add_task(async function () {
  // Copy dummy page to unique file in TmpD, so that we can safely delete it.
  let dummyPage = getChromeDir(getResolvedURI(gTestPath));
  dummyPage.append(DUMMY_FILE);
  let disappearingPage = Services.dirsvc.get("TmpD", Ci.nsIFile);
  let uniqueName = uuidGenerator.generateUUID().toString();
  dummyPage.copyTo(disappearingPage, uniqueName);
  disappearingPage.append(uniqueName);

  // Get file:// URI for new page and load in a new tab.
  const uriString = Services.io.newFileURI(disappearingPage).spec;
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, uriString);
  registerCleanupFunction(async function () {
    BrowserTestUtils.removeTab(tab);
  });

  // Delete the page, simulate a click of the reload button and check that we
  // get a neterror page.
  disappearingPage.remove(false);
  document.getElementById("reload-button").doCommand();
  await BrowserTestUtils.waitForErrorPage(tab.linkedBrowser);
  await SpecialPowers.spawn(tab.linkedBrowser, [], function () {
    ok(
      content.document.documentURI.startsWith("about:neterror"),
      "Check that a neterror page was loaded."
    );
  });
});