Skip to content

Commit

Permalink
RT: Fix t_page and t_resp missing from the beacon
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Apr 4, 2018
1 parent 42d6782 commit 6f1acad
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"jquery": "~2.1.4",
"json3": "~3.3.2",
"lodash": "~3.0.0",
"mocha": "~1.21.5",
"mocha": "~3.4.2",
"resourcetiming-compression": "^0.3.3",
"usertiming-compression": "~0.1.4"
},
Expand Down
6 changes: 4 additions & 2 deletions plugins/rt.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
// the value for the new request.
BOOMR.addVar("rt.start", source || "navigation");
this.navigationStart = ti.navigationStart || ti.fetchStart || undefined;
this.fetchStart = ti.fetchStart || undefined;
this.responseStart = ti.responseStart || undefined;

// bug in Firefox 7 & 8 https://bugzilla.mozilla.org/show_bug.cgi?id=691547
Expand Down Expand Up @@ -457,8 +458,9 @@
// Use NavTiming API to figure out resp latency and page time
// t_resp will use the cookie if available or fallback to NavTiming

// only use if the time looks legit (after navigationStart)
if (impl.responseStart >= impl.cached_t_start) {
// only use if the time looks legit (after navigationStart/fetchStart)
if (impl.responseStart >= impl.navigationStart &&
impl.responseStart >= impl.fetchStart) {
t_resp_start = impl.responseStart;
}
}
Expand Down
14 changes: 0 additions & 14 deletions tests/page-templates/06-bugs/04-resend-far-future.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@ describe("e2e/06-bugs/04-resend-far-future", function() {
var t = BOOMR_test;
var tf = BOOMR.plugins.TestFramework;

it("Should not have t_resp (if NavigationTiming is supported)", function() {
if (t.isNavigationTimingSupported()) {
var b = tf.lastBeacon();
assert.isUndefined(b.t_resp);
}
});

it("Should not have t_page (if NavigationTiming is supported)", function() {
if (t.isNavigationTimingSupported()) {
var b = tf.lastBeacon();
assert.isUndefined(b.t_page);
}
});

it("Should have nt_bad (if NavigationTiming is supported)", function() {
if (t.isNavigationTimingSupported()) {
var b = tf.lastBeacon();
Expand Down
9 changes: 9 additions & 0 deletions tests/page-templates/19-navtiming/02-front-end-back-end.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= header %>
<%= boomerangSnippet %>
<script src="02-front-end-back-end.js" type="text/javascript"></script>
<script>
BOOMR_test.init({
testAfterOnBeacon: true
});
</script>
<%= footer %>
51 changes: 51 additions & 0 deletions tests/page-templates/19-navtiming/02-front-end-back-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*eslint-env mocha*/
/*global BOOMR_test,assert*/

describe("e2e/19-navtiming/02-front-end-back-end", function() {
var tf = BOOMR.plugins.TestFramework;
var t = BOOMR_test;

it("Should have Front-End time (t_page) on the beacon (if NavigationTiming is supported)", function() {
if (!t.isNavigationTimingSupported()) {
return this.skip();
}

assert.isNumber(tf.lastBeacon().t_page);
});

it("Should not have Front-End time (t_page) on the beacon (if NavigationTiming is not supported)", function() {
if (t.isNavigationTimingSupported()) {
return this.skip();
}

assert.isUndefined(tf.lastBeacon().t_page);
});

it("Should have Back-End time (t_resp) on the beacon (if NavigationTiming is supported)", function() {
if (!t.isNavigationTimingSupported()) {
return this.skip();
}

assert.isNumber(tf.lastBeacon().t_resp);
});

it("Should not have Back-End time (t_resp) on the beacon (if NavigationTiming is not supported)", function() {
if (t.isNavigationTimingSupported()) {
return this.skip();
}

assert.isUndefined(tf.lastBeacon().t_resp);
});

it("Should have Back-End time + Front-End time equal Page Load time (t_resp + t_page = t_done) on the beacon (if NavigationTiming is supported)", function() {
if (!t.isNavigationTimingSupported()) {
return this.skip();
}

var fe = parseInt(tf.lastBeacon().t_page, 10);
var be = parseInt(tf.lastBeacon().t_resp, 10);
var tt = parseInt(tf.lastBeacon().t_done, 10);

assert.equal(fe + be, tt);
});
});

0 comments on commit 6f1acad

Please sign in to comment.