function testWebSocketConnection(url, expectedToConnect) {
  var ws = new WebSocket(url);
  var kMessage = 'test message';

  var keepAlive = chrome.test.callbackAdded();

  ws.onerror = function(error) {
    chrome.test.log('WebSocket error: ' + error);
    chrome.test.assertFalse(expectedToConnect);
    keepAlive();
  };
  ws.onmessage = function(messageEvent) {
    chrome.test.log('Message received: ' + messageEvent.data);
    chrome.test.assertTrue(expectedToConnect);
    chrome.test.assertEq(kMessage, messageEvent.data);
    ws.close();
  };
  ws.onclose = function(event) {
    chrome.test.log('WebSocket closed.');
    chrome.test.assertEq(expectedToConnect, event.wasClean);
  }

  ws.onopen = function() {
    chrome.test.log('WebSocket opened.');
    chrome.test.assertTrue(expectedToConnect);
    keepAlive();
    ws.send(kMessage);
  };
}
// makes sure WebSocket terminates with an error.
makes sure WebSocket terminates with an error.
makes sure WebSocket terminates with an error .
function testWebSocketConnection(url, expectedToConnect) {
  var ws = new WebSocket(url);
  var kMessage = 'test message';
  var keepAlive = chrome.test.callbackAdded();
  ws.onerror = function(error) {
    chrome.test.log('WebSocket error: ' + error);
    chrome.test.assertFalse(expectedToConnect);
    keepAlive();
  };
  ws.onmessage = function(messageEvent) {
    chrome.test.log('Message received: ' + messageEvent.data);
    chrome.test.assertTrue(expectedToConnect);
    chrome.test.assertEq(kMessage, messageEvent.data);
    ws.close();
  };
  ws.onclose = function(event) {
    chrome.test.log('WebSocket closed.');
    chrome.test.assertEq(expectedToConnect, event.wasClean);
  }
  ws.onopen = function() {
    chrome.test.log('WebSocket opened.');
    chrome.test.assertTrue(expectedToConnect);
    keepAlive();
    ws.send(kMessage);
  };
}
function testWebSocketConnection ( url , expectedToConnect ) { var ws = new WebSocket ( url ) ; var kMessage = 'test message' ; var keepAlive = chrome . test . callbackAdded ( ) ; ws . onerror = function ( error ) { chrome . test . log ( 'WebSocket error: ' + error ) ; chrome . test . assertFalse ( expectedToConnect ) ; keepAlive ( ) ; } ; ws . onmessage = function ( messageEvent ) { chrome . test . log ( 'Message received: ' + messageEvent . data ) ; chrome . test . assertTrue ( expectedToConnect ) ; chrome . test . assertEq ( kMessage , messageEvent . data ) ; ws . close ( ) ; } ; ws . onclose = function ( event ) { chrome . test . log ( 'WebSocket closed.' ) ; chrome . test . assertEq ( expectedToConnect , event . wasClean ) ; } ws . onopen = function ( ) { chrome . test . log ( 'WebSocket opened.' ) ; chrome . test . assertTrue ( expectedToConnect ) ; keepAlive ( ) ; ws . send ( kMessage ) ; } ; }
makes sure WebSocket terminates with an error.
makes sure WebSocket terminates with an error .