summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/longtask-timing/supported-longtask-types.window.js
blob: efb393ad8443f4286ce860749a6d1142734f491a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
test(() => {
  assert_implements(typeof PerformanceObserver.supportedEntryTypes !== "undefined", 'supportedEntryTypes is not supported');
  const types = PerformanceObserver.supportedEntryTypes;
  assert_true(types.includes("longtask"),
    "There should be 'longtask' in PerformanceObserver.supportedEntryTypes");
  assert_false(types.includes("taskattribution"),
    "There should NOT be 'taskattribution' in PerformanceObserver.supportedEntryTypes");
}, "supportedEntryTypes contains 'longtask' but not 'taskattribution'.");

function syncWait(waitDuration) {
  if (waitDuration <= 0)
    return;

  const startTime = performance.now();
  let unused = '';
  for (let i = 0; i < 10000; i++)
    unused += '' + Math.random();

  return syncWait(waitDuration - (performance.now() - startTime));
}

const entryType = "longtask";
promise_test(async () => {
  assert_implements(typeof PerformanceObserver.supportedEntryTypes !== "undefined", 'supportedEntryTypes is not supported');
  assert_implements(typeof PerformanceObserver.supportedEntryTypes.includes(entryType), `supportedEntryTypes does not include '${entryType}'`);
  await new Promise((resolve) => {
    new PerformanceObserver(function (list, observer) {
      observer.disconnect();
      resolve();
    }).observe({entryTypes: [entryType]});

    // Force the PerformanceEntry.
    syncWait(50);
  })
}, `'${entryType}' entries should be observable.`)