| OLD | NEW |
| 1 // Helper method that waits for a {success: <boolean>, result: any} reply on | 1 // Helper method that waits for a {success: <boolean>, result: any} reply on |
| 2 // a port and returns a promise that resolves (if success is true) or rejects | 2 // a port and returns a promise that resolves (if success is true) or rejects |
| 3 // the promise with the value of the result attribute. | 3 // the promise with the value of the result attribute. |
| 4 function reply_as_promise(t, port) { | 4 function reply_as_promise(t, port) { |
| 5 return new Promise(function(resolve, reject) { | 5 return new Promise(function(resolve, reject) { |
| 6 var got_reply = false; | 6 var got_reply = false; |
| 7 port.onmessage = t.step_func(function(event) { | 7 port.onmessage = t.step_func(function(event) { |
| 8 assert_false(got_reply); | 8 assert_false(got_reply); |
| 9 assert_true('success' in event.data); | 9 assert_true('success' in event.data); |
| 10 assert_true('result' in event.data); | 10 assert_true('result' in event.data); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 }; | 83 }; |
| 84 // Should use addEventListener and check source of event, but source isn't | 84 // Should use addEventListener and check source of event, but source isn't |
| 85 // set yet, so for now just assume only one wrapped port is used at a time
. | 85 // set yet, so for now just assume only one wrapped port is used at a time
. |
| 86 navigator.services.onmessage = function(event) { | 86 navigator.services.onmessage = function(event) { |
| 87 channel.port2.postMessage(event.data, event.ports); | 87 channel.port2.postMessage(event.data, event.ports); |
| 88 }; | 88 }; |
| 89 return channel.port1; | 89 return channel.port1; |
| 90 } | 90 } |
| 91 ); | 91 ); |
| 92 } | 92 } |
| 93 | |
| 94 var promise_tests = Promise.resolve(); | |
| 95 // Helper function to run promise tests one after the other. | |
| 96 // TODO(ortuno): Remove once https://github.com/w3c/testharness.js/pull/115/file
s | |
| 97 // gets through. | |
| 98 function sequential_promise_test(func, name) { | |
| 99 var test = async_test(name); | |
| 100 promise_tests = promise_tests.then(function() { | |
| 101 return test.step(func, test, test); | |
| 102 }).then(function() { | |
| 103 test.done(); | |
| 104 }).catch(test.step_func(function(value) { | |
| 105 // step_func catches the error again so the error doesn't propagate. | |
| 106 throw value; | |
| 107 })); | |
| 108 } | |
| OLD | NEW |