Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Jun 27, 2016
1 parent db4dfda commit b70cb23
Show file tree
Hide file tree
Showing 14 changed files with 684 additions and 68 deletions.
40 changes: 27 additions & 13 deletions boomerang.js
Expand Up @@ -255,11 +255,11 @@ BOOMR_check_doc_domain();
// Whether or not to send beacons on page load
autorun: true,

strip_query_string: false,
//! strip_query_string: false,

onloadfired: false,
//! onloadfired: false,

handlers_attached: false,
//! handlers_attached: false,
events: {
"page_ready": [],
"page_unload": [],
Expand Down Expand Up @@ -354,11 +354,9 @@ BOOMR_check_doc_domain();
// we don't overwrite anything additional that was added to BOOMR before this
// was called... for example, a plugin.
boomr = {
t_lstart: null,
//! t_lstart: value of BOOMR_lstart set in host page
t_start: BOOMR_start,
t_end: null,
//! t_pload: Value of the BOOMR_onload set in the host page
t_onload: undefined,
//! t_end: value set in zzz-last-plugin.js

url: myurl,

Expand Down Expand Up @@ -449,8 +447,6 @@ BOOMR_check_doc_domain();
cookies = cookies.substring(i, cookies.indexOf(";", i)).replace(/^"/, "").replace(/"$/, "");
return cookies;
}

return null;
},

setCookie: function(name, subcookies, max_age) {
Expand Down Expand Up @@ -795,7 +791,15 @@ BOOMR_check_doc_domain();

init: function(config) {
var i, k,
properties = ["beacon_url", "beacon_type", "site_domain", "user_ip", "strip_query_string", "secondary_beacons", "autorun"];
properties = [
"beacon_url",
"beacon_type",
"site_domain",
"user_ip",
"strip_query_string",
"secondary_beacons",
"autorun"
];

BOOMR_check_doc_domain();

Expand Down Expand Up @@ -943,9 +947,10 @@ BOOMR_check_doc_domain();
impl.handlers_attached = true;
return this;
},

/**
* Sends the page_ready beacon only if 'autorun' is still true after config.js
* arrives.
* Sends the page_ready beacon only if 'autorun' is still true after init
* is called.
*/
page_ready_autorun: function(ev) {
if (impl.autorun) {
Expand Down Expand Up @@ -1345,7 +1350,7 @@ BOOMR_check_doc_domain();
// This plugin wants the beacon to go somewhere else,
// so update the location
if (beacon_url_override) {
impl.beacon_url = beacon_url_override;
impl.beacon_url_override = beacon_url_override;
}

if (!impl.beaconQueued) {
Expand Down Expand Up @@ -1435,6 +1440,9 @@ BOOMR_check_doc_domain();
// If we reach here, all plugins have completed
impl.fireEvent("before_beacon", impl.vars);

// Use the override URL if given
impl.beacon_url = impl.beacon_url_override || impl.beacon_url;

// Don't send a beacon if no beacon_url has been set
// you would do this if you want to do some fancy beacon handling
// in the `before_beacon` event instead of a simple GET request
Expand Down Expand Up @@ -1488,6 +1496,12 @@ BOOMR_check_doc_domain();
return this;
}

if (!BOOMR.orig_XMLHttpRequest && (!BOOMR.window || !BOOMR.window.XMLHttpRequest)) {
// if we don't have XHR available, force an image beacon and hope
// for the best
useImg = true;
}

if (useImg) {
img = new Image();
img.src = url;
Expand Down
22 changes: 17 additions & 5 deletions plugins/rt.js
Expand Up @@ -10,7 +10,9 @@

/*eslint no-underscore-dangle:0*/

var d = w.document, impl;
var d, impl,
COOKIE_EXP = 60 * 60 * 24 * 7;


BOOMR = BOOMR || {};
BOOMR.plugins = BOOMR.plugins || {};
Expand All @@ -32,7 +34,7 @@
timers: {}, //! Custom timers that the developer can use
// Format for each timer is { start: XXX, end: YYY, delta: YYY-XXX }
cookie: "RT", //! Name of the cookie that stores the start time and referrer
cookie_exp: 600, //! Cookie expiry in seconds
cookie_exp: COOKIE_EXP, //! Cookie expiry in seconds (7 days)
strict_referrer: true, //! By default, don't beacon if referrers don't match.
// If set to false, beacon both referrer values and let
// the back end decide
Expand Down Expand Up @@ -95,6 +97,7 @@

if (timer) {
subcookies[timer] = t_start;
impl.lastActionTime = t_start;
}

BOOMR.debug("Setting cookie (timer=" + timer + ")\n" + BOOMR.utils.objectToString(subcookies), "rt");
Expand Down Expand Up @@ -183,7 +186,9 @@
nu: undefined, // clicked url
ul: undefined, // onbeforeunload time
cl: undefined, // onclick time
hd: undefined // onunload or onpagehide time
hd: undefined, // onunload or onpagehide time
ld: undefined, // last load time
rl: undefined
});
},

Expand Down Expand Up @@ -555,12 +560,14 @@
if (ename === "xhr") {
if (data && data.name && impl.timers[data.name]) {
// For xhr timers, t_start is stored in impl.timers.xhr_{page group name}
// and xhr.pg is set to {page group name}
t_start = impl.timers[data.name].start;
}
else if (data && data.timing && data.timing.requestStart) {
// For automatically instrumented xhr timers, we have detailed timing information
t_start = data.timing.requestStart;
}

if (typeof t_start === "undefined" && data && BOOMR.utils.inArray(data.initiator, BOOMR.constants.BEACON_TYPE_SPAS)) {
// if we don't have a start time, set to none so it can possibly be fixed up
BOOMR.addVar("rt.start", "none");
Expand Down Expand Up @@ -633,6 +640,7 @@
// where location.href is URL decoded
this.updateCookie({ "r": d.URL }, edata.type === "beforeunload" ? "ul" : "hd");


this.unloadfired = true;
},

Expand Down Expand Up @@ -708,7 +716,11 @@
d = w.document;

BOOMR.utils.pluginConfig(impl, config, "RT",
["cookie", "cookie_exp", "strict_referrer"]);
["cookie", "cookie_exp", "session_exp", "strict_referrer"]);

if (config && typeof config.autorun !== "undefined") {
impl.autorun = config.autorun;
}

// A beacon may be fired automatically on page load or if the page dev fires
// it manually with their own timers. It may not always contain a referrer
Expand All @@ -719,7 +731,7 @@
impl.r = impl.r2 = BOOMR.utils.hashQueryString(d.referrer, true);
}

// Now pull out start time information from the cookie
// Now pull out start time information and session information from the cookie
// We'll do this every time init is called, and every time we call it, it will
// overwrite values already set (provided there are values to read out)
impl.initFromCookie();
Expand Down
16 changes: 15 additions & 1 deletion tests/page-templates/06-bugs/100506.html
@@ -1,6 +1,19 @@
<%= header %>
<%= boomerangScript %>
<script>
window.BOOMR = window.BOOMR || {};
window.BOOMR.plugins = window.BOOMR.plugins || {};

var readyToSend = false;
window.BOOMR.plugins.Hold = {
readyToSend: function() {
return readyToSend;
},
is_complete: function() {
return true;
}
};
</script>
<script src="100506.js" type="text/javascript"></script>

<!--
Expand Down Expand Up @@ -31,9 +44,10 @@
</script>

<!--
Initializing Boomerang now as if config.json came down later
Initializing Boomerang now as if init was called later
-->
<script>
readyToSend = true;
BOOMR_test.init({
testAfterOnBeacon: 3
});
Expand Down
4 changes: 0 additions & 4 deletions tests/page-templates/06-bugs/104197.js
Expand Up @@ -26,10 +26,6 @@ describe("e2e/06-bugs/104197", function() {
assert.equal(tf.beacons[2]["vis.pre"], 1);
});

it("Should have the third beacon have PageParams (Page Group)", function() {
assert.equal(tf.beacons[2]["h.pg"], "Page Group");
});

it("Should have the third beacon have NavigationTiming data (if available)", function() {
if (t.isNavigationTimingSupported()) {
assert.isDefined(tf.beacons[2].nt_nav_st);
Expand Down
8 changes: 8 additions & 0 deletions tests/page-templates/06-bugs/support/92542-iframe.html
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title>IFRAME w/out UserTiming polyfill</title>
</head>
<body>
</body>
</html>

0 comments on commit b70cb23

Please sign in to comment.