Skip to content

Commit

Permalink
H5vccSystem WPT
Browse files Browse the repository at this point in the history
  • Loading branch information
yell0wd0g committed Feb 7, 2025
1 parent f88d345 commit 251e77e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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()');

Original file line number Diff line number Diff line change
@@ -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);
}

Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 251e77e

Please sign in to comment.