aboutsummaryrefslogtreecommitdiffstats
path: root/test/support/fake_xhr.js
blob: 3f0c9d9e5e8b79255a5fda43e7672478cea9d0da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(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')]
));