| 1 |
'use strict'; |
| 2 |
|
| 3 |
import {SubAppsService, SubAppsServiceReceiver, SubAppsServiceResultCode} from '/gen/third_party/blink/public/mojom/subapps/sub_apps_service.mojom.m.js'; |
| 4 |
|
| 5 |
self.SubAppsServiceTest = (() => { |
| 6 |
// Class that mocks SubAppsService interface defined in /third_party/blink/public/mojom/subapps/sub_apps_service.mojom |
| 7 |
|
| 8 |
class MockSubAppsService { |
| 9 |
constructor() { |
| 10 |
this.interceptor_ = |
| 11 |
new MojoInterfaceInterceptor(SubAppsService.$interfaceName); |
| 12 |
this.receiver_ = new SubAppsServiceReceiver(this); |
| 13 |
this.interceptor_.oninterfacerequest = |
| 14 |
e => this.receiver_.$.bindHandle(e.handle); |
| 15 |
this.interceptor_.start(); |
| 16 |
} |
| 17 |
|
| 18 |
reset() { |
| 19 |
this.interceptor_.stop(); |
| 20 |
this.receiver_.$.close(); |
| 21 |
} |
| 22 |
|
| 23 |
add(sub_apps) { |
| 24 |
return Promise.resolve({ |
| 25 |
result: testInternal.addCallReturnValue, |
| 26 |
}); |
| 27 |
} |
| 28 |
|
| 29 |
list() { |
| 30 |
return Promise.resolve({ |
| 31 |
result: { |
| 32 |
resultCode: testInternal.serviceResultCode, |
| 33 |
subAppsList: testInternal.listCallReturnValue, |
| 34 |
} |
| 35 |
}); |
| 36 |
} |
| 37 |
|
| 38 |
remove() { |
| 39 |
return Promise.resolve({ |
| 40 |
result: testInternal.removeCallReturnValue, |
| 41 |
}); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
let testInternal = { |
| 46 |
initialized: false, |
| 47 |
mockSubAppsService: null, |
| 48 |
serviceResultCode: 0, |
| 49 |
addCallReturnValue: [], |
| 50 |
listCallReturnValue: [], |
| 51 |
removeCallReturnValue: [], |
| 52 |
} |
| 53 |
|
| 54 |
class SubAppsServiceTestChromium { |
| 55 |
constructor() { |
| 56 |
Object.freeze(this); // Make it immutable. |
| 57 |
} |
| 58 |
|
| 59 |
initialize(service_result_code, add_call_return_value, list_call_return_value, remove_call_return_value) { |
| 60 |
if (!testInternal.initialized) { |
| 61 |
testInternal = { |
| 62 |
mockSubAppsService: new MockSubAppsService(), |
| 63 |
initialized: true, |
| 64 |
serviceResultCode: service_result_code, |
| 65 |
addCallReturnValue: add_call_return_value, |
| 66 |
listCallReturnValue: list_call_return_value, |
| 67 |
removeCallReturnValue: remove_call_return_value, |
| 68 |
}; |
| 69 |
}; |
| 70 |
} |
| 71 |
|
| 72 |
async reset() { |
| 73 |
if (testInternal.initialized) { |
| 74 |
testInternal.mockSubAppsService.reset(); |
| 75 |
testInternal = { |
| 76 |
mockSubAppsService: null, |
| 77 |
initialized: false, |
| 78 |
serviceResultCode: 0, |
| 79 |
addCallReturnValue: [], |
| 80 |
listCallReturnValue: [], |
| 81 |
removeCallReturnValue: [], |
| 82 |
}; |
| 83 |
await new Promise(resolve => setTimeout(resolve, 0)); |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
return SubAppsServiceTestChromium; |
| 89 |
})(); |