From 251e77e6f64786bfeffc2f1c97a4bf1d8b3e9151 Mon Sep 17 00:00:00 2001 From: Miguel Casas-Sanchez Date: Thu, 6 Feb 2025 23:17:32 -0800 Subject: [PATCH] H5vccSystem WPT --- .../wpt_internal/h5vcc/h5vcc-system/README.md | 6 +++ ...h5vcc-system-getAdvertisingId.https.any.js | 16 ++++++ .../h5vcc-system/resources/automation.js | 26 ++++++++++ .../resources/mock-h5vcc-system.js | 50 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/README.md create mode 100644 third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/h5vcc-system-getAdvertisingId.https.any.js create mode 100644 third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/automation.js create mode 100644 third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/mock-h5vcc-system.js diff --git a/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/README.md b/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/README.md new file mode 100644 index 000000000000..3f95d959ee6c --- /dev/null +++ b/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/README.md @@ -0,0 +1,6 @@ +# Web tests for H5vccSystem + +These automated tests rely on a test-only interface that must be provided by the +browser under test. The pattern from the Serial API is followed: an +implementation of the H5vccSystem Mojo interface is provided by +`../../resources/chromium/cobalt/fake-h5vcc-system-impl.js`. diff --git a/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/h5vcc-system-getAdvertisingId.https.any.js b/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/h5vcc-system-getAdvertisingId.https.any.js new file mode 100644 index 000000000000..74d946177fce --- /dev/null +++ b/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/h5vcc-system-getAdvertisingId.https.any.js @@ -0,0 +1,16 @@ +// META: global=window +// META: script=/resources/test-only-api.js +// META: script=resources/automation.js + +h5vcc_system_tests(async (t, mockH5vccSystem) => { + + assert_implements(window.h5vcc, "window.h5vcc not supported"); + assert_implements(window.h5vcc.system, "window.h5vcc.system not supported"); + + const advertisingID = '12345' + mockH5vccSystem.setAdvertisingIDForTesting(advertisingID); + + let result = await window.h5vcc.system.getAdvertisingId(); + assert_equals(result, advertisingID); +}, 'exercises H5vccSystem.getAdvertisingId()'); + diff --git a/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/automation.js b/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/automation.js new file mode 100644 index 000000000000..2d4cbdc22f5b --- /dev/null +++ b/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/automation.js @@ -0,0 +1,26 @@ +'use strict'; + + +let mockH5vccSystem = undefined; + +function h5vcc_system_tests(func, name, properties) { + promise_test(async t => { + if (mockH5vccSystem === undefined) { + if (isChromiumBased) { + const mocks = await import('./mock-h5vcc-system.js'); + mockH5vccSystem = mocks.mockH5vccSystem; + } + } + assert_implements( + mockH5vccSystem, 'missing mockH5vccSystem after initialization'); + + mockH5vccSystem.start(); + try { + await func(test, mockH5vccSystem); + } finally { + mockH5vccSystem.stop(); + mockH5vccSystem.reset(); + } + }, name, properties); +} + diff --git a/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/mock-h5vcc-system.js b/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/mock-h5vcc-system.js new file mode 100644 index 000000000000..14a6db7a8af6 --- /dev/null +++ b/third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/mock-h5vcc-system.js @@ -0,0 +1,50 @@ +import {H5vccSystem, H5vccSystemReceiver} from '/gen/cobalt/browser/h5vcc_system/public/mojom/h5vcc_system.mojom.m.js'; + +// Implementation of h5vcc_system.mojom.H5vccSystem. +class MockH5vccSystem { + constructor() { +/* + this.receiver_ = new H5vccSystemReceiver(this); + this.interceptor_ = + new MojoInterfaceInterceptor(H5vccSystem.$interfaceName); + this.interceptor_.oninterfacerequest = e => + this.receiver_.$.bindHandle(e.handle); +*/ + this.interceptor_ = + new MojoInterfaceInterceptor(H5vccSystem.$interfaceName); + this.interceptor_.oninterfacerequest = e => this.bind(e.handle); + this.receiver_ = new H5vccSystemReceiver(this); + + this.reset(); + } + + start() { + this.interceptor_.start(); + } + + stop() { + this.interceptor_.stop(); + } + + reset() { + this.id_ = 'defaultFakeAdvertisingID' + } + + bind(handle) { + this.receiver_.$.bindHandle(handle); + } + + setAdvertisingIDForTesting(id) { + console.log('setAdvertisingIDForTesting(): ' + id); + this.id_ = id; + } + + // h5vcc_system.mojom.H5vccSystem impl. + getAdvertisingId() { + // VERY IMPORTANT: this should return (a resolved Promise with) a dictionary + // with the same "key" as the mojom definition, in this case |id|. + return Promise.resolve({ id: this.id_ }); + } +} + +export const mockH5vccSystem = new MockH5vccSystem();