<commit_before><!DOCTYPE HTML>
<html>
<!--
-->
<head>
  <title>Test for SSDP.js</title>
  <script type="text/javascript" src="../src/ssdp.js"></script>
<script type="text/javascript">

// XXX fake udp socket api for test
function UDPSocket(options) {
  options = options || {};
  this._addressReuse = options.addressReuse || true;
  this._localAddress = options.localAddress || '127.0.0.1';
  this._localPort = options.localPort || 0;
  this._loopback = options.loopback || false;
}

UDPSocket.prototype = {
  _remoteAddress: null,
  _remotePort: null,
  _readyState: 'closed',
  _bufferAmount: 0,

  get localAddress() {
    return this._localAddress || '';
  },

  get localPort() {
    return this._localPort || 0;
  },

  get remoteAddress() {
    return this._remoteAddress || '';
  },

  get remotePort() {
    return this._remotePort || 0;
  },

  get addressReuse() {
    return this._addressReuse || false;
  },

  get loopback() {
    return this._loopback || false;
  },

  get bufferAmount() {
    return this._bufferAmount || 0;
  },

  get readyState() {
    return this._readyState;
  },

  set ondrain(callback) {},
  set onerror(callback) {},
  set onmessage(callback) {
    //XXX for test
    window.testOnMessage = callback;
  },

  close: function() { console.log('udp-socket::close'); },
  suspend: function() {},
  resume: function() {},
  joinMulticastGroup: function(multicastGroupAddress) {},
  leaveMulticastGroup: function(multicastGroupAddress) {},
  send: function(data, remoteAddress, remotePort) {
    remoteAddress = remoteAddress || this.remoteAddress;
    remotePort = remotePort || this.remotePort;
    console.log('udp-socket::send');
  },
};


function runTest() {

  function testAddServiceRecords(records) {
    records = [].concat(records);
    records.forEach(function(record) {
      const msgNotify = 'HTTP/1.1 200 OK\r\n' +
                        'CACHE-CONTROL: max-age=10\r\n' +
                        'DATE: ' + new Date().toUTCString() + '\r\n' +
                        'LOCATION: ' + record.location + '\r\n' +
                        'ST: ' + record.type.substr(5) + '\r\n' +
                        'USN: uuid:device-UUID::upnp:rootdevice\r\n';
      window.testOnMessage(msgNotify);
    });
  }

  const dummyType1 = 'upnp:urn:schemas-upnp-org:service:dummy:1';
  const dummyType2 = 'upnp:urn:schemas-upnp-org:service:dummy:2';
  const nonSupportType = 'zeroconf:_boxee-jsonrpc._tcp';
  const origin = window.location.origin;
  const fakeServices = [
    {
      id: 'uuid:bc0997f2-d613-43b1-93f5-03d7f3a86f30::urn:upnp-org:serviceId:dummy:1',
      name: 'upnp:urn:upnp-org:serviceId:dummy:1',
      type: dummyType1,
      url: '/dummy1/Control',
      deviceId: 'uuid:bc0997f2-d613-43b1-93f5-03d7f3a86f30',
      eventsUrl: '/dummy1/Event',
      location: origin + '/schien/ssdp.js/master/test/dummy1-desc-1.xml',
    },
    {
      id: 'uuid:7fae0ee7-87ba-4e44-a286-fcaef39be0d1::urn:upnp-org:serviceId:dummy:1',
      name: 'upnp:urn:upnp-org:serviceId:dummy:1',
      type: dummyType1,
      url: '/dummy1/Control',
      deviceId: 'uuid:7fae0ee7-87ba-4e44-a286-fcaef39be0d1',
      location: origin + '/schien/ssdp.js/master/test/dummy1-desc-2.xml',
    },
    {
      id: 'uuid:cc93d8e6-6b8b-4f60-87ca-228c36b5b0e8::urn:upnp-org:serviceId:dummy:2',
      name: 'upnp:urn:upnp-org:serviceId:dummy:2',
      type: dummyType2,
      url: '/dummy2/Control',
      deviceId: '/dummy2/Event',<commit_msg>mock SSDP response as an UDPMessageEvent<commit_after><!DOCTYPE HTML>
<html>
<!--
-->
<head>
  <title>Test for SSDP.js</title>
  <script type="text/javascript" src="../src/ssdp.js"></script>
<script type="text/javascript">

// XXX fake udp socket api for test
function UDPSocket(options) {
  options = options || {};
  this._addressReuse = options.addressReuse || true;
  this._localAddress = options.localAddress || '127.0.0.1';
  this._localPort = options.localPort || 0;
  this._loopback = options.loopback || false;
}

UDPSocket.prototype = {
  _remoteAddress: null,
  _remotePort: null,
  _readyState: 'closed',
  _bufferAmount: 0,

  get localAddress() {
    return this._localAddress || '';
  },

  get localPort() {
    return this._localPort || 0;
  },

  get remoteAddress() {
    return this._remoteAddress || '';
  },

  get remotePort() {
    return this._remotePort || 0;
  },

  get addressReuse() {
    return this._addressReuse || false;
  },

  get loopback() {
    return this._loopback || false;
  },

  get bufferAmount() {
    return this._bufferAmount || 0;
  },

  get readyState() {
    return this._readyState;
  },

  set ondrain(callback) {},
  set onerror(callback) {},
  set onmessage(callback) {
    //XXX for test
    window.testOnMessage = callback;
  },

  close: function() { console.log('udp-socket::close'); },
  suspend: function() {},
  resume: function() {},
  joinMulticastGroup: function(multicastGroupAddress) {},
  leaveMulticastGroup: function(multicastGroupAddress) {},
  send: function(data, remoteAddress, remotePort) {
    remoteAddress = remoteAddress || this.remoteAddress;
    remotePort = remotePort || this.remotePort;
    console.log('udp-socket::send');
  },
};

function UDPMessageEvent(options) {
  options = options || {};
  this.data = options.data || new ArrayBuffer(0);
  this.remoteAddress = options.remoteAddress || '';
  this.remotePort = options.remotePort || 0;
}

function runTest() {

  function testAddServiceRecords(records) {
    records = [].concat(records);
    records.forEach(function(record) {
      const msgNotify = 'HTTP/1.1 200 OK\r\n' +
                        'CACHE-CONTROL: max-age=10\r\n' +
                        'DATE: ' + new Date().toUTCString() + '\r\n' +
                        'LOCATION: ' + record.location + '\r\n' +
                        'ST: ' + record.type.substr(5) + '\r\n' +
                        'USN: uuid:device-UUID::upnp:rootdevice\r\n';
      var data = new ArrayBuffer(msgNotify.length);
      var u8array = new Uint8Array(data);
      for (var i = 0; i < msgNotify.length; i++) {
        u8array[i] = msgNotify.charCodeAt(i);
      }
      var event = new UDPMessageEvent({data: data});
      window.testOnMessage(event);
    });
  }

  const dummyType1 = 'upnp:urn:schemas-upnp-org:service:dummy:1';
  const dummyType2 = 'upnp:urn:schemas-upnp-org:service:dummy:2';
  const nonSupportType = 'zeroconf:_boxee-jsonrpc._tcp';
  const origin = window.location.origin;
  const fakeServices = [
    {
      id: 'uuid:bc0997f2-d613-43b1-93f5-03d7f3a86f30::urn:upnp-org:serviceId:dummy:1',
      name: 'upnp:urn:upnp-org:serviceId:dummy:1',
      type: dummyType1,
      url: '/dummy1/Control',
      deviceId: 'uuid:bc0997f2-d613-43b1-93f5-03d7f3a86f30',
      eventsUrl: '/dummy1/Event',
      location: origin + '/schien/ssdp.js/master/test/dummy1-desc-1.xml',
    },
    {
      id: 'uuid:7fae0ee7-87ba-4e44-a286-fcaef39be0d1::urn:upnp-org:serviceId:dummy:1',
      name: 'upnp:urn:upnp-org:serviceId:dummy:1',
      type: dummyType1,
      url: '/dummy1/Control',
      deviceId: 'uuid:7fae0ee7-87ba-4e44-a286-fcaef39be0d1',
      location: origin + '/schien/ssdp.js/master/test/dummy1-desc-2.xml',
    },
    {
      id: 'uuid:cc93d8e6-6b8b-4f60-87ca-228c36b5b0e8::urn:upnp-org:serviceId:dummy:2',
      name: 'upnp:urn:upnp-org:serviceId:dummy:2',
      type: dummyType2,
      url: '/dummy2/Control',
      deviceId: '/dummy2/Event',
{'fraction_non_alphanumeric': 0.15949264606665767, 'fraction_numerical': 0.036972068546754826, 'mean_word_length': 3.0905077262693155, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4077786', 'n_tokens_mistral': 2756, 'n_tokens_neox': 2620, 'n_words': 425}