Bug 1353150: Add tests for chrome Xray named element property access. r=bz draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 06 Apr 2017 21:32:47 -0700
changeset 557679 339ecf06aede37cd19501e4df6b78ba4741d5303
parent 557479 3dc13ed36ffa6cfaa4ff97bb5692fdba1ca1f29b
child 557680 883039a115295b8bd61990324d4a02411e3039ba
push id52781
push usermaglione.k@gmail.com
push dateFri, 07 Apr 2017 04:33:23 +0000
reviewersbz
bugs1353150
milestone55.0a1
Bug 1353150: Add tests for chrome Xray named element property access. r=bz MozReview-Commit-ID: 3Wyr8mkgE2c
js/xpconnect/tests/unit/test_xray_named_element_access.js
js/xpconnect/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_xray_named_element_access.js
@@ -0,0 +1,40 @@
+// See https://bugzilla.mozilla.org/show_bug.cgi?id=1273251
+"use strict"
+
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+
+Cu.import("resource://gre/modules/Preferences.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+const XRAY_PREF = "dom.allow_named_properties_object_for_xrays";
+
+add_task(function*() {
+  let webnav = Services.appShell.createWindowlessBrowser(false);
+
+  let docShell = webnav.QueryInterface(Ci.nsIInterfaceRequestor)
+                       .getInterface(Ci.nsIDocShell);
+
+  docShell.createAboutBlankContentViewer(null);
+
+  let window = webnav.getInterface(Ci.nsIDOMWindow);
+  let unwrapped = Cu.waiveXrays(window);
+
+  window.document.body.innerHTML = '<div id="foo"></div>';
+
+  equal(Preferences.get(XRAY_PREF), 1, "Should have pref=1 by default");
+
+  Preferences.set(XRAY_PREF, 0);
+  equal(typeof window.foo, "object", "Should have named X-ray property access with pref=0");
+  equal(typeof unwrapped.foo, "object", "Should always have non-X-ray named property access");
+
+  Preferences.set(XRAY_PREF, 1);
+  equal(typeof window.foo, "object", "Should have named X-ray property access with pref=1");
+  equal(typeof unwrapped.foo, "object", "Should always have non-X-ray named property access");
+
+  Preferences.set(XRAY_PREF, 2);
+  equal(window.foo, undefined, "Should not have named X-ray property access with pref=2");
+  equal(typeof unwrapped.foo, "object", "Should always have non-X-ray named property access");
+
+  webnav.close();
+});
+
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -123,13 +123,14 @@ head = head_watchdog.js
 [test_watchdog_default.js]
 head = head_watchdog.js
 [test_watchdog_hibernate.js]
 head = head_watchdog.js
 [test_weak_keys.js]
 [test_writeToGlobalPrototype.js]
 [test_xpcwn_tamperproof.js]
 [test_xrayed_iterator.js]
+[test_xray_named_element_access.js]
 [test_xray_SavedFrame.js]
 [test_xray_SavedFrame-02.js]
 [test_xray_regexp.js]
 [test_resolve_dead_promise.js]
 [test_asyncLoadSubScriptError.js]