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

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

Issue 2231873002: Added budget_service.mojom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@budget_api
Patch Set: Add a connection error handler to BudgetService Created 4 years, 4 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
new file mode 100644
index 0000000000000000000000000000000000000000..cb4afa32bd28a0e64aa05bd0fa6baa8330cc3648
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/budget/budget-service-mock.js
@@ -0,0 +1,42 @@
+/**
+ * Mock implementation of the budget service.
+ */
+
+"use strict";
+
+const TEST_BUDGET_COST = 1.2;
+const TEST_BUDGET_AT = 2.3;
+const TEST_BUDGET_TIME = new Date().getTime();
+
+let budgetServiceMock = loadMojoModules(
+ 'budgetServiceMock',
+ ['third_party/WebKit/public/platform/modules/budget_service/budget_service.mojom',
+ 'mojo/public/js/router'
+ ]).then(mojo => {
+ const [budgetService, router] = mojo.modules;
+
+ class BudgetServiceMock {
+ constructor(interfaceProvider) {
+ interfaceProvider.addInterfaceOverrideForTesting(
+ budgetService.BudgetService.name,
+ handle => this.connectBudgetService_(handle));
+
+ this.interfaceProvider_ = interfaceProvider;
+ }
+
+ connectBudgetService_(handle) {
+ this.budgetServiceStub_ = new budgetService.BudgetService.stubClass(this);
+ this.budgetServiceRouter_ = new router.Router(handle);
+ this.budgetServiceRouter_.setIncomingReceiver(this.budgetServiceStub_);
+ }
+
+ getCost(operationType) {
+ return Promise.resolve({ cost:TEST_BUDGET_COST });
+ }
+
+ getBudget() {
+ return Promise.resolve({ budget: [ { time:TEST_BUDGET_TIME, budget_at:TEST_BUDGET_AT } ] });
+ }
+ }
+ return new BudgetServiceMock(mojo.interfaces);
+});

Powered by Google App Engine
This is Rietveld 408576698