summaryrefslogtreecommitdiffstats
path: root/uriloader/exthandler/tests/mochitest/browser_standalone_application_chooser_window_fallback.js
blob: 40496fb3b2cfec9c83f2364175b81cfc182aa299 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test the fallback fixed in bug 1875460, if the modern tab dialog box is not
// supported.

const TEST_URL =
  "https://example.com/browser/" +
  "uriloader/exthandler/tests/mochitest/FTPprotocolHandler.html";

add_task(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [["security.external_protocol_requires_permission", false]],
  });

  // Load a page with an FTP link.
  let browser = gBrowser.selectedBrowser;
  BrowserTestUtils.startLoadingURIString(browser, TEST_URL);
  await BrowserTestUtils.browserLoaded(browser, false, TEST_URL);

  // Make sure no handler is set, forcing the dialog to show.
  let protoSvc = Cc[
    "@mozilla.org/uriloader/external-protocol-service;1"
  ].getService(Ci.nsIExternalProtocolService);
  let protoInfo = protoSvc.getProtocolHandlerInfo("ftp");
  ok(!protoInfo.preferredApplicationHandler, "no preferred handler is set");
  let handlers = protoInfo.possibleApplicationHandlers;
  is(0, handlers.length, "no handler registered for ftp");
  protoInfo.alwaysAskBeforeHandling = true;
  let handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService(
    Ci.nsIHandlerService
  );
  handlerSvc.store(protoInfo);

  // Delete getTabDialogBox from gBrowser, to test the fallback to the standalone
  // application chooser window.
  let _getTabDialogBox = gBrowser.getTabDialogBox;
  delete gBrowser.getTabDialogBox;

  let appChooserDialogOpenPromise = BrowserTestUtils.domWindowOpened(
    null,
    async win => {
      await BrowserTestUtils.waitForEvent(win, "load");
      Assert.ok(
        win.document.documentURI ==
          "chrome://mozapps/content/handling/appChooser.xhtml",
        "application chooser dialog opened"
      );
      return true;
    }
  );
  let link = "#link";
  await BrowserTestUtils.synthesizeMouseAtCenter(link, {}, browser);
  let appChooserDialog = await appChooserDialogOpenPromise;

  let appChooserDialogClosePromise =
    BrowserTestUtils.domWindowClosed(appChooserDialog);
  let dialog = appChooserDialog.document.getElementsByTagName("dialog")[0];
  let cancelButton = dialog.getButton("cancel");
  cancelButton.click();
  await appChooserDialogClosePromise;

  // Restore the original getTabDialogBox(), to not affect other tests.
  gBrowser.getTabDialogBox = _getTabDialogBox;
});