Bug 923904 - Tests. r=mccr8
authorBobby Holley <bobbyholley@gmail.com>
Fri, 14 Feb 2014 22:36:43 -0800
changeset 169269 f665d5a2292c06b7103de4773558b41242c8e263
parent 169268 dd1f8adbfecc0d2c5fa0bd6fdd97de0261ab2cdb
child 169270 ccf60cc8004bc4f7ccc6bdc874eb4453612b2d1f
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersmccr8
bugs923904, 968335
milestone30.0a1
Bug 923904 - Tests. r=mccr8 We land these before actually landing bug 923904, because we want to build the tests for bug 968335 on top of the same infrastructure.
b2g/installer/package-manifest.in
browser/installer/package-manifest.in
dom/bindings/test/TestInterfaceJS.js
dom/bindings/test/TestInterfaceJS.manifest
dom/bindings/test/mochitest.ini
dom/bindings/test/moz.build
dom/bindings/test/test_bug923904.html
dom/webidl/TestInterfaceJS.webidl
dom/webidl/moz.build
mobile/android/installer/package-manifest.in
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -560,16 +560,21 @@
 
 @BINPATH@/components/DownloadsAPI.js
 @BINPATH@/components/DownloadsAPI.manifest
 
 ; InputMethod API
 @BINPATH@/components/MozKeyboard.js
 @BINPATH@/components/InputMethod.manifest
 
+#ifdef MOZ_DEBUG
+@BINPATH@/components/TestInterfaceJS.js
+@BINPATH@/components/TestInterfaceJS.manifest
+#endif
+
 ; Modules
 @BINPATH@/modules/*
 
 ; Safe Browsing
 @BINPATH@/components/nsURLClassifier.manifest
 @BINPATH@/components/nsUrlClassifierHashCompleter.js
 @BINPATH@/components/nsUrlClassifierListManager.js
 @BINPATH@/components/nsUrlClassifierLib.js
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -579,16 +579,21 @@
 #ifdef MOZ_WEBSPEECH
 @BINPATH@/components/dom_webspeechsynth.xpt
 #endif
 
 ; InputMethod API
 @BINPATH@/components/MozKeyboard.js
 @BINPATH@/components/InputMethod.manifest
 
+#ifdef MOZ_DEBUG
+@BINPATH@/components/TestInterfaceJS.js
+@BINPATH@/components/TestInterfaceJS.manifest
+#endif
+
 ; Modules
 @BINPATH@/browser/modules/*
 @BINPATH@/modules/*
 
 ; Safe Browsing
 #ifdef MOZ_URL_CLASSIFIER
 @BINPATH@/components/nsURLClassifier.manifest
 @BINPATH@/components/nsUrlClassifierHashCompleter.js
new file mode 100644
--- /dev/null
+++ b/dom/bindings/test/TestInterfaceJS.js
@@ -0,0 +1,49 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const Cu = Components.utils;
+const Ci = Components.interfaces;
+
+"use strict";
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+var gGlobal = this;
+function checkGlobal(obj) {
+  if (typeof obj == 'object' && Cu.getGlobalForObject(obj) != gGlobal) {
+    // This message may not make it to the caller in a useful form, so dump
+    // as well.
+    var msg = "TestInterfaceJS received an object from a different scope!";
+    dump(msg + "\n");
+    throw new Error(msg);
+  }
+}
+
+function TestInterfaceJS(anyArg, objectArg) {}
+
+TestInterfaceJS.prototype = {
+  classID: Components.ID("{2ac4e026-cf25-47d5-b067-78d553c3cad8}"),
+  contractID: "@mozilla.org/dom/test-interface-js;1",
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
+
+  __init: function (anyArg, objectArg) {
+    this._anyAttr = undefined;
+    this._objectAttr = null;
+    this._anyArg = anyArg;
+    this._objectArg = objectArg;
+    checkGlobal(anyArg);
+    checkGlobal(objectArg);
+  },
+
+  get anyArg() { return this._anyArg; },
+  get objectArg() { return this._objectArg; },
+  get anyAttr() { return this._anyAttr; },
+  set anyAttr(val) { checkGlobal(val); this._anyAttr = val; },
+  get objectAttr() { return this._objectAttr; },
+  set objectAttr(val) { checkGlobal(val); this._objectAttr = val; },
+  pingPongAny: function(any) { checkGlobal(any); return any; },
+  pingPongObject: function(obj) { checkGlobal(obj); return obj; },
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestInterfaceJS])
new file mode 100644
--- /dev/null
+++ b/dom/bindings/test/TestInterfaceJS.manifest
@@ -0,0 +1,2 @@
+component {2ac4e026-cf25-47d5-b067-78d553c3cad8} TestInterfaceJS.js
+contract @mozilla.org/dom/test-interface-js;1 {2ac4e026-cf25-47d5-b067-78d553c3cad8}
--- a/dom/bindings/test/mochitest.ini
+++ b/dom/bindings/test/mochitest.ini
@@ -11,16 +11,20 @@ support-files =
 [test_bug560072.html]
 [test_bug707564.html]
 [test_bug742191.html]
 [test_bug759621.html]
 [test_bug773326.html]
 [test_bug788369.html]
 [test_bug852846.html]
 [test_bug862092.html]
+# When bug 923904 lands, this test can be turned on, but only for debug builds
+# where we have our test component. So this should become skip-if = debug == false.
+[test_bug923904.html]
+skip-if = true
 [test_barewordGetsWindow.html]
 [test_callback_default_thisval.html]
 [test_cloneAndImportNode.html]
 [test_defineProperty.html]
 [test_enums.html]
 [test_exceptionThrowing.html]
 [test_exception_messages.html]
 [test_forOf.html]
--- a/dom/bindings/test/moz.build
+++ b/dom/bindings/test/moz.build
@@ -5,16 +5,21 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 LIBXUL_LIBRARY = True
 # Do NOT export this library.  We don't actually want our test code
 # being added to libxul or anything.
 
 LIBRARY_NAME = 'dombindings_test_s'
 
+EXTRA_COMPONENTS += [
+    'TestInterfaceJS.js',
+    'TestInterfaceJS.manifest',
+]
+
 MOCHITEST_MANIFESTS += ['mochitest.ini']
 
 MOCHITEST_CHROME_MANIFESTS += ['chrome.ini']
 
 TEST_WEBIDL_FILES += [
     'TestDictionary.webidl',
     'TestJSImplInheritanceGen.webidl',
     'TestTypedef.webidl',
new file mode 100644
--- /dev/null
+++ b/dom/bindings/test/test_bug923904.html
@@ -0,0 +1,66 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=923904
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 923904</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for cloning of |any| and |object| for JS-Implemented WebIDL. **/
+  SimpleTest.waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, go);
+
+  function go() {
+    var someAny = { a: 11 };
+    var someObj = { b: 22, c: "str" };
+    var t = new TestInterfaceJS(someAny, someObj);
+    is(Object.getPrototypeOf(t), TestInterfaceJS.prototype, "Prototype setup works correctly");
+    is(t.anyArg.toSource(), someAny.toSource(), "anyArg comes back looking like what we sent");
+    is(t.objectArg.toSource(), someObj.toSource(), "objectArg comes back looking like what we sent");
+    isnot(t.anyArg, t.anyArg, "get a new anyArg each time");
+    isnot(t.objectArg, t.objectArg, "get a new objectArg each time");
+
+    t.anyAttr = 2;
+    is(t.anyAttr, 2, "ping-pong works");
+    testObjectCloned(t, 'anyAttr');
+    testObjectCloned(t, 'objectAttr');
+
+    is(someAny.toSource(), t.pingPongAny(someAny).toSource(), "ping-pong works with any");
+    is(someObj.toSource(), t.pingPongObject(someObj).toSource(), "ping-pong works with obj");
+    isnot(someAny, t.pingPongAny(someAny), "Clone works for ping-pong any");
+    isnot(someObj, t.pingPongObject(someObj), "Clone works for ping-pong obj");
+
+    SimpleTest.finish();
+  }
+
+  function testObjectCloned(iface, propname) {
+    var obj = { prop: 42 };
+    iface[propname] = obj;
+    is(iface[propname].prop, 42, "objects come back as well");
+    is(iface[propname].__proto__, Object.prototype, "vanilla object");
+    isnot(iface[propname], obj, "Should not be the original object");
+    isnot(iface[propname], iface[propname], "Should get cloned each time");
+    try {
+      iface[propname] = { stringProp: "hi", reflectorProp: document };
+      ok(false, "Should throw when trying to clone reflector");
+    } catch (e) {
+      ok(/cloned/.test(e), "Should throw clone error: " + e);
+    }
+  }
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=923904">Mozilla Bug 923904</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/webidl/TestInterfaceJS.webidl
@@ -0,0 +1,17 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+[JSImplementation="@mozilla.org/dom/test-interface-js;1",
+ Pref="dom.expose_test_interfaces",
+ Constructor(any anyArg, object objectArg)]
+interface TestInterfaceJS {
+  readonly attribute any anyArg;
+  readonly attribute object objectArg;
+  attribute any anyAttr;
+  attribute object objectAttr;
+  any pingPongAny(any arg);
+  object pingPongObject(any obj);
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -505,16 +505,21 @@ WEBIDL_FILES += [
     'RecordErrorEvent.webidl',
     'SmartCardEvent.webidl',
     'StorageEvent.webidl',
     'StyleRuleChangeEvent.webidl',
     'StyleSheetApplicableStateChangeEvent.webidl',
     'StyleSheetChangeEvent.webidl',
 ]
 
+# We only expose our prefable test interfaces in debug builds, just to be on
+# the safe side.
+if CONFIG['MOZ_DEBUG']:
+    WEBIDL_FILES += ['TestInterfaceJS.webidl']
+
 if CONFIG['MOZ_B2G_BT']:
     WEBIDL_FILES += [
         'BluetoothAdapter.webidl',
         'BluetoothDevice.webidl',
         'BluetoothManager.webidl',
     ]
 
 if CONFIG['MOZ_B2G_RIL']:
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -420,16 +420,21 @@
 @BINPATH@/components/CaptivePortalDetectComponents.manifest
 @BINPATH@/components/captivedetect.js
 #endif
 
 #ifdef MOZ_WEBSPEECH
 @BINPATH@/components/dom_webspeechsynth.xpt
 #endif
 
+#ifdef MOZ_DEBUG
+@BINPATH@/components/TestInterfaceJS.js
+@BINPATH@/components/TestInterfaceJS.manifest
+#endif
+
 ; Modules
 @BINPATH@/modules/*
 
 #ifdef MOZ_SAFE_BROWSING
 ; Safe Browsing
 @BINPATH@/components/nsURLClassifier.manifest
 @BINPATH@/components/nsUrlClassifierHashCompleter.js
 @BINPATH@/components/nsUrlClassifierListManager.js