forked from bluesmoon/boomerang
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoXHR: Don't wait for XHRs that .open() but don't .send()
- Loading branch information
1 parent
3bfe3d7
commit 583536b
Showing
3 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/page-templates/05-angular/112-autoxhr-open-without-send.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<%= header %> | ||
<%= boomerangScript %> | ||
<base href="/pages/05-angular/" /> | ||
<script src="../../vendor/angular/angular.js"></script> | ||
<script src="../../vendor/angular-resource/angular-resource.js"></script> | ||
<script src="../../vendor/angular-route/angular-route.js"></script> | ||
<script> | ||
window.angular_imgs = [3000]; | ||
|
||
window.angular_html5_mode = false; | ||
|
||
// view a widget then come back so debugging (F5) is easier | ||
window.angular_nav_routes = ["/widgets/1", "/"]; | ||
</script> | ||
<script src="support/app.js"></script> | ||
<div ng-app="app"> | ||
<div ng-view> | ||
</div> | ||
</div> | ||
<script src="112-autoxhr-open-without-send.js" type="text/javascript"></script> | ||
<script> | ||
var img, xhr, beaconCount = 0; | ||
BOOMR.subscribe("onbeacon", function(vars) { | ||
beaconCount++; | ||
if (beaconCount === 3) { | ||
setTimeout(function() { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "/delay?delay=100&file=/pages/05-angular/support/widgets.json&rnd=" + Math.random()); | ||
xhr.addEventListener("load", function() { | ||
img = document.createElement("img"); | ||
img.src = "/delay?delay=1000&id=xhr&file=/pages/05-angular/support/img.jpg"; | ||
document.body.appendChild(img); | ||
xhr2 = new XMLHttpRequest(); | ||
xhr2.open("GET", "/delay?delay=100&file=/pages/05-angular/support/widgets.json&rnd=" + Math.random()); | ||
// Don't call send on xhr | ||
}); | ||
xhr.send(null); | ||
}, 100); | ||
} | ||
}); | ||
BOOMR_test.init({ | ||
testAfterOnBeacon: 4, | ||
Angular: { | ||
enabled: true | ||
}, | ||
instrument_xhr: true, | ||
autorun: false | ||
}); | ||
|
||
// Timeout after 30s in case auto xhr is still waiting for a resource | ||
window.timerid = setTimeout(function() { | ||
BOOMR_test.runTests(); | ||
}, 30000); | ||
|
||
</script> | ||
<%= footer %> |
40 changes: 40 additions & 0 deletions
40
tests/page-templates/05-angular/112-autoxhr-open-without-send.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*eslint-env mocha*/ | ||
/*global BOOMR,BOOMR_test,describe,it*/ | ||
|
||
describe("e2e/05-angular/112-autoxhr-open-without-send", function() { | ||
var tf = BOOMR.plugins.TestFramework; | ||
var t = BOOMR_test; | ||
|
||
it("Should pass basic beacon validation", function(done) { | ||
t.validateBeaconWasSent(done); | ||
clearTimeout(window.timerid); | ||
}); | ||
|
||
it("Should have sent three beacons", function() { | ||
assert.equal(tf.beacons.length, 4); | ||
}); | ||
|
||
it("Should have sent the first beacon as http.initiator = spa_hard", function() { | ||
assert.equal(tf.beacons[0]["http.initiator"], "spa_hard"); | ||
}); | ||
|
||
it("Should have beacon 1 as a spa_hard", function() { | ||
if (t.isMutationObserverSupported() || t.isResourceTimingSupported()) { | ||
var b = tf.beacons[0]; | ||
assert.equal(b["http.initiator"], "spa_hard"); | ||
} | ||
}); | ||
|
||
it("Should have beacon 2 as a spa", function() { | ||
if (t.isMutationObserverSupported() || t.isResourceTimingSupported()) { | ||
var b = tf.beacons[1]; | ||
assert.equal(b["http.initiator"], "spa"); | ||
} | ||
}); | ||
|
||
it("Should have beacon 3 as a spa", function() { | ||
var b = tf.beacons[3]; | ||
assert.equal(b["http.initiator"], "xhr"); | ||
}); | ||
}); | ||
|