From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../resources/chromium/mock-managed-config.js | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 testing/web-platform/tests/resources/chromium/mock-managed-config.js (limited to 'testing/web-platform/tests/resources/chromium/mock-managed-config.js') 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; +})(); -- cgit v1.2.3