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

Unified Diff: mojo/public/js/router.js

Issue 2615633005: Mojo JS bindings: remove usage of the connection module. (Closed)
Patch Set: . Created 3 years, 11 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
« no previous file with comments | « mojo/public/js/connector.js ('k') | mojo/public/js/validation_unittests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/js/router.js
diff --git a/mojo/public/js/router.js b/mojo/public/js/router.js
index e3db0a6a7888252c5aa0768480333c6928f9877e..3f0d96bca5ebe63f3ec945c78413e7f87c291f12 100644
--- a/mojo/public/js/router.js
+++ b/mojo/public/js/router.js
@@ -24,6 +24,7 @@ define("mojo/public/js/router", [
this.nextRequestID_ = 0;
this.completers_ = new Map();
this.payloadValidators_ = [];
+ this.testingController_ = null;
this.connector_.setIncomingReceiver({
accept: this.handleIncomingMessage_.bind(this),
@@ -36,6 +37,7 @@ define("mojo/public/js/router", [
Router.prototype.close = function() {
this.completers_.clear(); // Drop any responders.
this.connector_.close();
+ this.testingController_ = null;
};
Router.prototype.accept = function(message) {
@@ -81,6 +83,11 @@ define("mojo/public/js/router", [
return this.connector_.encounteredError();
};
+ Router.prototype.enableTestingMode = function() {
+ this.testingController_ = new RouterTestingController(this.connector_);
+ return this.testingController_;
+ };
+
Router.prototype.handleIncomingMessage_ = function(message) {
var noError = validator.validationError.NONE;
var messageValidator = new Validator(message);
@@ -95,6 +102,9 @@ define("mojo/public/js/router", [
};
Router.prototype.handleValidIncomingMessage_ = function(message) {
+ if (this.testingController_)
+ return;
+
if (message.expectsResponse()) {
if (this.incomingReceiver_) {
this.incomingReceiver_.acceptWithResponder(message, this);
@@ -113,11 +123,20 @@ define("mojo/public/js/router", [
if (this.incomingReceiver_)
this.incomingReceiver_.accept(message);
}
- }
+ };
Router.prototype.handleInvalidIncomingMessage_ = function(message, error) {
- this.close();
- }
+ if (!this.testingController_) {
+ // TODO(yzshen): Consider logging and notifying the embedder.
+ // TODO(yzshen): This should also trigger connection error handler.
+ // Consider making accept() return a boolean and let the connector deal
+ // with this, as the C++ code does.
+ this.close();
+ return;
+ }
+
+ this.testingController_.onInvalidIncomingMessage(error);
+ };
Router.prototype.handleConnectionError_ = function(result) {
this.completers_.forEach(function(value) {
@@ -128,25 +147,30 @@ define("mojo/public/js/router", [
this.close();
};
- // The TestRouter subclass is only intended to be used in unit tests.
- // It defeats valid message handling and delgates invalid message handling.
+ // The RouterTestingController is used in unit tests. It defeats valid message
+ // handling and delgates invalid message handling.
- function TestRouter(handle, connectorFactory) {
- Router.call(this, handle, connectorFactory);
+ function RouterTestingController(connector) {
+ this.connector_ = connector;
+ this.invalidMessageHandler_ = null;
}
- TestRouter.prototype = Object.create(Router.prototype);
+ RouterTestingController.prototype.waitForNextMessage = function() {
+ this.connector_.waitForNextMessageForTesting();
+ };
- TestRouter.prototype.handleValidIncomingMessage_ = function() {
+ RouterTestingController.prototype.setInvalidIncomingMessageHandler =
+ function(callback) {
+ this.invalidMessageHandler_ = callback;
};
- TestRouter.prototype.handleInvalidIncomingMessage_ =
- function(message, error) {
- this.validationErrorHandler(error);
- };
+ RouterTestingController.prototype.onInvalidIncomingMessage =
+ function(error) {
+ if (this.invalidMessageHandler_)
+ this.invalidMessageHandler_(error);
+ };
var exports = {};
exports.Router = Router;
- exports.TestRouter = TestRouter;
return exports;
});
« no previous file with comments | « mojo/public/js/connector.js ('k') | mojo/public/js/validation_unittests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698