Commit 9d520789 authored by Thibaut Frain's avatar Thibaut Frain

Ensure redefining native acquired on the root gadget works

parent b6682be2
...@@ -711,7 +711,8 @@ ...@@ -711,7 +711,8 @@
embedded_channel, embedded_channel,
notifyReady, notifyReady,
notifyDeclareMethod, notifyDeclareMethod,
gadget_ready = false; gadget_ready = false,
last_acquisition_gadget;
// Create the gadget class for the current url // Create the gadget class for the current url
if (gadget_model_dict.hasOwnProperty(url)) { if (gadget_model_dict.hasOwnProperty(url)) {
...@@ -719,6 +720,21 @@ ...@@ -719,6 +720,21 @@
} }
loading_gadget_promise = new RSVP.Promise(function (resolve, reject) { loading_gadget_promise = new RSVP.Promise(function (resolve, reject) {
if (window.self === window.top) { if (window.self === window.top) {
last_acquisition_gadget = new RenderJSGadget();
last_acquisition_gadget.__acquired_method_dict = {
getTopURL: function () {
return url;
}
};
// Stop acquisition on the last acquisition gadget
// Do not put this on the klass, as their could be multiple instances
last_acquisition_gadget.__aq_parent = function (method_name) {
throw new renderJS.AcquisitionError(
"No gadget provides " + method_name
);
};
// XXX Copy/Paste from declareGadgetKlass // XXX Copy/Paste from declareGadgetKlass
tmp_constructor = function () { tmp_constructor = function () {
RenderJSGadget.call(this); RenderJSGadget.call(this);
...@@ -738,20 +754,8 @@ ...@@ -738,20 +754,8 @@
// Create the root gadget instance and put it in the loading stack // Create the root gadget instance and put it in the loading stack
root_gadget = new gadget_model_dict[url](); root_gadget = new gadget_model_dict[url]();
// Stop acquisition on the original root gadget setAqParent(root_gadget, last_acquisition_gadget);
// Do not put this on the klass, as their could be multiple instances
root_gadget.__aq_parent = function (method_name) {
throw new renderJS.AcquisitionError(
"No gadget provides " + method_name
);
};
tmp_constructor.prototype.__acquired_method_dict = {};
// Allow acquisition of getTopURL returning the top gadget path
tmp_constructor.allowPublicAcquisition('getTopURL', function () {
return root_gadget.__path;
});
} else { } else {
// Create the communication channel // Create the communication channel
embedded_channel = Channel.build({ embedded_channel = Channel.build({
...@@ -838,8 +842,9 @@ ...@@ -838,8 +842,9 @@
}); });
}); });
}; };
tmp_constructor.prototype.__acquired_method_dict = {};
} }
tmp_constructor.prototype.__acquired_method_dict = {};
gadget_loading_klass = tmp_constructor; gadget_loading_klass = tmp_constructor;
function init() { function init() {
......
...@@ -2765,10 +2765,22 @@ ...@@ -2765,10 +2765,22 @@
test('Check that the root gadget is cleanly implemented', function () { test('Check that the root gadget is cleanly implemented', function () {
var parsed = URI.parse(window.location.href), var parsed = URI.parse(window.location.href),
getTopURLCalled = false,
parent_path = URI.build({protocol: parsed.protocol, parent_path = URI.build({protocol: parsed.protocol,
hostname: parsed.hostname, hostname: parsed.hostname,
port: parsed.port, port: parsed.port,
path: parsed.path}).toString(); path: parsed.path}).toString();
root_gadget_klass
.declareAcquiredMethod('getTopURL', 'getTopURL')
.allowPublicAcquisition('getTopURL', function () {
getTopURLCalled = true;
this.getTopURL().then(function (topURL) {
equal(topURL, this.__path);
});
return this.getTopURL();
});
stop(); stop();
root_gadget_defer.promise root_gadget_defer.promise
.then(function (root_gadget) { .then(function (root_gadget) {
...@@ -2824,8 +2836,30 @@ ...@@ -2824,8 +2836,30 @@
ok(root_gadget.__aq_parent !== undefined); ok(root_gadget.__aq_parent !== undefined);
ok(root_gadget.hasOwnProperty("__sub_gadget_dict")); ok(root_gadget.hasOwnProperty("__sub_gadget_dict"));
deepEqual(root_gadget.__sub_gadget_dict, {}); deepEqual(root_gadget.__sub_gadget_dict, {});
equal(root_gadget.__acquired_method_dict.getTopURL(), return new RSVP.Queue()
window.location.href); .push(function () {
return root_gadget.getTopURL().then(function (topURL) {
equal(topURL, root_gadget.__path);
});
})
.push(function () {
return root_gadget.declareGadget("./embedded.html", {
sandbox: 'iframe',
element: document.querySelector('#qunit-fixture')
})
.then(function (new_gadget) {
return new_gadget.__aq_parent('getTopURL', []);
})
.then(function (topURL) {
equal(topURL, root_gadget.__path);
})
.then(function () {
ok(getTopURLCalled);
})
.fail(function () {
ok(false);
});
});
}) })
.fail(function (e) { .fail(function (e) {
ok(false, e); ok(false, e);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment