OLD | NEW |
---|---|
(Empty) | |
1 /** | |
2 * Mock implementation of the budget service. | |
3 */ | |
4 | |
5 "use strict"; | |
6 | |
7 const TEST_BUDGET_COST = 1.2; | |
8 const TEST_BUDGET_AT = 2.3; | |
9 const TEST_BUDGET_TIME = new Date().getTime(); | |
Peter Beverloo
2016/08/22 17:57:55
One thing to consider:
Rather than hard coding th
harkness
2016/08/23 09:38:18
I'll make this change in the next CL when I add in
| |
10 | |
11 let budgetServiceMock = loadMojoModules( | |
12 'budgetServiceMock', | |
13 ['third_party/WebKit/public/platform/modules/budget_service/budget_service.m ojom', | |
14 'mojo/public/js/router' | |
15 ]).then(mojo => { | |
16 let [budgetService, router] = mojo.modules; | |
Peter Beverloo
2016/08/22 17:57:55
nit: s/let/const/
harkness
2016/08/23 09:38:18
Done.
| |
17 | |
18 class BudgetServiceMock { | |
19 constructor(interfaceProvider) { | |
20 interfaceProvider.addInterfaceOverrideForTesting( | |
21 budgetService.BudgetService.name, | |
22 handle => this.connectBudgetService_(handle)); | |
23 | |
24 this.interfaceProvider_ = interfaceProvider; | |
25 } | |
26 | |
27 connectBudgetService_(handle) { | |
28 this.budgetServiceStub_ = new budgetService.BudgetService.stubClass(this); | |
29 this.budgetServiceRouter_ = new router.Router(handle); | |
30 this.budgetServiceRouter_.setIncomingReceiver(this.budgetServiceStub_); | |
31 } | |
32 | |
33 getCost(operationType) { | |
34 return Promise.resolve({ cost:TEST_BUDGET_COST }); | |
35 } | |
36 | |
37 getBudget() { | |
38 return Promise.resolve({ budget: [ { time:TEST_BUDGET_TIME, budget_at:TEST _BUDGET_AT } ] }); | |
39 } | |
40 } | |
41 // Connect to the Mojo interface. | |
Peter Beverloo
2016/08/22 17:57:55
nit: drop the comment. This doesn't actually "conn
harkness
2016/08/23 09:38:18
Done.
| |
42 return new BudgetServiceMock(mojo.interfaces); | |
43 }); | |
OLD | NEW |