forked from bluesmoon/boomerang
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoXHR: Fixes XHR after click missing beacon
- Loading branch information
Showing
3 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
}); |