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

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

Issue 8060042: Add downloads.onCreated apitest and fix a few bugs (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 9 years, 2 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
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..493303f2caac69a52a2b5ce244435264347fb694 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++;
@@ -30,17 +31,34 @@ chrome.test.getConfig(function(testConfig) {
}
chrome.test.runTests([
+ // TODO(benjhayden): Test onErased using remove().
function downloadFilename() {
chrome.experimental.downloads.download(
- {"url": getURL("pass"), "filename": "pass"},
+ {"url": getURL("slow?0"), "filename": "foo"},
Randy Smith (Not in Mondays) 2011/10/17 17:39:56 What pathway does "slow?0" use? Is that URLReques
benjhayden 2011/10/17 17:54:29 It's just a handler in testserver.py that returns
chrome.test.callbackPass(function(id) {
chrome.test.assertEq(getNextId(), id);
}));
// TODO(benjhayden): Test the filename using onChanged.
},
+ function downloadOnCreated() {
+ function myListener(item) {
+ // Remove the listener so that we don't call chrome.test.succeed
+ // spuriously for following test functions. Avoid
+ // chrome.test.callbackPass for event handlers so that we can use our
+ // own explicit version of the pendingCallbacks counter if necessary.
+ chrome.experimental.downloads.onCreated.removeListener(myListener);
+ chrome.test.succeed();
+ };
+ chrome.experimental.downloads.onCreated.addListener(myListener);
+ chrome.experimental.downloads.download(
+ {"url": getURL("slow?0")},
+ function(id) {
+ chrome.test.assertEq(getNextId(), id);
+ });
+ },
function downloadSubDirectoryFilename() {
chrome.experimental.downloads.download(
- {"url": getURL("pass"), "filename": "foo/pass"},
+ {"url": getURL("slow?0"), "filename": "foo/slow"},
chrome.test.callbackPass(function(id) {
chrome.test.assertEq(getNextId(), id);
}));
@@ -48,7 +66,7 @@ chrome.test.getConfig(function(testConfig) {
},
function downloadInvalidFilename() {
chrome.experimental.downloads.download(
- {"url": getURL("pass"), "filename": "../../../../../etc/passwd"},
+ {"url": getURL("slow?0"), "filename": "../../../../../etc/passwd"},
chrome.test.callbackFail("I'm afraid I can't do that."));
// TODO(benjhayden): Give a better error message.
},
@@ -59,13 +77,13 @@ chrome.test.getConfig(function(testConfig) {
},
function downloadInvalidSaveAs() {
assertThrows(chrome.experimental.downloads.download,
- {"url": getURL("pass"), "saveAs": "GOAT"},
+ {"url": getURL("slow?0"), "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": getURL("slow?0"), "headers": "GOAT"},
("Invalid value for argument 1. Property 'headers': " +
"Expected 'array' but got 'string'."));
},
@@ -76,37 +94,37 @@ chrome.test.getConfig(function(testConfig) {
},
function downloadInvalidMethod() {
assertThrows(chrome.experimental.downloads.download,
- {"url": getURL("pass"), "method": "GOAT"},
+ {"url": getURL("slow?0"), "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": getURL("slow?0")},
chrome.test.callbackPass(function(id) {
chrome.test.assertEq(getNextId(), id);
}));
},
function downloadHeader() {
chrome.experimental.downloads.download(
- {"url": getURL("pass"),
+ {"url": getURL("slow?0"),
"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": getURL("slow?0")},
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": getURL("slow?0"),
"headers": [{"name": "Cookie", "value": "fake"}]},
chrome.test.callbackFail("I'm afraid I can't do that."));
// TODO(benjhayden): Give a better error message.

Powered by Google App Engine
This is Rietveld 408576698