From f949217256abbaa32b1b2088e70307e4fcbdd981 Mon Sep 17 00:00:00 2001 From: Pierre Paridans Date: Tue, 21 Mar 2023 10:13:32 +0000 Subject: [PATCH] [FIX] web,mail,web_tour,test_main_flows,tests: no hardcoded user agent Main Flow Tour Mobile shouldn't require a specific `user_agent` as it targets a small screen and not a mobile platform (iOS, Android...). Actually, during refactoring of the tours (odoo/odoo@3a798039d6f200f8e28448ddb6a2d3c46654a203), a confusion was made between the legacy `isMobile`, which represents a small screen (cf. `env.isSmall`) and `isMobileOS`, which targets "mobile" platforms (ie. iOS, Android...) independently of the screen size. This commit applies the proper condition (isSmall) for the tours management and removes the useless `user_agent` property. It also removes the logic added to support custom user_agent in the Chrome automation for testing. closes odoo/odoo#116186 Signed-off-by: Aaron Bohy (aab) --- .../static/tests/helpers/patch_ui_size.js | 4 +- addons/web/static/src/core/ui/ui_service.js | 14 +++++-- .../static/src/tour_service/tour_service.js | 41 +++++++++---------- .../static/src/tour_service/tour_utils.js | 4 +- .../addons/test_main_flows/tests/test_flow.py | 4 -- odoo/tests/common.py | 5 --- 6 files changed, 34 insertions(+), 38 deletions(-) diff --git a/addons/mail/static/tests/helpers/patch_ui_size.js b/addons/mail/static/tests/helpers/patch_ui_size.js index 74322f66198..bd105900047 100644 --- a/addons/mail/static/tests/helpers/patch_ui_size.js +++ b/addons/mail/static/tests/helpers/patch_ui_size.js @@ -1,7 +1,7 @@ /** @odoo-module **/ import { browser } from "@web/core/browser/browser"; -import { MEDIAS_BREAKPOINTS, SIZES, uiService } from "@web/core/ui/ui_service"; +import { MEDIAS_BREAKPOINTS, SIZES, utils } from "@web/core/ui/ui_service"; import { patchWithCleanup } from "@web/../tests/helpers/utils"; import config from "web.config"; @@ -92,7 +92,7 @@ function patchUiSize({ height, size, width }) { innerWidth: width, innerHeight: height || browser.innerHeight, }); - patchWithCleanup(uiService, { + patchWithCleanup(utils, { getSize() { return size; }, diff --git a/addons/web/static/src/core/ui/ui_service.js b/addons/web/static/src/core/ui/ui_service.js index 3a1c0f59536..0c494c6143a 100644 --- a/addons/web/static/src/core/ui/ui_service.js +++ b/addons/web/static/src/core/ui/ui_service.js @@ -119,10 +119,16 @@ export function getMediaQueryLists() { // window size handling. const MEDIAS = getMediaQueryLists(); -export const uiService = { +export const utils = { getSize() { return MEDIAS.findIndex((media) => media.matches); }, + isSmall(ui = {}) { + return (ui.size || utils.getSize()) <= SIZES.SM; + }, +}; + +export const uiService = { start(env) { // block/unblock code const bus = new EventBus(); @@ -169,7 +175,7 @@ export const uiService = { const ui = { bus, - size: this.getSize(), + size: utils.getSize(), get activeElement() { return activeElems[activeElems.length - 1]; }, @@ -177,7 +183,7 @@ export const uiService = { return blockCount > 0; }, get isSmall() { - return ui.size <= SIZES.SM; + return utils.isSmall(ui); }, block, unblock, @@ -189,7 +195,7 @@ export const uiService = { // listen to media query status changes const updateSize = () => { const prevSize = ui.size; - ui.size = this.getSize(); + ui.size = utils.getSize(); if (ui.size !== prevSize) { bus.trigger("resize"); } diff --git a/addons/web_tour/static/src/tour_service/tour_service.js b/addons/web_tour/static/src/tour_service/tour_service.js index 7765bafa5d7..67f249d3b48 100644 --- a/addons/web_tour/static/src/tour_service/tour_service.js +++ b/addons/web_tour/static/src/tour_service/tour_service.js @@ -2,7 +2,6 @@ import { markup, whenReady, reactive } from "@odoo/owl"; import { browser } from "@web/core/browser/browser"; -import { isMobileOS } from "@web/core/browser/feature_detection"; import { _t } from "@web/core/l10n/translation"; import { MacroEngine } from "@web/core/macro"; import { registry } from "@web/core/registry"; @@ -73,27 +72,9 @@ function extractRegisteredTours() { return tours; } -/** - * @param {TourStep} step - * @param {TourMode} mode - */ -function shouldOmit(step, mode) { - const isDefined = (key, obj) => key in obj && obj[key] !== undefined; - const getEdition = () => - session.server_version_info.slice(-1)[0] === "e" ? "enterprise" : "community"; - const correctEdition = isDefined("edition", step) ? step.edition === getEdition() : true; - const correctDevice = isDefined("mobile", step) ? step.mobile === isMobileOS() : true; - return ( - !correctEdition || - !correctDevice || - // `step.auto = true` means omitting a step in a manual tour. - (mode === "manual" && step.auto) - ); -} - export const tourService = { - dependencies: ["orm", "effect"], - start: async (_env, { orm, effect }) => { + dependencies: ["orm", "effect", "ui"], + start: async (_env, { orm, effect, ui }) => { await whenReady(); const tours = extractRegisteredTours(); @@ -134,6 +115,24 @@ export const tourService = { }; } + /** + * @param {TourStep} step + * @param {TourMode} mode + */ + function shouldOmit(step, mode) { + const isDefined = (key, obj) => key in obj && obj[key] !== undefined; + const getEdition = () => + session.server_version_info.slice(-1)[0] === "e" ? "enterprise" : "community"; + const correctEdition = isDefined("edition", step) ? step.edition === getEdition() : true; + const correctDevice = isDefined("mobile", step) ? step.mobile === ui.isSmall : true; + return ( + !correctEdition || + !correctDevice || + // `step.auto = true` means omitting a step in a manual tour. + (mode === "manual" && step.auto) + ); + } + /** * @param {Tour} tour * @param {ReturnType} pointer diff --git a/addons/web_tour/static/src/tour_service/tour_utils.js b/addons/web_tour/static/src/tour_service/tour_utils.js index e0868ffd929..2622e36de90 100644 --- a/addons/web_tour/static/src/tour_service/tour_utils.js +++ b/addons/web_tour/static/src/tour_service/tour_utils.js @@ -1,9 +1,9 @@ /** @odoo-module **/ import { markup } from "@odoo/owl"; -import { isMobileOS } from "@web/core/browser/feature_detection"; import { _t } from "@web/core/l10n/translation"; import { _legacyIsVisible } from "@web/core/utils/ui"; +import { utils } from "@web/core/ui/ui_service"; /** * @typedef {string | (actions: RunningTourActionHelper) => void | Promise} RunCommand @@ -93,7 +93,7 @@ export function getConsumeEventType(element, runCommand) { return "apply.daterangepicker input"; } if ( - isMobileOS() && + utils.isSmall() && element.closest(".o_field_widget")?.matches(".o_field_many2one, .o_field_many2many") ) { return "click"; diff --git a/odoo/addons/test_main_flows/tests/test_flow.py b/odoo/addons/test_main_flows/tests/test_flow.py index 810be3f155b..ac9adde231e 100644 --- a/odoo/addons/test_main_flows/tests/test_flow.py +++ b/odoo/addons/test_main_flows/tests/test_flow.py @@ -80,9 +80,5 @@ class TestUiMobile(BaseTestUi): browser_size = '375x667' touch_enabled = True - # Taken from user agents provided in Chrome (Version 110.0.5481.100) dev tools. - # This is specified so that the feature_detection.js heuristics for `isMobileOS` can work. - user_agent = 'Mozilla/5.0 (Linux; Android 10; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Mobile Safari/537.36' - def test_01_main_flow_tour_mobile(self): self.main_flow_tour() diff --git a/odoo/tests/common.py b/odoo/tests/common.py index 721e28934c5..167eb20e35d 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -835,7 +835,6 @@ class ChromeBrowser: self.window_size = test_class.browser_size self.touch_enabled = test_class.touch_enabled - self.user_agent = test_class.user_agent self.sigxcpu_handler = None self._chrome_start() self._find_websocket() @@ -985,9 +984,6 @@ class ChromeBrowser: # "'ontouchstart' in window" switches['--touch-events'] = '' - if self.user_agent: - switches['--user-agent'] = self.user_agent - cmd = [self.executable] cmd += ['%s=%s' % (k, v) if v else k for k, v in switches.items()] url = 'about:blank' @@ -1554,7 +1550,6 @@ class HttpCase(TransactionCase): browser_size = '1366x768' touch_enabled = False allow_end_on_form = False - user_agent = None _logger: logging.Logger = None