Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 }); | 35 }); |
| 36 func.apply(null, args); | 36 func.apply(null, args); |
| 37 } catch (exception) { | 37 } catch (exception) { |
| 38 chrome.test.assertEq(exceptionMessage, exception.message); | 38 chrome.test.assertEq(exceptionMessage, exception.message); |
| 39 chrome.test.succeed(); | 39 chrome.test.succeed(); |
| 40 } | 40 } |
| 41 } | 41 } |
| 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 const SAFE_FAST_URL = getURL('slow?0'); |
| 46 var NEVER_FINISH_URL = getURL('download-known-size'); | 46 const NEVER_FINISH_URL = getURL('download-known-size'); |
| 47 var ERROR_GENERIC = downloads.ERROR_GENERIC; | 47 const POST_URL = 'files/post/downloads/a_zip_file.zip?expected_body=BODY' |
| 48 var ERROR_INVALID_URL = downloads.ERROR_INVALID_URL; | 48 const ERROR_GENERIC = downloads.ERROR_GENERIC; |
| 49 var ERROR_INVALID_OPERATION = downloads.ERROR_INVALID_OPERATION; | 49 const ERROR_INVALID_URL = downloads.ERROR_INVALID_URL; |
| 50 const ERROR_INVALID_OPERATION = downloads.ERROR_INVALID_OPERATION; | |
| 51 | |
| 52 console.log("I know all these console.logs stink up the place, but please " + | |
| 53 "leave them in: they will help you check that all the " + | |
| 54 "callbacks for a particular test run before the test harness " + | |
| 55 "thinks that that test is finished and that that test doesn't " + | |
| 56 "'finish' twice."); | |
| 57 console.log("All log lines that contain a download_id should appear " + | |
| 58 "before that test finishes. If a callback for test N runs " + | |
| 59 "after test N+1 begins, then that indicates a race condition " + | |
| 60 "in test N."); | |
| 50 | 61 |
| 51 chrome.test.runTests([ | 62 chrome.test.runTests([ |
| 52 // TODO(benjhayden): Test onErased using remove(). | 63 // TODO(benjhayden): Test onErased using remove(). |
| 64 | |
| 65 // TODO(benjhayden): Sub-directories depend on http://crbug.com/109443 | |
| 66 // function downloadSubDirectoryFilename() { | |
| 67 // var download_id = getNextId(); | |
| 68 // console.log("id: " + download_id); | |
| 69 // var callbackCompleted = chrome.test.callbackAdded(); | |
| 70 // function myListener(delta) { | |
| 71 // console.log("id: " + download_id); | |
| 72 // if (delta.filename) console.log("filename: " + delta.filename.new); | |
| 73 // if (delta.filename && | |
| 74 // delta.filename.new.indexOf('/foo/slow') !== -1) { | |
| 75 // downloads.onChanged.removeListener(myListener); | |
| 76 // callbackCompleted(); | |
| 77 // } | |
| 78 // } | |
| 79 // downloads.onChanged.addListener(myListener); | |
| 80 // downloads.download( | |
| 81 // {'url': SAFE_FAST_URL, 'filename': 'foo/slow'}, | |
| 82 // chrome.test.callback(function(id) { | |
| 83 // console.log("id: " + download_id); | |
| 84 // chrome.test.assertEq(download_id, id); | |
| 85 // })); | |
| 86 // }, | |
| 87 | |
| 88 function downloadSimple() { | |
| 89 // Test that we can begin a download. | |
| 90 const download_id = getNextId(); | |
| 91 console.log("id: " + download_id); | |
| 92 downloads.download( | |
| 93 {'url': SAFE_FAST_URL}, | |
| 94 chrome.test.callbackPass(function(id) { | |
| 95 console.log("id: " + download_id); | |
| 96 chrome.test.assertEq(download_id, id); | |
| 97 })); | |
| 98 }, | |
| 99 | |
| 100 function downloadPostSuccess() { | |
| 101 // Test the |method| download option. | |
| 102 const download_id = getNextId(); | |
| 103 console.log("id: " + download_id); | |
| 104 | |
| 105 var changedCompleted = chrome.test.callbackAdded(); | |
| 106 function changedListener(delta) { | |
| 107 console.log("id: " + delta.id); | |
| 108 if ((delta.id == download_id) && | |
| 109 delta.state) | |
| 110 console.log("state: " + delta.state.new); | |
| 111 // Ignore onChanged events for downloads besides our own, or events that | |
| 112 // signal any change besides completion. | |
| 113 if ((delta.id == download_id) && | |
| 114 delta.state && | |
| 115 (delta.state.new == downloads.STATE_COMPLETE)) { | |
| 116 console.log("id: " + delta.id); | |
| 117 chrome.test.assertEq(downloads.STATE_COMPLETE, delta.state.new); | |
| 118 downloads.search({id: download_id}, | |
| 119 chrome.test.callback(function(items) { | |
| 120 chrome.test.assertEq(1, items.length); | |
| 121 chrome.test.assertEq(download_id, items[0].id); | |
| 122 const kExpectedSize = 164; | |
| 123 chrome.test.assertEq(kExpectedSize, items[0].totalBytes); | |
| 124 chrome.test.assertEq(kExpectedSize, items[0].fileSize); | |
| 125 chrome.test.assertEq(kExpectedSize, items[0].bytesReceived); | |
| 126 })); | |
| 127 downloads.onChanged.removeListener(changedListener); | |
| 128 changedCompleted(); | |
| 129 } | |
| 130 } | |
| 131 downloads.onChanged.addListener(changedListener); | |
| 132 | |
| 133 downloads.download( | |
| 134 {'url': getURL(POST_URL), | |
| 135 'method': 'POST', | |
| 136 'filename': download_id + '.txt', | |
| 137 'body': 'BODY'}, | |
| 138 chrome.test.callbackPass(function(id) { | |
| 139 console.log("id: " + download_id); | |
| 140 chrome.test.assertEq(download_id, id); | |
| 141 })); | |
| 142 }, | |
| 143 | |
| 144 function downloadPostWouldFailWithoutMethod() { | |
| 145 // Test that downloadPostSuccess would fail if the resource requires the | |
| 146 // POST method, and chrome fails to propagate the |method| parameter back | |
| 147 // to the server. | |
| 148 const download_id = getNextId(); | |
| 149 console.log("id: " + download_id); | |
| 150 | |
| 151 var changedCompleted = chrome.test.callbackAdded(); | |
| 152 function changedListener(delta) { | |
| 153 console.log("id: " + delta.id); | |
| 154 if (delta.state) console.log("state: " + delta.state.new); | |
| 155 // Ignore onChanged events for downloads besides our own, or events that | |
| 156 // signal any change besides interruption. | |
| 157 if ((delta.id == download_id) && | |
| 158 delta.state && | |
| 159 ((delta.state.new == downloads.STATE_INTERRUPTED) || | |
| 160 (delta.state.new == downloads.STATE_COMPLETE))) { | |
| 161 console.log("id: " + delta.id); | |
| 162 // TODO(benjhayden): Figure out why this download isn't interrupted, | |
| 163 // why 4XX HTTP errors are not considered interruptions. | |
| 164 downloads.search({id: download_id}, | |
| 165 chrome.test.callback(function(items) { | |
| 166 chrome.test.assertEq(1, items.length); | |
| 167 chrome.test.assertEq(download_id, items[0].id); | |
| 168 chrome.test.assertEq(0, items[0].totalBytes); | |
| 169 })); | |
| 170 downloads.onChanged.removeListener(changedListener); | |
| 171 changedCompleted(); | |
| 172 } | |
| 173 } | |
| 174 downloads.onChanged.addListener(changedListener); | |
| 175 | |
| 176 downloads.download( | |
| 177 {'url': getURL(POST_URL), | |
| 178 'filename': download_id + '.txt', | |
| 179 'body': 'BODY'}, | |
| 180 chrome.test.callbackPass(function(id) { | |
| 181 console.log("id: " + download_id); | |
| 182 chrome.test.assertEq(download_id, id); | |
| 183 })); | |
| 184 }, | |
| 185 | |
| 186 function downloadPostWouldFailWithoutBody() { | |
| 187 // Test that downloadPostSuccess would fail if the resource requires the | |
| 188 // POST method and a request body, and chrome fails to propagate the | |
| 189 // |body| parameter back to the server. | |
| 190 const download_id = getNextId(); | |
| 191 console.log("id: " + download_id); | |
| 192 | |
| 193 var changedCompleted = chrome.test.callbackAdded(); | |
| 194 function changedListener(delta) { | |
| 195 console.log("id: " + delta.id); | |
| 196 if (delta.state) console.log("state: " + delta.state.new); | |
| 197 // Ignore onChanged events for downloads besides our own, or events that | |
| 198 // signal any change besides interruption. | |
| 199 if ((delta.id == download_id) && | |
| 200 delta.state && | |
| 201 ((delta.state.new == downloads.STATE_INTERRUPTED) || | |
| 202 (delta.state.new == downloads.STATE_COMPLETE))) { | |
| 203 console.log("id: " + delta.id); | |
| 204 // TODO(benjhayden): Figure out why this download isn't interrupted. | |
| 205 downloads.search({id: download_id}, | |
| 206 chrome.test.callback(function(items) { | |
| 207 chrome.test.assertEq(1, items.length); | |
| 208 chrome.test.assertEq(download_id, items[0].id); | |
| 209 chrome.test.assertEq(0, items[0].totalBytes); | |
| 210 })); | |
| 211 downloads.onChanged.removeListener(changedListener); | |
| 212 changedCompleted(); | |
| 213 } | |
| 214 } | |
| 215 downloads.onChanged.addListener(changedListener); | |
| 216 | |
| 217 downloads.download( | |
| 218 {'url': getURL(POST_URL), | |
| 219 'filename': download_id + '.txt', | |
| 220 'method': 'POST'}, | |
| 221 chrome.test.callbackPass(function(id) { | |
| 222 console.log("id: " + download_id); | |
| 223 chrome.test.assertEq(download_id, id); | |
| 224 })); | |
| 225 }, | |
| 226 | |
| 227 function downloadHeader() { | |
| 228 // Test the |headers| download option. | |
| 229 const download_id = getNextId(); | |
| 230 console.log("id: " + download_id); | |
| 231 downloads.download( | |
| 232 {'url': SAFE_FAST_URL, | |
| 233 'headers': [{'name': 'Foo', 'value': 'bar'}] | |
| 234 }, | |
| 235 chrome.test.callbackPass(function(id) { | |
| 236 console.log("id: " + download_id); | |
| 237 chrome.test.assertEq(download_id, id); | |
| 238 })); | |
| 239 }, | |
| 240 | |
| 241 function downloadInterrupted() { | |
| 242 // Test that cancel()ing an in-progress download causes its state to | |
| 243 // transition to interrupted, and test that that state transition is | |
| 244 // detectable by an onChanged event listener. | |
| 245 const download_id = getNextId(); | |
| 246 console.log("id: " + download_id); | |
| 247 | |
| 248 var createdCompleted = chrome.test.callbackAdded(); | |
| 249 function createdListener(created_item) { | |
| 250 console.log("created_id: " + created_item.id); | |
| 251 // Ignore onCreated events for any download besides our own. | |
| 252 if (created_item.id != download_id) | |
| 253 return; | |
| 254 // TODO(benjhayden) Move this cancel() into the download() callback | |
| 255 // after ensuring that DownloadItems are created before that callback | |
| 256 // is fired. | |
| 257 downloads.cancel(download_id, chrome.test.callback(function() { | |
| 258 console.log("id: " + download_id); | |
| 259 })); | |
| 260 downloads.onCreated.removeListener(createdListener); | |
| 261 createdCompleted(); | |
| 262 } | |
| 263 downloads.onCreated.addListener(createdListener); | |
| 264 | |
| 265 var changedCompleted = chrome.test.callbackAdded(); | |
| 266 function changedListener(delta) { | |
| 267 console.log("id: " + delta.id); | |
| 268 // Ignore onChanged events for downloads besides our own, or events that | |
| 269 // signal any change besides interruption. | |
| 270 if ((delta.id == download_id) && | |
| 271 delta.state && | |
| 272 (delta.state.new == downloads.STATE_INTERRUPTED)) { | |
| 273 console.log("id: " + delta.id); | |
| 274 downloads.onChanged.removeListener(changedListener); | |
| 275 changedCompleted(); | |
| 276 } | |
| 277 } | |
| 278 downloads.onChanged.addListener(changedListener); | |
| 279 | |
| 280 downloads.download( | |
| 281 {'url': NEVER_FINISH_URL}, | |
| 282 chrome.test.callback(function(id) { | |
| 283 console.log("id: " + download_id); | |
| 284 chrome.test.assertEq(download_id, id); | |
| 285 })); | |
| 286 }, | |
| 287 | |
| 288 | |
| 289 function downloadOnChanged() { | |
| 290 // Test that download completion is detectable by an onChanged event | |
| 291 // listener. | |
| 292 const download_id = getNextId(); | |
| 293 console.log("id: " + download_id); | |
| 294 var callbackCompleted = chrome.test.callbackAdded(); | |
| 295 function myListener(delta) { | |
| 296 console.log("id: " + delta.id); | |
| 297 if (delta.state) console.log("state: " + delta.state.new); | |
| 298 if (delta.state && delta.state.new == downloads.STATE_COMPLETE) { | |
| 299 downloads.onChanged.removeListener(myListener); | |
| 300 callbackCompleted(); | |
| 301 } | |
| 302 } | |
| 303 downloads.onChanged.addListener(myListener); | |
| 304 downloads.download( | |
| 305 {"url": getURL("slow?0")}, | |
| 306 chrome.test.callback(function(id) { | |
| 307 console.log("id: " + download_id); | |
| 308 chrome.test.assertEq(download_id, id); | |
| 309 })); | |
| 310 }, | |
| 311 | |
| 53 function downloadFilename() { | 312 function downloadFilename() { |
| 54 downloads.download( | 313 // Test that we can suggest a filename for a new download, and test that |
| 55 {'url': SAFE_FAST_URL, 'filename': 'foo'}, | 314 // we can detect filename changes with an onChanged event listener. |
| 56 chrome.test.callbackPass(function(id) { | 315 const kFilename = 'owiejtoiwjrfoiwjroiwjroiwjroiwjrfi'; |
| 57 chrome.test.assertEq(getNextId(), id); | 316 const download_id = getNextId(); |
| 58 })); | 317 console.log("id: " + download_id); |
| 59 // TODO(benjhayden): Test the filename using onChanged. | 318 var callbackCompleted = chrome.test.callbackAdded(); |
| 60 }, | 319 function myListener(delta) { |
| 320 console.log("id: " + download_id); | |
| 321 if (delta.filename) console.log("filename: " + delta.filename.new); | |
| 322 if (delta.filename && delta.filename.new.indexOf(kFilename) !== -1) { | |
| 323 downloads.onChanged.removeListener(myListener); | |
| 324 callbackCompleted(); | |
| 325 } | |
| 326 } | |
| 327 downloads.onChanged.addListener(myListener); | |
| 328 downloads.download( | |
| 329 {'url': SAFE_FAST_URL, 'filename': kFilename}, | |
| 330 chrome.test.callback(function(id) { | |
| 331 console.log("id: " + download_id); | |
| 332 chrome.test.assertEq(download_id, id); | |
| 333 })); | |
| 334 }, | |
| 335 | |
| 61 function downloadOnCreated() { | 336 function downloadOnCreated() { |
| 62 chrome.test.listenOnce(downloads.onCreated, | 337 // Test that the onCreated event fires when we start a download. |
| 63 chrome.test.callbackPass(function(item) {})); | 338 var download_id = getNextId(); |
| 339 console.log("id: " + download_id); | |
| 340 var createdCompleted = chrome.test.callbackAdded(); | |
| 341 function createdListener(item) { | |
| 342 if (item.id == download_id) { | |
| 343 createdCompleted(); | |
| 344 downloads.onCreated.removeListener(createdListener); | |
| 345 } | |
| 346 }; | |
| 347 downloads.onCreated.addListener(createdListener); | |
| 64 downloads.download( | 348 downloads.download( |
| 65 {'url': SAFE_FAST_URL}, | 349 {'url': SAFE_FAST_URL}, |
| 66 function(id) { | 350 chrome.test.callback(function(id) { |
| 67 chrome.test.assertEq(getNextId(), id); | 351 chrome.test.assertEq(download_id, id); |
| 68 }); | 352 })); |
| 69 }, | 353 }, |
| 70 function downloadSubDirectoryFilename() { | 354 |
| 71 downloads.download( | |
| 72 {'url': SAFE_FAST_URL, 'filename': 'foo/slow'}, | |
| 73 chrome.test.callbackPass(function(id) { | |
| 74 chrome.test.assertEq(getNextId(), id); | |
| 75 })); | |
| 76 // TODO(benjhayden): Test the filename using onChanged. | |
| 77 }, | |
| 78 function downloadInvalidFilename() { | 355 function downloadInvalidFilename() { |
| 356 // Test that we disallow invalid filenames for new downloads. | |
| 79 downloads.download( | 357 downloads.download( |
| 80 {'url': SAFE_FAST_URL, 'filename': '../../../../../etc/passwd'}, | 358 {'url': SAFE_FAST_URL, 'filename': '../../../../../etc/passwd'}, |
| 81 chrome.test.callbackFail(ERROR_GENERIC)); | 359 chrome.test.callbackFail(ERROR_GENERIC)); |
| 82 // TODO(benjhayden): Give a better error message. | 360 }, |
| 83 }, | 361 |
| 84 function downloadEmpty() { | 362 function downloadEmpty() { |
| 85 assertThrows(('Invalid value for argument 1. Property \'url\': ' + | 363 assertThrows(('Invalid value for argument 1. Property \'url\': ' + |
| 86 'Property is required.'), | 364 'Property is required.'), |
| 87 downloads.download, {}); | 365 downloads.download, {}); |
| 88 }, | 366 }, |
| 367 | |
| 89 function downloadInvalidSaveAs() { | 368 function downloadInvalidSaveAs() { |
| 90 assertThrows(('Invalid value for argument 1. Property \'saveAs\': ' + | 369 assertThrows(('Invalid value for argument 1. Property \'saveAs\': ' + |
| 91 'Expected \'boolean\' but got \'string\'.'), | 370 'Expected \'boolean\' but got \'string\'.'), |
| 92 downloads.download, | 371 downloads.download, |
| 93 {'url': SAFE_FAST_URL, 'saveAs': 'GOAT'}); | 372 {'url': SAFE_FAST_URL, 'saveAs': 'GOAT'}); |
| 94 }, | 373 }, |
| 374 | |
| 95 function downloadInvalidHeadersOption() { | 375 function downloadInvalidHeadersOption() { |
| 96 assertThrows(('Invalid value for argument 1. Property \'headers\': ' + | 376 assertThrows(('Invalid value for argument 1. Property \'headers\': ' + |
| 97 'Expected \'array\' but got \'string\'.'), | 377 'Expected \'array\' but got \'string\'.'), |
| 98 downloads.download, | 378 downloads.download, |
| 99 {'url': SAFE_FAST_URL, 'headers': 'GOAT'}); | 379 {'url': SAFE_FAST_URL, 'headers': 'GOAT'}); |
| 100 }, | 380 }, |
| 381 | |
| 101 function downloadInvalidURL() { | 382 function downloadInvalidURL() { |
| 383 // Test that download() requires a valid url. | |
|
cbentzel
2012/02/10 22:32:52
This comment isn't really needed.
| |
| 102 downloads.download( | 384 downloads.download( |
| 103 {'url': 'foo bar'}, | 385 {'url': 'foo bar'}, |
| 104 chrome.test.callbackFail(ERROR_INVALID_URL)); | 386 chrome.test.callbackFail(ERROR_INVALID_URL)); |
| 105 }, | 387 }, |
| 388 | |
| 106 function downloadInvalidMethod() { | 389 function downloadInvalidMethod() { |
| 107 assertThrows(('Invalid value for argument 1. Property \'method\': ' + | 390 assertThrows(('Invalid value for argument 1. Property \'method\': ' + |
| 108 'Value must be one of: [GET, POST].'), | 391 'Value must be one of: [GET, POST].'), |
| 109 downloads.download, | 392 downloads.download, |
| 110 {'url': SAFE_FAST_URL, 'method': 'GOAT'}); | 393 {'url': SAFE_FAST_URL, 'method': 'GOAT'}); |
| 111 }, | 394 }, |
| 112 function downloadSimple() { | 395 |
| 113 downloads.download( | |
| 114 {'url': SAFE_FAST_URL}, | |
| 115 chrome.test.callbackPass(function(id) { | |
| 116 chrome.test.assertEq(getNextId(), id); | |
| 117 })); | |
| 118 }, | |
| 119 function downloadPost() { | |
| 120 downloads.download( | |
| 121 {'url': getURL('files/post/downloads/a_zip_file.js'), | |
| 122 'method': 'POST', | |
| 123 'body': 'WOOHOO'}, | |
| 124 chrome.test.callbackPass(function(id) { | |
| 125 chrome.test.assertEq(getNextId(), id); | |
| 126 })); | |
| 127 }, | |
| 128 function downloadHeader() { | |
| 129 downloads.download( | |
| 130 {'url': SAFE_FAST_URL, | |
| 131 'headers': [{'name': 'Foo', 'value': 'bar'}] | |
| 132 }, | |
| 133 chrome.test.callbackPass(function(id) { | |
| 134 chrome.test.assertEq(getNextId(), id); | |
| 135 })); | |
| 136 }, | |
| 137 function downloadInterrupted() { | |
| 138 // TODO(benjhayden): Find a suitable URL and test that this id is | |
| 139 // eventually interrupted using onChanged. | |
| 140 downloads.download( | |
| 141 {'url': SAFE_FAST_URL}, | |
| 142 chrome.test.callbackPass(function(id) { | |
| 143 chrome.test.assertEq(getNextId(), id); | |
| 144 })); | |
| 145 }, | |
| 146 function downloadInvalidHeader() { | 396 function downloadInvalidHeader() { |
| 397 // Test that download() disallows setting the Cookie header. | |
| 147 downloads.download( | 398 downloads.download( |
| 148 {'url': SAFE_FAST_URL, | 399 {'url': SAFE_FAST_URL, |
| 149 'headers': [{ 'name': 'Cookie', 'value': 'fake'}] | 400 'headers': [{ 'name': 'Cookie', 'value': 'fake'}] |
| 150 }, | 401 }, |
| 151 chrome.test.callbackFail(ERROR_GENERIC)); | 402 chrome.test.callbackFail(ERROR_GENERIC)); |
| 152 // TODO(benjhayden): Give a better error message. | 403 }, |
| 153 }, | 404 |
| 154 function downloadGetFileIconInvalidOptions() { | 405 function downloadGetFileIconInvalidOptions() { |
| 155 assertThrows(('Invalid value for argument 2. Property \'cat\': ' + | 406 assertThrows(('Invalid value for argument 2. Property \'cat\': ' + |
| 156 'Unexpected property.'), | 407 'Unexpected property.'), |
| 157 downloads.getFileIcon, | 408 downloads.getFileIcon, |
| 158 -1, {cat: 'mouse'}); | 409 -1, {cat: 'mouse'}); |
| 159 }, | 410 }, |
| 411 | |
| 160 function downloadGetFileIconInvalidSize() { | 412 function downloadGetFileIconInvalidSize() { |
| 161 assertThrows(('Invalid value for argument 2. Property \'size\': ' + | 413 assertThrows(('Invalid value for argument 2. Property \'size\': ' + |
| 162 'Value must be one of: [16, 32].'), | 414 'Value must be one of: [16, 32].'), |
| 163 downloads.getFileIcon, -1, {size: 31}); | 415 downloads.getFileIcon, -1, {size: 31}); |
| 164 }, | 416 }, |
| 417 | |
| 165 function downloadGetFileIconInvalidId() { | 418 function downloadGetFileIconInvalidId() { |
| 166 downloads.getFileIcon(-42, {size: 32}, | 419 downloads.getFileIcon(-42, {size: 32}, |
| 167 chrome.test.callbackFail(ERROR_INVALID_OPERATION)); | 420 chrome.test.callbackFail(ERROR_INVALID_OPERATION)); |
| 168 }, | 421 }, |
| 169 function downloadNoComplete() { | 422 |
| 170 // This is used partly to test cleanUp. | |
| 171 downloads.download( | |
| 172 {'url': NEVER_FINISH_URL}, | |
| 173 chrome.test.callbackPass(function(id) { | |
| 174 chrome.test.assertEq(getNextId(), id); | |
| 175 })); | |
| 176 }, | |
| 177 function downloadPauseInvalidId() { | 423 function downloadPauseInvalidId() { |
| 178 downloads.pause(-42, chrome.test.callbackFail(ERROR_INVALID_OPERATION)); | 424 downloads.pause(-42, chrome.test.callbackFail(ERROR_INVALID_OPERATION)); |
| 179 }, | 425 }, |
| 426 | |
| 180 function downloadPauseInvalidType() { | 427 function downloadPauseInvalidType() { |
| 181 assertThrows(('Invalid value for argument 1. Expected \'integer\' ' + | 428 assertThrows(('Invalid value for argument 1. Expected \'integer\' ' + |
| 182 'but got \'string\'.'), | 429 'but got \'string\'.'), |
| 183 downloads.pause, | 430 downloads.pause, |
| 184 'foo'); | 431 'foo'); |
| 185 }, | 432 }, |
| 433 | |
| 186 function downloadResumeInvalidId() { | 434 function downloadResumeInvalidId() { |
| 187 downloads.resume(-42, chrome.test.callbackFail(ERROR_INVALID_OPERATION)); | 435 downloads.resume(-42, chrome.test.callbackFail(ERROR_INVALID_OPERATION)); |
| 188 }, | 436 }, |
| 437 | |
| 189 function downloadResumeInvalidType() { | 438 function downloadResumeInvalidType() { |
| 190 assertThrows(('Invalid value for argument 1. Expected \'integer\' ' + | 439 assertThrows(('Invalid value for argument 1. Expected \'integer\' ' + |
| 191 'but got \'string\'.'), | 440 'but got \'string\'.'), |
| 192 downloads.resume, | 441 downloads.resume, |
| 193 'foo'); | 442 'foo'); |
| 194 }, | 443 }, |
| 444 | |
| 195 function downloadCancelInvalidId() { | 445 function downloadCancelInvalidId() { |
| 196 // Canceling a non-existent download is not considered an error. | 446 // Canceling a non-existent download is not considered an error. |
| 197 downloads.cancel(-42, chrome.test.callbackPass(function() {})); | 447 downloads.cancel(-42, chrome.test.callbackPass(function() {})); |
| 198 }, | 448 }, |
| 449 | |
| 199 function downloadCancelInvalidType() { | 450 function downloadCancelInvalidType() { |
| 200 assertThrows(('Invalid value for argument 1. Expected \'integer\' ' + | 451 assertThrows(('Invalid value for argument 1. Expected \'integer\' ' + |
| 201 'but got \'string\'.'), | 452 'but got \'string\'.'), |
| 202 downloads.cancel, 'foo'); | 453 downloads.cancel, 'foo'); |
| 203 }, | 454 }, |
| 455 | |
| 456 function downloadNoComplete() { | |
| 457 // This is used partly to test cleanUp. | |
| 458 var download_id = getNextId(); | |
| 459 console.log("id: " + download_id); | |
| 460 downloads.download( | |
| 461 {'url': NEVER_FINISH_URL}, | |
| 462 chrome.test.callbackPass(function(id) { | |
| 463 console.log("id: " + download_id); | |
| 464 chrome.test.assertEq(download_id, id); | |
| 465 })); | |
| 466 }, | |
| 467 | |
| 204 function cleanUp() { | 468 function cleanUp() { |
| 205 // cleanUp must come last. It clears out all in-progress downloads | 469 // cleanUp must come last. It clears out all in-progress downloads |
| 206 // so the browser can shutdown cleanly. | 470 // so the browser can shutdown cleanly. |
| 207 for (var id = 0; id < nextId; ++id) { | 471 for (var id = 0; id < nextId; ++id) { |
| 208 downloads.cancel(id, chrome.test.callbackPass(function() {})); | 472 downloads.cancel(id, chrome.test.callbackPass(function() {})); |
| 209 } | 473 } |
| 210 } | 474 } |
| 211 ]); | 475 ]); |
| 212 }); | 476 }); |
| OLD | NEW |