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 3665b2963082674acae69c3818a2fa4babb162d1..aa93f7250f87c556941b8fc0fe524c5385f430a0 100644 |
| --- a/chrome/test/data/extensions/api_test/downloads/test.js |
| +++ b/chrome/test/data/extensions/api_test/downloads/test.js |
| @@ -5,9 +5,11 @@ |
| // downloads api test |
| // browser_tests.exe --gtest_filter=DownloadsApiTest.Downloads |
| +var downloads = chrome.experimental.downloads; |
| + |
| chrome.test.getConfig(function(testConfig) { |
| function getURL(path) { |
| - return "http://localhost:" + testConfig.testServer.port + "/" + path; |
| + return 'http://localhost:' + testConfig.testServer.port + '/' + path; |
| } |
| var nextId = 0; |
| @@ -21,8 +23,8 @@ chrome.test.getConfig(function(testConfig) { |
| func(arg, function() { |
| // Don't use chrome.test.callbackFail because it requires the |
| // callback to be called. |
| - chrome.test.fail("Failed to throw exception (" + |
| - expected_message + ")"); |
| + chrome.test.fail('Failed to throw exception (' + |
| + expected_message + ')'); |
| }); |
| } catch (exception) { |
| chrome.test.assertEq(expected_message, exception.message); |
| @@ -32,136 +34,147 @@ 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"); |
| - |
| - var ERROR_GENERIC = chrome.experimental.downloads.ERROR_GENERIC; |
| - var ERROR_INVALID_URL = chrome.experimental.downloads.ERROR_INVALID_URL; |
| - var ERROR_INVALID_OPERATION = |
| - chrome.experimental.downloads.ERROR_INVALID_OPERATION; |
| + var SAFE_FAST_URL = getURL('slow?0'); |
| + var NEVER_FINISH_URL = getURL('download-known-size'); |
| + var ERROR_GENERIC = downloads.ERROR_GENERIC; |
| + var ERROR_INVALID_URL = downloads.ERROR_INVALID_URL; |
| + var ERROR_INVALID_OPERATION = downloads.ERROR_INVALID_OPERATION; |
| chrome.test.runTests([ |
| // TODO(benjhayden): Test onErased using remove(). |
| function downloadFilename() { |
| - chrome.experimental.downloads.download( |
| - {"url": SAFE_FAST_URL, "filename": "foo"}, |
| - chrome.test.callbackPass(function(id) { |
| - chrome.test.assertEq(getNextId(), id); |
| - })); |
| + downloads.download( |
| + {'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); |
| - }); |
| + chrome.test.listenOnce(downloads.onCreated, |
| + chrome.test.callbackPass(function(item) {})); |
| + downloads.download( |
| + {'url': SAFE_FAST_URL}, |
| + function(id) { |
| + chrome.test.assertEq(getNextId(), id); |
| + }); |
| }, |
| function downloadSubDirectoryFilename() { |
| - chrome.experimental.downloads.download( |
| - {"url": SAFE_FAST_URL, "filename": "foo/slow"}, |
| - chrome.test.callbackPass(function(id) { |
| - chrome.test.assertEq(getNextId(), id); |
| - })); |
| + downloads.download( |
| + {'url': SAFE_FAST_URL, 'filename': 'foo/slow'}, |
| + chrome.test.callbackPass(function(id) { |
| + chrome.test.assertEq(getNextId(), id); |
| + })); |
| // TODO(benjhayden): Test the filename using onChanged. |
| }, |
| function downloadInvalidFilename() { |
| - chrome.experimental.downloads.download( |
| - {"url": SAFE_FAST_URL, "filename": "../../../../../etc/passwd"}, |
| - chrome.test.callbackFail("I'm afraid I can't do that.")); |
| + downloads.download( |
| + {'url': SAFE_FAST_URL, 'filename': '../../../../../etc/passwd'}, |
| + chrome.test.callbackFail('I\'m afraid I can\'t do that.')); |
|
asanka
2012/01/11 18:22:59
Nit: ERROR_GENERIC
cbentzel
2012/01/11 18:43:21
Done.
|
| // TODO(benjhayden): Give a better error message. |
| }, |
| function downloadEmpty() { |
| - assertThrows(chrome.experimental.downloads.download, {}, |
| - ("Invalid value for argument 1. Property 'url': " + |
| - "Property is required.")); |
| + assertThrows(downloads.download, {}, |
| + ('Invalid value for argument 1. Property \'url\': ' + |
| + 'Property is required.')); |
| }, |
| function downloadInvalidSaveAs() { |
| - assertThrows(chrome.experimental.downloads.download, |
| - {"url": SAFE_FAST_URL, "saveAs": "GOAT"}, |
| - ("Invalid value for argument 1. Property 'saveAs': " + |
| - "Expected 'boolean' but got 'string'.")); |
| + assertThrows(downloads.download, |
| + {'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": SAFE_FAST_URL, "headers": "GOAT"}, |
| - ("Invalid value for argument 1. Property 'headers': " + |
| - "Expected 'array' but got 'string'.")); |
| + assertThrows(downloads.download, |
| + {'url': SAFE_FAST_URL, 'headers': 'GOAT'}, |
| + ('Invalid value for argument 1. Property \'headers\': ' + |
| + 'Expected \'array\' but got \'string\'.')); |
| }, |
| function downloadInvalidURL() { |
| - chrome.experimental.downloads.download( |
| - {"url": "foo bar"}, |
| - chrome.test.callbackFail(ERROR_INVALID_URL)); |
| + downloads.download( |
| + {'url': 'foo bar'}, |
| + chrome.test.callbackFail(ERROR_INVALID_URL)); |
| }, |
| function downloadInvalidMethod() { |
| - assertThrows(chrome.experimental.downloads.download, |
| - {"url": SAFE_FAST_URL, "method": "GOAT"}, |
| - ("Invalid value for argument 1. Property 'method': " + |
| - "Value must be one of: [GET, POST].")); |
| + assertThrows(downloads.download, |
| + {'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": SAFE_FAST_URL}, |
| - chrome.test.callbackPass(function(id) { |
| - chrome.test.assertEq(getNextId(), id); |
| - })); |
| + downloads.download( |
| + {'url': SAFE_FAST_URL}, |
| + chrome.test.callbackPass(function(id) { |
| + chrome.test.assertEq(getNextId(), id); |
| + })); |
| }, |
| function downloadHeader() { |
| - chrome.experimental.downloads.download( |
| - {"url": SAFE_FAST_URL, |
| - "headers": [{"name": "Foo", "value": "bar"}]}, |
| - chrome.test.callbackPass(function(id) { |
| - chrome.test.assertEq(getNextId(), id); |
| - })); |
| + downloads.download( |
| + {'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": SAFE_FAST_URL}, |
| - chrome.test.callbackPass(function(id) { |
| - chrome.test.assertEq(getNextId(), id); |
| - })); |
| + downloads.download( |
| + {'url': SAFE_FAST_URL}, |
| + chrome.test.callbackPass(function(id) { |
| + chrome.test.assertEq(getNextId(), id); |
| + })); |
| }, |
| function downloadInvalidHeader() { |
| - chrome.experimental.downloads.download( |
| - {"url": SAFE_FAST_URL, |
| - "headers": [{"name": "Cookie", "value": "fake"}]}, |
| - chrome.test.callbackFail(ERROR_GENERIC)); |
| + downloads.download( |
| + {'url': SAFE_FAST_URL, |
| + 'headers': [{'name': 'Cookie', 'value': 'fake'}] |
| + }, |
| + chrome.test.callbackFail(ERROR_GENERIC)); |
| // TODO(benjhayden): Give a better error message. |
| }, |
| + function downloadNoComplete() { |
|
benjhayden
2012/01/11 17:39:44
Comment that this is to test cleanUp?
cbentzel
2012/01/11 18:43:21
Done.
|
| + downloads.download( |
| + {'url': NEVER_FINISH_URL}, |
| + chrome.test.callbackPass(function(id) { |
| + chrome.test.assertEq(getNextId(), id); |
| + })); |
| + }, |
| function downloadPauseInvalidId() { |
| - chrome.experimental.downloads.pause(-42, |
| - chrome.test.callbackFail(ERROR_INVALID_OPERATION)); |
| + downloads.pause(-42, chrome.test.callbackFail(ERROR_INVALID_OPERATION)); |
| }, |
| function downloadPauseInvalidType() { |
| - assertThrows(chrome.experimental.downloads.pause, |
| - "foo", |
| - ("Invalid value for argument 1. Expected 'integer' " + |
| - "but got 'string'.")); |
| + assertThrows(downloads.pause, |
| + 'foo', |
| + ('Invalid value for argument 1. Expected \'integer\' ' + |
| + 'but got \'string\'.')); |
| }, |
| function downloadResumeInvalidId() { |
| - chrome.experimental.downloads.resume(-42, |
| - chrome.test.callbackFail(ERROR_INVALID_OPERATION)); |
| + downloads.resume(-42, chrome.test.callbackFail(ERROR_INVALID_OPERATION)); |
| }, |
| function downloadResumeInvalidType() { |
| - assertThrows(chrome.experimental.downloads.resume, |
| - "foo", |
| - ("Invalid value for argument 1. Expected 'integer' " + |
| - "but got 'string'.")); |
| + assertThrows(downloads.resume, |
| + 'foo', |
| + ('Invalid value for argument 1. Expected \'integer\' ' + |
| + 'but got \'string\'.')); |
| }, |
| function downloadCancelInvalidId() { |
| // Canceling a non-existent download is not considered an error. |
| - chrome.experimental.downloads.cancel(-42, |
| - chrome.test.callbackPass(function() {})); |
| + downloads.cancel(-42, chrome.test.callbackPass(function() {})); |
| }, |
| function downloadCancelInvalidType() { |
| - assertThrows(chrome.experimental.downloads.cancel, |
| - "foo", |
| - ("Invalid value for argument 1. Expected 'integer' " + |
| - "but got 'string'.")); |
| + assertThrows(downloads.cancel, |
| + 'foo', |
| + ('Invalid value for argument 1. Expected \'integer\' ' + |
| + 'but got \'string\'.')); |
| + }, |
| + function cleanUp() { |
| + // cleanUp must come last. It clears out all in-progress downloads |
| + // so the browser can shutdown cleanly. |
| + for (var id = 0; id < nextId; ++id) { |
| + downloads.cancel(id, chrome.test.callbackPass(function() {})); |
| + } |
| } |
| ]); |
| }); |