Commit c8c811ae authored by Nicolás Peña Moreno's avatar Nicolás Peña Moreno Committed by Commit Bot

Gate Longtasks and PaintTiming tests under assert_precondition

Change-Id: I5716c032afe345989397e655370c3b294a251f2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2018172Reviewed-by: default avatarTom McKee <tommckee@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734950}
parent b49c7c19
async_test(function (t) { async_test(function (t) {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
new PerformanceObserver( new PerformanceObserver(
t.step_func_done(entryList => { t.step_func_done(entryList => {
const entries = entryList.getEntries(); const entries = entryList.getEntries();
......
...@@ -10,10 +10,7 @@ ...@@ -10,10 +10,7 @@
<div id="log"></div> <div id="log"></div>
<script> <script>
async_test(function (t) { async_test(function (t) {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
const observer = new PerformanceObserver( const observer = new PerformanceObserver(
t.step_func(function (entryList) { t.step_func(function (entryList) {
const entries = entryList.getEntries(); const entries = entryList.getEntries();
......
...@@ -10,10 +10,7 @@ ...@@ -10,10 +10,7 @@
<div id="log"></div> <div id="log"></div>
<script> <script>
async_test(function (t) { async_test(function (t) {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
const observer = new PerformanceObserver( const observer = new PerformanceObserver(
t.step_func(function (entryList) { t.step_func(function (entryList) {
const entries = entryList.getEntries(); const entries = entryList.getEntries();
......
...@@ -11,10 +11,7 @@ ...@@ -11,10 +11,7 @@
<script> <script>
const initialTime = performance.now(); const initialTime = performance.now();
async_test(function (t) { async_test(function (t) {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
const observer = new PerformanceObserver( const observer = new PerformanceObserver(
t.step_func(function (entryList) { t.step_func(function (entryList) {
const entries = entryList.getEntries(); const entries = entryList.getEntries();
......
...@@ -10,10 +10,7 @@ ...@@ -10,10 +10,7 @@
<div id="log"></div> <div id="log"></div>
<script> <script>
async_test(function (t) { async_test(function (t) {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
const observer = new PerformanceObserver( const observer = new PerformanceObserver(
t.step_func(function (entryList) { t.step_func(function (entryList) {
const entries = entryList.getEntries(); const entries = entryList.getEntries();
......
...@@ -8,10 +8,7 @@ ...@@ -8,10 +8,7 @@
<script> <script>
const t = async_test(t => { const t = async_test(t => {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
window.addEventListener('message', t.step_func(e => { window.addEventListener('message', t.step_func(e => {
assert_equals(e.data['entryType'], 'longtask'); assert_equals(e.data['entryType'], 'longtask');
assert_equals(e.data['frame-attribution'], 'same-origin-ancestor'); assert_equals(e.data['frame-attribution'], 'same-origin-ancestor');
......
...@@ -10,10 +10,7 @@ ...@@ -10,10 +10,7 @@
<div id="log"></div> <div id="log"></div>
<script> <script>
async_test(function (t) { async_test(function (t) {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
const observer = new PerformanceObserver( const observer = new PerformanceObserver(
t.step_func(function (entryList) { t.step_func(function (entryList) {
const entries = entryList.getEntries(); const entries = entryList.getEntries();
......
...@@ -8,10 +8,7 @@ ...@@ -8,10 +8,7 @@
<script> <script>
async_test(t => { async_test(t => {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
window.addEventListener('message', t.step_func(e => { window.addEventListener('message', t.step_func(e => {
assert_equals(e.data['entryType'], 'longtask'); assert_equals(e.data['entryType'], 'longtask');
assert_equals(e.data['frame-attribution'], 'cross-origin-unreachable'); assert_equals(e.data['frame-attribution'], 'cross-origin-unreachable');
......
...@@ -8,10 +8,7 @@ ...@@ -8,10 +8,7 @@
<script> <script>
async_test(t => { async_test(t => {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
window.addEventListener('message', t.step_func(e => { window.addEventListener('message', t.step_func(e => {
assert_equals(e.data['entryType'], 'longtask'); assert_equals(e.data['entryType'], 'longtask');
// Ignore any long task that may be produced by the top-level frame. // Ignore any long task that may be produced by the top-level frame.
......
...@@ -7,10 +7,7 @@ ...@@ -7,10 +7,7 @@
<body> <body>
<script> <script>
async_test(function (t) { async_test(function (t) {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
const observer = new PerformanceObserver( const observer = new PerformanceObserver(
t.step_func(function (entryList) { t.step_func(function (entryList) {
const entries = entryList.getEntries(); const entries = entryList.getEntries();
...@@ -74,4 +71,4 @@ ...@@ -74,4 +71,4 @@
}, 'Test toJSON() in PerformanceLongTaskTiming and TaskAttributionTiming'); }, 'Test toJSON() in PerformanceLongTaskTiming and TaskAttributionTiming');
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -11,10 +11,7 @@ ...@@ -11,10 +11,7 @@
This window opens a new window which contains a longtask. We test that the This window opens a new window which contains a longtask. We test that the
longtask from the new window is not observed by the observer of this window. */ longtask from the new window is not observed by the observer of this window. */
async_test(t => { async_test(t => {
if (typeof PerformanceLongTaskTiming === 'undefined') { assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
assert_unreached("Longtasks are not supported.");
t.done();
}
const observer = new PerformanceObserver( const observer = new PerformanceObserver(
t.step_func(function (entryList) { t.step_func(function (entryList) {
const entries = entryList.getEntries(); const entries = entryList.getEntries();
......
test(() => { test(() => {
if (typeof PerformanceObserver.supportedEntryTypes === "undefined") assert_precondition(typeof PerformanceObserver.supportedEntryTypes !== "undefined", 'supportedEntryTypes is not supported');
assert_unreached("supportedEntryTypes is not supported.");
const types = PerformanceObserver.supportedEntryTypes; const types = PerformanceObserver.supportedEntryTypes;
assert_true(types.includes("longtask"), assert_true(types.includes("longtask"),
"There should be 'longtask' in PerformanceObserver.supportedEntryTypes"); "There should be 'longtask' in PerformanceObserver.supportedEntryTypes");
...@@ -20,19 +19,17 @@ function syncWait(waitDuration) { ...@@ -20,19 +19,17 @@ function syncWait(waitDuration) {
return syncWait(waitDuration - (performance.now() - startTime)); return syncWait(waitDuration - (performance.now() - startTime));
} }
if (typeof PerformanceObserver.supportedEntryTypes !== "undefined") { const entryType = "longtask";
const entryType = "longtask"; promise_test(async () => {
if (PerformanceObserver.supportedEntryTypes.includes(entryType)) { assert_precondition(typeof PerformanceObserver.supportedEntryTypes !== "undefined", 'supportedEntryTypes is not supported');
promise_test(async () => { assert_precondition(typeof PerformanceObserver.supportedEntryTypes.includes(entryType), `supportedEntryTypes does not include '${entryType}'`);
await new Promise((resolve) => { await new Promise((resolve) => {
new PerformanceObserver(function (list, observer) { new PerformanceObserver(function (list, observer) {
observer.disconnect(); observer.disconnect();
resolve(); resolve();
}).observe({entryTypes: [entryType]}); }).observe({entryTypes: [entryType]});
// Force the PerformanceEntry. // Force the PerformanceEntry.
syncWait(50); syncWait(50);
}) })
}, `'${entryType}' entries should be observable.`) }, `'${entryType}' entries should be observable.`)
}
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<script> <script>
async_test(function(t) { async_test(function(t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
t.step(function() { t.step(function() {
const bufferedEntries = performance.getEntriesByType('paint'); const bufferedEntries = performance.getEntriesByType('paint');
assert_equals(bufferedEntries.length, 0, "No paint entries yet"); assert_equals(bufferedEntries.length, 0, "No paint entries yet");
......
async_test(t => { async_test(t => {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
// First observer creates second in callback to ensure the entry has been dispatched by the time // First observer creates second in callback to ensure the entry has been dispatched by the time
// the second observer begins observing. // the second observer begins observing.
let entries_seen = 0; let entries_seen = 0;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
window.addEventListener('message', t.step_func(e => { window.addEventListener('message', t.step_func(e => {
assert_equals(e.data, '2 paint first-paint paint first-contentful-paint'); assert_equals(e.data, '2 paint first-paint paint first-contentful-paint');
// When only child frame paints, expect only first-paint. // When only child frame paints, expect only first-paint.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<footer> <footer>
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
const body = document.getElementsByTagName('body')[0]; const body = document.getElementsByTagName('body')[0];
body.style.backgroundImage = 'url(resources/circles.png)'; body.style.backgroundImage = 'url(resources/circles.png)';
window.onload = function() { window.onload = function() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
const canvas = document.getElementById("canvas"); const canvas = document.getElementById("canvas");
const context = canvas.getContext("2d"); const context = canvas.getContext("2d");
context.beginPath(); context.beginPath();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
const img = document.createElement("IMG"); const img = document.createElement("IMG");
img.src = "resources/circles.png"; img.src = "resources/circles.png";
img.onload = function() { img.onload = function() {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
const bufferedEntries = performance.getEntriesByType('paint'); const bufferedEntries = performance.getEntriesByType('paint');
assert_equals(bufferedEntries.length, 0, "No paint entries yet"); assert_equals(bufferedEntries.length, 0, "No paint entries yet");
const div = document.createElement("div"); const div = document.createElement("div");
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
const img = document.createElement("IMG"); const img = document.createElement("IMG");
img.src = "resources/circle.svg"; img.src = "resources/circle.svg";
img.onload = function() { img.onload = function() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
const iframe = document.createElement('iframe'); const iframe = document.createElement('iframe');
iframe.id = 'child-iframe'; iframe.id = 'child-iframe';
iframe.src = 'resources/subframe-sending-paint.html'; iframe.src = 'resources/subframe-sending-paint.html';
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<footer> <footer>
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
document.body.style.backgroundColor = "#AA0000"; document.body.style.backgroundColor = "#AA0000";
function testPaintEntries() { function testPaintEntries() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
const div = document.createElement("div"); const div = document.createElement("div");
div.style.width = "100px"; div.style.width = "100px";
div.style.height = "100px"; div.style.height = "100px";
......
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<a id="link" href="./">link</a> <a id="link" href="./">link</a>
<script> <script>
/* This test ensures that an empty page is painted when there is an invisible visited link (that would be visible if the link was not visited). It's necessary that whether the page is painted or not does not depend on visitedness of the link. Otherwise the paint-timing API could be used to sniff whether a link has been visited or not. */ /* This test ensures that an empty page is painted when there is an invisible visited link (that
would be visible if the link was not visited). It's necessary that whether the page is painted or
not does not depend on visitedness of the link. Otherwise the paint-timing API could be used to
sniff whether a link has been visited or not. */
window.onload = function() { window.onload = function() {
/* Convenience helper to get the link into the browsing history. /* Convenience helper to get the link into the browsing history.
Using a relative path because some browsers only allow replaceState within the same domain. */ Using a relative path because some browsers only allow replaceState within the same domain. */
...@@ -18,6 +21,7 @@ window.onload = function() { ...@@ -18,6 +21,7 @@ window.onload = function() {
history.replaceState({}, "", current_url); history.replaceState({}, "", current_url);
} }
async_test(function(t) { async_test(function(t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
function testPaintEntries() { function testPaintEntries() {
const bufferedEntries = performance.getEntriesByType('paint'); const bufferedEntries = performance.getEntriesByType('paint');
if (bufferedEntries.length < 2) { if (bufferedEntries.length < 2) {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<iframe id="listening-iframe" src="resources/subframe-sending-paint.html"></iframe> <iframe id="listening-iframe" src="resources/subframe-sending-paint.html"></iframe>
<script> <script>
async_test(function (t) { async_test(function (t) {
assert_precondition(window.PerformancePaintTiming, "Paint Timing isn't supported.");
let paintingIframeHasDispatchedEntries = false; let paintingIframeHasDispatchedEntries = false;
window.addEventListener('message', t.step_func(e => { window.addEventListener('message', t.step_func(e => {
if (!paintingIframeHasDispatchedEntries) { if (!paintingIframeHasDispatchedEntries) {
......
test(() => { test(() => {
if (typeof PerformanceObserver.supportedEntryTypes === "undefined") assert_precondition(typeof PerformanceObserver.supportedEntryTypes !== "undefined", 'supportedEntryTypes is not supported');
assert_unreached("supportedEntryTypes is not supported.");
assert_true(PerformanceObserver.supportedEntryTypes.includes("paint"), assert_true(PerformanceObserver.supportedEntryTypes.includes("paint"),
"There should be an entry 'paint' in PerformanceObserver.supportedEntryTypes"); "There should be an entry 'paint' in PerformanceObserver.supportedEntryTypes");
}, "supportedEntryTypes contains 'paint'."); }, "supportedEntryTypes contains 'paint'.");
if (typeof PerformanceObserver.supportedEntryTypes !== "undefined") { const entryType = 'paint';
const entryType = 'paint'; promise_test(async() => {
if (PerformanceObserver.supportedEntryTypes.includes(entryType)) { assert_precondition(typeof PerformanceObserver.supportedEntryTypes !== "undefined", 'supportedEntryTypes is not supported');
promise_test(async() => { assert_precondition(typeof PerformanceObserver.supportedEntryTypes.includes(entryType), `supportedEntryTypes does not include '${entryType}'`);
await new Promise((resolve) => { await new Promise((resolve) => {
new PerformanceObserver(function (list, observer) { new PerformanceObserver(function (list, observer) {
observer.disconnect(); observer.disconnect();
resolve(); resolve();
}).observe({entryTypes: [entryType]}); }).observe({entryTypes: [entryType]});
// Force the PerformanceEntry. // Force the PerformanceEntry.
// Use `self` for Workers. // Use `self` for Workers.
if (self.document) if (self.document)
document.head.parentNode.appendChild(document.createTextNode('foo')); document.head.parentNode.appendChild(document.createTextNode('foo'));
}) })
}, `'${entryType}' entries should be observable.`) }, `'${entryType}' entries should be observable.`)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment