Skip to content

Commit

Permalink
01-beacon-type/04-send-beacon: Change how sendBeacon is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Apr 4, 2018
1 parent f67eac2 commit bc89347
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
15 changes: 0 additions & 15 deletions tests/boomerang-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,6 @@
done();
};

t.validateBeaconWasSendBeacon = function(done) {
if (!t.isResourceTimingSupported()) {
// need RT to validate
return done();
}

// look at the initiator
var res = this.findResourceTimingBeacon();
assert.isDefined(res, "sendBeacon existed in ResourceTiming");
assert.isNotNull(res, "sendBeacon existed in ResourceTiming");
assert.equal(res.initiator, "beacon");

done();
};

t.isMutationObserverSupported = function() {
return (window.MutationObserver && typeof window.MutationObserver === "function");
};
Expand Down
10 changes: 10 additions & 0 deletions tests/page-templates/01-beacon-type/04-sendbeacon.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<%= header %>
<script>
window.sendBeaconUrl = undefined;
window.sendBeaconData = undefined;
if (window.navigator && typeof window.navigator.sendBeacon === "function") {
window.navigator.sendBeacon = function(url, data) {
sendBeaconUrl = url;
sendBeaconData = data;
};
}
</script>
<%= boomerangSnippet %>
<script src="04-sendbeacon.js" type="text/javascript"></script>
<script>
Expand Down
13 changes: 7 additions & 6 deletions tests/page-templates/01-beacon-type/04-sendbeacon.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*eslint-env mocha*/
/*global BOOMR_test*/

describe("e2e/01-beacon-type/00-resourcetiming-disabled", function() {
it("Should send an beacon via navigator.sendBeacon if it is available", function(done) {
describe("e2e/01-beacon-type/04-send-beacon", function() {
it("Should send an beacon via navigator.sendBeacon if it is available", function() {
if (window && window.navigator && typeof window.navigator.sendBeacon === "function") {
// NOTE: Currently this doesn't work because the beacon isn't added to ResourceTiming in Chrome/Opera:
// https://bugs.chromium.org/p/chromium/issues/detail?id=711060
// BOOMR_test.validateBeaconWasSendBeacon(done);
assert.isDefined(window.sendBeaconUrl);
assert.equal(window.sendBeaconUrl, BOOMR_test.BEACON_URL);

assert.isDefined(window.sendBeaconData);
}
else {
done();
this.skip();
}
});
});

0 comments on commit bc89347

Please sign in to comment.