OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // downloads api test | 5 // downloads api test |
6 // browser_tests.exe --gtest_filter=DownloadsApiTest.Downloads | 6 // browser_tests.exe --gtest_filter=DownloadsApiTest.Downloads |
7 | 7 |
8 var downloads = chrome.experimental.downloads; | 8 var downloads = chrome.experimental.downloads; |
9 | 9 |
10 chrome.test.getConfig(function(testConfig) { | 10 chrome.test.getConfig(function(testConfig) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 // The "/slow" handler waits a specified amount of time before returning a | 43 // The "/slow" handler waits a specified amount of time before returning a |
44 // safe file. Specify zero seconds to return quickly. | 44 // safe file. Specify zero seconds to return quickly. |
45 var SAFE_FAST_URL = getURL('slow?0'); | 45 var SAFE_FAST_URL = getURL('slow?0'); |
46 var NEVER_FINISH_URL = getURL('download-known-size'); | 46 var NEVER_FINISH_URL = getURL('download-known-size'); |
47 var ERROR_GENERIC = downloads.ERROR_GENERIC; | 47 var ERROR_GENERIC = downloads.ERROR_GENERIC; |
48 var ERROR_INVALID_URL = downloads.ERROR_INVALID_URL; | 48 var ERROR_INVALID_URL = downloads.ERROR_INVALID_URL; |
49 var ERROR_INVALID_OPERATION = downloads.ERROR_INVALID_OPERATION; | 49 var ERROR_INVALID_OPERATION = downloads.ERROR_INVALID_OPERATION; |
50 | 50 |
51 chrome.test.runTests([ | 51 chrome.test.runTests([ |
52 // TODO(benjhayden): Test onErased using remove(). | 52 // TODO(benjhayden): Test onErased using remove(). |
Randy Smith (Not in Mondays)
2012/01/15 18:47:13
Why not as part of this CL, since it fires the OnE
benjhayden
2012/02/01 21:42:40
I need remove() in order to test onErased. I can't
Randy Smith (Not in Mondays)
2012/02/02 18:10:06
*snort* Right you are. Who knew? :-} (I.e. tha
| |
53 function downloadOnChanged() { | |
54 function myListener(delta) { | |
55 if (delta.state && delta.state.new == 'complete') { | |
56 chrome.experimental.downloads.onChanged.removeListener(myListener); | |
57 chrome.test.succeed(); | |
58 } | |
59 } | |
60 chrome.experimental.downloads.onChanged.addListener(myListener); | |
61 chrome.experimental.downloads.download( | |
62 {"url": getURL("slow?0")}, | |
63 function(id) { | |
64 chrome.test.assertEq(getNextId(), id); | |
65 }); | |
66 }, | |
53 function downloadFilename() { | 67 function downloadFilename() { |
68 function myListener(delta) { | |
69 if (delta.filename && delta.filename.new.indexOf('/foo') !== -1) { | |
70 chrome.experimental.downloads.onChanged.removeListener(myListener); | |
71 chrome.test.succeed(); | |
72 } | |
73 } | |
74 chrome.experimental.downloads.onChanged.addListener(myListener); | |
54 downloads.download( | 75 downloads.download( |
55 {'url': SAFE_FAST_URL, 'filename': 'foo'}, | 76 {'url': SAFE_FAST_URL, 'filename': 'foo'}, |
56 chrome.test.callbackPass(function(id) { | 77 function(id) { |
57 chrome.test.assertEq(getNextId(), id); | 78 chrome.test.assertEq(getNextId(), id); |
58 })); | 79 }); |
59 // TODO(benjhayden): Test the filename using onChanged. | |
60 }, | 80 }, |
61 function downloadOnCreated() { | 81 function downloadOnCreated() { |
62 chrome.test.listenOnce(downloads.onCreated, | 82 chrome.test.listenOnce(downloads.onCreated, |
63 chrome.test.callbackPass(function(item) {})); | 83 chrome.test.callbackPass(function(item) {})); |
64 downloads.download( | 84 downloads.download( |
65 {'url': SAFE_FAST_URL}, | 85 {'url': SAFE_FAST_URL}, |
66 function(id) { | 86 function(id) { |
67 chrome.test.assertEq(getNextId(), id); | 87 chrome.test.assertEq(getNextId(), id); |
68 }); | 88 }); |
69 }, | 89 }, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 }, | 223 }, |
204 function cleanUp() { | 224 function cleanUp() { |
205 // cleanUp must come last. It clears out all in-progress downloads | 225 // cleanUp must come last. It clears out all in-progress downloads |
206 // so the browser can shutdown cleanly. | 226 // so the browser can shutdown cleanly. |
207 for (var id = 0; id < nextId; ++id) { | 227 for (var id = 0; id < nextId; ++id) { |
208 downloads.cancel(id, chrome.test.callbackPass(function() {})); | 228 downloads.cancel(id, chrome.test.callbackPass(function() {})); |
209 } | 229 } |
210 } | 230 } |
211 ]); | 231 ]); |
212 }); | 232 }); |
OLD | NEW |