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: Wait once up to 1,000ms after an uninteresting mutation
- Loading branch information
Showing
3 changed files
with
110 additions
and
6 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
39 changes: 39 additions & 0 deletions
39
tests/page-templates/07-autoxhr/39-uninteresting-mo-followed-by-interesting.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,39 @@ | ||
<%= header %> | ||
<!-- | ||
Verify that creating uninteresting mutation observer events doesn't hold an xhr beacon from being sent | ||
--> | ||
<script src="39-uninteresting-mo-followed-by-interesting.js" type="text/javascript"></script> | ||
<%= boomerangSnippet %> | ||
<script> | ||
BOOMR_test.init({ | ||
"instrument_xhr": true, | ||
testAfterOnBeacon: BOOMR.plugins.AutoXHR ? 2 : 1, | ||
afterFirstBeacon: | ||
function() { | ||
if (!BOOMR.plugins.AutoXHR) { | ||
return; | ||
} | ||
|
||
// start a XHR | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "/assets/blank.html"); | ||
xhr.send(); | ||
|
||
// create a non-interesting MO event right afterwards. | ||
// this should extend the timeout to 1s. | ||
setTimeout(function() { | ||
var div = window.document.createElement("div"); | ||
window.document.body.appendChild(div); | ||
}, 10); | ||
|
||
// create an interesting MO event at 500ms. | ||
// this should trigger the beacon. | ||
setTimeout(function() { | ||
var img = window.document.createElement("img"); | ||
img.src = "/assets/img.jpg"; | ||
window.document.body.appendChild(img); | ||
}, 500); | ||
} | ||
}); | ||
</script> | ||
<%= footer %> |
43 changes: 43 additions & 0 deletions
43
tests/page-templates/07-autoxhr/39-uninteresting-mo-followed-by-interesting.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,43 @@ | ||
/*eslint-env mocha*/ | ||
/*global assert*/ | ||
|
||
describe("e2e/07-autoxhr/39-uninteresting-mo-followed-by-interesting", function() { | ||
var t = BOOMR_test; | ||
var tf = BOOMR.plugins.TestFramework; | ||
|
||
it("Should get 2 beacons: 1 onload, 1 click (XMLHttpRequest !== null)", function(done) { | ||
this.timeout(10000); | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
t.ensureBeaconCount(done, 2); | ||
}); | ||
}); | ||
|
||
it("Should have the first beacon be a page load beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[0].u, "39-uninteresting-mo-followed-by-interesting.html"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should have the second beacon be a XHR beacon (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.equal(tf.beacons[1]["http.initiator"], "xhr"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Should have the second beacon have the URL of the XHR (XMLHttpRequest !== null)", function(done) { | ||
t.ifAutoXHR( | ||
done, | ||
function() { | ||
assert.include(tf.beacons[1].u, "blank.html"); | ||
done(); | ||
}); | ||
}); | ||
}); |