editor/composer/test/test_bug1266815.html
author Kris Maglione <maglione.k@gmail.com>
Mon, 29 Jan 2018 15:20:18 -0800
changeset 454011 e6a7b5e11ba856ee3535f76c6bcca17ea29e3d5f
parent 453889 c6e0fe339cb1e7c0c029e68be5332e52f53ab6b7
child 468234 c10c705a1feae70c507bb644dcf2867cbe63db6f
permissions -rw-r--r--
Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian This was done using the following script: https://bitbucket.org/kmaglione/m-c-rewrites/src/37e3803c7a23385bab5ea077ba8692bcfe1608fc/processors/chromeutils-import.jsm MozReview-Commit-ID: 1Nc3XDu0wGl

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<script type="text/javascript">
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
const Cu = SpecialPowers.Cu;

const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {});

const HELPERAPP_DIALOG_CID =
        SpecialPowers.wrap(SpecialPowers.Components)
        .ID(Cc["@mozilla.org/helperapplauncherdialog;1"].number);
const HELPERAPP_DIALOG_CONTRACT_ID = "@mozilla.org/helperapplauncherdialog;1";
const MOCK_HELPERAPP_DIALOG_CID =
        SpecialPowers.wrap(SpecialPowers.Components)
        .ID("{391832c8-5232-4676-b838-cc8ad373f3d8}");

var registrar = SpecialPowers.wrap(Components).manager
                .QueryInterface(Ci.nsIComponentRegistrar);

var helperAppDlgPromise = new Promise(function(resolve) {
  var mockHelperAppService;

  function HelperAppLauncherDialog() {
  }

  HelperAppLauncherDialog.prototype = {
    show: function(aLauncher, aWindowContext, aReason) {
      ok(true, "Whether showing Dialog");
      resolve();
      registrar.unregisterFactory(MOCK_HELPERAPP_DIALOG_CID,
                                  mockHelperAppService);
    },
    QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog])
  };

  mockHelperAppService = XPCOMUtils._getFactory(HelperAppLauncherDialog);
  registrar.registerFactory(MOCK_HELPERAPP_DIALOG_CID, "",
                            HELPERAPP_DIALOG_CONTRACT_ID,
                            mockHelperAppService);
});

add_task(async function() {
  let promise = new Promise(function(resolve) {
    let iframe = document.createElement("iframe");
    iframe.onload = function() {
      is(iframe.contentDocument.getElementById("edit").innerText, "abc",
         "load iframe source");
      resolve();
    };
    iframe.id = "testframe";
    iframe.src = "data:text/html,<div id=edit contenteditable=true>abc</div>";
    document.body.appendChild(iframe);
  });

  await promise;

  let iframe = document.getElementById("testframe");
  let docShell = SpecialPowers.wrap(iframe.contentWindow)
                 .QueryInterface(Ci.nsIInterfaceRequestor)
                 .getInterface(Ci.nsIWebNavigation)
                 .QueryInterface(Ci.nsIDocShell);

  ok(docShell.hasEditingSession, "Should have editing session");

  document.getElementById("testframe").src =
    "data:application/octet-stream,TESTCONTENT";

  await helperAppDlgPromise;

  ok(docShell.hasEditingSession, "Should have editing session");
});
</script>
</body>
</html>