Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/downloads/test.js |
| diff --git a/chrome/test/data/extensions/api_test/downloads/test.js b/chrome/test/data/extensions/api_test/downloads/test.js |
| index c227f3277cd8b2c3e0c0830f05fd32d9a2e01ea7..c2bee81fff8c9955151cb59a9b49c76ff0049c55 100644 |
| --- a/chrome/test/data/extensions/api_test/downloads/test.js |
| +++ b/chrome/test/data/extensions/api_test/downloads/test.js |
| @@ -9,6 +9,7 @@ chrome.test.getConfig(function(testConfig) { |
| function getURL(path) { |
| return "http://localhost:" + testConfig.testServer.port + "/" + path; |
| } |
| + |
| var nextId = 0; |
| function getNextId() { |
| return nextId++; |
| @@ -29,18 +30,33 @@ chrome.test.getConfig(function(testConfig) { |
| } |
| } |
| + // The "/slow" handler waits a specified amount of time before returning a |
| + // safe file. Specify zero seconds to return quickly. |
| + var safe_fast_url = getURL("slow?0"); |
|
Mihai Parparita -not on Chrome
2011/10/18 20:39:02
This should be called SAFE_FAST_URL.
benjhayden
2011/10/20 19:05:44
Done.
|
| + |
| chrome.test.runTests([ |
| + // TODO(benjhayden): Test onErased using remove(). |
| function downloadFilename() { |
| chrome.experimental.downloads.download( |
| - {"url": getURL("pass"), "filename": "pass"}, |
| + {"url": safe_fast_url, "filename": "foo"}, |
| chrome.test.callbackPass(function(id) { |
| chrome.test.assertEq(getNextId(), id); |
| })); |
| // TODO(benjhayden): Test the filename using onChanged. |
| }, |
| + function downloadOnCreated() { |
| + chrome.test.listenOnce(chrome.experimental.downloads.onCreated, |
| + chrome.test.callbackPass(function(item) { |
| + })); |
| + chrome.experimental.downloads.download( |
| + {"url": safe_fast_url}, |
| + function(id) { |
| + chrome.test.assertEq(getNextId(), id); |
| + }); |
| + }, |
| function downloadSubDirectoryFilename() { |
| chrome.experimental.downloads.download( |
| - {"url": getURL("pass"), "filename": "foo/pass"}, |
| + {"url": safe_fast_url, "filename": "foo/slow"}, |
| chrome.test.callbackPass(function(id) { |
| chrome.test.assertEq(getNextId(), id); |
| })); |
| @@ -48,7 +64,7 @@ chrome.test.getConfig(function(testConfig) { |
| }, |
| function downloadInvalidFilename() { |
| chrome.experimental.downloads.download( |
| - {"url": getURL("pass"), "filename": "../../../../../etc/passwd"}, |
| + {"url": safe_fast_url, "filename": "../../../../../etc/passwd"}, |
| chrome.test.callbackFail("I'm afraid I can't do that.")); |
| // TODO(benjhayden): Give a better error message. |
| }, |
| @@ -59,13 +75,13 @@ chrome.test.getConfig(function(testConfig) { |
| }, |
| function downloadInvalidSaveAs() { |
| assertThrows(chrome.experimental.downloads.download, |
| - {"url": getURL("pass"), "saveAs": "GOAT"}, |
| + {"url": safe_fast_url, "saveAs": "GOAT"}, |
| ("Invalid value for argument 1. Property 'saveAs': " + |
| "Expected 'boolean' but got 'string'.")); |
| }, |
| function downloadInvalidHeadersOption() { |
| assertThrows(chrome.experimental.downloads.download, |
| - {"url": getURL("pass"), "headers": "GOAT"}, |
| + {"url": safe_fast_url, "headers": "GOAT"}, |
| ("Invalid value for argument 1. Property 'headers': " + |
| "Expected 'array' but got 'string'.")); |
| }, |
| @@ -76,37 +92,37 @@ chrome.test.getConfig(function(testConfig) { |
| }, |
| function downloadInvalidMethod() { |
| assertThrows(chrome.experimental.downloads.download, |
| - {"url": getURL("pass"), "method": "GOAT"}, |
| + {"url": safe_fast_url, "method": "GOAT"}, |
| ("Invalid value for argument 1. Property 'method': " + |
| "Value must be one of: [GET, POST].")); |
| }, |
| function downloadSimple() { |
| chrome.experimental.downloads.download( |
| - {"url": getURL("pass")}, |
| + {"url": safe_fast_url}, |
| chrome.test.callbackPass(function(id) { |
| chrome.test.assertEq(getNextId(), id); |
| })); |
| }, |
| function downloadHeader() { |
| chrome.experimental.downloads.download( |
| - {"url": getURL("pass"), |
| + {"url": safe_fast_url, |
| "headers": [{"name": "Foo", "value": "bar"}]}, |
| chrome.test.callbackPass(function(id) { |
| chrome.test.assertEq(getNextId(), id); |
| })); |
| }, |
| function downloadInterrupted() { |
| + // TODO(benjhayden): Find a suitable URL and test that this id is |
| + // eventually interrupted using onChanged. |
| chrome.experimental.downloads.download( |
| - {"url": getURL("compressedfiles/Picture_1.doc?L")}, |
| + {"url": safe_fast_url}, |
| chrome.test.callbackPass(function(id) { |
| chrome.test.assertEq(getNextId(), id); |
| - // TODO(benjhayden): Test that this id is eventually interrupted using |
| - // onChanged. |
| })); |
| }, |
| function downloadInvalidHeader() { |
| chrome.experimental.downloads.download( |
| - {"url": getURL("pass"), |
| + {"url": safe_fast_url, |
| "headers": [{"name": "Cookie", "value": "fake"}]}, |
| chrome.test.callbackFail("I'm afraid I can't do that.")); |
| // TODO(benjhayden): Give a better error message. |