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