Bug 1611320 [wpt PR 21400] - Gate Longtasks and PaintTiming tests under assert_precon...
[gecko.git] / testing / web-platform / tests / longtask-timing / long-microtask.window.js
blob9219fdb5c49b99b646343584fae37380d6f2a2b1
1 async_test(function (t) {
2     assert_precondition(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
3     new PerformanceObserver(
4         t.step_func_done(entryList => {
5             const entries = entryList.getEntries();
6             assert_equals(entries.length, 1,
7                 'Exactly one entry is expected.');
8             const longtask = entries[0];
9             assert_equals(longtask.entryType, 'longtask');
10             assert_equals(longtask.name, 'self');
11             assert_greater_than(longtask.duration, 50);
12             assert_greater_than_equal(longtask.startTime, 0);
13             const currentTime = performance.now();
14             assert_less_than_equal(longtask.startTime, currentTime);
15             t.done();
16         })
17     ).observe({entryTypes: ['longtask']});
19     window.onload = () => {
20         /* Generate a slow microtask */
21         Promise.resolve().then(() => {
22             const begin = window.performance.now();
23             while (window.performance.now() < begin + 60);
24         });
25     };
26 }, 'A short task followed by a long microtask is observable.');