[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>
This commit is contained in:
Alexandre Kühn
2019-12-04 14:46:28 +00:00
parent 46b1218094
commit 6245ed2bce
2 changed files with 8 additions and 1 deletions
+7 -1
View File
@@ -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();
@@ -230,6 +230,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
@@ -59,6 +59,7 @@ var MockMailService = Class.extend({
bus_service: function () {
return BusService.extend({
_poll: function () {}, // Do nothing
_registerWindowUnload: function () {}, // Do nothing
isOdooFocused: function () { return true; },
updateOption: function () {},
});