Skip to content

Commit

Permalink
AutoXHR: Fixes XHR after click missing beacon
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Apr 3, 2018
1 parent cc058d7 commit 970ad46
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/auto-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
// 3.1 & 3.3
if (last_ev.nodes_to_wait === 0 || !last_ev.resource.url) {
this.pending_events[i] = undefined;
return null;// abort
// continue with new event
}
// last_ev will no longer receive watches as ev will receive them
// last_ev will wait fall interesting nodes and then send event
Expand Down
63 changes: 63 additions & 0 deletions tests/page-templates/07-autoxhr/37-xhr-after-click.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<%= header %>
<%= boomerangScript %>

<div id="clickable">Click Me!</div>
<div id="picture"></div>

<script type="text/javascript">
(function(w, d) {
var imageHolder = d.getElementById("picture");
var clickable = d.getElementById("clickable");
function clickCb() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "support/img.jpg");
xhr.send();
}

function addEvent(element, event, funct){
if (element.attachEvent) {
return element.attachEvent("on" + event, funct);
}
else {
return element.addEventListener(event, funct);
}
}
addEvent(clickable, "mouseup", clickCb);
}(this, this.document));
</script>
<script src="37-xhr-after-click.js"></script>
<script>
var eventFired = false;
BOOMR_test.init({
testAfterOnBeacon: BOOMR.plugins.AutoXHR ? 2 : 1,
instrument_xhr: true,
ResourceTiming: {
enabled: true
},
autorun: true,
afterFirstBeacon: function() {
if (!BOOMR.plugins.AutoXHR || eventFired) {
return;
}

setTimeout(function() {
var clickable = document.getElementById("clickable");

function eventFire(etype){
if (clickable.fireEvent) {
clickable.fireEvent("on" + etype);
}
else {
var evObj = document.createEvent("MouseEvent");
evObj.initEvent(etype, true, false);
clickable.dispatchEvent(evObj);
}
eventFired = true;
}
eventFire("mouseup");
}, 50);
}
});
</script>

<%= footer %>
44 changes: 44 additions & 0 deletions tests/page-templates/07-autoxhr/37-xhr-after-click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*eslint-env mocha*/
/*global BOOMR_test,assert*/

describe("e2e/07-autoxhr/37-xhr-after-click", function() {
var t = BOOMR_test;
var tf = BOOMR.plugins.TestFramework;
it("Should have sent at least 2 beacons, 1x onload, 1x xhr", function(done) {
t.ifAutoXHR(
done,
function() {
assert.lengthOf(tf.beacons, 2);
done();
}
);
});

it("Should have a first beacon have the URL of the page", function(done){
if (window.MutationObserver && typeof window.MutationObserver === "function") {
t.ifAutoXHR(
done,
function() {
assert.include(tf.beacons[0].u, "37-xhr-after-click.html");
done();
});
}
else {
done();
}
});

it("Should have a second beacon with the XHR URL in it", function(done){
if (window.MutationObserver && typeof window.MutationObserver === "function") {
t.ifAutoXHR(
done,
function() {
assert.include(tf.beacons[1].u, "img.jpg");
done();
});
}
else {
done();
}
});
});

0 comments on commit 970ad46

Please sign in to comment.