summaryrefslogtreecommitdiff
path: root/addons/bus
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2019-12-04 12:45:33 +0000
committerAlexandre Kühn <aku@odoo.com>2019-12-04 14:46:28 +0000
commit6245ed2bce4382c3207baf9c6b2d4394384f0b4f (patch)
tree6f8025c97e7210e837cc1ba5b2356b6e075893a0 /addons/bus
parent46b1218094ec4d3b6e6d0ec4f66a94a587d575bd (diff)
[FIX] bus, mail: navigate from tests with mocked bus services
Before this commit, when navigating from test environment (e.g. page reload), it crashed with following error: `TypeError: Cannot convert undefined or null to object` This error comes from mocked bus services in tests: even when they have been destroyed, they handle the window event 'unload'. They no longer have a parented parent, so `this.call()` returns `undefined`, hence the crash. This commit prevents mocked bus services to listen on window 'unload' event. Tests must always simulate this window event by explicitly calling the handler. closes odoo/odoo#41378 X-original-commit: fd08d04f0a24fea52e7b668b90aec48b33d349a3 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/bus')
-rw-r--r--addons/bus/static/src/js/crosstab_bus.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/addons/bus/static/src/js/crosstab_bus.js b/addons/bus/static/src/js/crosstab_bus.js
index b939ecab3a5..8f66a64b286 100644
--- a/addons/bus/static/src/js/crosstab_bus.js
+++ b/addons/bus/static/src/js/crosstab_bus.js
@@ -109,7 +109,7 @@ var CrossTabBus = Longpolling.extend({
peers[this._id] = new Date().getTime();
this._callLocalStorage('setItem', 'peers', peers);
- $(window).on('unload.' + this._id, this._onUnload.bind(this));
+ this._registerWindowUnload();
if (!this._callLocalStorage('getItem', 'master')) {
this._startElection();
@@ -231,6 +231,12 @@ var CrossTabBus = Longpolling.extend({
this._heartbeatTimeout = setTimeout(this._heartbeat.bind(this), hbPeriod);
},
/**
+ * @private
+ */
+ _registerWindowUnload: function () {
+ $(window).on('unload.' + this._id, this._onUnload.bind(this));
+ },
+ /**
* Check with the local storage if the current tab is the master tab.
* If this tab became the master, trigger 'become_master' event
*