|
| 1 | +/*global assert*/ |
| 2 | +function iframeExecute(iframe, done, execute, assertCallback) { |
| 3 | + iframe.contentWindow.done = function () { |
| 4 | + try { |
| 5 | + assertCallback(iframe); |
| 6 | + done(); |
| 7 | + } catch (e) { |
| 8 | + done(e); |
| 9 | + } |
| 10 | + } |
| 11 | + iframe.contentWindow.eval('(' + execute.toString() + ')();'); |
| 12 | +} |
| 13 | + |
| 14 | +describe('integration', function () { |
| 15 | + beforeEach(function (done) { |
| 16 | + var iframe = this.iframe = document.createElement('iframe'); |
| 17 | + iframe.style.display = 'none'; |
| 18 | + iframe.src = './frame.html'; |
| 19 | + iframe.onload = function () { |
| 20 | + done(); |
| 21 | + }; |
| 22 | + document.body.appendChild(iframe); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(function () { |
| 26 | + document.body.removeChild(this.iframe); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('native', function () { |
| 30 | + it('should capture exceptions from event listeners', function (done) { |
| 31 | + var iframe = this.iframe; |
| 32 | + |
| 33 | + iframeExecute(iframe, done, |
| 34 | + function () { |
| 35 | + var div = document.createElement('div'); |
| 36 | + document.body.appendChild(div); |
| 37 | + div.addEventListener('click', function () { |
| 38 | + foo(); |
| 39 | + }, false); |
| 40 | + |
| 41 | + // use setTimeout to "normalize" stack origin |
| 42 | + setTimeout(function () { |
| 43 | + var evt; |
| 44 | + if (document.createEvent) { |
| 45 | + evt = document.createEvent('MouseEvents'); |
| 46 | + evt.initEvent('click', true, false); |
| 47 | + div.dispatchEvent(evt); |
| 48 | + } else if(document.createEventObject) { |
| 49 | + div.fireEvent('onclick'); |
| 50 | + } |
| 51 | + }); |
| 52 | + |
| 53 | + setTimeout(done); |
| 54 | + }, |
| 55 | + function () { |
| 56 | + var ravenData = iframe.contentWindow.ravenData; |
| 57 | + assert.equal(ravenData.exception.values[0].stacktrace.frames.length, 3); |
| 58 | + } |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should capture exceptions inside setTimeout', function (done) { |
| 63 | + var iframe = this.iframe; |
| 64 | + |
| 65 | + iframeExecute(iframe, done, |
| 66 | + function () { |
| 67 | + setTimeout(function () { |
| 68 | + setTimeout(done); |
| 69 | + foo(); |
| 70 | + }, 10); |
| 71 | + }, |
| 72 | + function () { |
| 73 | + var ravenData = iframe.contentWindow.ravenData; |
| 74 | + assert.equal(ravenData.exception.values[0].stacktrace.frames.length, 2); |
| 75 | + } |
| 76 | + ); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should capture exceptions inside setInterval', function (done) { |
| 80 | + var iframe = this.iframe; |
| 81 | + |
| 82 | + iframeExecute(iframe, done, |
| 83 | + function () { |
| 84 | + var exceptionInterval = setInterval(function () { |
| 85 | + setTimeout(done); |
| 86 | + clearInterval(exceptionInterval); |
| 87 | + foo(); |
| 88 | + }, 10); |
| 89 | + }, |
| 90 | + function () { |
| 91 | + var ravenData = iframe.contentWindow.ravenData; |
| 92 | + assert.equal(ravenData.exception.values[0].stacktrace.frames.length, 2); |
| 93 | + } |
| 94 | + ); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should capture exceptions inside requestAnimationFrame', function (done) { |
| 98 | + var iframe = this.iframe; |
| 99 | + // needs to be visible or requestAnimationFrame won't ever fire |
| 100 | + iframe.style.display = 'block'; |
| 101 | + |
| 102 | + iframeExecute(iframe, done, |
| 103 | + function () { |
| 104 | + requestAnimationFrame(function () { |
| 105 | + setTimeout(done); |
| 106 | + foo(); |
| 107 | + }); |
| 108 | + }, |
| 109 | + function () { |
| 110 | + var ravenData = iframe.contentWindow.ravenData; |
| 111 | + assert.equal(ravenData.exception.values[0].stacktrace.frames.length, 2); |
| 112 | + } |
| 113 | + ); |
| 114 | + }); |
| 115 | + }); |
| 116 | +}); |
0 commit comments