From f6790b9895fa3765c1beb3edb995269ab805a0a9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 20 Apr 2021 14:11:30 +0000 Subject: [PATCH] [IMP] web: drop event during click() dispatching if disabled Causes the failure of [0] on FF as it expects that clicking a disabled button does nothing, which is what happens for Chrome, but the event is dispatched for Firefox. Asking the internet it looks like Firefox is in the right here: click() ultimately calls dispatchEvent (directly), dispatchEvent should go through even on disabled event. This was specifically fixed in Firefox[1], and there is an issue opened against Chrome[2] (cf also: spec discussion[3]). There's an other issue which mentions inconsistencies between the actual browser and WPT[4], but for us Chrome always 100% does the "wrong" thing. Anyway add a disabled flag in click, though I don't know that it's the right fix, and it may need to be added to other events as well? [0] https://github.com/odoo/odoo/blob/c89cdcf11c66e80c33cd77edceaee7eb59a704b3/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js#L2044 [1] https://bugzilla.mozilla.org/show_bug.cgi?id=329509 [2] https://bugs.chromium.org/p/chromium/issues/detail?id=1115661 [3] https://github.com/whatwg/html/pull/5805#issuecomment-672960163 [4] https://bugs.chromium.org/p/chromium/issues/detail?id=1116161 --- addons/web/static/tests/helpers/test_utils_dom.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/web/static/tests/helpers/test_utils_dom.js b/addons/web/static/tests/helpers/test_utils_dom.js index ded399572eeae..94b6a814b0596 100644 --- a/addons/web/static/tests/helpers/test_utils_dom.js +++ b/addons/web/static/tests/helpers/test_utils_dom.js @@ -169,6 +169,9 @@ odoo.define('web.test_utils_dom', function (require) { if (validMatches.length === 0 && matches.length > 0) { throw new Error(`Element to click on is not visible ${selectorMsg}`); } + if (target.disabled) { + return; + } return triggerEvent(target, 'click'); }