Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js

Issue 2571903003: Mojo JS bindings: switch most usage of "connection"/"router" module to "bindings". (Closed)
Patch Set: remove the changes to web_ui_mojo.js which seemed to cause flakiness. Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * Mock implementation of the budget service. 2 * Mock implementation of the budget service.
3 */ 3 */
4 4
5 "use strict"; 5 "use strict";
6 6
7 const TEST_BUDGET_COST = 1.2; 7 const TEST_BUDGET_COST = 1.2;
8 const TEST_BUDGET_AT = 2.3; 8 const TEST_BUDGET_AT = 2.3;
9 const TEST_BUDGET_TIME = new Date().getTime(); 9 const TEST_BUDGET_TIME = new Date().getTime();
10 10
11 let budgetServiceMock = loadMojoModules( 11 let budgetServiceMock = loadMojoModules(
12 'budgetServiceMock', 12 'budgetServiceMock',
13 ['third_party/WebKit/public/platform/modules/budget_service/budget_service.m ojom', 13 ['third_party/WebKit/public/platform/modules/budget_service/budget_service.m ojom',
14 'mojo/public/js/router' 14 'mojo/public/js/bindings'
15 ]).then(mojo => { 15 ]).then(mojo => {
16 const [budgetService, router] = mojo.modules; 16 const [budgetService, bindings] = mojo.modules;
17 17
18 class BudgetServiceMock { 18 class BudgetServiceMock {
19 constructor(interfaceProvider) { 19 constructor(interfaceProvider) {
20 interfaceProvider.addInterfaceOverrideForTesting( 20 interfaceProvider.addInterfaceOverrideForTesting(
21 budgetService.BudgetService.name, 21 budgetService.BudgetService.name,
22 handle => this.connectBudgetService_(handle)); 22 handle => this.bindingSet_.addBinding(this, handle));
23 23
24 this.interfaceProvider_ = interfaceProvider; 24 this.interfaceProvider_ = interfaceProvider;
25 25
26 // Values to return for the next getBudget and getCost calls. 26 // Values to return for the next getBudget and getCost calls.
27 this.cost_ = {}; 27 this.cost_ = {};
28 this.budget_ = []; 28 this.budget_ = [];
29 this.error_ = budgetService.BudgetServiceErrorType.NONE; 29 this.error_ = budgetService.BudgetServiceErrorType.NONE;
30 } 30 this.bindingSet_ = new bindings.BindingSet(budgetService.BudgetService);
31
32 connectBudgetService_(handle) {
33 this.budgetServiceStub_ = new budgetService.BudgetService.stubClass(this);
34 this.budgetServiceRouter_ = new router.Router(handle);
35 this.budgetServiceRouter_.setIncomingReceiver(this.budgetServiceStub_);
36 } 31 }
37 32
38 // This is called directly from test JavaScript to set up the return value 33 // This is called directly from test JavaScript to set up the return value
39 // for the getCost Mojo call. The operationType mapping is needed to mirror 34 // for the getCost Mojo call. The operationType mapping is needed to mirror
40 // the mapping that happens in the Mojo layer. 35 // the mapping that happens in the Mojo layer.
41 setCost(operationType, cost) { 36 setCost(operationType, cost) {
42 let mojoOperationType = budgetService.BudgetOperationType.INVALID_OPERATIO N; 37 let mojoOperationType = budgetService.BudgetOperationType.INVALID_OPERATIO N;
43 if (operationType == "silent-push") 38 if (operationType == "silent-push")
44 mojoOperationType = budgetService.BudgetOperationType.SILENT_PUSH; 39 mojoOperationType = budgetService.BudgetOperationType.SILENT_PUSH;
45 40
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return Promise.resolve({ error_type: this.error_, budget: this.budget_ }); 83 return Promise.resolve({ error_type: this.error_, budget: this.budget_ });
89 } 84 }
90 85
91 // This provides an implementation for the Mojo serivce reserve call. 86 // This provides an implementation for the Mojo serivce reserve call.
92 reserve() { 87 reserve() {
93 return Promise.resolve({ error_type: this.error_, success: this.success_ } ); 88 return Promise.resolve({ error_type: this.error_, success: this.success_ } );
94 } 89 }
95 } 90 }
96 return new BudgetServiceMock(mojo.interfaces); 91 return new BudgetServiceMock(mojo.interfaces);
97 }); 92 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698