Browse Source

Change test case

Ben Hsieh 8 years ago
parent
commit
f69ced28ca
4 changed files with 239 additions and 239 deletions
  1. 1
    1
      test/test-0.7.0.js
  2. 1
    1
      test/test-0.8.2.js
  3. 2
    2
      test/test-init.js
  4. 235
    235
      test/test-xmlhttp.js

+ 1
- 1
test/test-0.7.0.js View File

@@ -19,7 +19,7 @@ const { Assert, Comparer, Info, prop } = RNTest
19 19
 const describe = RNTest.config({
20 20
   group : '0.7.0',
21 21
   run : true,
22
-  expand : true,
22
+  expand : false,
23 23
   timeout : 300000000,
24 24
 })
25 25
 const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()

+ 1
- 1
test/test-0.8.2.js View File

@@ -83,5 +83,5 @@ RNTest.config({
83 83
   setTimeout(() => {
84 84
     report(<Assert key="request does not retry" expect={1} actual={count}/>)
85 85
     done()
86
-  }, 12000)
86
+  }, 8000)
87 87
 })

+ 2
- 2
test/test-init.js View File

@@ -33,7 +33,7 @@ const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop()
33 33
 
34 34
 const describe = RNTest.config({
35 35
   run : true,
36
-  expand : false,
36
+  expand : true,
37 37
   timeout : 5000,
38 38
 })
39 39
 
@@ -70,6 +70,6 @@ describe('GET image from server', (report, done) => {
70 70
 // require('./test-fs')
71 71
 require('./test-xmlhttp')
72 72
 // require('./test-blob')
73
-require('./test-firebase')
73
+// require('./test-firebase')
74 74
 // require('./test-android')
75 75
 // require('./benchmark')

+ 235
- 235
test/test-xmlhttp.js View File

@@ -39,241 +39,241 @@ let file = RNTest.prop('image')
39 39
  * {@link https://github.com/w3c/web-platform-tests/blob/master/XMLHttpRequest/}
40 40
  */
41 41
 
42
-describe('unsent state test', (report, done) => {
43
-
44
-  let xhr = new XMLHttpRequest()
45
-
46
-  try {
47
-    xhr.setRequestHeader('x-test', 'test')
48
-  } catch(err) {
49
-    report(
50
-      <Assert key="should throw InvalidState if setRequestHeader()"
51
-        actual={/invalidstate/i.test(err)}
52
-        expect={true}
53
-      />)
54
-  }
55
-
56
-  try {
57
-    let xhr = new XMLHttpRequest()
58
-    xhr.send(null)
59
-  } catch(err) {
60
-    report(
61
-      <Assert key="should throw InvalidState if send()"
62
-        actual={/invalidstate/i.test(err)}
63
-        expect={true}
64
-      />)
65
-  }
66
-  try {
67
-    report(
68
-      <Assert key="status is 0"
69
-        expect={0}
70
-        actual={xhr.status} />,
71
-      <Assert key="statusText is empty"
72
-        expect={''}
73
-        actual={xhr.statusText} />,
74
-      <Assert key="responseHeaders is empty"
75
-        expect={''}
76
-        actual={xhr.getAllResponseHeaders()} />,
77
-      <Assert key="response header should not be set"
78
-        expect={null}
79
-        actual={xhr.getResponseHeader('x-test')} />,
80
-      <Assert key="readyState should correct"
81
-        expect={XMLHttpRequest.UNSENT}
82
-        actual={xhr.readyState} />
83
-    )
84
-    done()
85
-  } catch(err) {
86
-    console.log(err.stack)
87
-  }
88
-})
89
-
90
-describe('HTTP error should not throw error event', (report, done) => {
91
-
92
-  onError('GET', 200)
93
-  onError('GET', 400)
94
-  onError('GET', 401)
95
-  onError('GET', 404)
96
-  onError('GET', 410)
97
-  onError('GET', 500)
98
-  onError('GET', 699)
99
-
100
-  onError('HEAD', 200)
101
-  onError('HEAD', 404)
102
-  onError('HEAD', 500)
103
-  onError('HEAD', 699)
104
-
105
-  onError('POST', 200)
106
-  onError('POST', 404)
107
-  onError('POST', 500)
108
-  onError('POST', 699)
109
-
110
-  onError('PUT', 200)
111
-  onError('PUT', 404)
112
-  onError('PUT', 500)
113
-  onError('PUT', 699)
114
-
115
-  done()
116
-
117
-  let count = 0
118
-  function onError(method, code) {
119
-    let xhr = new XMLHttpRequest()
120
-    xhr.open(method, `${TEST_SERVER_URL}/xhr-code/${code}`)
121
-    xhr.onreadystatechange = function() {
122
-      count++
123
-      if(this.readyState == XMLHttpRequest.DONE) {
124
-        report(
125
-          <Assert
126
-            key={`#${count} response data of ${method} ${code} should be empty`}
127
-            expect=""
128
-            actual={xhr.response}/>,
129
-          <Assert
130
-            key={`#${count} status of ${method} ${code} should be ${code}`}
131
-            expect={code}
132
-            actual={xhr.status}/>
133
-        )
134
-      }
135
-    }
136
-    xhr.onerror = function() {
137
-      report(
138
-        <Assert
139
-          key={`HTTP error ${code} should not throw error event`}
140
-          expect={false}
141
-          actual={true}/>)
142
-    }
143
-    xhr.send()
144
-  }
145
-
146
-})
147
-
148
-describe('request headers records should be cleared by open()', (report, done) => {
149
-  let xhr = new XMLHttpRequest()
150
-  xhr.open('GET', `${TEST_SERVER_URL}/xhr-header`)
151
-  xhr.setRequestHeader('value', '100')
152
-  xhr.open('GET', `${TEST_SERVER_URL}/xhr-header`)
153
-  xhr.setRequestHeader('value', '200')
154
-  xhr.send()
155
-  xhr.onreadystatechange = function() {
156
-    if(this.readyState == 4) {
157
-      report(<Assert key="headers should be cleared by open()"
158
-        expect={'200'}
159
-        actual={this.response['value']}/>)
160
-      done()
161
-    }
162
-  }
163
-})
164
-
165
-/**
166
- *  {@link https://github.com/w3c/web-platform-tests/blob/master/XMLHttpRequest/setrequestheader-bogus-name.htm}
167
- */
168
-describe('invalid characters should not exists in header field', (report, done) => {
169
-  function try_name(name) {
170
-    try {
171
-      let client = new XMLHttpRequest()
172
-      client.open("GET", `${TEST_SERVER_URL}/public/github.png`)
173
-      client.setRequestHeader(name, '123')
174
-    } catch(err) {
175
-      report(
176
-        <Assert key={`invalid header type ${name} should throw SyntaxError`}
177
-          actual={/syntaxerror/i.test(err)}
178
-          expect={true}
179
-        />)
180
-    }
181
-  }
182
-  function try_byte_string(name) {
183
-    try {
184
-      let client = new XMLHttpRequest()
185
-      client.open("GET", `${TEST_SERVER_URL}/public/github.png`)
186
-      client.setRequestHeader(name, '123')
187
-    } catch(err) {
188
-      report(
189
-        <Assert key={`invalid header field ${name} type should throw TypeError`}
190
-          actual={/typeerror/i.test(err)}
191
-          expect={true}
192
-        />)
193
-    }
194
-  }
195
-  var invalid_headers = ["(", ")", "<", ">", "@", ",", ";", ":", "\\",
196
-                         "\"", "/", "[", "]", "?", "=", "{", "}", " ",
197
-                         "\u007f", "", "t\rt", "t\nt", "t: t", "t:t",
198
-                         "t<t", "t t", " tt", ":tt", "\ttt", "\vtt", "t\0t",
199
-                         "t\"t", "t,t", "t;t", "()[]{}", "a?B", "a=B"]
200
-  var invalid_byte_strings = ["テスト", "X-テスト"]
201
-  for (var i = 0; i < 32; ++i) {
202
-    invalid_headers.push(String.fromCharCode(i))
203
-  }
204
-  for (var i = 0; i < invalid_headers.length; ++i) {
205
-    try_name(invalid_headers[i])
206
-  }
207
-  for (var i = 0; i < invalid_byte_strings.length; ++i) {
208
-    try_byte_string(invalid_byte_strings[i])
209
-  }
210
-  done()
211
-
212
-})
213
-
214
-describe('invoke setRequestHeader() before open()', (report, done) => {
215
-  try {
216
-    let xhr = new XMLHttpRequest()
217
-    xhr.setRequestHeader('foo', 'bar')
218
-  } catch(err) {
219
-    report(
220
-      <Info key="error message">
221
-        <Text>{err}</Text>
222
-      </Info>,
223
-      <Assert key="should throw InvalidStateError"
224
-        expect={true}
225
-        actual={/invalidstateerror/i.test(err)}/>)
226
-      done()
227
-  }
228
-})
229
-
230
-describe('upload progress event test', (report, done) => {
231
-  let xhr = new XMLHttpRequest()
232
-  let time = Date.now()
233
-  let msg =  `time=${time}`
234
-  xhr.upload.onprogress = function(e) {
235
-    report(
236
-      <Assert key="event object is an instance of ProgressEvent"
237
-        expect={true}
238
-        actual={e instanceof ProgressEvent}/>)
239
-  }
240
-  xhr.onreadystatechange = function() {
241
-    if(this.readyState == XMLHttpRequest.DONE) {
242
-      console.log(xhr)
243
-      report(
244
-        <Assert key="reponse should correct"
245
-          expect={time}
246
-          actual={parseInt(xhr.response.time)}/>,
247
-        <Assert key="responseType should correct"
248
-          expect={'json'}
249
-          actual={xhr.responseType}/>)
250
-        done()
251
-    }
252
-  }
253
-  xhr.open('POST', `${TEST_SERVER_URL}/upload`)
254
-  xhr.overrideMimeType('application/x-www-form-urlencoded')
255
-  xhr.send(msg)
256
-
257
-})
258
-
259
-describe('timeout event catchable', (report, done) => {
260
-  let xhr = new XMLHttpRequest()
261
-  let count = 0
262
-  xhr.timeout = 1
263
-  xhr.ontimeout = function() {
264
-    report(
265
-      <Info key="event should only trigger once" uid="1000">
266
-        <Text>{count}</Text>
267
-      </Info>,
268
-      <Assert key="event catchable"
269
-        expect={true}
270
-        actual={true}/>)
271
-      done()
272
-  }
273
-  xhr.open('GET', `${TEST_SERVER_URL}/timeout/`)
274
-  xhr.send()
275
-
276
-})
42
+// describe('unsent state test', (report, done) => {
43
+//
44
+//   let xhr = new XMLHttpRequest()
45
+//
46
+//   try {
47
+//     xhr.setRequestHeader('x-test', 'test')
48
+//   } catch(err) {
49
+//     report(
50
+//       <Assert key="should throw InvalidState if setRequestHeader()"
51
+//         actual={/invalidstate/i.test(err)}
52
+//         expect={true}
53
+//       />)
54
+//   }
55
+//
56
+//   try {
57
+//     let xhr = new XMLHttpRequest()
58
+//     xhr.send(null)
59
+//   } catch(err) {
60
+//     report(
61
+//       <Assert key="should throw InvalidState if send()"
62
+//         actual={/invalidstate/i.test(err)}
63
+//         expect={true}
64
+//       />)
65
+//   }
66
+//   try {
67
+//     report(
68
+//       <Assert key="status is 0"
69
+//         expect={0}
70
+//         actual={xhr.status} />,
71
+//       <Assert key="statusText is empty"
72
+//         expect={''}
73
+//         actual={xhr.statusText} />,
74
+//       <Assert key="responseHeaders is empty"
75
+//         expect={''}
76
+//         actual={xhr.getAllResponseHeaders()} />,
77
+//       <Assert key="response header should not be set"
78
+//         expect={null}
79
+//         actual={xhr.getResponseHeader('x-test')} />,
80
+//       <Assert key="readyState should correct"
81
+//         expect={XMLHttpRequest.UNSENT}
82
+//         actual={xhr.readyState} />
83
+//     )
84
+//     done()
85
+//   } catch(err) {
86
+//     console.log(err.stack)
87
+//   }
88
+// })
89
+//
90
+// describe('HTTP error should not throw error event', (report, done) => {
91
+//
92
+//   onError('GET', 200)
93
+//   onError('GET', 400)
94
+//   onError('GET', 401)
95
+//   onError('GET', 404)
96
+//   onError('GET', 410)
97
+//   onError('GET', 500)
98
+//   onError('GET', 699)
99
+//
100
+//   onError('HEAD', 200)
101
+//   onError('HEAD', 404)
102
+//   onError('HEAD', 500)
103
+//   onError('HEAD', 699)
104
+//
105
+//   onError('POST', 200)
106
+//   onError('POST', 404)
107
+//   onError('POST', 500)
108
+//   onError('POST', 699)
109
+//
110
+//   onError('PUT', 200)
111
+//   onError('PUT', 404)
112
+//   onError('PUT', 500)
113
+//   onError('PUT', 699)
114
+//
115
+//   done()
116
+//
117
+//   let count = 0
118
+//   function onError(method, code) {
119
+//     let xhr = new XMLHttpRequest()
120
+//     xhr.open(method, `${TEST_SERVER_URL}/xhr-code/${code}`)
121
+//     xhr.onreadystatechange = function() {
122
+//       count++
123
+//       if(this.readyState == XMLHttpRequest.DONE) {
124
+//         report(
125
+//           <Assert
126
+//             key={`#${count} response data of ${method} ${code} should be empty`}
127
+//             expect=""
128
+//             actual={xhr.response}/>,
129
+//           <Assert
130
+//             key={`#${count} status of ${method} ${code} should be ${code}`}
131
+//             expect={code}
132
+//             actual={xhr.status}/>
133
+//         )
134
+//       }
135
+//     }
136
+//     xhr.onerror = function() {
137
+//       report(
138
+//         <Assert
139
+//           key={`HTTP error ${code} should not throw error event`}
140
+//           expect={false}
141
+//           actual={true}/>)
142
+//     }
143
+//     xhr.send()
144
+//   }
145
+//
146
+// })
147
+//
148
+// describe('request headers records should be cleared by open()', (report, done) => {
149
+//   let xhr = new XMLHttpRequest()
150
+//   xhr.open('GET', `${TEST_SERVER_URL}/xhr-header`)
151
+//   xhr.setRequestHeader('value', '100')
152
+//   xhr.open('GET', `${TEST_SERVER_URL}/xhr-header`)
153
+//   xhr.setRequestHeader('value', '200')
154
+//   xhr.send()
155
+//   xhr.onreadystatechange = function() {
156
+//     if(this.readyState == 4) {
157
+//       report(<Assert key="headers should be cleared by open()"
158
+//         expect={'200'}
159
+//         actual={this.response['value']}/>)
160
+//       done()
161
+//     }
162
+//   }
163
+// })
164
+//
165
+// /**
166
+//  *  {@link https://github.com/w3c/web-platform-tests/blob/master/XMLHttpRequest/setrequestheader-bogus-name.htm}
167
+//  */
168
+// describe('invalid characters should not exists in header field', (report, done) => {
169
+//   function try_name(name) {
170
+//     try {
171
+//       let client = new XMLHttpRequest()
172
+//       client.open("GET", `${TEST_SERVER_URL}/public/github.png`)
173
+//       client.setRequestHeader(name, '123')
174
+//     } catch(err) {
175
+//       report(
176
+//         <Assert key={`invalid header type ${name} should throw SyntaxError`}
177
+//           actual={/syntaxerror/i.test(err)}
178
+//           expect={true}
179
+//         />)
180
+//     }
181
+//   }
182
+//   function try_byte_string(name) {
183
+//     try {
184
+//       let client = new XMLHttpRequest()
185
+//       client.open("GET", `${TEST_SERVER_URL}/public/github.png`)
186
+//       client.setRequestHeader(name, '123')
187
+//     } catch(err) {
188
+//       report(
189
+//         <Assert key={`invalid header field ${name} type should throw TypeError`}
190
+//           actual={/typeerror/i.test(err)}
191
+//           expect={true}
192
+//         />)
193
+//     }
194
+//   }
195
+//   var invalid_headers = ["(", ")", "<", ">", "@", ",", ";", ":", "\\",
196
+//                          "\"", "/", "[", "]", "?", "=", "{", "}", " ",
197
+//                          "\u007f", "", "t\rt", "t\nt", "t: t", "t:t",
198
+//                          "t<t", "t t", " tt", ":tt", "\ttt", "\vtt", "t\0t",
199
+//                          "t\"t", "t,t", "t;t", "()[]{}", "a?B", "a=B"]
200
+//   var invalid_byte_strings = ["テスト", "X-テスト"]
201
+//   for (var i = 0; i < 32; ++i) {
202
+//     invalid_headers.push(String.fromCharCode(i))
203
+//   }
204
+//   for (var i = 0; i < invalid_headers.length; ++i) {
205
+//     try_name(invalid_headers[i])
206
+//   }
207
+//   for (var i = 0; i < invalid_byte_strings.length; ++i) {
208
+//     try_byte_string(invalid_byte_strings[i])
209
+//   }
210
+//   done()
211
+//
212
+// })
213
+//
214
+// describe('invoke setRequestHeader() before open()', (report, done) => {
215
+//   try {
216
+//     let xhr = new XMLHttpRequest()
217
+//     xhr.setRequestHeader('foo', 'bar')
218
+//   } catch(err) {
219
+//     report(
220
+//       <Info key="error message">
221
+//         <Text>{err}</Text>
222
+//       </Info>,
223
+//       <Assert key="should throw InvalidStateError"
224
+//         expect={true}
225
+//         actual={/invalidstateerror/i.test(err)}/>)
226
+//       done()
227
+//   }
228
+// })
229
+//
230
+// describe('upload progress event test', (report, done) => {
231
+//   let xhr = new XMLHttpRequest()
232
+//   let time = Date.now()
233
+//   let msg =  `time=${time}`
234
+//   xhr.upload.onprogress = function(e) {
235
+//     report(
236
+//       <Assert key="event object is an instance of ProgressEvent"
237
+//         expect={true}
238
+//         actual={e instanceof ProgressEvent}/>)
239
+//   }
240
+//   xhr.onreadystatechange = function() {
241
+//     if(this.readyState == XMLHttpRequest.DONE) {
242
+//       console.log(xhr)
243
+//       report(
244
+//         <Assert key="reponse should correct"
245
+//           expect={time}
246
+//           actual={parseInt(xhr.response.time)}/>,
247
+//         <Assert key="responseType should correct"
248
+//           expect={'json'}
249
+//           actual={xhr.responseType}/>)
250
+//         done()
251
+//     }
252
+//   }
253
+//   xhr.open('POST', `${TEST_SERVER_URL}/upload`)
254
+//   xhr.overrideMimeType('application/x-www-form-urlencoded')
255
+//   xhr.send(msg)
256
+//
257
+// })
258
+//
259
+// describe('timeout event catchable', (report, done) => {
260
+//   let xhr = new XMLHttpRequest()
261
+//   let count = 0
262
+//   xhr.timeout = 1
263
+//   xhr.ontimeout = function() {
264
+//     report(
265
+//       <Info key="event should only trigger once" uid="1000">
266
+//         <Text>{count}</Text>
267
+//       </Info>,
268
+//       <Assert key="event catchable"
269
+//         expect={true}
270
+//         actual={true}/>)
271
+//       done()
272
+//   }
273
+//   xhr.open('GET', `${TEST_SERVER_URL}/timeout/`)
274
+//   xhr.send()
275
+//
276
+// })
277 277
 
278 278
 describe('upload progress event should not be triggered when body is empty', (report, done) => {
279 279
   let xhr = new XMLHttpRequest()