Bug 1310279 - add "wm" to Services shim; r?jdescottes draft
authorTom Tromey <tom@tromey.com>
Thu, 20 Oct 2016 14:34:23 -0600
changeset 434932 85fdf6611216b702aefe7518190c44c9498536cb
parent 434910 a73ad8b09a99eb4c7ec3d2942c81d8892dc34a1d
child 536163 e9c0fa4380ba802627235f2e36c5ded5681c26a4
push id34877
push userbmo:ttromey@mozilla.com
push dateMon, 07 Nov 2016 19:06:23 +0000
reviewersjdescottes
bugs1310279
milestone52.0a1
Bug 1310279 - add "wm" to Services shim; r?jdescottes MozReview-Commit-ID: 2uW8RM2ufaf
devtools/client/shared/shim/Services.js
devtools/client/shared/shim/test/file_service_wm.html
devtools/client/shared/shim/test/mochitest.ini
devtools/client/shared/shim/test/test_service_wm.html
--- a/devtools/client/shared/shim/Services.js
+++ b/devtools/client/shared/shim/Services.js
@@ -579,16 +579,32 @@ const Services = {
       // Sets the focus via side effect in the filter.
       if (type === Services.focus.MOVEFOCUS_FORWARD) {
         iter.nextNode();
       } else {
         iter.previousNode();
       }
     },
   },
+
+  /**
+   * An implementation of Services.wm that provides a shim for
+   * getMostRecentWindow.
+   */
+  wm: {
+    getMostRecentWindow: function () {
+      // Having the returned object implement openUILinkIn is
+      // sufficient for our purposes.
+      return {
+        openUILinkIn: function (url) {
+          window.open(url, "_blank");
+        },
+      };
+    },
+  },
 };
 
 /**
  * Create a new preference.  This is used during startup (see
  * devtools/client/preferences/devtools.js) to install the
  * default preferences.
  *
  * @param {String} name the name of the preference
new file mode 100644
--- /dev/null
+++ b/devtools/client/shared/shim/test/file_service_wm.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script>
+// Silence eslint complaint about the onload below.
+/* eslint-disable no-unused-vars */
+
+"use strict";
+
+function load() {
+  (window.opener || window.parent).hurray();
+  window.close();
+}
+</script>
+</head>
+
+<body onload='load()'>
+</body>
+
+</html>
--- a/devtools/client/shared/shim/test/mochitest.ini
+++ b/devtools/client/shared/shim/test/mochitest.ini
@@ -1,8 +1,10 @@
 [DEFAULT]
 support-files =
+  file_service_wm.html
   prefs-wrapper.js
 
 [test_service_appinfo.html]
 [test_service_focus.html]
 [test_service_prefs.html]
 [test_service_prefs_defaults.html]
+[test_service_wm.html]
new file mode 100644
--- /dev/null
+++ b/devtools/client/shared/shim/test/test_service_wm.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1310279
+-->
+<head>
+  <title>Test for Bug 1310279 - replace Services.wm</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css"
+        href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+  <script type="application/javascript;version=1.8">
+  "use strict";
+  var exports = {}
+  var module = {exports};
+  </script>
+
+  <script type="application/javascript;version=1.8"
+	  src="resource://devtools/client/shared/shim/Services.js"></script>
+</head>
+<body>
+
+<script type="application/javascript;version=1.8">
+  "use strict";
+
+  function hurray(window) {
+    ok(true, "window loaded");
+    SimpleTest.finish();
+  }
+
+  SimpleTest.waitForExplicitFinish();
+  Services.wm.getMostRecentWindow().openUILinkIn("file_service_wm.html");
+
+</script>
+</body>