aboutsummaryrefslogblamecommitdiffstats
path: root/test/support/fake_xhr.js
blob: 3f0c9d9e5e8b79255a5fda43e7672478cea9d0da (plain) (tree)
1
2
3
4
5
6
7
8
9






                              

                                 

   

                         


















                                            

                                                        








                                


                                                
   
(function(module) {

  function FakeXhr() {
    this.openArgs = null;
    this.sendArgs = null;
    this.headers = {};
    this.responseHeaders = {};

    FakeXhr.instances.push(this);
  }

  FakeXhr.instances = [];

  FakeXhr.prototype = {
    open: function() {
      this.openArgs = arguments;
    },

    getResponseHeader: function(key) {
      return this.responseHeaders[key];
    },

    setRequestHeader: function(key, value) {
      this.headers[key] = value;
    },

    send: function() {
      this.sendArgs = arguments;
    },

    respond: function(data, code) {
      this.readyState = 4;
      this.responseHeaders['content-type'] = 'text/xml';
      this.responseText = data;
      this.status = code || 200;
      this.onreadystatechange();
    }
  };

  module.exports = FakeXhr;

}.apply(
  this,
  (this.Caldav) ?
    [Caldav('support/fake_xhr'), Caldav] :
    [module, require('../../lib/caldav/caldav')]
));