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 @@
embedded_channel,
notifyReady,
notifyDeclareMethod,
gadget_ready = false;
gadget_ready = false,
last_acquisition_gadget;
// Create the gadget class for the current url
if (gadget_model_dict.hasOwnProperty(url)) {
......@@ -719,6 +720,21 @@
}
loading_gadget_promise = new RSVP.Promise(function (resolve, reject) {
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
tmp_constructor = function () {
RenderJSGadget.call(this);
......@@ -738,20 +754,8 @@
// Create the root gadget instance and put it in the loading stack
root_gadget = new gadget_model_dict[url]();
// Stop acquisition on the original root 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 = {};
setAqParent(root_gadget, last_acquisition_gadget);
// Allow acquisition of getTopURL returning the top gadget path
tmp_constructor.allowPublicAcquisition('getTopURL', function () {
return root_gadget.__path;
});
} else {
// Create the communication channel
embedded_channel = Channel.build({
......@@ -838,8 +842,9 @@
});
});
};
tmp_constructor.prototype.__acquired_method_dict = {};
}
tmp_constructor.prototype.__acquired_method_dict = {};
gadget_loading_klass = tmp_constructor;
function init() {
......
......@@ -2765,10 +2765,22 @@
test('Check that the root gadget is cleanly implemented', function () {
var parsed = URI.parse(window.location.href),
getTopURLCalled = false,
parent_path = URI.build({protocol: parsed.protocol,
hostname: parsed.hostname,
port: parsed.port,
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();
root_gadget_defer.promise
.then(function (root_gadget) {
......@@ -2824,8 +2836,30 @@
ok(root_gadget.__aq_parent !== undefined);
ok(root_gadget.hasOwnProperty("__sub_gadget_dict"));
deepEqual(root_gadget.__sub_gadget_dict, {});
equal(root_gadget.__acquired_method_dict.getTopURL(),
window.location.href);
return new RSVP.Queue()
.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) {
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