Bug 1310279 - add "wm" to Services shim; r=jdescottes
authorTom Tromey <tom@tromey.com>
Thu, 20 Oct 2016 14:34:23 -0600
changeset 351508 0440791609bd3a6f4b525f8ab754518573de1a3f
parent 351507 1d01138a95d9607d534808bc47eba1bc70f0f9fb
child 351509 df734c2011d14ea2be10ac7efb0cb0f1812f0642
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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>