-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
16 changes: 16 additions & 0 deletions
16
...link/web_tests/wpt_internal/h5vcc/h5vcc-system/h5vcc-system-getAdvertisingId.https.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()'); | ||
|
26 changes: 26 additions & 0 deletions
26
third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/automation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
50 changes: 50 additions & 0 deletions
50
third_party/blink/web_tests/wpt_internal/h5vcc/h5vcc-system/resources/mock-h5vcc-system.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |