1 | var Util = require('./util')
|
2 |
|
3 |
|
4 |
|
5 | function open() {
|
6 |
|
7 | }
|
8 |
|
9 | function send() {
|
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 | var FakeXMLHttpRequest = (function() {
|
46 |
|
47 | var STATES = {
|
48 |
|
49 | UNSENT: 0,
|
50 |
|
51 | OPENED: 1,
|
52 |
|
53 | HEADERS_RECEIVED: 2,
|
54 |
|
55 | LOADING: 3,
|
56 |
|
57 | DONE: 4
|
58 | }
|
59 |
|
60 | var HTTP_STATUS_CODES = {
|
61 | 100: "Continue",
|
62 | 101: "Switching Protocols",
|
63 | 200: "OK",
|
64 | 201: "Created",
|
65 | 202: "Accepted",
|
66 | 203: "Non-Authoritative Information",
|
67 | 204: "No Content",
|
68 | 205: "Reset Content",
|
69 | 206: "Partial Content",
|
70 | 300: "Multiple Choice",
|
71 | 301: "Moved Permanently",
|
72 | 302: "Found",
|
73 | 303: "See Other",
|
74 | 304: "Not Modified",
|
75 | 305: "Use Proxy",
|
76 | 307: "Temporary Redirect",
|
77 | 400: "Bad Request",
|
78 | 401: "Unauthorized",
|
79 | 402: "Payment Required",
|
80 | 403: "Forbidden",
|
81 | 404: "Not Found",
|
82 | 405: "Method Not Allowed",
|
83 | 406: "Not Acceptable",
|
84 | 407: "Proxy Authentication Required",
|
85 | 408: "Request Timeout",
|
86 | 409: "Conflict",
|
87 | 410: "Gone",
|
88 | 411: "Length Required",
|
89 | 412: "Precondition Failed",
|
90 | 413: "Request Entity Too Large",
|
91 | 414: "Request-URI Too Long",
|
92 | 415: "Unsupported Media Type",
|
93 | 416: "Requested Range Not Satisfiable",
|
94 | 417: "Expectation Failed",
|
95 | 422: "Unprocessable Entity",
|
96 | 500: "Internal Server Error",
|
97 | 501: "Not Implemented",
|
98 | 502: "Bad Gateway",
|
99 | 503: "Service Unavailable",
|
100 | 504: "Gateway Timeout",
|
101 | 505: "HTTP Version Not Supported"
|
102 | }
|
103 |
|
104 | function FakeXMLHttpRequest() {
|
105 | this.readyState = 0
|
106 |
|
107 | this.timeout = 0
|
108 |
|
109 | this.status = 0
|
110 | this.statusText = ""
|
111 | this.responseType = ""
|
112 | this.response = ""
|
113 | this.responseText = ""
|
114 | this.responseXML = null
|
115 | }
|
116 |
|
117 | Util.extend(FakeXMLHttpRequest, STATES)
|
118 | Util.extend(FakeXMLHttpRequest.prototype, STATES)
|
119 |
|
120 |
|
121 | Util.extend(FakeXMLHttpRequest.prototype, {
|
122 | open: function open(method, url, async, username, password) {
|
123 |
|
124 | },
|
125 | setRequestHeader: function setRequestHeader(name, value) {
|
126 |
|
127 | },
|
128 | timeout: 0,
|
129 | withCredentials: false,
|
130 | upload: {},
|
131 | send: send(data),
|
132 | abort: abort()
|
133 | })
|
134 |
|
135 |
|
136 | Util.extend(FakeXMLHttpRequest.prototype, {
|
137 | responseURL: '',
|
138 | status: '',
|
139 | statusText: '',
|
140 | getResponseHeader: function getResponseHeader(name) {
|
141 |
|
142 | },
|
143 | getAllResponseHeaders: function getAllResponseHeaders() {},
|
144 | overrideMimeType: function overrideMimeType(mime) {},
|
145 | responseType: '',
|
146 | response: undefined,
|
147 | responseText: '',
|
148 | responseXML: ''
|
149 | })
|
150 |
|
151 |
|
152 | Util.extend(FakeXMLHttpRequest.prototype, {
|
153 | addEventListene: function addEventListene() {},
|
154 | removeEventListener: function removeEventListener() {},
|
155 | dispatchEvent: function dispatchEvent() {}
|
156 | })
|
157 |
|
158 | return FakeXMLHttpRequest
|
159 |
|
160 | })()
|