| OLD | NEW |
| 1 // Runs a series of tests related to importing scripts on a worklet. | 1 // Runs a series of tests related to importing scripts on a worklet. |
| 2 // | 2 // |
| 3 // Usage: | 3 // Usage: |
| 4 // runImportTests(workletType); | 4 // runImportTests(workletType); |
| 5 function runImportTests(worklet, opt_path) { | 5 function runImportTests(worklet, opt_path) { |
| 6 const path = opt_path || ''; | 6 const path = opt_path || ''; |
| 7 | 7 |
| 8 promise_test(function() { | 8 promise_test(function() { |
| 9 return worklet.import(path + 'resources/empty-worklet-script.js').then(f
unction(undefined_arg) { | 9 return worklet.import(path + 'resources/empty-worklet-script.js').then(f
unction(undefined_arg) { |
| 10 assert_equals(undefined_arg, undefined, 'Promise should resolve with
no arguments.'); | 10 assert_equals(undefined_arg, undefined, 'Promise should resolve with
no arguments.'); |
| 11 }).catch(function(error) { | |
| 12 assert_unreached('unexpected rejection: ' + error); | |
| 13 }); | 11 }); |
| 14 | |
| 15 }, 'Importing a script resolves the given promise.'); | 12 }, 'Importing a script resolves the given promise.'); |
| 16 | 13 |
| 17 promise_test(function() { | 14 promise_test(function() { |
| 15 return Promise.all([ |
| 16 worklet.import(path + 'resources/empty-worklet-script.js?1'), |
| 17 worklet.import(path + 'resources/empty-worklet-script.js?2'), |
| 18 worklet.import(path + 'resources/empty-worklet-script.js?3') |
| 19 ]).then(function(undefined_args) { |
| 20 assert_array_equals(undefined_args, [undefined, undefined, undefined
], 'Promise should resolve with no arguments.'); |
| 21 }); |
| 22 }, 'Importing scripts resolves all the given promises.'); |
| 18 | 23 |
| 24 promise_test(function() { |
| 19 return worklet.import(path + 'resources/throwing-worklet-script.js').the
n(function(undefined_arg) { | 25 return worklet.import(path + 'resources/throwing-worklet-script.js').the
n(function(undefined_arg) { |
| 20 assert_equals(undefined_arg, undefined, 'Promise should resolve with
no arguments.'); | 26 assert_equals(undefined_arg, undefined, 'Promise should resolve with
no arguments.'); |
| 21 }).catch(function(error) { | |
| 22 assert_unreached('unexpected rejection: ' + error); | |
| 23 }); | 27 }); |
| 24 | |
| 25 }, 'Importing a script which throws should still resolve the given promise.'
); | 28 }, 'Importing a script which throws should still resolve the given promise.'
); |
| 26 | 29 |
| 27 promise_test(function() { | 30 promise_test(function() { |
| 28 | |
| 29 return worklet.import(path + 'non-existant-worklet-script.js').then(func
tion() { | 31 return worklet.import(path + 'non-existant-worklet-script.js').then(func
tion() { |
| 30 assert_unreached('import should fail.'); | 32 assert_unreached('import should fail.'); |
| 31 }).catch(function(error) { | 33 }).catch(function(error) { |
| 32 assert_equals(error.name, 'NetworkError', 'error should be a Network
Error.'); | 34 assert_equals(error.name, 'NetworkError', 'error should be a Network
Error.'); |
| 33 }); | 35 }); |
| 34 | |
| 35 }, 'Importing a non-existant script rejects the given promise with a Network
Error.'); | 36 }, 'Importing a non-existant script rejects the given promise with a Network
Error.'); |
| 36 | 37 |
| 37 promise_test(function() { | 38 promise_test(function() { |
| 38 | |
| 39 return worklet.import('http://invalid:123$').then(function() { | 39 return worklet.import('http://invalid:123$').then(function() { |
| 40 assert_unreached('import should fail.'); | 40 assert_unreached('import should fail.'); |
| 41 }).catch(function(error) { | 41 }).catch(function(error) { |
| 42 assert_equals(error.name, 'SyntaxError', 'error should be a SyntaxEr
ror.'); | 42 assert_equals(error.name, 'SyntaxError', 'error should be a SyntaxEr
ror.'); |
| 43 }); | 43 }); |
| 44 | |
| 45 }, 'Attempting to resolve an invalid URL should reject the given promise wit
h a SyntaxError.'); | 44 }, 'Attempting to resolve an invalid URL should reject the given promise wit
h a SyntaxError.'); |
| 46 } | 45 } |
| OLD | NEW |