| Index: chrome/test/data/extensions/api_test/media_remoting/test_rpc.js
|
| diff --git a/chrome/test/data/extensions/api_test/media_remoting/test_rpc.js b/chrome/test/data/extensions/api_test/media_remoting/test_rpc.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1df3c31e40ebfa2d55dd2107d5ca8b4be765c937
|
| --- /dev/null
|
| +++ b/chrome/test/data/extensions/api_test/media_remoting/test_rpc.js
|
| @@ -0,0 +1,267 @@
|
| +// Copyright 2017 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.
|
| +
|
| +'use strict';
|
| +
|
| +// The RPCs used in this test. These should keep identical with those defined in
|
| +// src/media/remoting/rpc.proto.
|
| +mrTest.RpcProc = {
|
| + RPC_ACQUIRE_RENDERER: 1,
|
| + RPC_ACQUIRE_RENDERER_DONE: 2,
|
| + RPC_R_INITIALIZE: 1000,
|
| + RPC_R_STARTPLAYINGFROM: 1002,
|
| + RPC_R_INITIALIZE_CALLBACK: 1100,
|
| + RPC_DS_INITIALIZE: 3000,
|
| + RPC_DS_INITIALIZE_CALLBACK: 3100
|
| +};
|
| +
|
| +mrTest.WireType = {
|
| + INVALID: -1,
|
| + VARINT: 0,
|
| + FIXED64: 1,
|
| + DELIMITED: 2,
|
| + START_GROUP: 3,
|
| + END_GROUP: 4,
|
| + FIXED32: 5
|
| +};
|
| +
|
| +mrTest.RpcMessage = class {
|
| + constructor() {
|
| + this.handle = null;
|
| + this.proc = null;
|
| + this.integerValue = null;
|
| + this.boolValue = null;
|
| + this.rendererInitializeRpc = null;
|
| + }
|
| +
|
| + setHandle(handle) { this.handle = handle; }
|
| + setProc(proc) { this.proc = proc; }
|
| + setIntegerValue(value) { this.integerValue = value; }
|
| + setBool(boolValue) { this.boolValue = boolValue; }
|
| + setRendererInitializeRpc(msg) { this.rendererInitializeRpc = msg; }
|
| +
|
| + getHandle() { return this.handle; }
|
| + getProc() { return this.proc; }
|
| + getIntegerValue() { return this.integerValue; }
|
| + getBool() { return this.boolValue; }
|
| + getRendererInitializeRpc() { return this.rendererInitializeRpc; }
|
| +};
|
| +
|
| +mrTest.RendererInitializeRpc = class {
|
| + constructor() {
|
| + this.handle = null;
|
| + this.audioDemuxerHandle = null;
|
| + this.videoDemuxerHandle = null;
|
| + this.callbackHandle = null;
|
| + }
|
| +
|
| + setHandle(handle) { this.handle = handle; }
|
| + setAudioDemuxerHandle(handle) { this.audioDemuxerHandle = handle; }
|
| + setVideoDemuxerHandle(handle) { this.videoDemuxerHandle = handle; }
|
| + setCallbackHandle(handle) { this.callbackHandle = handle; }
|
| +
|
| + getHandle() { return this.handle; }
|
| + getAudioDemuxerHandle() { return this.audioDemuxerHandle; }
|
| + getVideoDemuxerHandle() { return this.videoDemuxerHandle; }
|
| + getCallbackHandle() { return this.callbackHandle; }
|
| +}
|
| +
|
| +// A partial RPC message deserializer.
|
| +mrTest.reader = class {
|
| + constructor(message) {
|
| + this.buf = message;
|
| + this.nextField = null;
|
| + this.nextWireType = null;
|
| + this.readPos = 0;
|
| + this.end = this.buf.length;
|
| + }
|
| +
|
| + // Returns false when reaches the end.
|
| + readNextField() {
|
| + if (this.readPos >= this.end) {
|
| + this.nextField = null;
|
| + this.nextWireType = null;
|
| + return false;
|
| + }
|
| +
|
| + let header = this.readInt32();
|
| + this.nextField = header >>> 3;
|
| + this.nextWireType = header & 0x7;
|
| + return true;
|
| + }
|
| +
|
| + readInt32() {
|
| + var tmp;
|
| + let x = 0;
|
| + for (var i = 0; i < 4; i++) {
|
| + tmp = this.buf[this.readPos++];
|
| + x |= (tmp & 0x7F) << (i * 7);
|
| + if (tmp < 128)
|
| + return x;
|
| + }
|
| + tmp = this.buf[this.readPos++];
|
| + x |= (tmp & 0x0F) << 28;
|
| + if (tmp < 128)
|
| + return x >>> 0;
|
| +
|
| + chrome.test.assertEq(tmp & 0xF0, 0xF0);
|
| + return x;
|
| + }
|
| +
|
| + deserializeRendererInitializeRpc(msg) {
|
| + let len = this.readInt32();
|
| + let oldEnd = this.end;
|
| + this.end = this.readPos + len;
|
| + while (this.readNextField()) {
|
| + if (this.nextWireType == mrTest.WireType.END_GROUP)
|
| + break;
|
| + switch (this.nextField) {
|
| + case 1:
|
| + msg.setHandle(this.readInt32());
|
| + break;
|
| + case 2:
|
| + msg.setAudioDemuxerHandle(this.readInt32());
|
| + break;
|
| + case 3:
|
| + msg.setVideoDemuxerHandle(this.readInt32());
|
| + break;
|
| + case 4:
|
| + msg.setCallbackHandle(this.readInt32());
|
| + break;
|
| + default:
|
| + // Ignore other fields.
|
| + this.skipField();
|
| + }
|
| + }
|
| + this.readPos = this.end;
|
| + this.end = oldEnd;
|
| + }
|
| +
|
| + deserializeBinary(msg) {
|
| + while (this.readNextField()) {
|
| + if (this.nextWireType == mrTest.WireType.END_GROUP)
|
| + break;
|
| + switch (this.nextField) {
|
| + case 1:
|
| + chrome.test.assertEq(this.nextWireType, mrTest.WireType.VARINT);
|
| + msg.setHandle(this.readInt32());
|
| + break;
|
| + case 2:
|
| + chrome.test.assertEq(this.nextWireType, mrTest.WireType.VARINT);
|
| + msg.setProc(this.readInt32());
|
| + break;
|
| + case 3:
|
| + chrome.test.assertEq(this.nextWireType, mrTest.WireType.VARINT);
|
| + msg.setIntegerValue(this.readInt32());
|
| + break;
|
| + case 6:
|
| + chrome.test.assertEq(this.nextWireType, mrTest.WireType.VARINT);
|
| + let value = this.readInt32();
|
| + msg.setBool(!!value);
|
| + break;
|
| + case 100:
|
| + let rendererInitializeMsg = new mrTest.RendererInitializeRpc();
|
| + this.deserializeRendererInitializeRpc(rendererInitializeMsg);
|
| + msg.setRendererInitializeRpc(rendererInitializeMsg);
|
| + break;
|
| + default:
|
| + this.skipField();
|
| + }
|
| + }
|
| + }
|
| +
|
| + skipField() {
|
| + switch (this.nextWireType) {
|
| + case mrTest.WireType.VARINT:
|
| + while (this.buf[this.readPos++] & 0x80) {}
|
| + break;
|
| + case mrTest.WireType.FIXED64:
|
| + this.readPos += 8;
|
| + break;
|
| + case mrTest.WireType.DELIMITED:
|
| + let len = this.readInt32();
|
| + this.readPos += len;
|
| + break;
|
| + case mrTest.WireType.FIXED32:
|
| + this.readPos += 4;
|
| + break;
|
| + case mrTest.WireType.START_GROUP:
|
| + this.skipGroup();
|
| + break;
|
| + default:
|
| + chrome.test.fail('wrong nextWireType_.' + this.nextWireType);
|
| + }
|
| + }
|
| +
|
| + skipGroup() {
|
| + let nestedGroups = [this.nextField];
|
| + do {
|
| + chrome.test.assertTrue(this.readNextField());
|
| + if (this.nextWireType == mrTest.WireType.START_GROUP) {
|
| + nestedGroups.push(this.nextField);
|
| + } else if (this.nextWireType == mrTest.WireType.END_GROUP) {
|
| + chrome.test.assertEq(this.nextField, nestedGroups.pop());
|
| + }
|
| + } while (nestedGroups.length > 0);
|
| + }
|
| +
|
| +};
|
| +
|
| +// A partial RPC message serializer.
|
| +mrTest.Writer = class {
|
| + constructor() {
|
| + this.buf = [];
|
| + }
|
| +
|
| + serializeMessage(msg) {
|
| + if (msg.getHandle()) {
|
| + this.writeFieldHeader(1, mrTest.WireType.VARINT);
|
| + this.writeSignedVarint32(msg.getHandle());
|
| + }
|
| + if (msg.getProc()) {
|
| + this.writeFieldHeader(2, mrTest.WireType.VARINT);
|
| + this.writeSignedVarint32(msg.getProc());
|
| + }
|
| + if (msg.getIntegerValue()) {
|
| + this.writeFieldHeader(3, mrTest.WireType.VARINT);
|
| + this.writeSignedVarint32(msg.getIntegerValue());
|
| + }
|
| + if (msg.getBool() != null) {
|
| + this.writeFieldHeader(6, mrTest.WireType.VARINT);
|
| + this.writeSignedVarint32(msg.getBool() ? 1 : 0);
|
| + }
|
| + }
|
| +
|
| + getResultBuffer() {
|
| + let flat = new Uint8Array(this.buf.length);
|
| + flat.set(this.buf, 0);
|
| + return flat;
|
| + }
|
| +
|
| + writeUnsignedVarint32(value) {
|
| + while (value > 127) {
|
| + this.buf.push((value & 0x7f) | 0x80);
|
| + value = value >>> 7;
|
| + }
|
| + this.buf.push(value);
|
| + }
|
| +
|
| + writeSignedVarint32(value) {
|
| + if (value >= 0) {
|
| + this.writeUnsignedVarint32(value);
|
| + return;
|
| + }
|
| +
|
| + for (var i=0; i < 9; i++) {
|
| + this.buf.push((value & 0x7f) | 0x80);
|
| + value = value >> 7;
|
| + }
|
| + this.buf.push(1);
|
| + }
|
| +
|
| + writeFieldHeader(field, wireType) {
|
| + this.writeUnsignedVarint32((field << 3) + wireType);
|
| + }
|
| +}
|
| +
|
|
|