From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- .../tests/resources/chromium/mock-subapps.js | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 testing/web-platform/tests/resources/chromium/mock-subapps.js (limited to 'testing/web-platform/tests/resources/chromium/mock-subapps.js') diff --git a/testing/web-platform/tests/resources/chromium/mock-subapps.js b/testing/web-platform/tests/resources/chromium/mock-subapps.js new file mode 100644 index 0000000000..b81936713b --- /dev/null +++ b/testing/web-platform/tests/resources/chromium/mock-subapps.js @@ -0,0 +1,89 @@ +'use strict'; + +import {SubAppsService, SubAppsServiceReceiver, SubAppsServiceResultCode} from '/gen/third_party/blink/public/mojom/subapps/sub_apps_service.mojom.m.js'; + +self.SubAppsServiceTest = (() => { + // Class that mocks SubAppsService interface defined in /third_party/blink/public/mojom/subapps/sub_apps_service.mojom + + class MockSubAppsService { + constructor() { + this.interceptor_ = + new MojoInterfaceInterceptor(SubAppsService.$interfaceName); + this.receiver_ = new SubAppsServiceReceiver(this); + this.interceptor_.oninterfacerequest = + e => this.receiver_.$.bindHandle(e.handle); + this.interceptor_.start(); + } + + reset() { + this.interceptor_.stop(); + this.receiver_.$.close(); + } + + add(sub_apps) { + return Promise.resolve({ + result: testInternal.addCallReturnValue, + }); + } + + list() { + return Promise.resolve({ + result: { + resultCode: testInternal.serviceResultCode, + subAppsList: testInternal.listCallReturnValue, + } + }); + } + + remove() { + return Promise.resolve({ + result: testInternal.removeCallReturnValue, + }); + } + } + + let testInternal = { + initialized: false, + mockSubAppsService: null, + serviceResultCode: 0, + addCallReturnValue: [], + listCallReturnValue: [], + removeCallReturnValue: [], + } + + class SubAppsServiceTestChromium { + constructor() { + Object.freeze(this); // Make it immutable. + } + + initialize(service_result_code, add_call_return_value, list_call_return_value, remove_call_return_value) { + if (!testInternal.initialized) { + testInternal = { + mockSubAppsService: new MockSubAppsService(), + initialized: true, + serviceResultCode: service_result_code, + addCallReturnValue: add_call_return_value, + listCallReturnValue: list_call_return_value, + removeCallReturnValue: remove_call_return_value, + }; + }; + } + + async reset() { + if (testInternal.initialized) { + testInternal.mockSubAppsService.reset(); + testInternal = { + mockSubAppsService: null, + initialized: false, + serviceResultCode: 0, + addCallReturnValue: [], + listCallReturnValue: [], + removeCallReturnValue: [], + }; + await new Promise(resolve => setTimeout(resolve, 0)); + } + } + } + + return SubAppsServiceTestChromium; +})(); -- cgit v1.2.3