Bug 1564790 [wpt PR 17633] - Add buffered flag tests for UserTiming and ElementTiming, a=testonly

Automatic update from web-platform-tests
Add buffered flag tests for UserTiming and ElementTiming

Bug: 969123
Change-Id: Ibca6cfabbe42bb9604bba4f7cecd13cdcf9086c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1686791
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: Yoav Weiss <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675258}

--

wpt-commits: a8d8e612cc838b344aa29f64746bc1bbff862ab9
wpt-pr: 17633
This commit is contained in:
Nicolás Peña Moreno 2019-07-19 19:44:54 +00:00 коммит произвёл James Graham
Родитель 00e99ecded
Коммит e1fc6b004c
6 изменённых файлов: 141 добавлений и 0 удалений

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

@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Element Timing: observe element with buffered flag</title>
<body>
<style>
body {
margin: 0;
}
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/element-timing-helpers.js"></script>
<script>
async_test(t => {
const beforeRender = performance.now();
const img = document.createElement('img');
if (!window.PerformanceElementTiming) {
assert_unreached("PerformanceElementTiming is not implemented");
}
// Initial observer used to know when entry has been dispatched
new PerformanceObserver(() => {
// Second observer should require buffered flag to receive the already-dispatched entry.
new PerformanceObserver(t.step_func_done(entryList => {
assert_equals(entryList.getEntries().length, 1);
const entry = entryList.getEntries()[0];
const pathname = window.location.origin + '/images/black-rectangle.png';
checkElement(entry, pathname, 'my_image', 'my_id', beforeRender, document.getElementById('my_id'));
// Test that viewport size is at least 100, so element is fully visible.
assert_greater_than_equal(document.documentElement.clientWidth, 100, 'Width should be >= 100');
assert_greater_than_equal(document.documentElement.clientHeight, 100, 'Height should be >= 100');
checkRect(entry, [0, 100, 0, 50]);
checkNaturalSize(entry, 100, 50);
})).observe({type: 'element', buffered: true});
}).observe({type: 'element'});
img.src = '/images/black-rectangle.png';
img.setAttribute('elementtiming', 'my_image');
img.setAttribute('id', 'my_id');
document.body.appendChild(img);
}, 'Element Timing entries are observable via buffered flag.');
</script>
</body>

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

@ -0,0 +1,11 @@
async_test(t => {
performance.mark('foo');
t.step_timeout(() => {
// After a timeout, PerformanceObserver should still receive entry if using the buffered flag.
new PerformanceObserver(t.step_func_done(list => {
const entries = list.getEntries();
assert_equals(entries.length, 1, 'There should be 1 mark entry.');
assert_equals(entries[0].entryType, 'mark');
})).observe({type: 'mark', buffered: true});
}, 100);
}, 'PerformanceObserver with buffered flag sees entry after timeout');

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

@ -0,0 +1,15 @@
async_test( t=> {
for (let i = 0; i < 50; i++)
performance.mark('foo' + i);
let marksCreated = 50;
let marksReceived = 0;
new PerformanceObserver(list => {
marksReceived += list.getEntries().length;
if (marksCreated < 100) {
performance.mark('bar' + marksCreated);
marksCreated++;
}
if (marksReceived == 100)
t.done();
}).observe({type: 'mark', buffered: true});
}, 'PerformanceObserver with buffered flag should see past and future entries.');

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

@ -0,0 +1,32 @@
promise_test(() => {
// The first promise waits for one buffered flag observer to receive 3 entries.
const promise1 = new Promise(resolve1 => {
let numObserved1 = 0;
new PerformanceObserver((entryList, obs) => {
// This buffered flag observer is constructed after a regular observer detects a mark.
new PerformanceObserver(list => {
numObserved1 += list.getEntries().length;
if (numObserved1 == 3)
resolve1();
}).observe({type: 'mark', buffered: true});
obs.disconnect();
}).observe({entryTypes: ['mark']});
performance.mark('foo');
});
// The second promise waits for another buffered flag observer to receive 3 entries.
const promise2 = new Promise(resolve2 => {
step_timeout(() => {
let numObserved2 = 0;
// This buffered flag observer is constructed after a delay of 100ms.
new PerformanceObserver(list => {
numObserved2 += list.getEntries().length;
if (numObserved2 == 3)
resolve2();
}).observe({type: 'mark', buffered: true});
}, 100);
performance.mark('bar');
});
performance.mark('meow');
// Pass if and only if both buffered observers received all 3 mark entries.
return Promise.all([promise1, promise2]);
}, 'Multiple PerformanceObservers with buffered flag see all entries');

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

@ -0,0 +1,12 @@
async_test(t => {
performance.mark('foo');
// Use a timeout to ensure the remainder of the test runs after the entry is created.
t.step_timeout(() => {
// Observer with buffered flag set to false should not see entry.
new PerformanceObserver(() => {
assert_unreached('Should not have observed any entry!');
}).observe({type: 'mark', buffered: false});
// Use a timeout to give time to the observer.
t.step_timeout(t.step_func_done(() => {}), 100);
}, 0);
}, 'PerformanceObserver without buffered flag set to false cannot see past entries.');

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

@ -0,0 +1,29 @@
async_test(t => {
// First observer creates second in callback to ensure the entry has been dispatched by the time
// the second observer begins observing.
new PerformanceObserver(() => {
// Second observer requires 'buffered: true' to see an entry.
new PerformanceObserver(list => {
const entries = list.getEntries();
assert_equals(entries.length, 1, 'There should be 1 mark entry.');
assert_equals(entries[0].entryType, 'mark');
t.done();
}).observe({type: 'mark', buffered: true});
}).observe({entryTypes: ['mark']});
performance.mark('foo');
}, 'PerformanceObserver with buffered flag sees previous marks');
async_test(t => {
// First observer creates second in callback to ensure the entry has been dispatched by the time
// the second observer begins observing.
new PerformanceObserver(() => {
// Second observer requires 'buffered: true' to see an entry.
new PerformanceObserver(list => {
const entries = list.getEntries();
assert_equals(entries.length, 1, 'There should be 1 measure entry.');
assert_equals(entries[0].entryType, 'measure');
t.done();
}).observe({type: 'measure', buffered: true});
}).observe({entryTypes: ['measure']});
performance.measure('bar');
}, 'PerformanceObserver with buffered flag sees previous measures');