OLD | NEW |
(Empty) | |
| 1 // note, this template substitution is XSS, but no way to avoid it in this frame
work |
| 2 var expected_alerts = {{GET[alerts]}}; |
| 3 var timeout= "{{GET[timeout]}}"; |
| 4 if (timeout == "") { |
| 5 timeout = 2; |
| 6 } |
| 7 |
| 8 if(expected_alerts.length == 0) { |
| 9 function alert_assert(msg) { |
| 10 test(function () { assert_unreached(msg) }); |
| 11 } |
| 12 } else { |
| 13 var t_alert = async_test('Expecting alerts: {{GET[alerts]}}'); |
| 14 step_timeout(function() { |
| 15 if(t_alert.phase != t_alert.phases.COMPLETE) { |
| 16 t_alert.step(function() { assert_unreached('Alert timeout, expected alerts
' + expected_alerts + ' not fired.') }); |
| 17 t_alert.done(); |
| 18 } |
| 19 }, timeout * 1000); |
| 20 var alert_assert = function (msg) { |
| 21 t_alert.step(function () { |
| 22 if(msg && msg instanceof Error) { |
| 23 msg = msg.message; |
| 24 } |
| 25 if (msg && msg.match(/^FAIL/i)) { |
| 26 assert_unreached(msg); |
| 27 t_alert.done(); |
| 28 } |
| 29 for (var i = 0; i < expected_alerts.length; i++) { |
| 30 if (expected_alerts[i] == msg) { |
| 31 assert_true(expected_alerts[i] == msg); |
| 32 expected_alerts.splice(i, 1); |
| 33 if (expected_alerts.length == 0) { |
| 34 t_alert.done(); |
| 35 } |
| 36 return; |
| 37 } |
| 38 } |
| 39 assert_unreached('unexpected alert: ' + msg); |
| 40 t_log.done(); |
| 41 }); |
| 42 }.bind(this); |
| 43 } |
OLD | NEW |