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

Unified Diff: mojo/bindings/js/validation_unittests.js

Issue 406993002: Validate incoming JS Message Headers Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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: mojo/bindings/js/validation_unittests.js
diff --git a/mojo/bindings/js/validation_unittests.js b/mojo/bindings/js/validation_unittests.js
new file mode 100644
index 0000000000000000000000000000000000000000..e33ec6410577af3ebb17c093437786fb18728f5e
--- /dev/null
+++ b/mojo/bindings/js/validation_unittests.js
@@ -0,0 +1,42 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+define([
+ "console",
+ "gin/test/expect",
+ "mojo/public/js/bindings/codec",
+ "mojo/public/js/bindings/validator",
+ "mojo/bindings/js/message_file_parser"
+ ], function(console, expect, codec, validator, parser) {
+
+ function testValidateMessageHeader() {
+ var testFiles = [
+ "conformance_msghdr_incomplete_struct",
+ "conformance_msghdr_incomplete_struct_header",
+ "conformance_msghdr_invalid_flags",
+ "conformance_msghdr_missing_request_id",
+ "conformance_msghdr_num_bytes_huge",
+ //"conformance_msghdr_num_bytes_less_than_min_requirement",
+ "conformance_msghdr_num_bytes_less_than_struct_header",
+ "conformance_msghdr_num_bytes_num_fields_mismatch_1",
+ "conformance_msghdr_num_bytes_num_fields_mismatch_2",
+ "conformance_msghdr_num_bytes_num_fields_mismatch_3",
+ "conformance_msghdr_num_fields_less_than_min_requirement"
+ ];
+
+ for (var i = 0; i < testFiles.length; i++) {
+ var filename = "mojo/public/interfaces/bindings/tests/data/validation/" +
+ testFiles[i];
+ var testMessage = parser.readTestMessage(filename);
+ var buffer = new codec.Buffer(testMessage.message.data.buffer);
+ var message = new codec.Message(buffer);
+ var actualResult = validator.validateMessageHeader(message);
+ expect(actualResult).toEqual(testMessage.expected);
+ }
+ }
+
+ parser.testMessageParser();
+ testValidateMessageHeader();
+ this.result = "PASS";
+});

Powered by Google App Engine
This is Rietveld 408576698