tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug1266815.html (3180B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      5  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
      6 </head>
      7 <body>
      8 <p id="display"></p>
      9 <script type="text/javascript">
     10 // XXX(nika): Why are we using SpecialPowers here? If we're a chrome mochitest
     11 // can't we avoid using the SpecialPowers wrappers?
     12 const Cc = SpecialPowers.Cc;
     13 const Ci = SpecialPowers.Ci;
     14 const Cu = SpecialPowers.Cu;
     15 
     16 const { ComponentUtils } = ChromeUtils.importESModule(
     17  "resource://gre/modules/ComponentUtils.sys.mjs"
     18 );
     19 
     20 const HELPERAPP_DIALOG_CID =
     21        SpecialPowers.wrap(SpecialPowers.Components)
     22        .ID(Cc["@mozilla.org/helperapplauncherdialog;1"].number);
     23 const HELPERAPP_DIALOG_CONTRACT_ID = "@mozilla.org/helperapplauncherdialog;1";
     24 const MOCK_HELPERAPP_DIALOG_CID =
     25        SpecialPowers.wrap(SpecialPowers.Components)
     26        .ID("{391832c8-5232-4676-b838-cc8ad373f3d8}");
     27 
     28 var registrar = SpecialPowers.wrap(Components).manager
     29                .QueryInterface(Ci.nsIComponentRegistrar);
     30 
     31 const HandlerService = Cc[
     32  "@mozilla.org/uriloader/handler-service;1"
     33 ].getService(Ci.nsIHandlerService);
     34 
     35 const MIMEService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
     36 
     37 var helperAppDlgPromise = new Promise(function(resolve) {
     38  var mockHelperAppService;
     39 
     40  function HelperAppLauncherDialog() {
     41  }
     42 
     43  HelperAppLauncherDialog.prototype = {
     44    show() {
     45      ok(true, "Whether showing Dialog");
     46      resolve();
     47      registrar.unregisterFactory(MOCK_HELPERAPP_DIALOG_CID,
     48                                  mockHelperAppService);
     49    },
     50    QueryInterface: ChromeUtils.generateQI(["nsIHelperAppLauncherDialog"]),
     51  };
     52 
     53  mockHelperAppService = ComponentUtils.generateSingletonFactory(HelperAppLauncherDialog);
     54  registrar.registerFactory(MOCK_HELPERAPP_DIALOG_CID, "",
     55                            HELPERAPP_DIALOG_CONTRACT_ID,
     56                            mockHelperAppService);
     57 });
     58 
     59 add_task(async function() {
     60  // ensure the download triggers the external app dialog
     61  const mimeInfo = MIMEService.getFromTypeAndExtension("application/octet-stream", "");
     62  mimeInfo.alwaysAskBeforeHandling = true;
     63  HandlerService.store(mimeInfo);
     64 
     65  SimpleTest.registerCleanupFunction(() => {
     66    HandlerService.remove(mimeInfo);
     67  });
     68 
     69  let promise = new Promise(function(resolve) {
     70    let iframe = document.createElement("iframe");
     71    iframe.onload = function() {
     72      is(iframe.contentDocument.getElementById("edit").innerText, "abc",
     73         "load iframe source");
     74      resolve();
     75    };
     76    iframe.id = "testframe";
     77    iframe.src = "data:text/html,<div id=edit contenteditable=true>abc</div>";
     78    document.body.appendChild(iframe);
     79  });
     80 
     81  await promise;
     82 
     83  let iframe = document.getElementById("testframe");
     84  let docShell = SpecialPowers.wrap(iframe.contentWindow).docShell;
     85 
     86  ok(docShell.hasEditingSession, "Should have editing session");
     87 
     88  document.getElementById("testframe").src =
     89    "data:application/octet-stream,TESTCONTENT";
     90 
     91  await helperAppDlgPromise;
     92 
     93  ok(docShell.hasEditingSession, "Should have editing session");
     94 });
     95 </script>
     96 </body>
     97 </html>