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

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

Issue 2309863002: Plumb reserve method of the BudgetAPI (Closed)
Patch Set: Rename BudgetServiceErrorType::NO_ERROR to ::NONE to avoid Windows constant name clash. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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..e404dbc7c584c339838b34a5ca9cd74448dc6196 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.NONE;
}
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
+ // 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.NONE;
+ 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({ error_type: this.error_, budget: this.budget_ });
+ }
+
+ // This provides an implementation for the Mojo serivce reserve call.
+ reserve() {
+ return Promise.resolve({ error_type: this.error_, success: this.success_ });
}
}
return new BudgetServiceMock(mojo.interfaces);
« no previous file with comments | « chrome/browser/budget_service/budget_service_impl.cc ('k') | third_party/WebKit/LayoutTests/http/tests/budget/get-budget.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698