Chromium Code Reviews| 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..ec106c11f82095315a2ac51efbb959fde450c0a1 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_ = {}; |
| + this.budget_ = []; |
| + this.error_ = budgetService.BudgetServiceErrorType.NO_ERROR; |
| } |
| connectBudgetService_(handle) { |
| @@ -30,12 +35,62 @@ let budgetServiceMock = loadMojoModules( |
| this.budgetServiceRouter_.setIncomingReceiver(this.budgetServiceStub_); |
| } |
| + // This is called directly from test javascript to set up the return value |
|
Peter Beverloo
2016/09/06 15:54:10
OCD: JavaScript
harkness
2016/09/06 16:17:26
Done.
|
| + // for the getCost Mojo call. The operationType mapping is needed to mirror |
| + // the mapping that happens in the Mojo layer. |
| + setCost(operationType, cost) { |
| + let mojoOperationType = budgetService.BudgetOperationType.INVALID_OPERATION; |
| + if (operationType == "silent-push") |
| + mojoOperationType = budgetService.BudgetOperationType.SILENT_PUSH; |
| + |
| + this.cost_[mojoOperationType] = cost; |
| + } |
| + |
| + |
| + // This is called directly from test javascript to set up the budget that is |
| + // returned from a later getBudget Mojo call. This adds an entry into the |
| + // budget array. |
| + addBudget(addTime, addBudget) { |
| + this.budget_.push({ time: addTime, budget_at: addBudget }); |
| + } |
| + |
| + // This is called from test javascript. It sets whether the next reserve |
| + // call should return success or not. |
| + setReserveSuccess(success) { |
| + this.success_ = success; |
| + } |
| + |
| + // Called from test javascript, this sets the error to be returned by the |
| + // Mojo service to the BudgetService in Blink. This error is never surfaced |
| + // to the test javascript, but the test code may get an exception if one of |
| + // these is set. |
| + 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; |
| + } |
| + } |
| + |
| + // This provides an implementation for the Mojo serivce getCost call. |
| getCost(operationType) { |
| - return Promise.resolve({ cost:TEST_BUDGET_COST }); |
| + return Promise.resolve({ cost: this.cost_[operationType] }); |
| } |
| + // This provides an implementation for the Mojo serivce getBudget call. |
| getBudget() { |
| - return Promise.resolve({ budget: [ { time:TEST_BUDGET_TIME, budget_at:TEST_BUDGET_AT } ] }); |
| + return Promise.resolve({ errorType: this.error_, budget: this.budget_ }); |
| + } |
| + |
| + // This provides an implementation for the Mojo serivce reserve call. |
| + reserve() { |
| + return Promise.resolve({ errorType: this.error_, success: this.success_ }); |
| } |
| } |
| return new BudgetServiceMock(mojo.interfaces); |