Skip to content

Commit

Permalink
Merge pull request YahooArchive#47 from SOASTA/bug-92560
Browse files Browse the repository at this point in the history
Fixes bug 92560, exclude list not honored in IE, reviewed by Nic
  • Loading branch information
Charles Vazac committed Apr 27, 2015
2 parents a07f83b + d045c9e commit 8238023
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 33 deletions.
44 changes: 35 additions & 9 deletions plugins/auto_xhr.js
Expand Up @@ -24,6 +24,37 @@ if (BOOMR.plugins.AutoXHR) {
return;
}

function getPathName(anchor) {
if (!anchor) {
return null;
}

/*
correct relativism in IE
anchor.href = "./path/file";
anchor.pathname == "./path/file"; //should be "/path/file"
*/
anchor.href = anchor.href;

/*
correct missing leading slash in IE
anchor.href = "path/file";
anchor.pathname === "path/file"; //should be "/path/file"
*/
var pathName = anchor.pathname;
if (pathName.charAt(0) !== "/") {
pathName = "/" + pathName;
}

return pathName;
}

function shouldExcludeXhr(anchor) {
return BOOMR.xhr_excludes.hasOwnProperty(anchor.href) ||
BOOMR.xhr_excludes.hasOwnProperty(anchor.hostname) ||
BOOMR.xhr_excludes.hasOwnProperty(getPathName(anchor));
}

/*
How should this work?
Expand Down Expand Up @@ -303,10 +334,7 @@ MutationHandler.prototype.wait_for_node = function(node, index) {
if (!current_event.resource.url && node.nodeName === "SCRIPT") {
a.href = url;

if (BOOMR.xhr_excludes.hasOwnProperty(a.href)
|| BOOMR.xhr_excludes.hasOwnProperty(a.hostname)
|| BOOMR.xhr_excludes.hasOwnProperty(a.pathname)
) {
if (shouldExcludeXhr(a)) {
// excluded resource, so abort
return false;
}
Expand Down Expand Up @@ -427,10 +455,7 @@ function instrumentXHR() {
req.open = function(method, url, async) {
a.href = url;

if (BOOMR.xhr_excludes.hasOwnProperty(a.href)
|| BOOMR.xhr_excludes.hasOwnProperty(a.hostname)
|| BOOMR.xhr_excludes.hasOwnProperty(a.pathname)
) {
if (shouldExcludeXhr(a)) {
// skip instrumentation and call the original open method
return orig_open.apply(req, arguments);
}
Expand Down Expand Up @@ -516,7 +541,8 @@ BOOMR.plugins.AutoXHR = {
else if (config.instrument_xhr === false) {
BOOMR.uninstrumentXHR();
}
}
},
getPathname: getPathName
};

})();
14 changes: 13 additions & 1 deletion tests/boomerang-test-framework.js
Expand Up @@ -35,6 +35,9 @@

return this.beacons[this.beacons.length - 1];
},
beaconCount: function() {
return this.beacons.length;
},
before_unload: function() {
this.fired_before_unload = true;
},
Expand All @@ -54,7 +57,12 @@
},
is_complete: function() {
return true;
}
},
initXMLHttpRequest: function() {
return window.XMLHttpRequest ?
new XMLHttpRequest() :
new ActiveXObject("Microsoft.XMLHTTP");
}
};
})(window);

Expand Down Expand Up @@ -170,6 +178,10 @@
// initialize boomerang
BOOMR.init(config);

if (config.afterBoomerangLoad) {
config.afterBoomerangLoad();
}

// fake session details so beacons send
BOOMR.addVar({
"h.key": "aaaaa-bbbbb-ccccc-ddddd-eeeee",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e.json
@@ -1 +1 @@
[{"path":"00-basic","file":"00-onload"},{"path":"00-basic","file":"01-onunload"},{"path":"01-beacon-type","file":"00-resourcetiming-disabled"},{"path":"01-beacon-type","file":"01-resourcetiming-enabled-browser-supports"},{"path":"01-beacon-type","file":"02-resourcetiming-enabled-browser-unsupported"},{"path":"02-snippet","file":"00-snippet"},{"path":"03-load-order","file":"00-before-page-load"},{"path":"03-load-order","file":"01-after-page-load"},{"path":"03-load-order","file":"02-after-page-load-tag-manager"},{"path":"04-page-params","file":"00-custom-metrics"},{"path":"04-page-params","file":"01-page-group-order"},{"path":"04-page-params","file":"02-page-group-xhrs"},{"path":"04-page-params","file":"03-custom-dimensions-js"},{"path":"04-page-params","file":"04-custom-dimensions-cookies"},{"path":"06-bugs","file":"92542"}]
[{"path":"00-basic","file":"00-onload"},{"path":"00-basic","file":"01-onunload"},{"path":"01-beacon-type","file":"00-resourcetiming-disabled"},{"path":"01-beacon-type","file":"01-resourcetiming-enabled-browser-supports"},{"path":"01-beacon-type","file":"02-resourcetiming-enabled-browser-unsupported"},{"path":"02-snippet","file":"00-snippet"},{"path":"03-load-order","file":"00-before-page-load"},{"path":"03-load-order","file":"01-after-page-load"},{"path":"03-load-order","file":"02-after-page-load-tag-manager"},{"path":"04-page-params","file":"00-custom-metrics"},{"path":"04-page-params","file":"01-page-group-order"},{"path":"04-page-params","file":"02-page-group-xhrs"},{"path":"04-page-params","file":"03-custom-dimensions-js"},{"path":"04-page-params","file":"04-custom-dimensions-cookies"},{"path":"06-bugs","file":"92542"},{"path":"06-bugs","file":"92560"}]
28 changes: 7 additions & 21 deletions tests/page-templates/04-page-params/02-page-group-xhrs.html
Expand Up @@ -18,27 +18,13 @@
parameter2: "XHR Test Pages_subresource"
},
]
}
},
afterBoomerangLoad:
function() {
var xhr = BOOMR.plugins.TestFramework.initXMLHttpRequest();
xhr.open("GET", "/pages/blah", true);
xhr.send();
}
});

function sendXhr() {
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}

xhr.open("GET", "/pages/blah", true);
xhr.send();
}

// wait until Boomerang is loaded (and instrumented XHRs) to send
if (window.document.addEventListener) {
window.document.addEventListener("onBoomerangLoaded", sendXhr);
} else if (window.document.attachEvent) {
window.document.attachEvent("onBoomerangLoaded", sendXhr);
}

</script>
<%= footer %>
2 changes: 1 addition & 1 deletion tests/page-templates/04-page-params/02-page-group-xhrs.js
Expand Up @@ -10,7 +10,7 @@ describe("e2e/04-page-params/02-page-group-xhrs", function() {
});

it("Should have sent two beacons", function() {
assert.equal(tf.beacons.length, typeof window.MutationObserver === "function" ? 2 : 1);
assert.equal(tf.beaconCount(), typeof window.MutationObserver === "function" ? 2 : 1);
});

it("Should set the Page Group of the first beacon 'Test Pages'", function() {
Expand Down
37 changes: 37 additions & 0 deletions tests/page-templates/06-bugs/92560.html
@@ -0,0 +1,37 @@
<%= header %>
<!--
IE doesn't return a leading slash (/) on anchor.pathname, XHR exclude list was not being honored
-->
<script src="92560.js" type="text/javascript"></script>
<%= boomerangSnippet %>
<script>
BOOMR_test.init({
"instrument_xhr": true,
testAfterOnBeacon: 2,
afterBoomerangLoad:
function() {
var xhrSent = false;
BOOMR.xhr_excludes["/pages/06-bugs/support/script2.js"] = true;
BOOMR.subscribe(
"onbeacon",
function() {
if (xhrSent) {
return;
}
xhrSent = true;

var xhr;
xhr = BOOMR.plugins.TestFramework.initXMLHttpRequest();
xhr.open("GET", "support/script1.js");
xhr.send(null);

setTimeout(function(){
xhr = BOOMR.plugins.TestFramework.initXMLHttpRequest();
xhr.open("GET", "support/script2.js");
xhr.send(null);
}, 500);
});
}
});
</script>
<%= footer %>
10 changes: 10 additions & 0 deletions tests/page-templates/06-bugs/92560.js
@@ -0,0 +1,10 @@
/*eslint-env mocha*/
/*global assert*/

describe("e2e/06-bugs/92560", function() {
var tf = BOOMR.plugins.TestFramework;

it("Should get 2 beacons: 1 onload, 1 xhr (2nd xhr should be excluded)", function() {
assert.equal(tf.beaconCount(), 2);
});
});
32 changes: 32 additions & 0 deletions tests/unit/04-plugins-autoxhr.js
@@ -0,0 +1,32 @@
/*eslint-env mocha*/
/*global chai*/

describe("BOOMR.plugins.AutoXHR", function() {
var assert = chai.assert;

describe("exports", function() {
it("Should have a getPathname() function", function() {
assert.isFunction(BOOMR.plugins.AutoXHR.getPathname);
});

it("getPathname test", function() {
var anchor = document.createElement("a");
function test(href, expected) {
anchor.href = href;
assert.equal(
BOOMR.plugins.AutoXHR.getPathname(anchor),
expected);
}

test("path/file.js", "/unit/path/file.js");
test("/path/file.js", "/path/file.js");
test("//path/file.js", "/file.js");
test("./path/file.js", "/unit/path/file.js");
test("../path/file.js", "/path/file.js");
test("#ref", "/unit/");
test("?val=1", "/unit/");
test("", "/unit/");
test("../../../../file.js", "/file.js");
});
});
});
1 change: 1 addition & 0 deletions tests/unit/index.html
Expand Up @@ -27,6 +27,7 @@
<script src="02-utils-pluginconfig.js"></script>
<script src="02-utils-cookies.js"></script>
<script src="03-checkdocumentdomain.js"></script>
<script src="04-plugins-autoxhr.js"></script>
<script src="04-plugins-pageparams.js"></script>
<script src="04-plugins-restiming.js"></script>
<script src="../boomerang-test-framework.js" type="text/javascript"></script>
Expand Down

0 comments on commit 8238023

Please sign in to comment.