diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/resources/chromium/mock-subapps.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/resources/chromium/mock-subapps.js')
-rw-r--r-- | testing/web-platform/tests/resources/chromium/mock-subapps.js | 86 |
1 files changed, 86 insertions, 0 deletions
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..467d932465 --- /dev/null +++ b/testing/web-platform/tests/resources/chromium/mock-subapps.js @@ -0,0 +1,86 @@ +'use strict'; + +import {SubAppsService, SubAppsServiceReceiver, SubAppsServiceResult} 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: { + code: testInternal.serviceResultCode, + subApps: testInternal.listCallReturnValue, + } + }); + } + + remove() { + return Promise.resolve({ + result: testInternal.serviceResultCode, + }); + } + } + + let testInternal = { + initialized: false, + mockSubAppsService: null, + serviceResultCode: 0, + addCallReturnValue: [], + listCallReturnValue: [], + } + + class SubAppsServiceTestChromium { + constructor() { + Object.freeze(this); // Make it immutable. + } + + initialize(service_result_code, add_call_return_value, list_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, + }; + }; + } + + async reset() { + if (testInternal.initialized) { + testInternal.mockSubAppsService.reset(); + testInternal = { + mockSubAppsService: null, + initialized: false, + serviceResultCode: 0, + addCallReturnValue: [], + listCallReturnValue: [], + }; + await new Promise(resolve => setTimeout(resolve, 0)); + } + } + } + + return SubAppsServiceTestChromium; +})(); |