function assertPortsEntangled(port1, port2) {
  const port2Promise = new GoogPromise((resolve, reject) => {
                         port2.onmessage = resolve;
                       }).then((e) => {
    assertEquals(
        'First port 1 should send a message to port 2', 'port1 to port2',
        e.data);
    port2.postMessage('port2 to port1');
  });

  const port1Promise = new GoogPromise((resolve, reject) => {
                         port1.onmessage = resolve;
                       }).then((e) => {
    assertEquals(
        'Then port 2 should respond to port 1', 'port2 to port1', e.data);
  });

  port1.postMessage('port1 to port2');
  return GoogPromise.all([port1Promise, port2Promise]);
}
Assert that two HTML5 MessagePorts are entangled by posting messages from
each to the other.
@param {!MessagePort} port1
@param {!MessagePort} port2
@return {!GoogPromise} Promise that settles when the assertion is complete.