Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: Fix all outstanding integration tests on Chrome/FF/Safari
- Fix MouseEvents related integration tests on Chrome
- Fix Mouse/KeyboardEvents related integration tests on Firefox
- Update captureException test assertion for Safari
- Fix non-error throws in onerror handler on Firefox
- Simplify _normalizeFrame edgecase and comment on event factories
  • Loading branch information
kamilogorek committed Sep 8, 2017
commit bb620cb1c82229e24b6112873d4c5e82ecd939de
15 changes: 11 additions & 4 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All @@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All @@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
203 changes: 15 additions & 188 deletions test/integration/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('integration', function() {
},
function() {
var ravenData = iframe.contentWindow.ravenData[0];
assert.isAbove(ravenData.stacktrace.frames.length, 1);
assert.isAbove(ravenData.stacktrace.frames.length, 0);

// verify trimHeadFrames hasn't slipped into final payload
assert.isUndefined(ravenData.trimHeadFrames);
Expand Down Expand Up @@ -458,14 +458,8 @@ describe('integration', function() {
false
);

var evt;
if (document.createEvent) {
evt = document.createEvent('MouseEvents');
evt.initEvent('click', true, false);
div.dispatchEvent(evt);
} else if (document.createEventObject) {
div.fireEvent('onclick');
}
var click = createMouseEvent();
div.dispatchEvent(click);
},
function() {
var ravenData = iframe.contentWindow.ravenData[0];
Expand Down Expand Up @@ -828,24 +822,7 @@ describe('integration', function() {
input.addEventListener('click', clickHandler);

// click <input/>
var evt = document.createEvent('MouseEvent');
evt.initMouseEvent(
'click',
true /* bubble */,
true /* cancelable */,
window,
null,
0,
0,
0,
0 /* coordinates */,
false,
false,
false,
false /* modifier keys */,
0 /*left*/,
null
);
var evt = createMouseEvent();
input.dispatchEvent(evt);
},
function() {
Expand Down Expand Up @@ -878,24 +855,7 @@ describe('integration', function() {
Raven._breadcrumbs = [];

// click <input/>
var evt = document.createEvent('MouseEvent');
evt.initMouseEvent(
'click',
true /* bubble */,
true /* cancelable */,
window,
null,
0,
0,
0,
0 /* coordinates */,
false,
false,
false,
false /* modifier keys */,
0 /*left*/,
null
);
var evt = createMouseEvent();

var input = document.getElementsByTagName('input')[0];
input.dispatchEvent(evt);
Expand Down Expand Up @@ -941,24 +901,7 @@ describe('integration', function() {
document.querySelector('.c').addEventListener('click', clickHandler);

// click <input/>
var evt = document.createEvent('MouseEvent');
evt.initMouseEvent(
'click',
true /* bubble */,
true /* cancelable */,
window,
null,
0,
0,
0,
0 /* coordinates */,
false,
false,
false,
false /* modifier keys */,
0 /*left*/,
null
);
var evt = createMouseEvent();

var input = document.querySelector('.a'); // leaf node
input.dispatchEvent(evt);
Expand Down Expand Up @@ -993,25 +936,7 @@ describe('integration', function() {
Raven._breadcrumbs = [];

// click <input/>
var evt = document.createEvent('MouseEvent');
evt.initMouseEvent(
evt,
'click',
true /* bubble */,
true /* cancelable */,
window,
null,
0,
0,
0,
0 /* coordinates */,
false,
false,
false,
false /* modifier keys */,
0 /*left*/,
null
);
var evt = createMouseEvent();

function kaboom() {
throw new Error('lol');
Expand Down Expand Up @@ -1049,31 +974,8 @@ describe('integration', function() {
Raven._breadcrumbs = [];

// keypress <input/> twice
var keypress1 = document.createEvent('KeyboardEvent');
keypress1.initKeyboardEvent(
'keypress',
true,
true,
window,
'b',
66,
0,
'',
false
);

var keypress2 = document.createEvent('KeyboardEvent');
keypress2.initKeyboardEvent(
'keypress',
true,
true,
window,
'a',
65,
0,
'',
false
);
var keypress1 = createKeyboardEvent('a');
var keypress2 = createKeyboardEvent('b');

var input = document.getElementsByTagName('input')[0];
input.dispatchEvent(keypress1);
Expand Down Expand Up @@ -1107,18 +1009,7 @@ describe('integration', function() {
Raven._breadcrumbs = [];

// keypress <input/>
var keypress = document.createEvent('KeyboardEvent');
keypress.initKeyboardEvent(
'keypress',
true,
true,
window,
'b',
66,
0,
'',
false
);
var keypress = createKeyboardEvent();

var input = document.getElementsByTagName('input')[0];
input.dispatchEvent(keypress);
Expand Down Expand Up @@ -1156,52 +1047,11 @@ describe('integration', function() {
Raven._breadcrumbs = [];

// 1st keypress <input/>
var keypress1 = document.createEvent('KeyboardEvent');
keypress1.initKeyboardEvent(
'keypress',
true,
true,
window,
'b',
66,
0,
'',
false
);

var keypress1 = createKeyboardEvent('a');
// click <input/>
var click = document.createEvent('MouseEvent');
click.initMouseEvent(
'click',
true /* bubble */,
true /* cancelable */,
window,
null,
0,
0,
0,
0 /* coordinates */,
false,
false,
false,
false /* modifier keys */,
0 /*left*/,
null
);

var click = createMouseEvent();
// 2nd keypress
var keypress2 = document.createEvent('KeyboardEvent');
keypress2.initKeyboardEvent(
'keypress',
true,
true,
window,
'a',
65,
0,
'',
false
);
var keypress2 = createKeyboardEvent('b');

var input = document.getElementsByTagName('input')[0];
input.dispatchEvent(keypress1);
Expand Down Expand Up @@ -1251,31 +1101,8 @@ describe('integration', function() {
Raven._breadcrumbs = [];

// keypress <input/> twice
var keypress1 = document.createEvent('KeyboardEvent');
keypress1.initKeyboardEvent(
'keypress',
true,
true,
window,
'b',
66,
0,
'',
false
);

var keypress2 = document.createEvent('KeyboardEvent');
keypress2.initKeyboardEvent(
'keypress',
true,
true,
window,
'a',
65,
0,
'',
false
);
var keypress1 = createKeyboardEvent('a');
var keypress2 = createKeyboardEvent('b');

var div = document.querySelector('[contenteditable]');
div.dispatchEvent(keypress1);
Expand Down