blob: e27e910a72a9fb6136e2110c929631ca2f3a963a [file] [log] [blame]
'use strict';
/**
* Allows to override specific interface request handlers for
* DocumentInterfaceBroker for testing purposes
* @param {Object} overrides an object where the keys are names of
* DocumentInterfaceBroker's methods and the values are corresponding handler
* functions taking a request parameter and binding its handle to the relevant
* testing implementation.
* Example:
* const testFooImpl = new FooInterfaceCallbackRouter;
* ... override FooInterface methods ...
* setDocumentInterfaceBrokerOverrides({getFooInterface: request => {
* testFooImpl.bindHandle(request.handle);
* }});
*/
function setDocumentInterfaceBrokerOverrides(overrides) {
const {handle0, handle1} = Mojo.createMessagePipe();
const realBrokerProxy = new blink.mojom.DocumentInterfaceBrokerProxy(
Mojo.replaceDocumentInterfaceBrokerForTesting(handle0));
for (const method of Object.keys(overrides)) {
realBrokerProxy[method] = overrides[method];
}
// Use the real broker (with overrides) as the implementation of the JS-side broker
const testBrokerBinding = new blink.mojom.DocumentInterfaceBroker(realBrokerProxy);
testBrokerBinding.bindHandle(handle1);
}