Bug 1266815 - Part 2. Add editing session test. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 29 Jul 2016 12:39:59 +0900
changeset 307620 10857066c347fdbf01a71573693369e9877728c0
parent 307619 59fa797ab43876d3c44e63bba2b30e30293c3494
child 307621 22dc92f747141efcaf3f926ad701a563d1ea5585
push id20188
push usercbook@mozilla.com
push dateTue, 02 Aug 2016 15:14:32 +0000
treeherderfx-team@cbdc4af95b6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1266815
milestone50.0a1
Bug 1266815 - Part 2. Add editing session test. r=masayuki Use Promiose instead of setTimeout MozReview-Commit-ID: HwgorIZbZpM
editor/composer/test/chrome.ini
editor/composer/test/test_bug1266815.html
--- a/editor/composer/test/chrome.ini
+++ b/editor/composer/test/chrome.ini
@@ -7,8 +7,9 @@ skip-if = buildapp == 'b2g' || os == 'an
 [test_bug678842.html]
 [test_bug697981.html]
 [test_bug717433.html]
 [test_bug1204147.html]
 [test_bug1200533.html]
 [test_bug1205983.html]
 [test_bug1209414.html]
 [test_bug1219928.html]
+[test_bug1266815.html]
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/test_bug1266815.html
@@ -0,0 +1,82 @@
+<!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} = Cu.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(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);
+  });
+
+  yield 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";
+
+  yield helperAppDlgPromise;
+
+  ok(docShell.hasEditingSession, "Should have editing session");
+});
+</script>
+</body>
+</html>