mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const SmsProvider = (() => {
|
|
|
|
class MockSmsReceiver {
|
|
|
|
constructor() {
|
|
this.mojoReceiver_ = new blink.mojom.SmsReceiverReceiver(this);
|
|
|
|
this.interceptor_ = new MojoInterfaceInterceptor(
|
|
blink.mojom.SmsReceiver.$interfaceName, "context", true)
|
|
|
|
this.interceptor_.oninterfacerequest = (e) => {
|
|
this.mojoReceiver_.$.bindHandle(e.handle);
|
|
}
|
|
this.interceptor_.start();
|
|
|
|
this.returnValues_ = {};
|
|
}
|
|
|
|
receive() {
|
|
let call = this.returnValues_.receive ?
|
|
this.returnValues_.receive.shift() : null;
|
|
if (!call) {
|
|
throw new Error("Unexpected call.");
|
|
}
|
|
return call();
|
|
}
|
|
|
|
pushReturnValuesForTesting(callName, value) {
|
|
this.returnValues_[callName] = this.returnValues_[callName] || [];
|
|
this.returnValues_[callName].push(value);
|
|
return this;
|
|
}
|
|
|
|
}
|
|
|
|
const mockSmsReceiver = new MockSmsReceiver();
|
|
|
|
class SmsProviderChromium {
|
|
constructor() {
|
|
Object.freeze(this); // Make it immutable.
|
|
}
|
|
|
|
pushReturnValuesForTesting(callName, callback) {
|
|
mockSmsReceiver.pushReturnValuesForTesting(callName, callback);
|
|
}
|
|
}
|
|
|
|
return SmsProviderChromium;
|
|
})();
|