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 0a1368c87aaebfcd15db05b3747c253b60c14074..08de71c4ba2806a16adfeba3ba51148d4d6ccd00 100644 |
--- a/chrome/test/data/extensions/api_test/downloads/test.js |
+++ b/chrome/test/data/extensions/api_test/downloads/test.js |
@@ -48,38 +48,175 @@ chrome.test.getConfig(function(testConfig) { |
var ERROR_INVALID_URL = downloads.ERROR_INVALID_URL; |
var ERROR_INVALID_OPERATION = downloads.ERROR_INVALID_OPERATION; |
+ console.log("I know all these console.logs stink up the place, but please " + |
+ "leave them in: they will help you check that all the " + |
+ "callbacks for a particular test run before the test harness " + |
+ "thinks that that test is finished and that that test doesn't " + |
+ "'finish' twice."); |
+ console.log("All log lines that contain a download_id should appear " + |
+ "before that test finishes. If a callback for test N runs " + |
+ "after test N+1 begins, then that indicates a race condition " + |
+ "in test N."); |
Randy Smith (Not in Mondays)
2012/02/02 18:10:07
Is there really no way for us to check for this pr
benjhayden
2012/02/02 20:40:38
chrome.test already tests it programmatically by a
Randy Smith (Not in Mondays)
2012/02/03 20:02:00
Would it satisfy your goals to change the above tw
benjhayden
2012/02/10 18:53:07
I think that if I saw test output as verbose as th
Randy Smith (Not in Mondays)
2012/02/13 16:13:08
It looks like you've nuked the logging; was that i
benjhayden
2012/02/13 19:01:31
Chris said that it was generally not acceptable.
|
+ |
chrome.test.runTests([ |
Randy Smith (Not in Mondays)
2012/02/02 18:10:07
Could you put in a short comment about what these
benjhayden
2012/02/02 20:40:38
Um, you might want to have a look at download_exte
Randy Smith (Not in Mondays)
2012/02/03 20:02:00
I think I didn't read as closely as I should have.
benjhayden
2012/02/10 18:53:07
Done.
|
- // TODO(benjhayden): Test onErased using remove(). |
- function downloadFilename() { |
+ function downloadSimple() { |
+ var download_id = getNextId(); |
+ console.log("id: " + download_id); |
downloads.download( |
- {'url': SAFE_FAST_URL, 'filename': 'foo'}, |
+ {'url': SAFE_FAST_URL}, |
chrome.test.callbackPass(function(id) { |
- chrome.test.assertEq(getNextId(), id); |
+ console.log("id: " + download_id); |
+ chrome.test.assertEq(download_id, id); |
})); |
- // TODO(benjhayden): Test the filename using onChanged. |
}, |
- function downloadOnCreated() { |
- chrome.test.listenOnce(downloads.onCreated, |
- chrome.test.callbackPass(function(item) {})); |
+ function downloadPost() { |
+ var download_id = getNextId(); |
+ console.log("id: " + download_id); |
downloads.download( |
- {'url': SAFE_FAST_URL}, |
- function(id) { |
- chrome.test.assertEq(getNextId(), id); |
- }); |
+ {'url': getURL('files/post/downloads/a_zip_file.js'), |
+ 'method': 'POST', |
+ 'body': 'WOOHOO'}, |
+ chrome.test.callbackPass(function(id) { |
+ console.log("id: " + download_id); |
+ chrome.test.assertEq(download_id, id); |
+ })); |
}, |
- function downloadSubDirectoryFilename() { |
+ function downloadHeader() { |
+ var download_id = getNextId(); |
+ console.log("id: " + download_id); |
downloads.download( |
- {'url': SAFE_FAST_URL, 'filename': 'foo/slow'}, |
+ {'url': SAFE_FAST_URL, |
+ 'headers': [{'name': 'Foo', 'value': 'bar'}] |
+ }, |
chrome.test.callbackPass(function(id) { |
- chrome.test.assertEq(getNextId(), id); |
+ console.log("id: " + download_id); |
+ chrome.test.assertEq(download_id, id); |
+ })); |
+ }, |
+ function downloadInterrupted() { |
+ var download_id = getNextId(); |
+ console.log("id: " + download_id); |
+ |
+ var createdCompleted = chrome.test.callbackAdded(); |
+ function createdListener(created_item) { |
+ console.log("created_id: " + created_item.id); |
+ if (created_item.id != download_id) |
+ return; |
+ // TODO(benjhayden) Move this cancel() into the download() callback |
+ // after ensuring that DownloadItems are created before that callback |
+ // is fired. |
+ downloads.cancel(download_id, chrome.test.callback(function() { |
+ console.log("id: " + download_id); |
+ })); |
+ downloads.onCreated.removeListener(createdListener); |
+ createdCompleted(); |
+ } |
+ downloads.onCreated.addListener(createdListener); |
+ |
+ var changedCompleted = chrome.test.callbackAdded(); |
+ function changedListener(delta) { |
+ console.log("id: " + delta.id); |
+ if ((delta.id == download_id) && |
+ delta.state && |
+ (delta.state.new == 'interrupted')) { |
+ console.log("id: " + delta.id); |
+ downloads.onChanged.removeListener(changedListener); |
+ changedCompleted(); |
+ } |
+ } |
+ downloads.onChanged.addListener(changedListener); |
+ |
+ downloads.download( |
+ {'url': NEVER_FINISH_URL}, |
+ chrome.test.callback(function(id) { |
+ console.log("id: " + download_id); |
+ chrome.test.assertEq(download_id, id); |
+ })); |
+ }, |
+ // TODO(benjhayden): Test onErased using remove(). |
+ function downloadOnChanged() { |
+ var download_id = getNextId(); |
+ console.log("id: " + download_id); |
+ var callbackCompleted = chrome.test.callbackAdded(); |
+ console.log("id: " + download_id); |
+ function myListener(delta) { |
+ console.log("id: " + delta.id); |
+ if (delta.state) console.log("state: " + delta.state.new); |
+ if (delta.state && delta.state.new == 'complete') { |
+ downloads.onChanged.removeListener(myListener); |
+ callbackCompleted(); |
+ } |
+ } |
+ downloads.onChanged.addListener(myListener); |
+ downloads.download( |
+ {"url": getURL("slow?0")}, |
+ chrome.test.callback(function(id) { |
+ console.log("id: " + download_id); |
+ chrome.test.assertEq(download_id, id); |
+ })); |
+ }, |
+ function downloadFilename() { |
+ const kFilename = 'owiejtoiwjrfoiwjroiwjroiwjroiwjrfi'; |
+ var download_id = getNextId(); |
+ console.log("id: " + download_id); |
+ var callbackCompleted = chrome.test.callbackAdded(); |
+ function myListener(delta) { |
+ console.log("id: " + download_id); |
+ if (delta.filename) console.log("filename: " + delta.filename.new); |
+ if (delta.filename && delta.filename.new.indexOf(kFilename) !== -1) { |
+ downloads.onChanged.removeListener(myListener); |
+ callbackCompleted(); |
+ } |
+ } |
+ downloads.onChanged.addListener(myListener); |
+ downloads.download( |
+ {'url': SAFE_FAST_URL, 'filename': kFilename}, |
+ chrome.test.callback(function(id) { |
+ console.log("id: " + download_id); |
+ chrome.test.assertEq(download_id, id); |
})); |
- // TODO(benjhayden): Test the filename using onChanged. |
}, |
+ function downloadOnCreated() { |
+ var download_id = getNextId(); |
+ console.log("id: " + download_id); |
+ chrome.test.listenOnce(downloads.onCreated, function(item) { |
+ // This callback is implicitly wrapped by chrome.test.callbackPass(), |
+ // so if onCreated never fires, then this test will timeout. |
+ }); |
+ downloads.download( |
+ {'url': SAFE_FAST_URL}, |
+ chrome.test.callback(function(id) { |
+ chrome.test.assertEq(download_id, id); |
+ })); |
+ }, |
+ // TODO(benjhayden): Talk to Asanka about a way to make the filename |
+ // sanitizer respect filenames from the downloads api (instead of replace |
+ // slashes with underscores). |
Randy Smith (Not in Mondays)
2012/02/02 18:10:07
I'd suggest you have a plan sketch (and maybe a bu
benjhayden
2012/02/02 20:40:38
Added the bug id, and Asanka has a vague plan if I
Randy Smith (Not in Mondays)
2012/02/03 20:02:00
Yep; if there's a bug id I agree the discussion sh
benjhayden
2012/02/10 18:53:07
Done.
|
+ // function downloadSubDirectoryFilename() { |
+ // var download_id = getNextId(); |
+ // console.log("id: " + download_id); |
+ // var callbackCompleted = chrome.test.callbackAdded(); |
+ // function myListener(delta) { |
+ // console.log("id: " + download_id); |
+ // if (delta.filename) console.log("filename: " + delta.filename.new); |
+ // if (delta.filename && |
+ // delta.filename.new.indexOf('/foo/slow') !== -1) { |
+ // downloads.onChanged.removeListener(myListener); |
+ // callbackCompleted(); |
+ // } |
+ // } |
+ // downloads.onChanged.addListener(myListener); |
+ // downloads.download( |
+ // {'url': SAFE_FAST_URL, 'filename': 'foo/slow'}, |
+ // chrome.test.callback(function(id) { |
+ // console.log("id: " + download_id); |
+ // chrome.test.assertEq(download_id, id); |
+ // })); |
+ // }, |
function downloadInvalidFilename() { |
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\': ' + |
@@ -109,47 +246,12 @@ chrome.test.getConfig(function(testConfig) { |
downloads.download, |
{'url': SAFE_FAST_URL, 'method': 'GOAT'}); |
}, |
- function downloadSimple() { |
- downloads.download( |
- {'url': SAFE_FAST_URL}, |
- chrome.test.callbackPass(function(id) { |
- chrome.test.assertEq(getNextId(), id); |
- })); |
- }, |
- function downloadPost() { |
- downloads.download( |
- {'url': getURL('files/post/downloads/a_zip_file.js'), |
- 'method': 'POST', |
- 'body': 'WOOHOO'}, |
- chrome.test.callbackPass(function(id) { |
- chrome.test.assertEq(getNextId(), id); |
- })); |
- }, |
- function downloadHeader() { |
- 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. |
- downloads.download( |
- {'url': SAFE_FAST_URL}, |
- chrome.test.callbackPass(function(id) { |
- chrome.test.assertEq(getNextId(), id); |
- })); |
- }, |
function downloadInvalidHeader() { |
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\': ' + |
@@ -168,10 +270,13 @@ chrome.test.getConfig(function(testConfig) { |
}, |
function downloadNoComplete() { |
// This is used partly to test cleanUp. |
+ var download_id = getNextId(); |
+ console.log("id: " + download_id); |
downloads.download( |
{'url': NEVER_FINISH_URL}, |
chrome.test.callbackPass(function(id) { |
- chrome.test.assertEq(getNextId(), id); |
+ console.log("id: " + download_id); |
+ chrome.test.assertEq(download_id, id); |
})); |
}, |
function downloadPauseInvalidId() { |