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-managed-config.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.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-managed-config.js')
-rw-r--r-- | testing/web-platform/tests/resources/chromium/mock-managed-config.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/testing/web-platform/tests/resources/chromium/mock-managed-config.js b/testing/web-platform/tests/resources/chromium/mock-managed-config.js new file mode 100644 index 0000000000..c9980e1285 --- /dev/null +++ b/testing/web-platform/tests/resources/chromium/mock-managed-config.js @@ -0,0 +1,91 @@ +'use strict' + +import{ManagedConfigurationObserverRemote, ManagedConfigurationService, ManagedConfigurationServiceReceiver} from '/gen/third_party/blink/public/mojom/device/device.mojom.m.js'; + + +self.ManagedConfigTest = (() => { + // Class that mocks ManagedConfigurationService interface defined in + // https://source.chromium.org/chromium/chromium/src/third_party/blink/public/mojom/device/device.mojom + class MockManagedConfig { + constructor() { + this.receiver_ = new ManagedConfigurationServiceReceiver(this); + this.interceptor_ = new MojoInterfaceInterceptor( + ManagedConfigurationService.$interfaceName); + this.interceptor_.oninterfacerequest = e => + this.receiver_.$.bindHandle(e.handle); + this.interceptor_.start(); + this.subscription_ = null; + this.reset(); + } + + reset() { + this.configuration_ = null; + this.onObserverAdd_ = null; + } + + async getManagedConfiguration(keys) { + if (this.configuration_ === null) { + return {}; + } + + return { + configurations: Object.keys(this.configuration_) + .filter(key => keys.includes(key)) + .reduce( + (obj, key) => { + obj[key] = + JSON.stringify(this.configuration_[key]); + return obj; + }, + {}) + }; + } + + subscribeToManagedConfiguration(remote) { + this.subscription_ = remote; + if (this.onObserverAdd_ !== null) { + this.onObserverAdd_(); + } + } + + setManagedConfig(value) { + this.configuration_ = value; + if (this.subscription_ !== null) { + this.subscription_.onConfigurationChanged(); + } + } + } + + let testInternal = { + initialized: false, + mockManagedConfig: null + } + + class ManagedConfigTestChromium { + constructor() { + Object.freeze(this); // Make it immutable. + } + + initialize() { + if (testInternal.mockManagedConfig !== null) { + testInternal.mockManagedConfig.reset(); + return; + } + + testInternal.mockManagedConfig = new MockManagedConfig; + testInternal.initialized = true; + } + + setManagedConfig(config) { + testInternal.mockManagedConfig.setManagedConfig(config); + } + + async nextObserverAdded() { + await new Promise(resolve => { + testInternal.mockManagedConfig.onObserverAdd_ = resolve; + }); + } + } + + return ManagedConfigTestChromium; +})(); |