OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // downloads api test | 5 // downloads api test |
6 // browser_tests.exe --gtest_filter=DownloadsApiTest.Downloads | 6 // browser_tests.exe --gtest_filter=DownloadsApiTest.Downloads |
7 | 7 |
8 // Comment this out to enable debugging. | 8 // Comment this out to enable debugging. |
9 console.debug = function() {}; | 9 console.debug = function() {}; |
10 | 10 |
11 function debugObject(obj) { | 11 function debugObject(obj) { |
12 for (var property in obj) { | 12 for (var property in obj) { |
13 console.debug(property + ': ' + obj[property]); | 13 console.debug(property + ': ' + obj[property]); |
14 } | 14 } |
15 } | 15 } |
16 | 16 |
17 var downloads = chrome.experimental.downloads; | |
18 window.requestFileSystem = (window.requestFileSystem || | 17 window.requestFileSystem = (window.requestFileSystem || |
19 window.webkitRequestFileSystem); | 18 window.webkitRequestFileSystem); |
20 window.BlobBuilder = (window.BlobBuilder || | 19 window.BlobBuilder = (window.BlobBuilder || |
21 window.WebKitBlobBuilder); | 20 window.WebKitBlobBuilder); |
22 | 21 |
| 22 var downloads = chrome.downloads; |
| 23 |
| 24 // These strings may change. Do not rely on them in non-test extensions. |
| 25 var ERROR_GENERIC = "I'm afraid I can't do that."; |
| 26 var ERROR_INVALID_URL = 'Invalid URL.'; |
| 27 var ERROR_INVALID_OPERATION = 'Invalid operation.'; |
| 28 |
23 chrome.test.getConfig(function(testConfig) { | 29 chrome.test.getConfig(function(testConfig) { |
24 function getURL(path) { | 30 function getURL(path) { |
25 return 'http://localhost:' + testConfig.testServer.port + '/' + path; | 31 return 'http://localhost:' + testConfig.testServer.port + '/' + path; |
26 } | 32 } |
27 | 33 |
28 var nextId = 0; | 34 var nextId = 0; |
29 function getNextId() { | 35 function getNextId() { |
30 return nextId++; | 36 return nextId++; |
31 } | 37 } |
32 | 38 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // TODO(benjhayden): Test onErased using remove(). | 84 // TODO(benjhayden): Test onErased using remove(). |
79 | 85 |
80 // TODO(benjhayden): Sub-directories depend on http://crbug.com/109443 | 86 // TODO(benjhayden): Sub-directories depend on http://crbug.com/109443 |
81 // TODO(benjhayden): Windows slashes. | 87 // TODO(benjhayden): Windows slashes. |
82 // function downloadSubDirectoryFilename() { | 88 // function downloadSubDirectoryFilename() { |
83 // var downloadId = getNextId(); | 89 // var downloadId = getNextId(); |
84 // var callbackCompleted = chrome.test.callbackAdded(); | 90 // var callbackCompleted = chrome.test.callbackAdded(); |
85 // function myListener(delta) { | 91 // function myListener(delta) { |
86 // if ((delta.id != downloadId) || | 92 // if ((delta.id != downloadId) || |
87 // !delta.filename || | 93 // !delta.filename || |
88 // (delta.filename.new.indexOf('/foo/slow') == -1)) | 94 // (delta.filename.current.indexOf('/foo/slow') == -1)) |
89 // return; | 95 // return; |
90 // downloads.onChanged.removeListener(myListener); | 96 // downloads.onChanged.removeListener(myListener); |
91 // callbackCompleted(); | 97 // callbackCompleted(); |
92 // } | 98 // } |
93 // downloads.onChanged.addListener(myListener); | 99 // downloads.onChanged.addListener(myListener); |
94 // downloads.download( | 100 // downloads.download( |
95 // {'url': SAFE_FAST_URL, 'filename': 'foo/slow'}, | 101 // {'url': SAFE_FAST_URL, 'filename': 'foo/slow'}, |
96 // chrome.test.callback(function(id) { | 102 // chrome.test.callback(function(id) { |
97 // chrome.test.assertEq(downloadId, id); | 103 // chrome.test.assertEq(downloadId, id); |
98 // })); | 104 // })); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 })); | 163 })); |
158 }, | 164 }, |
159 | 165 |
160 function downloadOnChanged() { | 166 function downloadOnChanged() { |
161 // Test that download completion is detectable by an onChanged event | 167 // Test that download completion is detectable by an onChanged event |
162 // listener. | 168 // listener. |
163 var downloadId = getNextId(); | 169 var downloadId = getNextId(); |
164 console.debug(downloadId); | 170 console.debug(downloadId); |
165 var callbackCompleted = chrome.test.callbackAdded(); | 171 var callbackCompleted = chrome.test.callbackAdded(); |
166 function myListener(delta) { | 172 function myListener(delta) { |
167 console.debug(delta.id); | 173 console.debug(JSON.stringify(delta)); |
168 if ((delta.id != downloadId) || | 174 if ((delta.id != downloadId) || |
169 !delta.state) | 175 !delta.state) |
170 return; | 176 return; |
171 chrome.test.assertEq(downloads.STATE_COMPLETE, delta.state.new); | 177 chrome.test.assertEq('complete', delta.state.current); |
172 console.debug(downloadId); | 178 console.debug(downloadId); |
173 downloads.onChanged.removeListener(myListener); | 179 downloads.onChanged.removeListener(myListener); |
174 callbackCompleted(); | 180 callbackCompleted(); |
175 } | 181 } |
176 downloads.onChanged.addListener(myListener); | 182 downloads.onChanged.addListener(myListener); |
177 downloads.download( | 183 downloads.download( |
178 {"url": SAFE_FAST_URL}, | 184 {"url": SAFE_FAST_URL}, |
179 chrome.test.callback(function(id) { | 185 chrome.test.callback(function(id) { |
180 console.debug(downloadId); | 186 console.debug(downloadId); |
181 chrome.test.assertEq(downloadId, id); | 187 chrome.test.assertEq(downloadId, id); |
182 })); | 188 })); |
183 }, | 189 }, |
184 | 190 |
185 function downloadAuthBasicFail() { | 191 function downloadAuthBasicFail() { |
186 var downloadId = getNextId(); | 192 var downloadId = getNextId(); |
187 console.debug(downloadId); | 193 console.debug(downloadId); |
188 | 194 |
189 var changedCompleted = chrome.test.callbackAdded(); | 195 var changedCompleted = chrome.test.callbackAdded(); |
190 function changedListener(delta) { | 196 function changedListener(delta) { |
191 console.debug(delta.id); | 197 console.debug(delta.id); |
192 // Ignore onChanged events for downloads besides our own, or events that | 198 // Ignore onChanged events for downloads besides our own, or events that |
193 // signal any change besides completion. | 199 // signal any change besides completion. |
194 if ((delta.id != downloadId) || | 200 if ((delta.id != downloadId) || |
195 !delta.state || | 201 !delta.state || |
196 !delta.error) | 202 !delta.error) |
197 return; | 203 return; |
198 console.debug(downloadId); | 204 console.debug(downloadId); |
199 chrome.test.assertEq(downloads.STATE_INTERRUPTED, delta.state.new); | 205 chrome.test.assertEq('interrupted', delta.state.current); |
200 chrome.test.assertEq(30, delta.error.new); | 206 chrome.test.assertEq(30, delta.error.current); |
201 downloads.onChanged.removeListener(changedListener); | 207 downloads.onChanged.removeListener(changedListener); |
202 if (changedCompleted) { | 208 if (changedCompleted) { |
203 changedCompleted(); | 209 changedCompleted(); |
204 changedCompleted = null; | 210 changedCompleted = null; |
205 } | 211 } |
206 } | 212 } |
207 downloads.onChanged.addListener(changedListener); | 213 downloads.onChanged.addListener(changedListener); |
208 | 214 |
209 // Sometimes the DownloadsEventRouter detects the item for the first time | 215 // Sometimes the DownloadsEventRouter detects the item for the first time |
210 // after the item has already been interrupted. In this case, the | 216 // after the item has already been interrupted. In this case, the |
211 // onChanged event never fires, so run the changedListener manually. If | 217 // onChanged event never fires, so run the changedListener manually. If |
212 // the DownloadsEventRouter detects the item before it's interrupted, then | 218 // the DownloadsEventRouter detects the item before it's interrupted, then |
213 // the onChanged event should fire correctly. | 219 // the onChanged event should fire correctly. |
214 var createdCompleted = chrome.test.callbackAdded(); | 220 var createdCompleted = chrome.test.callbackAdded(); |
215 function createdListener(createdItem) { | 221 function createdListener(createdItem) { |
216 console.debug(createdItem.id); | 222 console.debug(createdItem.id); |
217 // Ignore events for any download besides our own. | 223 // Ignore events for any download besides our own. |
218 if (createdItem.id != downloadId) | 224 if (createdItem.id != downloadId) |
219 return; | 225 return; |
220 console.debug(downloadId); | 226 console.debug(downloadId); |
221 downloads.onCreated.removeListener(createdListener); | 227 downloads.onCreated.removeListener(createdListener); |
222 createdCompleted(); | 228 createdCompleted(); |
223 if (createdItem.state == downloads.STATE_INTERRUPTED) { | 229 if (createdItem.state == 'interrupted') { |
224 changedListener({id: downloadId, state: {new: createdItem.state}, | 230 changedListener({id: downloadId, |
225 error: {new: createdItem.error}}); | 231 state: {current: createdItem.state}, |
| 232 error: {current: createdItem.error}}); |
226 } | 233 } |
227 } | 234 } |
228 downloads.onCreated.addListener(createdListener); | 235 downloads.onCreated.addListener(createdListener); |
229 | 236 |
230 downloads.download( | 237 downloads.download( |
231 {'url': AUTH_BASIC_URL, | 238 {'url': AUTH_BASIC_URL, |
232 'filename': downloadId + '.txt'}, | 239 'filename': downloadId + '.txt'}, |
233 chrome.test.callback(function(id) { | 240 chrome.test.callback(function(id) { |
234 console.debug(downloadId); | 241 console.debug(downloadId); |
235 chrome.test.assertEq(downloadId, id); | 242 chrome.test.assertEq(downloadId, id); |
236 })); | 243 })); |
237 }, | 244 }, |
238 | 245 |
239 function downloadAuthBasicSucceed() { | 246 function downloadAuthBasicSucceed() { |
240 var downloadId = getNextId(); | 247 var downloadId = getNextId(); |
241 console.debug(downloadId); | 248 console.debug(downloadId); |
242 | 249 |
243 var changedCompleted = chrome.test.callbackAdded(); | 250 var changedCompleted = chrome.test.callbackAdded(); |
244 function changedListener(delta) { | 251 function changedListener(delta) { |
245 console.debug(delta.id); | 252 console.debug(delta.id); |
246 // Ignore onChanged events for downloads besides our own, or events that | 253 // Ignore onChanged events for downloads besides our own, or events that |
247 // signal any change besides completion. | 254 // signal any change besides completion. |
248 if ((delta.id != downloadId) || | 255 if ((delta.id != downloadId) || |
249 !delta.state) | 256 !delta.state) |
250 return; | 257 return; |
251 chrome.test.assertEq(downloads.STATE_COMPLETE, delta.state.new); | 258 chrome.test.assertEq('complete', delta.state.current); |
252 console.debug(downloadId); | 259 console.debug(downloadId); |
253 downloads.onChanged.removeListener(changedListener); | 260 downloads.onChanged.removeListener(changedListener); |
254 changedCompleted(); | 261 changedCompleted(); |
255 } | 262 } |
256 downloads.onChanged.addListener(changedListener); | 263 downloads.onChanged.addListener(changedListener); |
257 | 264 |
258 downloads.download( | 265 downloads.download( |
259 {'url': AUTH_BASIC_URL, | 266 {'url': AUTH_BASIC_URL, |
260 'headers': [{'name': 'Authorization', | 267 'headers': [{'name': 'Authorization', |
261 'value': 'Basic ' + AUTHORIZATION}], | 268 'value': 'Basic ' + AUTHORIZATION}], |
262 'filename': downloadId + '.txt'}, | 269 'filename': downloadId + '.txt'}, |
263 chrome.test.callback(function(id) { | 270 chrome.test.callback(function(id) { |
264 console.debug(downloadId); | 271 console.debug(downloadId); |
265 chrome.test.assertEq(downloadId, id); | 272 chrome.test.assertEq(downloadId, id); |
266 })); | 273 })); |
267 }, | 274 }, |
268 | 275 |
269 function downloadPostSuccess() { | 276 function downloadPostSuccess() { |
270 // Test the |method| download option. | 277 // Test the |method| download option. |
271 var downloadId = getNextId(); | 278 var downloadId = getNextId(); |
272 console.debug(downloadId); | 279 console.debug(downloadId); |
273 var changedCompleted = chrome.test.callbackAdded(); | 280 var changedCompleted = chrome.test.callbackAdded(); |
274 function changedListener(delta) { | 281 function changedListener(delta) { |
275 console.debug(delta.id); | 282 console.debug(delta.id); |
276 // Ignore onChanged events for downloads besides our own, or events that | 283 // Ignore onChanged events for downloads besides our own, or events that |
277 // signal any change besides completion. | 284 // signal any change besides completion. |
278 if ((delta.id != downloadId) || | 285 if ((delta.id != downloadId) || |
279 !delta.state) | 286 !delta.state) |
280 return; | 287 return; |
281 chrome.test.assertEq(downloads.STATE_COMPLETE, delta.state.new); | 288 chrome.test.assertEq('complete', delta.state.current); |
282 console.debug(downloadId); | 289 console.debug(downloadId); |
283 downloads.search({id: downloadId}, | 290 downloads.search({id: downloadId}, |
284 chrome.test.callback(function(items) { | 291 chrome.test.callback(function(items) { |
285 console.debug(downloadId); | 292 console.debug(downloadId); |
286 chrome.test.assertEq(1, items.length); | 293 chrome.test.assertEq(1, items.length); |
287 chrome.test.assertEq(downloadId, items[0].id); | 294 chrome.test.assertEq(downloadId, items[0].id); |
288 debugObject(items[0]); | 295 debugObject(items[0]); |
289 var EXPECTED_SIZE = 164; | 296 var EXPECTED_SIZE = 164; |
290 chrome.test.assertEq(EXPECTED_SIZE, items[0].bytesReceived); | 297 chrome.test.assertEq(EXPECTED_SIZE, items[0].bytesReceived); |
291 })); | 298 })); |
(...skipping 24 matching lines...) Expand all Loading... |
316 | 323 |
317 var changedCompleted = chrome.test.callbackAdded(); | 324 var changedCompleted = chrome.test.callbackAdded(); |
318 function changedListener(delta) { | 325 function changedListener(delta) { |
319 console.debug(delta.id); | 326 console.debug(delta.id); |
320 // Ignore onChanged events for downloads besides our own, or events that | 327 // Ignore onChanged events for downloads besides our own, or events that |
321 // signal any change besides interruption. | 328 // signal any change besides interruption. |
322 if ((delta.id != downloadId) || | 329 if ((delta.id != downloadId) || |
323 !delta.state || | 330 !delta.state || |
324 !delta.error) | 331 !delta.error) |
325 return; | 332 return; |
326 chrome.test.assertEq(downloads.STATE_INTERRUPTED, delta.state.new); | 333 chrome.test.assertEq('interrupted', delta.state.current); |
327 chrome.test.assertEq(33, delta.error.new); | 334 chrome.test.assertEq(33, delta.error.current); |
328 console.debug(downloadId); | 335 console.debug(downloadId); |
329 downloads.onChanged.removeListener(changedListener); | 336 downloads.onChanged.removeListener(changedListener); |
330 if (changedCompleted) { | 337 if (changedCompleted) { |
331 changedCompleted(); | 338 changedCompleted(); |
332 changedCompleted = null; | 339 changedCompleted = null; |
333 } | 340 } |
334 } | 341 } |
335 downloads.onChanged.addListener(changedListener); | 342 downloads.onChanged.addListener(changedListener); |
336 | 343 |
337 // Sometimes the DownloadsEventRouter detects the item for the first time | 344 // Sometimes the DownloadsEventRouter detects the item for the first time |
338 // after the item has already been interrupted. In this case, the | 345 // after the item has already been interrupted. In this case, the |
339 // onChanged event never fires, so run the changedListener manually. If | 346 // onChanged event never fires, so run the changedListener manually. If |
340 // the DownloadsEventRouter detects the item before it's interrupted, then | 347 // the DownloadsEventRouter detects the item before it's interrupted, then |
341 // the onChanged event should fire correctly. | 348 // the onChanged event should fire correctly. |
342 var createdCompleted = chrome.test.callbackAdded(); | 349 var createdCompleted = chrome.test.callbackAdded(); |
343 function createdListener(createdItem) { | 350 function createdListener(createdItem) { |
344 console.debug(createdItem.id); | 351 console.debug(createdItem.id); |
345 // Ignore events for any download besides our own. | 352 // Ignore events for any download besides our own. |
346 if (createdItem.id != downloadId) | 353 if (createdItem.id != downloadId) |
347 return; | 354 return; |
348 console.debug(downloadId); | 355 console.debug(downloadId); |
349 downloads.onCreated.removeListener(createdListener); | 356 downloads.onCreated.removeListener(createdListener); |
350 createdCompleted(); | 357 createdCompleted(); |
351 if (createdItem.state == downloads.STATE_INTERRUPTED) { | 358 if (createdItem.state == 'interrupted') { |
352 changedListener({id: downloadId, state: {new: createdItem.state}, | 359 changedListener({id: downloadId, |
353 error: {new: createdItem.error}}); | 360 state: {current: createdItem.state}, |
| 361 error: {current: createdItem.error}}); |
354 } | 362 } |
355 } | 363 } |
356 downloads.onCreated.addListener(createdListener); | 364 downloads.onCreated.addListener(createdListener); |
357 | 365 |
358 downloads.download( | 366 downloads.download( |
359 {'url': POST_URL, | 367 {'url': POST_URL, |
360 'filename': downloadId + '.txt', // Prevent 'file' danger. | 368 'filename': downloadId + '.txt', // Prevent 'file' danger. |
361 'body': 'BODY'}, | 369 'body': 'BODY'}, |
362 chrome.test.callback(function(id) { | 370 chrome.test.callback(function(id) { |
363 console.debug(downloadId); | 371 console.debug(downloadId); |
(...skipping 12 matching lines...) Expand all Loading... |
376 | 384 |
377 var changedCompleted = chrome.test.callbackAdded(); | 385 var changedCompleted = chrome.test.callbackAdded(); |
378 function changedListener(delta) { | 386 function changedListener(delta) { |
379 console.debug(delta.id); | 387 console.debug(delta.id); |
380 // Ignore onChanged events for downloads besides our own, or events that | 388 // Ignore onChanged events for downloads besides our own, or events that |
381 // signal any change besides interruption. | 389 // signal any change besides interruption. |
382 if ((delta.id != downloadId) || | 390 if ((delta.id != downloadId) || |
383 !delta.state || | 391 !delta.state || |
384 !delta.error) | 392 !delta.error) |
385 return; | 393 return; |
386 chrome.test.assertEq(downloads.STATE_INTERRUPTED, delta.state.new); | 394 chrome.test.assertEq('interrupted', delta.state.current); |
387 chrome.test.assertEq(33, delta.error.new); | 395 chrome.test.assertEq(33, delta.error.current); |
388 if (delta.error) console.debug(delta.error.new); | 396 if (delta.error) console.debug(delta.error.current); |
389 console.debug(downloadId); | 397 console.debug(downloadId); |
390 downloads.onChanged.removeListener(changedListener); | 398 downloads.onChanged.removeListener(changedListener); |
391 if (changedCompleted) { | 399 if (changedCompleted) { |
392 changedCompleted(); | 400 changedCompleted(); |
393 changedCompleted = null; | 401 changedCompleted = null; |
394 } | 402 } |
395 } | 403 } |
396 downloads.onChanged.addListener(changedListener); | 404 downloads.onChanged.addListener(changedListener); |
397 | 405 |
398 // Sometimes the DownloadsEventRouter detects the item for the first time | 406 // Sometimes the DownloadsEventRouter detects the item for the first time |
399 // after the item has already been interrupted. In this case, the | 407 // after the item has already been interrupted. In this case, the |
400 // onChanged event never fires, so run the changedListener manually. If | 408 // onChanged event never fires, so run the changedListener manually. If |
401 // the DownloadsEventRouter detects the item before it's interrupted, then | 409 // the DownloadsEventRouter detects the item before it's interrupted, then |
402 // the onChanged event should fire correctly. | 410 // the onChanged event should fire correctly. |
403 var createdCompleted = chrome.test.callbackAdded(); | 411 var createdCompleted = chrome.test.callbackAdded(); |
404 function createdListener(createdItem) { | 412 function createdListener(createdItem) { |
405 console.debug(createdItem.id); | 413 console.debug(createdItem.id); |
406 // Ignore events for any download besides our own. | 414 // Ignore events for any download besides our own. |
407 if (createdItem.id != downloadId) | 415 if (createdItem.id != downloadId) |
408 return; | 416 return; |
409 console.debug(downloadId); | 417 console.debug(downloadId); |
410 downloads.onCreated.removeListener(createdListener); | 418 downloads.onCreated.removeListener(createdListener); |
411 createdCompleted(); | 419 createdCompleted(); |
412 if (createdItem.state == downloads.STATE_INTERRUPTED) { | 420 if (createdItem.state == 'interrupted') { |
413 changedListener({id: downloadId, state: {new: createdItem.state}, | 421 changedListener({id: downloadId, |
414 error: {new: createdItem.error}}); | 422 state: {current: createdItem.state}, |
| 423 error: {current: createdItem.error}}); |
415 } | 424 } |
416 } | 425 } |
417 downloads.onCreated.addListener(createdListener); | 426 downloads.onCreated.addListener(createdListener); |
418 | 427 |
419 downloads.download( | 428 downloads.download( |
420 {'url': POST_URL, | 429 {'url': POST_URL, |
421 'filename': downloadId + '.txt', // Prevent 'file' danger. | 430 'filename': downloadId + '.txt', // Prevent 'file' danger. |
422 'method': 'POST'}, | 431 'method': 'POST'}, |
423 chrome.test.callback(function(id) { | 432 chrome.test.callback(function(id) { |
424 console.debug(downloadId); | 433 console.debug(downloadId); |
425 chrome.test.assertEq(downloadId, id); | 434 chrome.test.assertEq(downloadId, id); |
426 })); | 435 })); |
427 }, | 436 }, |
428 | 437 |
429 function downloadHeadersSuccess() { | 438 function downloadHeadersSuccess() { |
430 // Test the |header| download option. | 439 // Test the |header| download option. |
431 var downloadId = getNextId(); | 440 var downloadId = getNextId(); |
432 console.debug(downloadId); | 441 console.debug(downloadId); |
433 var changedCompleted = chrome.test.callbackAdded(); | 442 var changedCompleted = chrome.test.callbackAdded(); |
434 function changedListener(delta) { | 443 function changedListener(delta) { |
435 console.debug(delta.id); | 444 console.debug(delta.id); |
436 // Ignore onChanged events for downloads besides our own, or events that | 445 // Ignore onChanged events for downloads besides our own, or events that |
437 // signal any change besides completion. | 446 // signal any change besides completion. |
438 if ((delta.id != downloadId) || | 447 if ((delta.id != downloadId) || |
439 !delta.state) | 448 !delta.state) |
440 return; | 449 return; |
441 chrome.test.assertEq(downloads.STATE_COMPLETE, delta.state.new); | 450 chrome.test.assertEq('complete', delta.state.current); |
442 console.debug(downloadId); | 451 console.debug(downloadId); |
443 downloads.search({id: downloadId}, | 452 downloads.search({id: downloadId}, |
444 chrome.test.callback(function(items) { | 453 chrome.test.callback(function(items) { |
445 console.debug(downloadId); | 454 console.debug(downloadId); |
446 chrome.test.assertEq(1, items.length); | 455 chrome.test.assertEq(1, items.length); |
447 chrome.test.assertEq(downloadId, items[0].id); | 456 chrome.test.assertEq(downloadId, items[0].id); |
448 debugObject(items[0]); | 457 debugObject(items[0]); |
449 var EXPECTED_SIZE = 164; | 458 var EXPECTED_SIZE = 164; |
450 chrome.test.assertEq(EXPECTED_SIZE, items[0].bytesReceived); | 459 chrome.test.assertEq(EXPECTED_SIZE, items[0].bytesReceived); |
451 })); | 460 })); |
(...skipping 18 matching lines...) Expand all Loading... |
470 var downloadId = getNextId(); | 479 var downloadId = getNextId(); |
471 console.debug(downloadId); | 480 console.debug(downloadId); |
472 var changedCompleted = chrome.test.callbackAdded(); | 481 var changedCompleted = chrome.test.callbackAdded(); |
473 function changedListener(delta) { | 482 function changedListener(delta) { |
474 console.debug(delta.id); | 483 console.debug(delta.id); |
475 // Ignore onChanged events for downloads besides our own, or events that | 484 // Ignore onChanged events for downloads besides our own, or events that |
476 // signal any change besides completion. | 485 // signal any change besides completion. |
477 if ((delta.id != downloadId) || | 486 if ((delta.id != downloadId) || |
478 !delta.state) | 487 !delta.state) |
479 return; | 488 return; |
480 chrome.test.assertEq(downloads.STATE_COMPLETE, delta.state.new); | 489 chrome.test.assertEq('complete', delta.state.current); |
481 console.debug(downloadId); | 490 console.debug(downloadId); |
482 downloads.search({id: downloadId}, | 491 downloads.search({id: downloadId}, |
483 chrome.test.callback(function(items) { | 492 chrome.test.callback(function(items) { |
484 console.debug(downloadId); | 493 console.debug(downloadId); |
485 chrome.test.assertEq(1, items.length); | 494 chrome.test.assertEq(1, items.length); |
486 chrome.test.assertEq(downloadId, items[0].id); | 495 chrome.test.assertEq(downloadId, items[0].id); |
487 debugObject(items[0]); | 496 debugObject(items[0]); |
488 var EXPECTED_SIZE = 164; | 497 var EXPECTED_SIZE = 164; |
489 chrome.test.assertEq(EXPECTED_SIZE, items[0].bytesReceived); | 498 chrome.test.assertEq(EXPECTED_SIZE, items[0].bytesReceived); |
490 })); | 499 })); |
(...skipping 24 matching lines...) Expand all Loading... |
515 | 524 |
516 var changedCompleted = chrome.test.callbackAdded(); | 525 var changedCompleted = chrome.test.callbackAdded(); |
517 function changedListener(delta) { | 526 function changedListener(delta) { |
518 console.debug(delta.id); | 527 console.debug(delta.id); |
519 // Ignore onChanged events for downloads besides our own, or events that | 528 // Ignore onChanged events for downloads besides our own, or events that |
520 // signal any change besides interruption. | 529 // signal any change besides interruption. |
521 if ((delta.id != downloadId) || | 530 if ((delta.id != downloadId) || |
522 !delta.state || | 531 !delta.state || |
523 !delta.error) | 532 !delta.error) |
524 return; | 533 return; |
525 chrome.test.assertEq(downloads.STATE_INTERRUPTED, delta.state.new); | 534 chrome.test.assertEq('interrupted', delta.state.current); |
526 chrome.test.assertEq(33, delta.error.new); | 535 chrome.test.assertEq(33, delta.error.current); |
527 console.debug(downloadId); | 536 console.debug(downloadId); |
528 downloads.onChanged.removeListener(changedListener); | 537 downloads.onChanged.removeListener(changedListener); |
529 if (changedCompleted) { | 538 if (changedCompleted) { |
530 changedCompleted(); | 539 changedCompleted(); |
531 changedCompleted = null; | 540 changedCompleted = null; |
532 } | 541 } |
533 } | 542 } |
534 downloads.onChanged.addListener(changedListener); | 543 downloads.onChanged.addListener(changedListener); |
535 | 544 |
536 // Sometimes the DownloadsEventRouter detects the item for the first time | 545 // Sometimes the DownloadsEventRouter detects the item for the first time |
537 // after the item has already been interrupted. In this case, the | 546 // after the item has already been interrupted. In this case, the |
538 // onChanged event never fires, so run the changedListener manually. If | 547 // onChanged event never fires, so run the changedListener manually. If |
539 // the DownloadsEventRouter detects the item before it's interrupted, then | 548 // the DownloadsEventRouter detects the item before it's interrupted, then |
540 // the onChanged event should fire correctly. | 549 // the onChanged event should fire correctly. |
541 var createdCompleted = chrome.test.callbackAdded(); | 550 var createdCompleted = chrome.test.callbackAdded(); |
542 function createdListener(createdItem) { | 551 function createdListener(createdItem) { |
543 console.debug(createdItem.id); | 552 console.debug(createdItem.id); |
544 // Ignore events for any download besides our own. | 553 // Ignore events for any download besides our own. |
545 if (createdItem.id != downloadId) | 554 if (createdItem.id != downloadId) |
546 return; | 555 return; |
547 console.debug(downloadId); | 556 console.debug(downloadId); |
548 downloads.onCreated.removeListener(createdListener); | 557 downloads.onCreated.removeListener(createdListener); |
549 createdCompleted(); | 558 createdCompleted(); |
550 if (createdItem.state == downloads.STATE_INTERRUPTED) { | 559 if (createdItem.state == 'interrupted') { |
551 changedListener({id: downloadId, state: {new: createdItem.state}, | 560 changedListener({id: downloadId, |
552 error: {new: createdItem.error}}); | 561 state: {current: createdItem.state}, |
| 562 error: {current: createdItem.error}}); |
553 } | 563 } |
554 } | 564 } |
555 downloads.onCreated.addListener(createdListener); | 565 downloads.onCreated.addListener(createdListener); |
556 | 566 |
557 downloads.download( | 567 downloads.download( |
558 {'url': HEADERS_URL}, | 568 {'url': HEADERS_URL}, |
559 chrome.test.callback(function(id) { | 569 chrome.test.callback(function(id) { |
560 console.debug(downloadId); | 570 console.debug(downloadId); |
561 chrome.test.assertEq(downloadId, id); | 571 chrome.test.assertEq(downloadId, id); |
562 })); | 572 })); |
563 }, | 573 }, |
564 | 574 |
565 function downloadHeadersInvalid0() { | 575 function downloadHeadersInvalid0() { |
566 // Test that we disallow certain headers case-insensitive. | 576 // Test that we disallow certain headers case-insensitive. |
567 downloads.download( | 577 downloads.download( |
568 {'url': SAFE_FAST_URL, | 578 {'url': SAFE_FAST_URL, |
569 'headers': [{'name': 'Accept-chArsEt', 'value': 'evil'}]}, | 579 'headers': [{'name': 'Accept-chArsEt', 'value': 'evil'}]}, |
570 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 580 chrome.test.callbackFail(ERROR_GENERIC)); |
571 }, | 581 }, |
572 | 582 |
573 function downloadHeadersInvalid1() { | 583 function downloadHeadersInvalid1() { |
574 // Test that we disallow certain headers. | 584 // Test that we disallow certain headers. |
575 downloads.download( | 585 downloads.download( |
576 {'url': SAFE_FAST_URL, | 586 {'url': SAFE_FAST_URL, |
577 'headers': [{'name': 'accept-eNcoding', 'value': 'evil'}]}, | 587 'headers': [{'name': 'accept-eNcoding', 'value': 'evil'}]}, |
578 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 588 chrome.test.callbackFail(ERROR_GENERIC)); |
579 }, | 589 }, |
580 | 590 |
581 function downloadHeadersInvalid2() { | 591 function downloadHeadersInvalid2() { |
582 // Test that we disallow certain headers. | 592 // Test that we disallow certain headers. |
583 downloads.download( | 593 downloads.download( |
584 {'url': SAFE_FAST_URL, | 594 {'url': SAFE_FAST_URL, |
585 'headers': [{'name': 'coNNection', 'value': 'evil'}]}, | 595 'headers': [{'name': 'coNNection', 'value': 'evil'}]}, |
586 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 596 chrome.test.callbackFail(ERROR_GENERIC)); |
587 }, | 597 }, |
588 | 598 |
589 function downloadHeadersInvalid3() { | 599 function downloadHeadersInvalid3() { |
590 // Test that we disallow certain headers. | 600 // Test that we disallow certain headers. |
591 downloads.download( | 601 downloads.download( |
592 {'url': SAFE_FAST_URL, | 602 {'url': SAFE_FAST_URL, |
593 'headers': [{'name': 'coNteNt-leNgth', 'value': 'evil'}]}, | 603 'headers': [{'name': 'coNteNt-leNgth', 'value': 'evil'}]}, |
594 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 604 chrome.test.callbackFail(ERROR_GENERIC)); |
595 }, | 605 }, |
596 | 606 |
597 function downloadHeadersInvalid4() { | 607 function downloadHeadersInvalid4() { |
598 // Test that we disallow certain headers. | 608 // Test that we disallow certain headers. |
599 downloads.download( | 609 downloads.download( |
600 {'url': SAFE_FAST_URL, | 610 {'url': SAFE_FAST_URL, |
601 'headers': [{'name': 'cooKIE', 'value': 'evil'}]}, | 611 'headers': [{'name': 'cooKIE', 'value': 'evil'}]}, |
602 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 612 chrome.test.callbackFail(ERROR_GENERIC)); |
603 }, | 613 }, |
604 | 614 |
605 function downloadHeadersInvalid5() { | 615 function downloadHeadersInvalid5() { |
606 // Test that we disallow certain headers. | 616 // Test that we disallow certain headers. |
607 downloads.download( | 617 downloads.download( |
608 {'url': SAFE_FAST_URL, | 618 {'url': SAFE_FAST_URL, |
609 'headers': [{'name': 'cOOkie2', 'value': 'evil'}]}, | 619 'headers': [{'name': 'cOOkie2', 'value': 'evil'}]}, |
610 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 620 chrome.test.callbackFail(ERROR_GENERIC)); |
611 }, | 621 }, |
612 | 622 |
613 function downloadHeadersInvalid6() { | 623 function downloadHeadersInvalid6() { |
614 // Test that we disallow certain headers. | 624 // Test that we disallow certain headers. |
615 downloads.download( | 625 downloads.download( |
616 {'url': SAFE_FAST_URL, | 626 {'url': SAFE_FAST_URL, |
617 'headers': [{'name': 'coNteNt-traNsfer-eNcodiNg', 'value': 'evil'}]}, | 627 'headers': [{'name': 'coNteNt-traNsfer-eNcodiNg', 'value': 'evil'}]}, |
618 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 628 chrome.test.callbackFail(ERROR_GENERIC)); |
619 }, | 629 }, |
620 | 630 |
621 function downloadHeadersInvalid7() { | 631 function downloadHeadersInvalid7() { |
622 // Test that we disallow certain headers. | 632 // Test that we disallow certain headers. |
623 downloads.download( | 633 downloads.download( |
624 {'url': SAFE_FAST_URL, | 634 {'url': SAFE_FAST_URL, |
625 'headers': [{'name': 'dAtE', 'value': 'evil'}]}, | 635 'headers': [{'name': 'dAtE', 'value': 'evil'}]}, |
626 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 636 chrome.test.callbackFail(ERROR_GENERIC)); |
627 }, | 637 }, |
628 | 638 |
629 function downloadHeadersInvalid8() { | 639 function downloadHeadersInvalid8() { |
630 // Test that we disallow certain headers. | 640 // Test that we disallow certain headers. |
631 downloads.download( | 641 downloads.download( |
632 {'url': SAFE_FAST_URL, | 642 {'url': SAFE_FAST_URL, |
633 'headers': [{'name': 'ExpEcT', 'value': 'evil'}]}, | 643 'headers': [{'name': 'ExpEcT', 'value': 'evil'}]}, |
634 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 644 chrome.test.callbackFail(ERROR_GENERIC)); |
635 }, | 645 }, |
636 | 646 |
637 function downloadHeadersInvalid9() { | 647 function downloadHeadersInvalid9() { |
638 // Test that we disallow certain headers. | 648 // Test that we disallow certain headers. |
639 downloads.download( | 649 downloads.download( |
640 {'url': SAFE_FAST_URL, | 650 {'url': SAFE_FAST_URL, |
641 'headers': [{'name': 'hOsT', 'value': 'evil'}]}, | 651 'headers': [{'name': 'hOsT', 'value': 'evil'}]}, |
642 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 652 chrome.test.callbackFail(ERROR_GENERIC)); |
643 }, | 653 }, |
644 | 654 |
645 function downloadHeadersInvalid10() { | 655 function downloadHeadersInvalid10() { |
646 // Test that we disallow certain headers. | 656 // Test that we disallow certain headers. |
647 downloads.download( | 657 downloads.download( |
648 {'url': SAFE_FAST_URL, | 658 {'url': SAFE_FAST_URL, |
649 'headers': [{'name': 'kEEp-aLivE', 'value': 'evil'}]}, | 659 'headers': [{'name': 'kEEp-aLivE', 'value': 'evil'}]}, |
650 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 660 chrome.test.callbackFail(ERROR_GENERIC)); |
651 }, | 661 }, |
652 | 662 |
653 function downloadHeadersInvalid11() { | 663 function downloadHeadersInvalid11() { |
654 // Test that we disallow certain headers. | 664 // Test that we disallow certain headers. |
655 downloads.download( | 665 downloads.download( |
656 {'url': SAFE_FAST_URL, | 666 {'url': SAFE_FAST_URL, |
657 'headers': [{'name': 'rEfErEr', 'value': 'evil'}]}, | 667 'headers': [{'name': 'rEfErEr', 'value': 'evil'}]}, |
658 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 668 chrome.test.callbackFail(ERROR_GENERIC)); |
659 }, | 669 }, |
660 | 670 |
661 function downloadHeadersInvalid12() { | 671 function downloadHeadersInvalid12() { |
662 // Test that we disallow certain headers. | 672 // Test that we disallow certain headers. |
663 downloads.download( | 673 downloads.download( |
664 {'url': SAFE_FAST_URL, | 674 {'url': SAFE_FAST_URL, |
665 'headers': [{'name': 'tE', 'value': 'evil'}]}, | 675 'headers': [{'name': 'tE', 'value': 'evil'}]}, |
666 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 676 chrome.test.callbackFail(ERROR_GENERIC)); |
667 }, | 677 }, |
668 | 678 |
669 function downloadHeadersInvalid13() { | 679 function downloadHeadersInvalid13() { |
670 // Test that we disallow certain headers. | 680 // Test that we disallow certain headers. |
671 downloads.download( | 681 downloads.download( |
672 {'url': SAFE_FAST_URL, | 682 {'url': SAFE_FAST_URL, |
673 'headers': [{'name': 'trAilER', 'value': 'evil'}]}, | 683 'headers': [{'name': 'trAilER', 'value': 'evil'}]}, |
674 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 684 chrome.test.callbackFail(ERROR_GENERIC)); |
675 }, | 685 }, |
676 | 686 |
677 function downloadHeadersInvalid14() { | 687 function downloadHeadersInvalid14() { |
678 // Test that we disallow certain headers. | 688 // Test that we disallow certain headers. |
679 downloads.download( | 689 downloads.download( |
680 {'url': SAFE_FAST_URL, | 690 {'url': SAFE_FAST_URL, |
681 'headers': [{'name': 'trANsfer-eNcodiNg', 'value': 'evil'}]}, | 691 'headers': [{'name': 'trANsfer-eNcodiNg', 'value': 'evil'}]}, |
682 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 692 chrome.test.callbackFail(ERROR_GENERIC)); |
683 }, | 693 }, |
684 | 694 |
685 function downloadHeadersInvalid15() { | 695 function downloadHeadersInvalid15() { |
686 // Test that we disallow certain headers. | 696 // Test that we disallow certain headers. |
687 downloads.download( | 697 downloads.download( |
688 {'url': SAFE_FAST_URL, | 698 {'url': SAFE_FAST_URL, |
689 'headers': [{'name': 'upGRAde', 'value': 'evil'}]}, | 699 'headers': [{'name': 'upGRAde', 'value': 'evil'}]}, |
690 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 700 chrome.test.callbackFail(ERROR_GENERIC)); |
691 }, | 701 }, |
692 | 702 |
693 function downloadHeadersInvalid16() { | 703 function downloadHeadersInvalid16() { |
694 // Test that we disallow certain headers. | 704 // Test that we disallow certain headers. |
695 downloads.download( | 705 downloads.download( |
696 {'url': SAFE_FAST_URL, | 706 {'url': SAFE_FAST_URL, |
697 'headers': [{'name': 'usER-agENt', 'value': 'evil'}]}, | 707 'headers': [{'name': 'usER-agENt', 'value': 'evil'}]}, |
698 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 708 chrome.test.callbackFail(ERROR_GENERIC)); |
699 }, | 709 }, |
700 | 710 |
701 function downloadHeadersInvalid17() { | 711 function downloadHeadersInvalid17() { |
702 // Test that we disallow certain headers. | 712 // Test that we disallow certain headers. |
703 downloads.download( | 713 downloads.download( |
704 {'url': SAFE_FAST_URL, | 714 {'url': SAFE_FAST_URL, |
705 'headers': [{'name': 'viA', 'value': 'evil'}]}, | 715 'headers': [{'name': 'viA', 'value': 'evil'}]}, |
706 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 716 chrome.test.callbackFail(ERROR_GENERIC)); |
707 }, | 717 }, |
708 | 718 |
709 function downloadHeadersInvalid18() { | 719 function downloadHeadersInvalid18() { |
710 // Test that we disallow certain headers. | 720 // Test that we disallow certain headers. |
711 downloads.download( | 721 downloads.download( |
712 {'url': SAFE_FAST_URL, | 722 {'url': SAFE_FAST_URL, |
713 'headers': [{'name': 'pRoxY-', 'value': 'evil'}]}, | 723 'headers': [{'name': 'pRoxY-', 'value': 'evil'}]}, |
714 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 724 chrome.test.callbackFail(ERROR_GENERIC)); |
715 }, | 725 }, |
716 | 726 |
717 function downloadHeadersInvalid19() { | 727 function downloadHeadersInvalid19() { |
718 // Test that we disallow certain headers. | 728 // Test that we disallow certain headers. |
719 downloads.download( | 729 downloads.download( |
720 {'url': SAFE_FAST_URL, | 730 {'url': SAFE_FAST_URL, |
721 'headers': [{'name': 'sEc-', 'value': 'evil'}]}, | 731 'headers': [{'name': 'sEc-', 'value': 'evil'}]}, |
722 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 732 chrome.test.callbackFail(ERROR_GENERIC)); |
723 }, | 733 }, |
724 | 734 |
725 function downloadHeadersInvalid20() { | 735 function downloadHeadersInvalid20() { |
726 // Test that we disallow certain headers. | 736 // Test that we disallow certain headers. |
727 downloads.download( | 737 downloads.download( |
728 {'url': SAFE_FAST_URL, | 738 {'url': SAFE_FAST_URL, |
729 'headers': [{'name': 'pRoxY-probably-not-evil', 'value': 'evil'}]}, | 739 'headers': [{'name': 'pRoxY-probably-not-evil', 'value': 'evil'}]}, |
730 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 740 chrome.test.callbackFail(ERROR_GENERIC)); |
731 }, | 741 }, |
732 | 742 |
733 function downloadHeadersInvalid21() { | 743 function downloadHeadersInvalid21() { |
734 // Test that we disallow certain headers. | 744 // Test that we disallow certain headers. |
735 downloads.download( | 745 downloads.download( |
736 {'url': SAFE_FAST_URL, | 746 {'url': SAFE_FAST_URL, |
737 'headers': [{'name': 'sEc-probably-not-evil', 'value': 'evil'}]}, | 747 'headers': [{'name': 'sEc-probably-not-evil', 'value': 'evil'}]}, |
738 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 748 chrome.test.callbackFail(ERROR_GENERIC)); |
739 }, | 749 }, |
740 | 750 |
741 function downloadHeadersInvalid22() { | 751 function downloadHeadersInvalid22() { |
742 // Test that we disallow certain headers. | 752 // Test that we disallow certain headers. |
743 downloads.download( | 753 downloads.download( |
744 {'url': SAFE_FAST_URL, | 754 {'url': SAFE_FAST_URL, |
745 'headers': [{'name': 'oRiGiN', 'value': 'evil'}]}, | 755 'headers': [{'name': 'oRiGiN', 'value': 'evil'}]}, |
746 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 756 chrome.test.callbackFail(ERROR_GENERIC)); |
747 }, | 757 }, |
748 | 758 |
749 function downloadHeadersInvalid23() { | 759 function downloadHeadersInvalid23() { |
750 // Test that we disallow certain headers. | 760 // Test that we disallow certain headers. |
751 downloads.download( | 761 downloads.download( |
752 {'url': SAFE_FAST_URL, | 762 {'url': SAFE_FAST_URL, |
753 'headers': [{'name': 'Access-Control-Request-Headers', | 763 'headers': [{'name': 'Access-Control-Request-Headers', |
754 'value': 'evil'}]}, | 764 'value': 'evil'}]}, |
755 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 765 chrome.test.callbackFail(ERROR_GENERIC)); |
756 }, | 766 }, |
757 | 767 |
758 function downloadHeadersInvalid24() { | 768 function downloadHeadersInvalid24() { |
759 // Test that we disallow certain headers. | 769 // Test that we disallow certain headers. |
760 downloads.download( | 770 downloads.download( |
761 {'url': SAFE_FAST_URL, | 771 {'url': SAFE_FAST_URL, |
762 'headers': [{'name': 'Access-Control-Request-Method', | 772 'headers': [{'name': 'Access-Control-Request-Method', |
763 'value': 'evil'}]}, | 773 'value': 'evil'}]}, |
764 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 774 chrome.test.callbackFail(ERROR_GENERIC)); |
765 }, | 775 }, |
766 | 776 |
767 function downloadInterrupted() { | 777 function downloadInterrupted() { |
768 // Test that cancel()ing an in-progress download causes its state to | 778 // Test that cancel()ing an in-progress download causes its state to |
769 // transition to interrupted, and test that that state transition is | 779 // transition to interrupted, and test that that state transition is |
770 // detectable by an onChanged event listener. | 780 // detectable by an onChanged event listener. |
771 // TODO(benjhayden): Test other sources of interruptions such as server | 781 // TODO(benjhayden): Test other sources of interruptions such as server |
772 // death. | 782 // death. |
773 var downloadId = getNextId(); | 783 var downloadId = getNextId(); |
774 console.debug(downloadId); | 784 console.debug(downloadId); |
(...skipping 18 matching lines...) Expand all Loading... |
793 | 803 |
794 var changedCompleted = chrome.test.callbackAdded(); | 804 var changedCompleted = chrome.test.callbackAdded(); |
795 function changedListener(delta) { | 805 function changedListener(delta) { |
796 console.debug(delta.id); | 806 console.debug(delta.id); |
797 // Ignore onChanged events for downloads besides our own, or events that | 807 // Ignore onChanged events for downloads besides our own, or events that |
798 // signal any change besides interruption. | 808 // signal any change besides interruption. |
799 if ((delta.id != downloadId) || | 809 if ((delta.id != downloadId) || |
800 !delta.state || | 810 !delta.state || |
801 !delta.error) | 811 !delta.error) |
802 return; | 812 return; |
803 chrome.test.assertEq(downloads.STATE_INTERRUPTED, delta.state.new); | 813 chrome.test.assertEq('interrupted', delta.state.current); |
804 chrome.test.assertEq(40, delta.error.new); | 814 chrome.test.assertEq(40, delta.error.current); |
805 console.debug(downloadId); | 815 console.debug(downloadId); |
806 downloads.onChanged.removeListener(changedListener); | 816 downloads.onChanged.removeListener(changedListener); |
807 changedCompleted(); | 817 changedCompleted(); |
808 } | 818 } |
809 downloads.onChanged.addListener(changedListener); | 819 downloads.onChanged.addListener(changedListener); |
810 | 820 |
811 downloads.download( | 821 downloads.download( |
812 {'url': NEVER_FINISH_URL}, | 822 {'url': NEVER_FINISH_URL}, |
813 chrome.test.callback(function(id) { | 823 chrome.test.callback(function(id) { |
814 console.debug(downloadId); | 824 console.debug(downloadId); |
815 chrome.test.assertEq(downloadId, id); | 825 chrome.test.assertEq(downloadId, id); |
816 })); | 826 })); |
817 }, | 827 }, |
818 | 828 |
819 function downloadFilename() { | 829 function downloadFilename() { |
820 // Test that we can suggest a filename for a new download, and test that | 830 // Test that we can suggest a filename for a new download, and test that |
821 // we can detect filename changes with an onChanged event listener. | 831 // we can detect filename changes with an onChanged event listener. |
822 var FILENAME = 'owiejtoiwjrfoiwjroiwjroiwjroiwjrfi'; | 832 var FILENAME = 'owiejtoiwjrfoiwjroiwjroiwjroiwjrfi'; |
823 var downloadId = getNextId(); | 833 var downloadId = getNextId(); |
824 console.debug(downloadId); | 834 console.debug(downloadId); |
825 var callbackCompleted = chrome.test.callbackAdded(); | 835 var callbackCompleted = chrome.test.callbackAdded(); |
826 function myListener(delta) { | 836 function myListener(delta) { |
827 console.debug(delta.id); | 837 console.debug(delta.id); |
828 if ((delta.id != downloadId) || | 838 if ((delta.id != downloadId) || |
829 !delta.filename || | 839 !delta.filename || |
830 (delta.filename.new.indexOf(FILENAME) == -1)) | 840 (delta.filename.current.indexOf(FILENAME) == -1)) |
831 return; | 841 return; |
832 console.debug(downloadId); | 842 console.debug(downloadId); |
833 downloads.onChanged.removeListener(myListener); | 843 downloads.onChanged.removeListener(myListener); |
834 callbackCompleted(); | 844 callbackCompleted(); |
835 } | 845 } |
836 downloads.onChanged.addListener(myListener); | 846 downloads.onChanged.addListener(myListener); |
837 downloads.download( | 847 downloads.download( |
838 {'url': SAFE_FAST_URL, 'filename': FILENAME}, | 848 {'url': SAFE_FAST_URL, 'filename': FILENAME}, |
839 chrome.test.callback(function(id) { | 849 chrome.test.callback(function(id) { |
840 console.debug(downloadId); | 850 console.debug(downloadId); |
841 chrome.test.assertEq(downloadId, id); | 851 chrome.test.assertEq(downloadId, id); |
842 })); | 852 })); |
843 }, | 853 }, |
844 | 854 |
845 // TODO(benjhayden): Update this test when downloading to sub-directories is | 855 // TODO(benjhayden): Update this test when downloading to sub-directories is |
846 // supported. | 856 // supported. |
847 function downloadFilenameDisallowSlashes() { | 857 function downloadFilenameDisallowSlashes() { |
848 downloads.download( | 858 downloads.download( |
849 {'url': SAFE_FAST_URL, 'filename': 'subdirectory/file.txt'}, | 859 {'url': SAFE_FAST_URL, 'filename': 'subdirectory/file.txt'}, |
850 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 860 chrome.test.callbackFail(ERROR_GENERIC)); |
851 }, | 861 }, |
852 | 862 |
853 function downloadOnCreated() { | 863 function downloadOnCreated() { |
854 // Test that the onCreated event fires when we start a download. | 864 // Test that the onCreated event fires when we start a download. |
855 var downloadId = getNextId(); | 865 var downloadId = getNextId(); |
856 console.debug(downloadId); | 866 console.debug(downloadId); |
857 var createdCompleted = chrome.test.callbackAdded(); | 867 var createdCompleted = chrome.test.callbackAdded(); |
858 function createdListener(item) { | 868 function createdListener(item) { |
859 console.debug(item.id); | 869 console.debug(item.id); |
860 if (item.id != downloadId) | 870 if (item.id != downloadId) |
861 return; | 871 return; |
862 console.debug(downloadId); | 872 console.debug(downloadId); |
863 createdCompleted(); | 873 createdCompleted(); |
864 downloads.onCreated.removeListener(createdListener); | 874 downloads.onCreated.removeListener(createdListener); |
865 }; | 875 }; |
866 downloads.onCreated.addListener(createdListener); | 876 downloads.onCreated.addListener(createdListener); |
867 downloads.download( | 877 downloads.download( |
868 {'url': SAFE_FAST_URL}, | 878 {'url': SAFE_FAST_URL}, |
869 chrome.test.callback(function(id) { | 879 chrome.test.callback(function(id) { |
870 console.debug(downloadId); | 880 console.debug(downloadId); |
871 chrome.test.assertEq(downloadId, id); | 881 chrome.test.assertEq(downloadId, id); |
872 })); | 882 })); |
873 }, | 883 }, |
874 | 884 |
875 function downloadInvalidFilename() { | 885 function downloadInvalidFilename() { |
876 // Test that we disallow invalid filenames for new downloads. | 886 // Test that we disallow invalid filenames for new downloads. |
877 downloads.download( | 887 downloads.download( |
878 {'url': SAFE_FAST_URL, 'filename': '../../../../../etc/passwd'}, | 888 {'url': SAFE_FAST_URL, 'filename': '../../../../../etc/passwd'}, |
879 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 889 chrome.test.callbackFail(ERROR_GENERIC)); |
880 }, | 890 }, |
881 | 891 |
882 function downloadEmpty() { | 892 function downloadEmpty() { |
883 assertThrows(('Invalid value for argument 1. Property \'url\': ' + | 893 assertThrows(('Invalid value for argument 1. Property \'url\': ' + |
884 'Property is required.'), | 894 'Property is required.'), |
885 downloads.download, {}); | 895 downloads.download, {}); |
886 }, | 896 }, |
887 | 897 |
888 function downloadInvalidSaveAs() { | 898 function downloadInvalidSaveAs() { |
889 assertThrows(('Invalid value for argument 1. Property \'saveAs\': ' + | 899 assertThrows(('Invalid value for argument 1. Property \'saveAs\': ' + |
890 'Expected \'boolean\' but got \'string\'.'), | 900 'Expected \'boolean\' but got \'string\'.'), |
891 downloads.download, | 901 downloads.download, |
892 {'url': SAFE_FAST_URL, 'saveAs': 'GOAT'}); | 902 {'url': SAFE_FAST_URL, 'saveAs': 'GOAT'}); |
893 }, | 903 }, |
894 | 904 |
895 function downloadInvalidHeadersOption() { | 905 function downloadInvalidHeadersOption() { |
896 assertThrows(('Invalid value for argument 1. Property \'headers\': ' + | 906 assertThrows(('Invalid value for argument 1. Property \'headers\': ' + |
897 'Expected \'array\' but got \'string\'.'), | 907 'Expected \'array\' but got \'string\'.'), |
898 downloads.download, | 908 downloads.download, |
899 {'url': SAFE_FAST_URL, 'headers': 'GOAT'}); | 909 {'url': SAFE_FAST_URL, 'headers': 'GOAT'}); |
900 }, | 910 }, |
901 | 911 |
902 function downloadInvalidURL0() { | 912 function downloadInvalidURL0() { |
903 // Test that download() requires a valid url. | 913 // Test that download() requires a valid url. |
904 downloads.download( | 914 downloads.download( |
905 {'url': 'foo bar'}, | 915 {'url': 'foo bar'}, |
906 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 916 chrome.test.callbackFail(ERROR_INVALID_URL)); |
907 }, | 917 }, |
908 | 918 |
909 function downloadInvalidURL1() { | 919 function downloadInvalidURL1() { |
910 // Test that download() requires a valid url, including protocol and | 920 // Test that download() requires a valid url, including protocol and |
911 // hostname. | 921 // hostname. |
912 downloads.download( | 922 downloads.download( |
913 {'url': '../hello'}, | 923 {'url': '../hello'}, |
914 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 924 chrome.test.callbackFail(ERROR_INVALID_URL)); |
915 }, | 925 }, |
916 | 926 |
917 function downloadInvalidURL2() { | 927 function downloadInvalidURL2() { |
918 // Test that download() requires a valid url, including protocol and | 928 // Test that download() requires a valid url, including protocol and |
919 // hostname. | 929 // hostname. |
920 downloads.download( | 930 downloads.download( |
921 {'url': '/hello'}, | 931 {'url': '/hello'}, |
922 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 932 chrome.test.callbackFail(ERROR_INVALID_URL)); |
923 }, | 933 }, |
924 | 934 |
925 function downloadInvalidURL3() { | 935 function downloadInvalidURL3() { |
926 // Test that download() requires a valid url, including protocol. | 936 // Test that download() requires a valid url, including protocol. |
927 downloads.download( | 937 downloads.download( |
928 {'url': 'google.com/'}, | 938 {'url': 'google.com/'}, |
929 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 939 chrome.test.callbackFail(ERROR_INVALID_URL)); |
930 }, | 940 }, |
931 | 941 |
932 function downloadInvalidURL4() { | 942 function downloadInvalidURL4() { |
933 // Test that download() requires a valid url, including protocol and | 943 // Test that download() requires a valid url, including protocol and |
934 // hostname. | 944 // hostname. |
935 downloads.download( | 945 downloads.download( |
936 {'url': 'http://'}, | 946 {'url': 'http://'}, |
937 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 947 chrome.test.callbackFail(ERROR_INVALID_URL)); |
938 }, | 948 }, |
939 | 949 |
940 function downloadInvalidURL5() { | 950 function downloadInvalidURL5() { |
941 // Test that download() requires a valid url, including protocol and | 951 // Test that download() requires a valid url, including protocol and |
942 // hostname. | 952 // hostname. |
943 downloads.download( | 953 downloads.download( |
944 {'url': '#frag'}, | 954 {'url': '#frag'}, |
945 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 955 chrome.test.callbackFail(ERROR_INVALID_URL)); |
946 }, | 956 }, |
947 | 957 |
948 function downloadInvalidURL6() { | 958 function downloadInvalidURL6() { |
949 // Test that download() requires a valid url, including protocol and | 959 // Test that download() requires a valid url, including protocol and |
950 // hostname. | 960 // hostname. |
951 downloads.download( | 961 downloads.download( |
952 {'url': 'foo/bar.html#frag'}, | 962 {'url': 'foo/bar.html#frag'}, |
953 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 963 chrome.test.callbackFail(ERROR_INVALID_URL)); |
954 }, | 964 }, |
955 | 965 |
956 function downloadAllowFragments() { | 966 function downloadAllowFragments() { |
957 // Valid URLs plus fragments are still valid URLs. | 967 // Valid URLs plus fragments are still valid URLs. |
958 var downloadId = getNextId(); | 968 var downloadId = getNextId(); |
959 console.debug(downloadId); | 969 console.debug(downloadId); |
960 downloads.download( | 970 downloads.download( |
961 {'url': SAFE_FAST_URL + '#frag'}, | 971 {'url': SAFE_FAST_URL + '#frag'}, |
962 chrome.test.callback(function(id) { | 972 chrome.test.callback(function(id) { |
963 chrome.test.assertEq(downloadId, id); | 973 chrome.test.assertEq(downloadId, id); |
(...skipping 17 matching lines...) Expand all Loading... |
981 {'url': 'file:///'}, | 991 {'url': 'file:///'}, |
982 chrome.test.callback(function(id) { | 992 chrome.test.callback(function(id) { |
983 chrome.test.assertEq(downloadId, id); | 993 chrome.test.assertEq(downloadId, id); |
984 })); | 994 })); |
985 }, | 995 }, |
986 | 996 |
987 function downloadInvalidURL7() { | 997 function downloadInvalidURL7() { |
988 // Test that download() rejects javascript urls. | 998 // Test that download() rejects javascript urls. |
989 downloads.download( | 999 downloads.download( |
990 {'url': 'javascript:document.write("hello");'}, | 1000 {'url': 'javascript:document.write("hello");'}, |
991 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 1001 chrome.test.callbackFail(ERROR_INVALID_URL)); |
992 }, | 1002 }, |
993 | 1003 |
994 function downloadInvalidURL8() { | 1004 function downloadInvalidURL8() { |
995 // Test that download() rejects javascript urls. | 1005 // Test that download() rejects javascript urls. |
996 downloads.download( | 1006 downloads.download( |
997 {'url': 'javascript:return false;'}, | 1007 {'url': 'javascript:return false;'}, |
998 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 1008 chrome.test.callbackFail(ERROR_INVALID_URL)); |
999 }, | 1009 }, |
1000 | 1010 |
1001 function downloadInvalidURL9() { | 1011 function downloadInvalidURL9() { |
1002 // Test that download() rejects otherwise-valid URLs that fail the host | 1012 // Test that download() rejects otherwise-valid URLs that fail the host |
1003 // permissions check. | 1013 // permissions check. |
1004 downloads.download( | 1014 downloads.download( |
1005 {'url': 'ftp://example.com/example.txt'}, | 1015 {'url': 'ftp://example.com/example.txt'}, |
1006 chrome.test.callbackFail(downloads.ERROR_INVALID_URL)); | 1016 chrome.test.callbackFail(ERROR_INVALID_URL)); |
1007 }, | 1017 }, |
1008 | 1018 |
1009 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to | 1019 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to |
1010 // permissions, maybe update downloadInvalidURL9. | 1020 // permissions, maybe update downloadInvalidURL9. |
1011 // function downloadAllowFTPURLs() { | 1021 // function downloadAllowFTPURLs() { |
1012 // // Valid ftp URLs are valid URLs. | 1022 // // Valid ftp URLs are valid URLs. |
1013 // var downloadId = getNextId(); | 1023 // var downloadId = getNextId(); |
1014 // console.debug(downloadId); | 1024 // console.debug(downloadId); |
1015 // downloads.download( | 1025 // downloads.download( |
1016 // {'url': 'ftp://localhost:' + testConfig.testServer.port + '/'}, | 1026 // {'url': 'ftp://localhost:' + testConfig.testServer.port + '/'}, |
1017 // chrome.test.callback(function(id) { | 1027 // chrome.test.callback(function(id) { |
1018 // chrome.test.assertEq(downloadId, id); | 1028 // chrome.test.assertEq(downloadId, id); |
1019 // })); | 1029 // })); |
1020 // }, | 1030 // }, |
1021 | 1031 |
1022 function downloadInvalidMethod() { | 1032 function downloadInvalidMethod() { |
1023 assertThrows(('Invalid value for argument 1. Property \'method\': ' + | 1033 assertThrows(('Invalid value for argument 1. Property \'method\': ' + |
1024 'Value must be one of: [GET, POST].'), | 1034 'Value must be one of: [GET, POST].'), |
1025 downloads.download, | 1035 downloads.download, |
1026 {'url': SAFE_FAST_URL, 'method': 'GOAT'}); | 1036 {'url': SAFE_FAST_URL, 'method': 'GOAT'}); |
1027 }, | 1037 }, |
1028 | 1038 |
1029 function downloadInvalidHeader() { | 1039 function downloadInvalidHeader() { |
1030 // Test that download() disallows setting the Cookie header. | 1040 // Test that download() disallows setting the Cookie header. |
1031 downloads.download( | 1041 downloads.download( |
1032 {'url': SAFE_FAST_URL, | 1042 {'url': SAFE_FAST_URL, |
1033 'headers': [{ 'name': 'Cookie', 'value': 'fake'}] | 1043 'headers': [{ 'name': 'Cookie', 'value': 'fake'}] |
1034 }, | 1044 }, |
1035 chrome.test.callbackFail(downloads.ERROR_GENERIC)); | 1045 chrome.test.callbackFail(ERROR_GENERIC)); |
1036 }, | 1046 }, |
1037 | 1047 |
1038 function downloadGetFileIconInvalidOptions() { | 1048 function downloadGetFileIconInvalidOptions() { |
1039 assertThrows(('Invalid value for argument 2. Property \'cat\': ' + | 1049 assertThrows(('Invalid value for argument 2. Property \'cat\': ' + |
1040 'Unexpected property.'), | 1050 'Unexpected property.'), |
1041 downloads.getFileIcon, | 1051 downloads.getFileIcon, |
1042 -1, {cat: 'mouse'}); | 1052 -1, {cat: 'mouse'}); |
1043 }, | 1053 }, |
1044 | 1054 |
1045 function downloadGetFileIconInvalidSize() { | 1055 function downloadGetFileIconInvalidSize() { |
1046 assertThrows(('Invalid value for argument 2. Property \'size\': ' + | 1056 assertThrows(('Invalid value for argument 2. Property \'size\': ' + |
1047 'Value must be one of: [16, 32].'), | 1057 'Value must be one of: [16, 32].'), |
1048 downloads.getFileIcon, -1, {size: 31}); | 1058 downloads.getFileIcon, -1, {size: 31}); |
1049 }, | 1059 }, |
1050 | 1060 |
1051 function downloadGetFileIconInvalidId() { | 1061 function downloadGetFileIconInvalidId() { |
1052 downloads.getFileIcon(-42, {size: 32}, | 1062 downloads.getFileIcon(-42, {size: 32}, |
1053 chrome.test.callbackFail(downloads.ERROR_INVALID_OPERATION)); | 1063 chrome.test.callbackFail(ERROR_INVALID_OPERATION)); |
1054 }, | 1064 }, |
1055 | 1065 |
1056 function downloadPauseInvalidId() { | 1066 function downloadPauseInvalidId() { |
1057 downloads.pause(-42, chrome.test.callbackFail( | 1067 downloads.pause(-42, chrome.test.callbackFail( |
1058 downloads.ERROR_INVALID_OPERATION)); | 1068 ERROR_INVALID_OPERATION)); |
1059 }, | 1069 }, |
1060 | 1070 |
1061 function downloadPauseInvalidType() { | 1071 function downloadPauseInvalidType() { |
1062 assertThrows(('Invocation of form experimental.downloads.pause(string,' + | 1072 assertThrows(('Invocation of form downloads.pause(string, function) ' + |
1063 ' function) doesn\'t match definition experimental.' + | 1073 'doesn\'t match definition downloads.pause(integer ' + |
1064 'downloads.pause(integer id, optional function callback)'), | 1074 'downloadId, optional function NullCallback)'), |
1065 downloads.pause, | 1075 downloads.pause, |
1066 'foo'); | 1076 'foo'); |
1067 }, | 1077 }, |
1068 | 1078 |
1069 function downloadResumeInvalidId() { | 1079 function downloadResumeInvalidId() { |
1070 downloads.resume(-42, chrome.test.callbackFail( | 1080 downloads.resume(-42, chrome.test.callbackFail( |
1071 downloads.ERROR_INVALID_OPERATION)); | 1081 ERROR_INVALID_OPERATION)); |
1072 }, | 1082 }, |
1073 | 1083 |
1074 function downloadResumeInvalidType() { | 1084 function downloadResumeInvalidType() { |
1075 assertThrows(('Invocation of form experimental.downloads.resume(string,' + | 1085 assertThrows(('Invocation of form downloads.resume(string, function) ' + |
1076 ' function) doesn\'t match definition experimental.' + | 1086 'doesn\'t match definition downloads.resume(integer ' + |
1077 'downloads.resume(integer id, optional function callback)'), | 1087 'downloadId, optional function NullCallback)'), |
1078 downloads.resume, | 1088 downloads.resume, |
1079 'foo'); | 1089 'foo'); |
1080 }, | 1090 }, |
1081 | 1091 |
1082 function downloadCancelInvalidId() { | 1092 function downloadCancelInvalidId() { |
1083 // Canceling a non-existent download is not considered an error. | 1093 // Canceling a non-existent download is not considered an error. |
1084 downloads.cancel(-42, chrome.test.callback(function() { | 1094 downloads.cancel(-42, chrome.test.callback(function() { |
1085 console.debug(''); | 1095 console.debug(''); |
1086 })); | 1096 })); |
1087 }, | 1097 }, |
1088 | 1098 |
1089 function downloadCancelInvalidType() { | 1099 function downloadCancelInvalidType() { |
1090 assertThrows(('Invocation of form experimental.downloads.cancel(string,' + | 1100 assertThrows(('Invocation of form downloads.cancel(string, function) ' + |
1091 ' function) doesn\'t match definition experimental.' + | 1101 'doesn\'t match definition downloads.cancel(integer ' + |
1092 'downloads.cancel(integer id, optional function callback)'), | 1102 'downloadId, optional function NullCallback)'), |
1093 downloads.cancel, 'foo'); | 1103 downloads.cancel, 'foo'); |
1094 }, | 1104 }, |
1095 | 1105 |
1096 function downloadNoComplete() { | 1106 function downloadNoComplete() { |
1097 // This is used partly to test cleanUp. | 1107 // This is used partly to test cleanUp. |
1098 var downloadId = getNextId(); | 1108 var downloadId = getNextId(); |
1099 console.debug(downloadId); | 1109 console.debug(downloadId); |
1100 downloads.download( | 1110 downloads.download( |
1101 {'url': NEVER_FINISH_URL}, | 1111 {'url': NEVER_FINISH_URL}, |
1102 chrome.test.callback(function(id) { | 1112 chrome.test.callback(function(id) { |
(...skipping 17 matching lines...) Expand all Loading... |
1120 }, | 1130 }, |
1121 | 1131 |
1122 function callNotifyPass() { | 1132 function callNotifyPass() { |
1123 chrome.test.notifyPass(); | 1133 chrome.test.notifyPass(); |
1124 setTimeout(chrome.test.callback(function() { | 1134 setTimeout(chrome.test.callback(function() { |
1125 console.debug(''); | 1135 console.debug(''); |
1126 }), 0); | 1136 }), 0); |
1127 } | 1137 } |
1128 ]); | 1138 ]); |
1129 }); | 1139 }); |
OLD | NEW |