Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Unified Diff: chrome/test/data/extensions/api_test/downloads/test.js

Issue 9110042: Re-enable DownloadsApiTest.Downloads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another rebase Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/download/download_extension_apitest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a1dc3c30a01e6c747b94b44efd84ec7cd09b0ad2..8db4ed579590c42c96e8b72e56b13a6638dc6dfe 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;
@@ -28,8 +30,8 @@ chrome.test.getConfig(function(testConfig) {
args.push(function() {
// Don't use chrome.test.callbackFail because it requires the
// callback to be called.
- chrome.test.fail("Failed to throw exception (" +
- exceptionMessage + ")");
+ chrome.test.fail('Failed to throw exception (' +
+ exceptionMessage + ')');
});
func.apply(null, args);
} catch (exception) {
@@ -40,151 +42,162 @@ 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(ERROR_GENERIC));
// TODO(benjhayden): Give a better error message.
},
function downloadEmpty() {
- assertThrows(("Invalid value for argument 1. Property 'url': " +
- "Property is required."),
- chrome.experimental.downloads.download, {});
+ assertThrows(('Invalid value for argument 1. Property \'url\': ' +
+ 'Property is required.'),
+ downloads.download, {});
},
function downloadInvalidSaveAs() {
- assertThrows(("Invalid value for argument 1. Property 'saveAs': " +
- "Expected 'boolean' but got 'string'."),
- chrome.experimental.downloads.download,
- {"url": SAFE_FAST_URL, "saveAs": "GOAT"});
+ assertThrows(('Invalid value for argument 1. Property \'saveAs\': ' +
+ 'Expected \'boolean\' but got \'string\'.'),
+ downloads.download,
+ {'url': SAFE_FAST_URL, 'saveAs': 'GOAT'});
},
function downloadInvalidHeadersOption() {
- assertThrows(("Invalid value for argument 1. Property 'headers': " +
- "Expected 'array' but got 'string'."),
- chrome.experimental.downloads.download,
- {"url": SAFE_FAST_URL, "headers": "GOAT"});
+ assertThrows(('Invalid value for argument 1. Property \'headers\': ' +
+ 'Expected \'array\' but got \'string\'.'),
+ downloads.download,
+ {'url': SAFE_FAST_URL, 'headers': 'GOAT'});
},
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(("Invalid value for argument 1. Property 'method': " +
- "Value must be one of: [GET, POST]."),
- chrome.experimental.downloads.download,
- {"url": SAFE_FAST_URL, "method": "GOAT"});
+ assertThrows(('Invalid value for argument 1. Property \'method\': ' +
+ 'Value must be one of: [GET, POST].'),
+ downloads.download,
+ {'url': SAFE_FAST_URL, 'method': 'GOAT'});
},
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"}]},
+ downloads.download(
+ {'url': SAFE_FAST_URL,
+ 'headers': [{ 'name': 'Cookie', 'value': 'fake'}]
+ },
chrome.test.callbackFail(ERROR_GENERIC));
// TODO(benjhayden): Give a better error message.
},
function downloadGetFileIconInvalidOptions() {
- assertThrows(("Invalid value for argument 2. Property 'cat': " +
- "Unexpected property."),
- chrome.experimental.downloads.getFileIcon,
- -1, {cat: "mouse"});
+ assertThrows(('Invalid value for argument 2. Property \'cat\': ' +
+ 'Unexpected property.'),
+ downloads.getFileIcon,
+ -1, {cat: 'mouse'});
},
function downloadGetFileIconInvalidSize() {
- assertThrows(("Invalid value for argument 2. Property 'size': " +
- "Value must be one of: [16, 32]."),
- chrome.experimental.downloads.getFileIcon, -1, {size: 31});
+ assertThrows(('Invalid value for argument 2. Property \'size\': ' +
+ 'Value must be one of: [16, 32].'),
+ downloads.getFileIcon, -1, {size: 31});
},
function downloadGetFileIconInvalidId() {
- chrome.experimental.downloads.getFileIcon(-42, {size: 32},
+ downloads.getFileIcon(-42, {size: 32},
chrome.test.callbackFail(ERROR_INVALID_OPERATION));
},
+ function downloadNoComplete() {
+ // This is used partly to test cleanUp.
+ 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(("Invalid value for argument 1. Expected 'integer' " +
- "but got 'string'."),
- chrome.experimental.downloads.pause,
- "foo");
+ assertThrows(('Invalid value for argument 1. Expected \'integer\' ' +
+ 'but got \'string\'.'),
+ downloads.pause,
+ 'foo');
},
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(("Invalid value for argument 1. Expected 'integer' " +
- "but got 'string'."),
- chrome.experimental.downloads.resume,
- "foo");
+ assertThrows(('Invalid value for argument 1. Expected \'integer\' ' +
+ 'but got \'string\'.'),
+ downloads.resume,
+ 'foo');
},
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(("Invalid value for argument 1. Expected 'integer' " +
- "but got 'string'."),
- chrome.experimental.downloads.cancel,
- "foo");
+ assertThrows(('Invalid value for argument 1. Expected \'integer\' ' +
+ 'but got \'string\'.'),
+ downloads.cancel, 'foo');
+ },
+ 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() {}));
+ }
}
]);
});
« no previous file with comments | « chrome/browser/download/download_extension_apitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698