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 --- testing/web-platform/tests/managed/META.yml | 1 + .../managed/managed-config-error.https.window.js | 14 ++++++ .../managed/managed-config-success.https.window.js | 56 ++++++++++++++++++++++ .../resources/managed-configuration-helper.js | 51 ++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 testing/web-platform/tests/managed/META.yml create mode 100644 testing/web-platform/tests/managed/managed-config-error.https.window.js create mode 100644 testing/web-platform/tests/managed/managed-config-success.https.window.js create mode 100644 testing/web-platform/tests/managed/resources/managed-configuration-helper.js (limited to 'testing/web-platform/tests/managed') diff --git a/testing/web-platform/tests/managed/META.yml b/testing/web-platform/tests/managed/META.yml new file mode 100644 index 0000000000..2971ec82a9 --- /dev/null +++ b/testing/web-platform/tests/managed/META.yml @@ -0,0 +1 @@ +spec: https://wicg.github.io/WebApiDevice/managed_config/ diff --git a/testing/web-platform/tests/managed/managed-config-error.https.window.js b/testing/web-platform/tests/managed/managed-config-error.https.window.js new file mode 100644 index 0000000000..ab58fba5df --- /dev/null +++ b/testing/web-platform/tests/managed/managed-config-error.https.window.js @@ -0,0 +1,14 @@ +promise_test(t => { + return promise_rejects_js( + t, TypeError, navigator.managed.getManagedConfiguration(-1)); +}, 'Number instead of keys'); + +promise_test(t => { + return promise_rejects_js( + t, TypeError, navigator.managed.getManagedConfiguration()); +}, 'Empty key list'); + +promise_test(t => { + return promise_rejects_js( + t, TypeError, navigator.managed.getManagedConfiguration({'a': 2})); +}, 'Dictionary instead of list'); diff --git a/testing/web-platform/tests/managed/managed-config-success.https.window.js b/testing/web-platform/tests/managed/managed-config-success.https.window.js new file mode 100644 index 0000000000..ef9ad81a15 --- /dev/null +++ b/testing/web-platform/tests/managed/managed-config-success.https.window.js @@ -0,0 +1,56 @@ +// META: script=/resources/test-only-api.js +// META: script=resources/managed-configuration-helper.js + +'use strict' + +managed_config_test(async (test, managedConfigTest) => { + promise_rejects_dom( + test, 'NotAllowedError', + navigator.managed.getManagedConfiguration(['a'])); +}, 'App is not managed.'); + +managed_config_test(async (test, managedConfigTest) => { + managedConfigTest.setManagedConfig({a: 2}); + const result = await navigator.managed.getManagedConfiguration(['a']); + assert_equals(Object.keys(result).length, 1); + assert_equals(result.a, 2); +}, 'Configuration is returned'); + +managed_config_test(async (test, managedConfigTest) => { + managedConfigTest.setManagedConfig({a: 2, b: 3, c: 1}); + const result = await navigator.managed.getManagedConfiguration(['b', 'c']); + assert_equals(Object.keys(result).length, 2); + assert_equals(result.b, 3); + assert_equals(result.c, 1); +}, 'Selected keys are returned.'); + +managed_config_test(async (test, managedConfigTest) => { + managedConfigTest.setManagedConfig({a: 2, b: 3, c: 1}); + const result = await navigator.managed.getManagedConfiguration(['b', 'e']); + assert_equals(Object.keys(result).length, 1); + assert_equals(result.b, 3); +}, 'Only existing keys are returned.'); + +managed_config_test(async (test, managedConfigTest) => { + managedConfigTest.setManagedConfig({a: 2, b: false, c: {x: 3}}); + const result = + await navigator.managed.getManagedConfiguration(['a', 'b', 'c']); + assert_equals(Object.keys(result).length, 3); + assert_equals(result.a, 2); + assert_equals(result.b, false); + assert_equals(Object.keys(result.c).length, 1); + assert_equals(result.c.x, 3); +}, 'Values can be of any type'); + +managed_config_test(async (test, managedConfigTest) => { + const nextObserverAdded = managedConfigTest.nextObserverAdded(); + const watcher = + new EventWatcher(test, navigator.managed, ['managedconfigurationchange']); + await nextObserverAdded; + const event = watcher.wait_for(['managedconfigurationchange']); + managedConfigTest.setManagedConfig({'a': 2}); + await event; + const result = await navigator.managed.getManagedConfiguration(['a']); + assert_equals(Object.keys(result).length, 1); + assert_equals(result.a, 2); +}, 'A change in managed configuration is observed.'); diff --git a/testing/web-platform/tests/managed/resources/managed-configuration-helper.js b/testing/web-platform/tests/managed/resources/managed-configuration-helper.js new file mode 100644 index 0000000000..c3213a4dad --- /dev/null +++ b/testing/web-platform/tests/managed/resources/managed-configuration-helper.js @@ -0,0 +1,51 @@ +'use strict'; + +// These tests rely on the User Agent providing an implementation of +// Managed Configuration API +// (https://wicg.github.io/WebApiDevice/managed_config). +// +// In Chromium-based browsers this implementation is provided by a polyfill +// in order to reduce the amount of test-only code shipped to users. To enable +// these tests the browser must be run with these options: +// +// --enable-blink-features=MojoJS,MojoJSTest +let fakeManagedConfigurationService = undefined; + +async function loadChromiumResources() { + await import('/resources/chromium/mock-managed-config.js'); +} + +// User Agents must provide their own implementation of `ManagedConfigTest`, +// which must contain the following this interface: +// class ManagedConfigTest { +// /** Replaces the provided managed config with the given one. */ +// /** @param {?Object} config */ +// setManagedConfig(config); +// /** Asynchronously waits for a new observer to be added */ +// waitTillObserverAdded(); +// } + +async function createManagedConfigTest() { + if (typeof ManagedConfigTest === 'undefined') { + if (isChromiumBased) { + await loadChromiumResources(); + } + } + assert_implements(ManagedConfigTest, 'ManagedConfigTest is unavailable.'); + + if (fakeManagedConfigurationService !== undefined) { + await fakeManagedConfigurationService.initialize(); + return fakeManagedConfigurationService; + } + let managedConfigTest = new ManagedConfigTest(); + await managedConfigTest.initialize(); + fakeManagedConfigurationService = managedConfigTest; + return managedConfigTest; +} + +function managed_config_test(func, description) { + promise_test(async test => { + const managedConfigTest = await createManagedConfigTest(); + await func(test, managedConfigTest); + }, description); +} -- cgit v1.2.3