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

Unified Diff: third_party/protobuf/js/message_test.js

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 4 years 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 | « third_party/protobuf/js/message.js ('k') | third_party/protobuf/js/package.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/protobuf/js/message_test.js
diff --git a/third_party/protobuf/js/message_test.js b/third_party/protobuf/js/message_test.js
index 082da944b3b1ff4c61932dbd91fa11dbb308e14e..01add5f1dd279d9b1a6c4fa7f29eccca4980770a 100644
--- a/third_party/protobuf/js/message_test.js
+++ b/third_party/protobuf/js/message_test.js
@@ -34,7 +34,6 @@ goog.setTestOnly();
goog.require('goog.json');
goog.require('goog.testing.asserts');
-goog.require('goog.userAgent');
// CommonJS-LoadFromFile: google-protobuf jspb
goog.require('jspb.Message');
@@ -67,18 +66,15 @@ goog.require('proto.jspb.test.Simple1');
goog.require('proto.jspb.test.Simple2');
goog.require('proto.jspb.test.SpecialCases');
goog.require('proto.jspb.test.TestClone');
-goog.require('proto.jspb.test.TestEndsWithBytes');
goog.require('proto.jspb.test.TestGroup');
goog.require('proto.jspb.test.TestGroup1');
goog.require('proto.jspb.test.TestMessageWithOneof');
goog.require('proto.jspb.test.TestReservedNames');
goog.require('proto.jspb.test.TestReservedNamesExtension');
-goog.require('proto.jspb.test.Deeply.Nested.Message');
// CommonJS-LoadFromFile: test2_pb proto.jspb.test
goog.require('proto.jspb.test.ExtensionMessage');
goog.require('proto.jspb.test.TestExtensionsMessage');
-goog.require('proto.jspb.test.ForeignNestedFieldMessage');
@@ -217,10 +213,6 @@ describe('Message test suite', function() {
assertEquals(true, response.getBoolField());
assertEquals(11, response.getIntField());
assertEquals(13, response.getEnumField());
- assertFalse(response.hasStringField());
- assertFalse(response.hasBoolField());
- assertFalse(response.hasIntField());
- assertFalse(response.hasEnumField());
// Test with null values, as would be returned by a JSON serializer.
response = makeDefault([null, null, null, null]);
@@ -228,10 +220,6 @@ describe('Message test suite', function() {
assertEquals(true, response.getBoolField());
assertEquals(11, response.getIntField());
assertEquals(13, response.getEnumField());
- assertFalse(response.hasStringField());
- assertFalse(response.hasBoolField());
- assertFalse(response.hasIntField());
- assertFalse(response.hasEnumField());
// Test with false-like values.
response = makeDefault(['', false, 0, 0]);
@@ -239,10 +227,6 @@ describe('Message test suite', function() {
assertEquals(false, response.getBoolField());
assertEquals(true, response.getIntField() == 0);
assertEquals(true, response.getEnumField() == 0);
- assertTrue(response.hasStringField());
- assertTrue(response.hasBoolField());
- assertTrue(response.hasIntField());
- assertTrue(response.hasEnumField());
// Test that clearing the values reverts them to the default state.
response = makeDefault(['blah', false, 111, 77]);
@@ -252,10 +236,6 @@ describe('Message test suite', function() {
assertEquals(true, response.getBoolField());
assertEquals(11, response.getIntField());
assertEquals(13, response.getEnumField());
- assertFalse(response.hasStringField());
- assertFalse(response.hasBoolField());
- assertFalse(response.hasIntField());
- assertFalse(response.hasEnumField());
// Test that setFoo(null) clears the values.
response = makeDefault(['blah', false, 111, 77]);
@@ -265,19 +245,18 @@ describe('Message test suite', function() {
assertEquals(true, response.getBoolField());
assertEquals(11, response.getIntField());
assertEquals(13, response.getEnumField());
- assertFalse(response.hasStringField());
- assertFalse(response.hasBoolField());
- assertFalse(response.hasIntField());
- assertFalse(response.hasEnumField());
});
- it('testMessageRegistration', /** @suppress {visibility} */ function() {
+ it('testMessageRegistration', function() {
// goog.require(SomeResponse) will include its library, which will in
// turn add SomeResponse to the message registry.
assertEquals(jspb.Message.registry_['res'], proto.jspb.test.SomeResponse);
});
it('testClearFields', function() {
+ // We don't set 'proper' defaults, rather, bools, strings,
+ // etc, are cleared to undefined or null and take on the Javascript
+ // meaning for that value. Repeated fields are set to [] when cleared.
var data = ['str', true, [11], [[22], [33]], ['s1', 's2']];
var foo = new proto.jspb.test.OptionalFields(data);
foo.clearAString();
@@ -285,11 +264,9 @@ describe('Message test suite', function() {
foo.clearANestedMessage();
foo.clearARepeatedMessageList();
foo.clearARepeatedStringList();
- assertEquals('', foo.getAString());
- assertEquals(false, foo.getABool());
+ assertUndefined(foo.getAString());
+ assertUndefined(foo.getABool());
assertUndefined(foo.getANestedMessage());
- assertFalse(foo.hasAString());
- assertFalse(foo.hasABool());
assertObjectEquals([], foo.getARepeatedMessageList());
assertObjectEquals([], foo.getARepeatedStringList());
// NOTE: We want the missing fields in 'expected' to be undefined,
@@ -299,17 +276,51 @@ describe('Message test suite', function() {
var expected = [,,, [], []];
expected[0] = expected[1] = expected[2] = undefined;
assertObjectEquals(expected, foo.toArray());
+
+ // Test set(null). We could deprecated this in favor of clear(), but
+ // it's also convenient to have.
+ data = ['str', true, [11], [[22], [33]], ['s1', 's2']];
+ foo = new proto.jspb.test.OptionalFields(data);
+ foo.setAString(null);
+ foo.setABool(null);
+ foo.setANestedMessage(null);
+ foo.setARepeatedMessageList(null);
+ foo.setARepeatedStringList(null);
+ assertNull(foo.getAString());
+ assertNull(foo.getABool());
+ assertNull(foo.getANestedMessage());
+ assertObjectEquals([], foo.getARepeatedMessageList());
+ assertObjectEquals([], foo.getARepeatedStringList());
+ assertObjectEquals([null, null, null, [], []], foo.toArray());
+
+ // Test set(undefined). Again, not something we really need, and not
+ // supported directly by our typing, but it should 'do the right thing'.
+ data = ['str', true, [11], [[22], [33]], ['s1', 's2']];
+ foo = new proto.jspb.test.OptionalFields(data);
+ foo.setAString(undefined);
+ foo.setABool(undefined);
+ foo.setANestedMessage(undefined);
+ foo.setARepeatedMessageList(undefined);
+ foo.setARepeatedStringList(undefined);
+ assertUndefined(foo.getAString());
+ assertUndefined(foo.getABool());
+ assertUndefined(foo.getANestedMessage());
+ assertObjectEquals([], foo.getARepeatedMessageList());
+ assertObjectEquals([], foo.getARepeatedStringList());
+ expected = [,,, [], []];
+ expected[0] = expected[1] = expected[2] = undefined;
+ assertObjectEquals(expected, foo.toArray());
});
- it('testDifferenceRawObject', /** @suppress {visibility} */ function() {
+ it('testDifferenceRawObject', function() {
var p1 = new proto.jspb.test.HasExtensions(['hi', 'diff', {}]);
var p2 = new proto.jspb.test.HasExtensions(['hi', 'what',
{1000: 'unique'}]);
var diff = /** @type {proto.jspb.test.HasExtensions} */
(jspb.Message.difference(p1, p2));
- assertEquals('', diff.getStr1());
+ assertUndefined(diff.getStr1());
assertEquals('what', diff.getStr2());
- assertEquals('', diff.getStr3());
+ assertUndefined(diff.getStr3());
assertEquals('unique', diff.extensionObject_[1000]);
});
@@ -427,8 +438,6 @@ describe('Message test suite', function() {
});
it('testClone', function() {
- var supportsUint8Array =
- !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10');
var original = new proto.jspb.test.TestClone();
original.setStr('v1');
var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]);
@@ -436,14 +445,12 @@ describe('Message test suite', function() {
var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]);
original.setSimple1(simple1);
original.setSimple2List([simple2, simple3]);
- var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123';
- original.setBytesField(bytes1);
var extension = new proto.jspb.test.CloneExtension();
extension.setExt('e1');
original.setExtension(proto.jspb.test.IsExtension.extField, extension);
- var clone = original.clone();
+ var clone = original.cloneMessage();
assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
- [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }],
+ [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]],,, { 100: [, 'e1'] }],
clone.toArray());
clone.setStr('v2');
var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]);
@@ -451,26 +458,18 @@ describe('Message test suite', function() {
var simple6 = new proto.jspb.test.Simple1(['a3', ['b3', 'c3']]);
clone.setSimple1(simple4);
clone.setSimple2List([simple5, simple6]);
- if (supportsUint8Array) {
- clone.getBytesField()[0] = 4;
- assertObjectEquals(bytes1, original.getBytesField());
- }
- var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456';
- clone.setBytesField(bytes2);
var newExtension = new proto.jspb.test.CloneExtension();
newExtension.setExt('e2');
clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension);
assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],,
- [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2,, { 100: [, 'e2'] }],
+ [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]],,, { 100: [, 'e2'] }],
clone.toArray());
assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
- [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }],
+ [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]],,, { 100: [, 'e1'] }],
original.toArray());
});
it('testCopyInto', function() {
- var supportsUint8Array =
- !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10');
var original = new proto.jspb.test.TestClone();
original.setStr('v1');
var dest = new proto.jspb.test.TestClone();
@@ -485,10 +484,6 @@ describe('Message test suite', function() {
original.setSimple2List([simple2, simple3]);
dest.setSimple1(destSimple1);
dest.setSimple2List([destSimple2, destSimple3]);
- var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123';
- var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456';
- original.setBytesField(bytes1);
- dest.setBytesField(bytes2);
var extension = new proto.jspb.test.CloneExtension();
extension.setExt('e1');
original.setExtension(proto.jspb.test.CloneExtension.extField, extension);
@@ -501,15 +496,6 @@ describe('Message test suite', function() {
dest.getSimple1().setAString('new value');
assertNotEquals(dest.getSimple1().getAString(),
original.getSimple1().getAString());
- if (supportsUint8Array) {
- dest.getBytesField()[0] = 7;
- assertObjectEquals(bytes1, original.getBytesField());
- assertObjectEquals(new Uint8Array([7, 2, 3]), dest.getBytesField());
- } else {
- dest.setBytesField('789');
- assertObjectEquals(bytes1, original.getBytesField());
- assertObjectEquals('789', dest.getBytesField());
- }
dest.getExtension(proto.jspb.test.CloneExtension.extField).
setExt('new value');
assertNotEquals(
@@ -676,12 +662,11 @@ describe('Message test suite', function() {
assertArrayEquals([1, 2, 3, {1: 'hi'}], msg.toArray());
});
- it('testExtendedMessageEnsureObject',
- /** @suppress {visibility} */ function() {
- var data =
- new proto.jspb.test.HasExtensions(['str1', {'a_key': 'an_object'}]);
- assertEquals('an_object', data.extensionObject_['a_key']);
- });
+ it('testExtendedMessageEnsureObject', function() {
+ var data = new proto.jspb.test.HasExtensions(['str1',
+ {'a_key': 'an_object'}]);
+ assertEquals('an_object', data.extensionObject_['a_key']);
+ });
it('testToObject_hasExtensionField', function() {
var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]);
@@ -768,7 +753,7 @@ describe('Message test suite', function() {
var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']);
assertEquals('x', message.getPone());
- assertEquals('', message.getPthree());
+ assertUndefined(message.getPthree());
assertEquals(
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
message.getPartialOneofCase());
@@ -777,7 +762,7 @@ describe('Message test suite', function() {
it('testKeepsLastWireValueSetInUnion_multipleValues', function() {
var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']);
- assertEquals('', message.getPone());
+ assertUndefined('x', message.getPone());
assertEquals('y', message.getPthree());
assertEquals(
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
@@ -786,47 +771,35 @@ describe('Message test suite', function() {
it('testSettingOneofFieldClearsOthers', function() {
var message = new proto.jspb.test.TestMessageWithOneof;
- assertEquals('', message.getPone());
- assertEquals('', message.getPthree());
- assertFalse(message.hasPone());
- assertFalse(message.hasPthree());
+ assertUndefined(message.getPone());
+ assertUndefined(message.getPthree());
message.setPone('hi');
assertEquals('hi', message.getPone());
- assertEquals('', message.getPthree());
- assertTrue(message.hasPone());
- assertFalse(message.hasPthree());
+ assertUndefined(message.getPthree());
message.setPthree('bye');
- assertEquals('', message.getPone());
+ assertUndefined(message.getPone());
assertEquals('bye', message.getPthree());
- assertFalse(message.hasPone());
- assertTrue(message.hasPthree());
});
it('testSettingOneofFieldDoesNotClearFieldsFromOtherUnions', function() {
var other = new proto.jspb.test.TestMessageWithOneof;
var message = new proto.jspb.test.TestMessageWithOneof;
- assertEquals('', message.getPone());
- assertEquals('', message.getPthree());
+ assertUndefined(message.getPone());
+ assertUndefined(message.getPthree());
assertUndefined(message.getRone());
- assertFalse(message.hasPone());
- assertFalse(message.hasPthree());
message.setPone('hi');
message.setRone(other);
assertEquals('hi', message.getPone());
- assertEquals('', message.getPthree());
+ assertUndefined(message.getPthree());
assertEquals(other, message.getRone());
- assertTrue(message.hasPone());
- assertFalse(message.hasPthree());
message.setPthree('bye');
- assertEquals('', message.getPone());
+ assertUndefined(message.getPone());
assertEquals('bye', message.getPthree());
assertEquals(other, message.getRone());
- assertFalse(message.hasPone());
- assertTrue(message.hasPthree());
});
it('testUnsetsOneofCaseWhenFieldIsCleared', function() {
@@ -851,7 +824,7 @@ describe('Message test suite', function() {
it('testMessageWithDefaultOneofValues', function() {
var message = new proto.jspb.test.TestMessageWithOneof;
assertEquals(1234, message.getAone());
- assertEquals(0, message.getAtwo());
+ assertUndefined(message.getAtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofACase
.DEFAULT_ONEOF_A_NOT_SET,
@@ -859,7 +832,7 @@ describe('Message test suite', function() {
message.setAone(567);
assertEquals(567, message.getAone());
- assertEquals(0, message.getAtwo());
+ assertUndefined(message.getAtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE,
message.getDefaultOneofACase());
@@ -873,7 +846,7 @@ describe('Message test suite', function() {
message.clearAtwo();
assertEquals(1234, message.getAone());
- assertEquals(0, message.getAtwo());
+ assertUndefined(message.getAtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofACase
.DEFAULT_ONEOF_A_NOT_SET,
@@ -882,10 +855,8 @@ describe('Message test suite', function() {
it('testMessageWithDefaultOneofValues_defaultNotOnFirstField', function() {
var message = new proto.jspb.test.TestMessageWithOneof;
- assertEquals(0, message.getBone());
+ assertUndefined(message.getBone());
assertEquals(1234, message.getBtwo());
- assertFalse(message.hasBone());
- assertFalse(message.hasBtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase
.DEFAULT_ONEOF_B_NOT_SET,
@@ -894,25 +865,19 @@ describe('Message test suite', function() {
message.setBone(2);
assertEquals(2, message.getBone());
assertEquals(1234, message.getBtwo());
- assertTrue(message.hasBone());
- assertFalse(message.hasBtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
message.getDefaultOneofBCase());
message.setBtwo(3);
- assertEquals(0, message.getBone());
- assertFalse(message.hasBone());
- assertTrue(message.hasBtwo());
+ assertUndefined(message.getBone());
assertEquals(3, message.getBtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
message.getDefaultOneofBCase());
message.clearBtwo();
- assertEquals(0, message.getBone());
- assertFalse(message.hasBone());
- assertFalse(message.hasBtwo());
+ assertUndefined(message.getBone());
assertEquals(1234, message.getBtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase
@@ -924,7 +889,7 @@ describe('Message test suite', function() {
var message =
new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567));
assertEquals(567, message.getAone());
- assertEquals(0, message.getAtwo());
+ assertUndefined(message.getAtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE,
message.getDefaultOneofACase());
@@ -960,7 +925,7 @@ describe('Message test suite', function() {
message =
new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890));
- assertEquals(0, message.getBone());
+ assertUndefined(message.getBone());
assertEquals(890, message.getBtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
@@ -968,7 +933,7 @@ describe('Message test suite', function() {
message = new proto.jspb.test.TestMessageWithOneof(
new Array(11).concat(567, 890));
- assertEquals(0, message.getBone());
+ assertUndefined(message.getBone());
assertEquals(890, message.getBtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
@@ -985,7 +950,7 @@ describe('Message test suite', function() {
var other = new proto.jspb.test.TestMessageWithOneof;
message.setRone(other);
assertEquals(other, message.getRone());
- assertEquals('', message.getRtwo());
+ assertUndefined(message.getRtwo());
assertEquals(
proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RONE,
message.getRecursiveOneofCase());
@@ -1003,7 +968,7 @@ describe('Message test suite', function() {
var message = new proto.jspb.test.TestMessageWithOneof;
message.setPone('x');
assertEquals('x', message.getPone());
- assertEquals('', message.getPthree());
+ assertUndefined(message.getPthree());
assertEquals(
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
message.getPartialOneofCase());
@@ -1042,21 +1007,4 @@ describe('Message test suite', function() {
assertNan(message.getDefaultDoubleField());
});
- // Verify that we can successfully use a field referring to a nested message
- // from a different .proto file.
- it('testForeignNestedMessage', function() {
- var msg = new proto.jspb.test.ForeignNestedFieldMessage();
- var nested = new proto.jspb.test.Deeply.Nested.Message();
- nested.setCount(5);
- msg.setDeeplyNestedMessage(nested);
- assertEquals(5, msg.getDeeplyNestedMessage().getCount());
-
- // After a serialization-deserialization round trip we should get back the
- // same data we started with.
- var serialized = msg.serializeBinary();
- var deserialized =
- proto.jspb.test.ForeignNestedFieldMessage.deserializeBinary(serialized);
- assertEquals(5, deserialized.getDeeplyNestedMessage().getCount());
- });
-
});
« no previous file with comments | « third_party/protobuf/js/message.js ('k') | third_party/protobuf/js/package.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698