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

Side by Side Diff: mojo/public/js/bindings/router.js

Issue 551293004: Mojo JS validation unit test should check Connection et al (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 define("mojo/public/js/bindings/router", [ 5 define("mojo/public/js/bindings/router", [
6 "mojo/public/js/bindings/codec", 6 "mojo/public/js/bindings/codec",
7 "mojo/public/js/bindings/connector", 7 "mojo/public/js/bindings/connector",
8 "mojo/public/js/bindings/validator", 8 "mojo/public/js/bindings/validator",
9 ], function(codec, connector, validator) { 9 ], function(codec, connector, validator) {
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 Router.prototype.encounteredError = function() { 64 Router.prototype.encounteredError = function() {
65 return this.connector_.encounteredError(); 65 return this.connector_.encounteredError();
66 }; 66 };
67 67
68 Router.prototype.handleIncomingMessage_ = function(message) { 68 Router.prototype.handleIncomingMessage_ = function(message) {
69 var noError = validator.validationError.NONE; 69 var noError = validator.validationError.NONE;
70 var messageValidator = new validator.Validator(message); 70 var messageValidator = new validator.Validator(message);
71 var err = messageValidator.validateMessageHeader(); 71 var err = messageValidator.validateMessageHeader();
72 for (var i = 0; err === noError && i < this.payloadValidators_.length; ++i) 72 for (var i = 0; err === noError && i < this.payloadValidators_.length; ++i)
73 err = this.payloadValidators_[i](messageValidator); 73 err = this.payloadValidators_[i](messageValidator);
74 if (err !== noError)
75 this.close();
76 74
75 if (err == noError)
76 this.handleValidIncomingMessage_(message);
77 else
78 this.handleInvalidIncomingMessage_(message, err);
79 };
80
81 Router.prototype.handleValidIncomingMessage_ = function(message) {
77 if (message.expectsResponse()) { 82 if (message.expectsResponse()) {
78 if (this.incomingReceiver_) { 83 if (this.incomingReceiver_) {
79 this.incomingReceiver_.acceptWithResponder(message, this); 84 this.incomingReceiver_.acceptWithResponder(message, this);
80 } else { 85 } else {
81 // If we receive a request expecting a response when the client is not 86 // If we receive a request expecting a response when the client is not
82 // listening, then we have no choice but to tear down the pipe. 87 // listening, then we have no choice but to tear down the pipe.
83 this.close(); 88 this.close();
84 } 89 }
85 } else if (message.isResponse()) { 90 } else if (message.isResponse()) {
86 var reader = new codec.MessageReader(message); 91 var reader = new codec.MessageReader(message);
87 var requestID = reader.requestID; 92 var requestID = reader.requestID;
88 var responder = this.responders_[requestID]; 93 var responder = this.responders_[requestID];
89 delete this.responders_[requestID]; 94 delete this.responders_[requestID];
90 responder.accept(message); 95 responder.accept(message);
91 } else { 96 } else {
92 if (this.incomingReceiver_) 97 if (this.incomingReceiver_)
93 this.incomingReceiver_.accept(message); 98 this.incomingReceiver_.accept(message);
94 } 99 }
95 }; 100 }
101
102 Router.prototype.handleInvalidIncomingMessage_ = function(message, error) {
103 this.close();
104 }
96 105
97 Router.prototype.handleConnectionError_ = function(result) { 106 Router.prototype.handleConnectionError_ = function(result) {
98 for (var each in this.responders_) 107 for (var each in this.responders_)
99 this.responders_[each].reject(result); 108 this.responders_[each].reject(result);
100 this.close(); 109 this.close();
101 }; 110 };
102 111
103 var exports = {}; 112 var exports = {};
104 exports.Router = Router; 113 exports.Router = Router;
105 return exports; 114 return exports;
106 }); 115 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698