// Store a property as an expando on the bound element. this._prop = "propVal"; // Wait for both constructors to fire. window.constructorCount = (window.constructorCount + 1) || 1; if (window.constructorCount != 3) return; // Grab some basic infrastructure off the content window. var win = XPCNativeWrapper.unwrap(window); SpecialPowers = win.SpecialPowers; Cu = SpecialPowers.Cu; is = win.is; ok = win.ok; SimpleTest = win.SimpleTest; // Stick some expandos on the content window. window.xrayExpando = 3; win.primitiveExpando = 11; win.stringExpando = "stringExpando"; win.objectExpando = { foo: 12 }; win.globalExpando = SpecialPowers.unwrap(Cu.getGlobalForObject({})); win.functionExpando = function() { return "called" }; win.functionExpando.prop = 2; // Make sure we're Xraying. ok(Cu.isXrayWrapper(window), "Window is Xrayed"); ok(Cu.isXrayWrapper(document), "Document is Xrayed"); var bound = document.getElementById('bound'); var bound2 = document.getElementById('bound2'); var bound3 = document.getElementById('bound3'); ok(bound, "bound is non-null"); is(bound.method('baz'), "method:baz", "Xray methods work"); is(bound.prop, "propVal", "Property Xrays work"); is(bound.primitiveField, undefined, "Xrays don't show fields"); is(bound.wrappedJSObject.primitiveField, 2, "Waiving Xrays show fields"); // Check exposure behavior. is(typeof bound.unexposedMethod, 'function', "Unexposed method should be visible to XBL"); is(typeof bound.wrappedJSObject.unexposedMethod, 'undefined', "Unexposed method should not be defined in content"); is(typeof bound.unexposedProperty, 'number', "Unexposed property should be visible to XBL"); is(typeof bound.wrappedJSObject.unexposedProperty, 'undefined', "Unexposed property should not be defined in content"); // Check that here HTMLImageElement.QueryInterface works var img = document.querySelector("img"); ok("QueryInterface" in img, "Should have a img.QueryInterface here"); is(img.QueryInterface(Components.interfaces.nsIImageLoadingContent), img, "Should be able to QI the image"); // Make sure standard constructors work right in the presence of // sandboxPrototype and Xray-resolved constructors. is(window.Function, XPCNativeWrapper(window.wrappedJSObject.Function), "window.Function comes from the window, not the global"); ok(Function != window.Function, "Function constructors are distinct"); is(Object.getPrototypeOf(Function.prototype), Object.getPrototypeOf({foo: 42}), "Function constructor is local"); ok(Object.getPrototypeOf(bound.wrappedJSObject) == Object.getPrototypeOf(bound2.wrappedJSObject), "Div and div should have the same content-side prototype"); ok(Object.getPrototypeOf(bound.wrappedJSObject) != Object.getPrototypeOf(bound3.wrappedJSObject), "Div and span should have different content-side prototypes"); ok(bound.wrappedJSObject.method == bound3.wrappedJSObject.method, "Methods should be shared"); // This gets invoked by an event handler. window.finish = function() { // Content messed with stuff. Make sure we still see the right thing. is(bound.method('bay'), "method:bay", "Xray methods work"); is(bound.wrappedJSObject.method('bay'), "hah", "Xray waived methods work"); is(bound.prop, "set:someOtherVal", "Xray props work"); is(bound.wrappedJSObject.prop, "redefined", "Xray waived props work"); is(bound.wrappedJSObject.primitiveField, 321, "Can't do anything about redefined fields"); SimpleTest.finish(); } // Hand things off to content. Content will call us back. win.go(); 2 return "method:" + arg; is(typeof arg.prop, 'undefined', "No properties"); is(Object.getOwnPropertyNames(arg).length, 0, "Should have no own properties"); try { arg.foo = 2; ok(true, "Stuff fails silently"); } catch (e) { ok(false, "Stuff should fail silently"); } is(typeof arg.foo, 'undefined', "Shouldn't place props"); return this._prop; this._prop = "set:" + val; Mozilla Bug 821850

Bound element
Bound element
Bound element