Bug 1310279 - add "wm" to Services shim; r?jdescottes
MozReview-Commit-ID: 2uW8RM2ufaf
--- 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>