Index: third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js |
diff --git a/third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js b/third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js |
index cb4afa32bd28a0e64aa05bd0fa6baa8330cc3648..3f5a0afd6ff86e648eec6a46379feceec2d7167e 100644 |
--- a/third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js |
+++ b/third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js |
@@ -22,6 +22,11 @@ let budgetServiceMock = loadMojoModules( |
handle => this.connectBudgetService_(handle)); |
this.interfaceProvider_ = interfaceProvider; |
+ |
+ // Values to return for the next getBudget and getCost calls. |
+ this.cost = new Object(); |
Peter Beverloo
2016/09/05 17:06:16
this.cost_ = {};
(underscore suffix to indicate t
harkness
2016/09/06 15:45:00
Done.
|
+ this.budget = new Array(); |
Peter Beverloo
2016/09/05 17:06:16
this.budget_ = [];
harkness
2016/09/06 15:45:00
Done.
|
+ this.error = budgetService.BudgetServiceErrorType.NO_ERROR; |
Peter Beverloo
2016/09/05 17:06:16
this.error_ = budgetService....
harkness
2016/09/06 15:45:00
Done.
|
} |
connectBudgetService_(handle) { |
@@ -30,12 +35,52 @@ let budgetServiceMock = loadMojoModules( |
this.budgetServiceRouter_.setIncomingReceiver(this.budgetServiceStub_); |
} |
+ // Set the cost of an operation type for future queries. The operationType |
+ // mapping is needed to mirror the mapping that happens in the mojo layer. |
Peter Beverloo
2016/09/05 17:06:16
My gut feel is that adding some comments above the
Peter Beverloo
2016/09/05 17:06:16
micro nit: mojo -> Mojo
harkness
2016/09/06 15:45:00
I added in a lot of comments, possibly too many. T
harkness
2016/09/06 15:45:00
Done.
|
+ setCost(operationType, cost) { |
+ var mojoOperationType = budgetService.BudgetOperationType.INVALID_OPERATION; |
Peter Beverloo
2016/09/05 17:06:16
nit: var -> let
(Try to avoid "var" everywhere. U
harkness
2016/09/06 15:45:00
Done.
|
+ if (operationType == "silent-push") |
+ mojoOperationType = budgetService.BudgetOperationType.SILENT_PUSH; |
+ |
+ this.cost[mojoOperationType] = cost; |
+ } |
+ |
getCost(operationType) { |
- return Promise.resolve({ cost:TEST_BUDGET_COST }); |
+ return Promise.resolve({ cost:this.cost[operationType] }); |
+ } |
+ |
+ // Add an entry into the budget array to be returned on the next call. |
+ addBudget(addTime, addBudget) { |
+ this.budget.push({time:addTime, budget_at:addBudget}); |
Peter Beverloo
2016/09/05 17:06:16
nit: this indentation is inconsistent with the val
harkness
2016/09/06 15:45:00
Done.
|
+ } |
+ |
+ // Set the error to be returned. This will be acted upon by the |
+ // BudgetService in blink. |
+ setError(errorName) { |
+ switch (errorName) { |
+ case "database-error": |
+ this.error = budgetService.BudgetServiceErrorType.DATABASE_ERROR; |
+ break; |
+ case "not-supported": |
+ this.error = budgetService.BudgetServiceErrorType.NOT_SUPPORTED; |
+ break; |
+ case "no-error": |
+ this.error = budgetService.BudgetServiceErrorType.NO_ERROR; |
+ break; |
+ } |
} |
getBudget() { |
- return Promise.resolve({ budget: [ { time:TEST_BUDGET_TIME, budget_at:TEST_BUDGET_AT } ] }); |
+ return Promise.resolve({ errorType:this.error, budget:this.budget }); |
+ } |
+ |
+ // Set whether the next reserve call should return success or not. |
+ setReserveSuccess(success) { |
+ this.success = success; |
+ } |
+ |
+ reserve() { |
+ return Promise.resolve({ errorType:this.error, success:this.success }); |
} |
} |
return new BudgetServiceMock(mojo.interfaces); |