Index: third_party/protobuf/js/binary/proto_test.js |
diff --git a/third_party/protobuf/js/binary/proto_test.js b/third_party/protobuf/js/binary/proto_test.js |
index 14d0f42e9549b64389b7c85cb3f0cfc387377e53..f86dc6455bb4896ba34b1484cc082db04858b823 100644 |
--- a/third_party/protobuf/js/binary/proto_test.js |
+++ b/third_party/protobuf/js/binary/proto_test.js |
@@ -32,6 +32,7 @@ |
goog.require('goog.crypt.base64'); |
goog.require('goog.testing.asserts'); |
+goog.require('jspb.BinaryWriter'); |
goog.require('jspb.Message'); |
// CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test |
@@ -87,6 +88,9 @@ goog.require('proto.jspb.test.extendRepeatedStringList'); |
goog.require('proto.jspb.test.extendRepeatedUint32List'); |
goog.require('proto.jspb.test.extendRepeatedUint64List'); |
+// CommonJS-LoadFromFile: ../node_modules/google-protobuf/google/protobuf/any_pb proto.google.protobuf |
+goog.require('proto.google.protobuf.Any'); |
+ |
var suite = {}; |
@@ -194,8 +198,6 @@ function bytesCompare(arr, expected) { |
* @param {proto.jspb.test.TestAllTypes} copy |
*/ |
function checkAllFields(original, copy) { |
- assertTrue(jspb.Message.equals(original, copy)); |
- |
assertEquals(copy.getOptionalInt32(), -42); |
assertEquals(copy.getOptionalInt64(), -0x7fffffff00000000); |
assertEquals(copy.getOptionalUint32(), 0x80000000); |
@@ -270,6 +272,9 @@ function checkAllFields(original, copy) { |
assertElementsEquals(copy.getPackedRepeatedFloatList(), [1.5]); |
assertElementsEquals(copy.getPackedRepeatedDoubleList(), [-1.5]); |
+ |
+ // Check last so we get more granular errors first. |
+ assertTrue(jspb.Message.equals(original, copy)); |
} |
@@ -496,7 +501,7 @@ describe('protoBinaryTest', function() { |
msg.setRepeatedBytesList([BYTES_B64, BYTES_B64]); |
assertGetters(); |
- msg.setRepeatedBytesList(null); |
+ msg.setRepeatedBytesList([]); |
assertEquals(0, msg.getRepeatedBytesList().length); |
assertEquals(0, msg.getRepeatedBytesList_asB64().length); |
assertEquals(0, msg.getRepeatedBytesList_asU8().length); |
@@ -625,4 +630,36 @@ describe('protoBinaryTest', function() { |
var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); |
checkExtensions(decoded); |
}); |
+ |
+ /** |
+ * Tests that unknown extensions don't cause deserialization failure. |
+ */ |
+ it('testUnknownExtension', function() { |
+ var msg = new proto.jspb.test.TestExtendable(); |
+ fillExtensions(msg); |
+ var writer = new jspb.BinaryWriter(); |
+ writer.writeBool((1 << 29) - 1, true); |
+ proto.jspb.test.TestExtendable.serializeBinaryToWriter(msg, writer); |
+ var encoded = writer.getResultBuffer(); |
+ var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); |
+ checkExtensions(decoded); |
+ }); |
+ |
+ it('testAnyWellKnownType', function() { |
+ var any = new proto.google.protobuf.Any(); |
+ var msg = new proto.jspb.test.TestAllTypes(); |
+ |
+ fillAllFields(msg); |
+ |
+ any.pack(msg.serializeBinary(), 'jspb.test.TestAllTypes'); |
+ |
+ assertEquals('type.googleapis.com/jspb.test.TestAllTypes', |
+ any.getTypeUrl()); |
+ |
+ var msg2 = any.unpack( |
+ proto.jspb.test.TestAllTypes.deserializeBinary, |
+ 'jspb.test.TestAllTypes'); |
+ |
+ checkAllFields(msg, msg2); |
+ }); |
}); |