Commit ee57ec47 authored by Robert Knight's avatar Robert Knight

Move test for `requestId` property into `isMessage` function

Since all message types now include this property, we can check for it
in `isMessage` instead of requiring a separate check.
parent 03099a20
......@@ -139,7 +139,7 @@ export class PortProvider {
const handleRequest = event => {
const { data, origin, source } = /** @type {MessageEvent} */ (event);
if (!isMessage(data) || data.type !== 'request' || !data.requestId) {
if (!isMessage(data) || data.type !== 'request') {
// If this does not look like a message intended for us, ignore it.
return;
}
......
......@@ -24,7 +24,7 @@ export function isMessage(data) {
return false;
}
for (let property of ['frame1', 'frame2', 'type']) {
for (let property of ['frame1', 'frame2', 'type', 'requestId']) {
if (typeof data[property] !== 'string') {
return false;
}
......
......@@ -14,6 +14,7 @@ describe('port-util', () => {
frame1: 'guest',
frame2: 'sidebar',
type: 'request',
requestId: 'bar',
extraField: 'foo',
},
].forEach(data => {
......@@ -27,7 +28,15 @@ describe('port-util', () => {
undefined,
{},
'str',
{ frame1: 'guest', frame2: false, type: 'request' },
// Wrong type for a property
{ frame1: 'guest', frame2: false, type: 'request', requestId: 'bar' },
// Missing properties
{ frame2: 'sidebar', type: 'request', requestId: 'r1' }, // Missing 'frame1'
{ frame1: 'guest', type: 'request', requestId: 'r1' }, // Missing 'frame2'
{ frame1: 'guest', frame2: 'sidebar', requestId: 'r1' }, // Missing 'type'
{ frame1: 'guest', frame2: 'sidebar', type: 'request' }, // Missing 'requestId'
].forEach(data => {
it('returns false if data is not a valid message', () => {
assert.isFalse(isMessage(data));
......
......@@ -171,6 +171,7 @@ describe('FrameSyncService', () => {
frame1: 'guest',
frame2: 'sidebar',
type: 'offer',
requestId: 'abc',
},
[port1]
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment