Bug 1312514 - Part 4: Add a test to ensure that splitting timeouts into two buckets doesn't affect the order in which we fire them; r=bkelly

We're adding this test to test_timer_flood.html since it already
examines dispatching thousands of timeouts.  Putting the timeouts in the
two buckets randomly ensures that the test isn't biased towards, for
example, alternating ordering of the timeouts.
This commit is contained in:
Ehsan Akhgari 2016-12-01 10:45:52 -05:00
Родитель 35e93a7bdf
Коммит 87a8f718ea
2 изменённых файлов: 28 добавлений и 5 удалений

Просмотреть файл

@ -3,15 +3,25 @@
<body>
<script>
let count = 0;
function cb() {
let last_timer_set = 0;
let last_timer_observed = 0;
function cb(timer_observed) {
if (timer_observed > last_timer_observed) {
// In order to make the test more efficient, we don't use the SimpleTest
// ok() function to avoid generating one test assertion per one of these
// checks. We only send a message to the parent which fails the test if
// we detect out of order firing of timeouts.
window.parent.postMessage('OUT_OF_ORDER', '*');
}
last_timer_observed = timer_observed;
count += 1;
// Notify our parent that we are ready once the timer flood has
// warmed up.
if (count === 10000) {
window.parent.postMessage('STARTED', '*');
}
setTimeout(cb, 0);
setTimeout(cb, 0);
last_timer_set = setTimeout(cb.bind(last_timer_set), 0);
last_timer_set = setTimeout(cb.bind(last_timer_set), 0);
}
addEventListener('load', cb);
</script>

Просмотреть файл

@ -20,15 +20,24 @@ function onLoad() {
});
}
function setPrefs() {
// Put timeouts randomly in the tracking or normal buffer. We do this in order to
// test to ensure that by default, this will not change the scheduling of timeouts.
return SpecialPowers.pushPrefEnv({"set": [["dom.timeout_bucketing_strategy", 3]]});
}
// Create a frame that executes a timer flood. The frame signals
// that is ready once the flood has had a chance to warm up.
function withFloodFrame() {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
let frame = document.createElement('iframe');
addEventListener('message', function onMsg(evt) {
if (evt.data === 'STARTED') {
removeEventListener('message', onMsg);
resolve(frame);
} else if (evt.data == 'OUT_OF_ORDER') {
ok(false, "Out of order timeout observed");
reject();
}
});
frame.src = 'file_timer_flood.html';
@ -75,7 +84,9 @@ function testRequestAnimationFrame() {
let floodFrame;
onLoad().then(_ => {
onLoad()
.then(setPrefs)
.then(_ => {
// Start a timer flood in a frame.
return withFloodFrame();
}).then(frame => {
@ -109,6 +120,8 @@ onLoad().then(_ => {
ok(true, 'completed tests without timing out');
floodFrame.remove();
SimpleTest.finish();
}).catch(_ => {
SimpleTest.finish();
});
</script>
</pre>