forked from bluesmoon/boomerang
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoXHR: Do not extend the event timeout with each uninteresting muta…
…tion
- Loading branch information
1 parent
58b0879
commit 1fdfcda
Showing
3 changed files
with
200 additions
and
5 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
77 changes: 77 additions & 0 deletions
77
tests/page-templates/07-autoxhr/38-xhr-uninteresting-mo.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,77 @@ | ||
<%= header %> | ||
<!-- | ||
Verify that creating uninteresting mutation observer events doesn't hold an xhr beacon from being sent | ||
--> | ||
<script src="38-xhr-uninteresting-mo.js" type="text/javascript"></script> | ||
<%= boomerangSnippet %> | ||
<script> | ||
// create non interesting MO events a few times per second | ||
function addDiv() { | ||
var div = window.document.createElement("div"); | ||
window.document.body.appendChild(div); | ||
setTimeout(addDiv, 200); | ||
}; | ||
setTimeout(addDiv, 200); | ||
|
||
BOOMR_test.init({ | ||
"instrument_xhr": true, | ||
afterFirstBeacon: | ||
function() { | ||
if (!BOOMR.plugins.AutoXHR) { | ||
return; | ||
} | ||
|
||
var xhrNum = 0; | ||
function sendBeacon() { | ||
setTimeout(function() { | ||
var xhr; | ||
if (xhrNum === 0) { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "support/script200.js"); //200, async | ||
xhr.send(null); | ||
} | ||
else if (xhrNum === 1) { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "support/script200.js", false); //200, sync | ||
xhr.send(null); | ||
} | ||
else if (xhrNum === 2) { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "support/script404.js"); //404, async | ||
xhr.send(null); | ||
} | ||
else if (xhrNum === 3) { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "support/script404.js", false); //404, sync | ||
xhr.send(null); | ||
} | ||
else if (xhrNum === 4) { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "http://soasta.com"); //error | ||
xhr.send(null); | ||
} | ||
else if (xhrNum === 5) { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "support/script200.js"); //200, async, abort | ||
xhr.send(null); | ||
xhr.abort(); | ||
} | ||
else if (xhrNum === 6) { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "support/script200.js"); //200, async, timeout | ||
xhr.timeout = 1; | ||
xhr.send(null); | ||
} | ||
xhrNum++; | ||
}, 100); | ||
} | ||
|
||
// send a new XHR on each beacon | ||
BOOMR.subscribe("onbeacon", sendBeacon); | ||
|
||
// start the first beacon | ||
sendBeacon(); | ||
} | ||
}); | ||
</script> | ||
<%= footer %> |
115 changes: 115 additions & 0 deletions
115
tests/page-templates/07-autoxhr/38-xhr-uninteresting-mo.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,115 @@ | ||
/*eslint-env mocha*/ | ||
/*global assert*/ | ||
|
||
describe("e2e/07-autoxhr/38-xhr-uninteresting-mo", function() { | ||
var t = BOOMR_test; | ||
var tf = BOOMR.plugins.TestFramework; | ||
|
||
it("Should get 8 beacons: 1 onload, 7 xhr (XMLHttpRequest !== null)", function(done) { | ||
this.timeout(10000); | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
t.ensureBeaconCount(done, 8); | ||
}); | ||
}); | ||
|
||
it("Should get 8 beacons: 1st onload beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[0].u, "38-xhr-uninteresting-mo.html"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should get 8 beacons: 2nd XHR 200 async beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[1].u, "script200.js"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should get 8 beacons: 3rd XHR 200 sync beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[2].u, "script200.js"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should get 8 beacons: 4th XHR 404 async beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[3].u, "script404.js"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should get 8 beacons: 5th XHR 404 sync beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[4].u, "script404.js"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should get 8 beacons: 6th X-O beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[5].u, "soasta.com"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should get 8 beacons: 7th abort beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[6].u, "script200.js"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should get 8 beacons: 8th timeout beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[7].u, "script200.js"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should get 1 beacons: 1 onload, 0 xhr (XMLHttpRequest === null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
undefined, | ||
function() { | ||
t.ensureBeaconCount(done, 1); | ||
}); | ||
}); | ||
|
||
it("Should have all beacons set rt.nstart = navigationTiming (if NavigationTiming is supported)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
undefined, | ||
function() { | ||
if (typeof BOOMR.plugins.RT.navigationStart() !== "undefined") { | ||
for (var i = 0; i <= 7; i++) { | ||
assert.equal(tf.beacons[i]["rt.nstart"], BOOMR.plugins.RT.navigationStart()); | ||
} | ||
} | ||
else { | ||
done(); | ||
} | ||
} | ||
); | ||
}); | ||
|
||
}); |