Bug 1353150: Add tests for chrome Xray named element property access. r=bz
MozReview-Commit-ID: 3Wyr8mkgE2c
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]