B2G/gecko/dom/network/tests/unit/test_tcpsocket.js
/**
 * Test that calling send with enough data to buffer causes ondrain to
 * be invoked once the data has been sent, and then test that calling send
 * and buffering again causes ondrain to be fired again.
 */
Test that calling send with enough data to buffer causes ondrain to
be invoked once the data has been sent, and then test that calling send
and buffering again causes ondrain to be fired again.
Test that calling send with enough data to buffer causes ondrain to be invoked once the data has been sent and then test that calling send and buffering again causes ondrain to be fired again .
function drainTwice() {
  let yays = makeJointSuccess(
    ['ondrain', 'ondrain2',
    'ondata', 'ondata2',
    'serverclose', 'clientclose']);
  function serverSideCallback() {
    yays.ondata();
    server.ondata = makeExpectData(
      "ondata2", BIG_TYPED_ARRAY_2, false, yays.ondata2);
    sock.ondrain = yays.ondrain2;
    if (sock.send(BIG_ARRAY_BUFFER_2)) {
      do_throw("sock.send(BIG_TYPED_ARRAY_2) did not return false to indicate buffering");
    }
    sock.close();
  }
  server.onclose = yays.serverclose;
  server.ondata = makeExpectData(
    "ondata", BIG_TYPED_ARRAY, false, serverSideCallback);
  sock.onclose = yays.clientclose;
  sock.ondrain = yays.ondrain;
  if (sock.send(BIG_ARRAY_BUFFER)) {
    throw new Error("sock.send(BIG_TYPED_ARRAY) did not return false to indicate buffering");
  }
}
function drainTwice ( ) { let yays = makeJointSuccess ( [ 'ondrain' , 'ondrain2' , 'ondata' , 'ondata2' , 'serverclose' , 'clientclose' ] ) ; function serverSideCallback ( ) { yays . ondata ( ) ; server . ondata = makeExpectData ( "ondata2" , BIG_TYPED_ARRAY_2 , false , yays . ondata2 ) ; sock . ondrain = yays . ondrain2 ; if ( sock . send ( BIG_ARRAY_BUFFER_2 ) ) { do_throw ( "sock.send(BIG_TYPED_ARRAY_2) did not return false to indicate buffering" ) ; } sock . close ( ) ; } server . onclose = yays . serverclose ; server . ondata = makeExpectData ( "ondata" , BIG_TYPED_ARRAY , false , serverSideCallback ) ; sock . onclose = yays . clientclose ; sock . ondrain = yays . ondrain ; if ( sock . send ( BIG_ARRAY_BUFFER ) ) { throw new Error ( "sock.send(BIG_TYPED_ARRAY) did not return false to indicate buffering" ) ; } }
Test that calling send with enough data to buffer causes ondrain to
 be invoked once the data has been sent, and then test that calling send
 and buffering again causes ondrain to be fired again.
Test that calling send with enough data to buffer causes ondrain to be invoked once the data has been sent and then test that calling send and buffering again causes ondrain to be fired again .