From b70cb237c175debf1fda31ab9ae44e1cfa7996ca Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Sun, 26 Jun 2016 19:28:13 -0500 Subject: [PATCH] Test fixes --- boomerang.js | 40 +- plugins/rt.js | 22 +- tests/page-templates/06-bugs/100506.html | 16 +- tests/page-templates/06-bugs/104197.js | 4 - .../06-bugs/support/92542-iframe.html | 8 + .../06-bugs/support/usertiming.js | 560 ++++++++++++++++++ .../06-xhr-before-config-alwayssendxhr.js | 10 +- .../page-templates/09-backbone/00-simple.html | 7 +- ...-delayed-boomerang-pre-config-snippet.html | 25 +- tests/server/app.js | 2 + tests/server/config/05-angular-103-96463.js | 1 + tests/server/env.json.sample | 3 +- ...25-delayed-boomerang-pre-config-snippet.js | 16 +- tests/unit/02-utils-cookies.js | 38 +- 14 files changed, 684 insertions(+), 68 deletions(-) create mode 100644 tests/page-templates/06-bugs/support/92542-iframe.html create mode 100644 tests/page-templates/06-bugs/support/usertiming.js diff --git a/boomerang.js b/boomerang.js index 43bd1a086..7039aa1e6 100644 --- a/boomerang.js +++ b/boomerang.js @@ -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": [], @@ -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, @@ -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) { @@ -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(); @@ -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) { @@ -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) { @@ -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 @@ -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; diff --git a/plugins/rt.js b/plugins/rt.js index 2d77ecf3f..5ebdc43e8 100644 --- a/plugins/rt.js +++ b/plugins/rt.js @@ -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 || {}; @@ -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 @@ -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"); @@ -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 }); }, @@ -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"); @@ -633,6 +640,7 @@ // where location.href is URL decoded this.updateCookie({ "r": d.URL }, edata.type === "beforeunload" ? "ul" : "hd"); + this.unloadfired = true; }, @@ -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 @@ -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(); diff --git a/tests/page-templates/06-bugs/100506.html b/tests/page-templates/06-bugs/100506.html index e8985c835..f2c856405 100644 --- a/tests/page-templates/06-bugs/100506.html +++ b/tests/page-templates/06-bugs/100506.html @@ -1,6 +1,19 @@ <%= header %> <%= boomerangScript %> + diff --git a/tests/page-templates/09-backbone/25-delayed-boomerang-pre-config-snippet.html b/tests/page-templates/09-backbone/25-delayed-boomerang-pre-config-snippet.html index 2e3818259..97e82e1e9 100644 --- a/tests/page-templates/09-backbone/25-delayed-boomerang-pre-config-snippet.html +++ b/tests/page-templates/09-backbone/25-delayed-boomerang-pre-config-snippet.html @@ -1,5 +1,18 @@ <%= header %> <%= boomerangDelayedSnippet %> + @@ -19,18 +32,6 @@ }); } }; - -BOOMR_test.init({ - testAfterOnBeacon: 2, - Backbone: { - enabled: true - }, - AutoXHR: { - alwaysSendXhr: true - }, - instrument_xhr: true, - autorun: false -}); diff --git a/tests/server/app.js b/tests/server/app.js index 00504e831..bbf106ddd 100644 --- a/tests/server/app.js +++ b/tests/server/app.js @@ -63,6 +63,7 @@ function respond301(req, res) { // // Routes // + // /blackhole and /204: returns a 204 app.get("/blackhole", respond204); app.post("/blackhole", respond204); @@ -79,6 +80,7 @@ app.post("/redirect", respond301); app.get("/chunked", require("./route-chunked")); app.post("/chunked", require("./route-chunked")); +// add CORS headers app.get("/pages/*/support/*", require("./headers")); // all static content follows afterwards diff --git a/tests/server/config/05-angular-103-96463.js b/tests/server/config/05-angular-103-96463.js index 37c276d12..e2432bca7 100644 --- a/tests/server/config/05-angular-103-96463.js +++ b/tests/server/config/05-angular-103-96463.js @@ -1,4 +1,5 @@ BOOMR_configt=new Date().getTime(); +BOOMR.addVar({"h.t":{{H_T}},"h.cr":"{{H_CR}}"}); BOOMR.init({ Angular: { enabled: true diff --git a/tests/server/env.json.sample b/tests/server/env.json.sample index c32491641..a96626c75 100644 --- a/tests/server/env.json.sample +++ b/tests/server/env.json.sample @@ -1,4 +1,5 @@ { "www": "tests", - "port": 3000 + "port": 3000, + "publish": "/home/www" } diff --git a/tests/test-templates/spa/25-delayed-boomerang-pre-config-snippet.js b/tests/test-templates/spa/25-delayed-boomerang-pre-config-snippet.js index cfd8ad99b..bd15616f6 100644 --- a/tests/test-templates/spa/25-delayed-boomerang-pre-config-snippet.js +++ b/tests/test-templates/spa/25-delayed-boomerang-pre-config-snippet.js @@ -15,8 +15,15 @@ BOOMR_test.templates.SPA["25-delayed-boomerang-pre-config-snippet"] = function() }); }); - it("Should have had the first beacon was an xhr beacon", function() { + it("Should have had the first beacon was an spa_hard beacon", function() { var b = tf.beacons[0]; + assert.equal(b["http.initiator"], "spa_hard"); + assert.include(b.u, "25-delayed-boomerang-pre-config-snippet.html"); + assert.isUndefined(b.pgu); + }); + + it("Should have had the second beacon was an xhr beacon", function() { + var b = tf.beacons[1]; assert.equal(b["http.initiator"], "xhr"); assert.equal(b["rt.tstart"], 5); assert.equal(b["rt.start"], "manual"); @@ -25,11 +32,4 @@ BOOMR_test.templates.SPA["25-delayed-boomerang-pre-config-snippet"] = function() assert.equal(b.u, "http://foo.com/xhr/"); assert.include(b.pgu, "25-delayed-boomerang-pre-config-snippet.html"); }); - - it("Should have had the second beacon was an spa_hard beacon", function() { - var b = tf.beacons[1]; - assert.equal(b["http.initiator"], "spa_hard"); - assert.include(b.u, "25-delayed-boomerang-pre-config-snippet.html"); - assert.isUndefined(b.pgu); - }); }; diff --git a/tests/unit/02-utils-cookies.js b/tests/unit/02-utils-cookies.js index d9dfb0505..5c99d0991 100644 --- a/tests/unit/02-utils-cookies.js +++ b/tests/unit/02-utils-cookies.js @@ -7,30 +7,30 @@ describe("BOOMR.utils cookies", function() { var cookieName = "myCookie"; /* - NOTE: + NOTE: - These tests can only run in a client-server setup with a properly - configured FQDN for the server. + These tests can only run in a client-server setup with a properly + configured FQDN for the server. - Please read: - RFC 2109 (https://www.ietf.org/rfc/rfc2109.txt) - and this thread on the chromium bugtracker: - https://code.google.com/p/chromium/issues/detail?id=535 + Please read: + RFC 2109 (https://www.ietf.org/rfc/rfc2109.txt) + and this thread on the chromium bugtracker: + https://code.google.com/p/chromium/issues/detail?id=535 - In your development environment please configure your localhost with a fully - qualified domain name locally: + In your development environment please configure your localhost with a fully + qualified domain name locally: - In a UNIX/Mac/Linux environment you can add a name for 127.0.0.1 to - your /etc/hosts such as: - 127.0.0.1 www.example.org www + In a UNIX/Mac/Linux environment you can add a name for 127.0.0.1 to + your /etc/hosts such as: + 127.0.0.1 www.example.org www - You can do the same under windows, however the path to the file is a - little different: + You can do the same under windows, however the path to the file is a + little different: - Valid for Windown Vista/7/2008/2012: C:\Windows\System32\drivers\etc\hosts + Valid for Windown Vista/7/2008/2012: C:\Windows\System32\drivers\etc\hosts - We (as in the boomerang team) are not responsible for any accidental or - direct damages and or damage claims. See LICENSE for further information. + We (as in the boomerang team) are not responsible for any accidental or + direct damages and or damage claims. See LICENSE for further information. */ if (window.location.protocol === "file:") { @@ -56,6 +56,10 @@ describe("BOOMR.utils cookies", function() { it("Should return null when calling with null as first argument", function() { assert.isNull(BOOMR.utils.getCookie(null)); }); + + it("Should return undefined when calling with not existing cookie", function() { + assert.isUndefined(BOOMR.utils.getCookie("some-none-existing-cooke")); + }); }); describe("BOOMR.utils.getSubCookies()", function() {