11cb0ef41Sopenharmony_ci// This file may needs to be updated to wpt:
21cb0ef41Sopenharmony_ci// https://github.com/web-platform-tests/wpt
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciimport '../common/index.mjs';
51cb0ef41Sopenharmony_ciimport assert from 'assert';
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciimport { performance } from 'perf_hooks';
81cb0ef41Sopenharmony_ciimport { setTimeout } from 'timers/promises';
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Order by startTime
111cb0ef41Sopenharmony_ciperformance.mark('one');
121cb0ef41Sopenharmony_ciawait setTimeout(50);
131cb0ef41Sopenharmony_ciperformance.mark('two');
141cb0ef41Sopenharmony_ciawait setTimeout(50);
151cb0ef41Sopenharmony_ciperformance.mark('three');
161cb0ef41Sopenharmony_ciawait setTimeout(50);
171cb0ef41Sopenharmony_ciperformance.measure('three', 'three');
181cb0ef41Sopenharmony_ciawait setTimeout(50);
191cb0ef41Sopenharmony_ciperformance.measure('two', 'two');
201cb0ef41Sopenharmony_ciawait setTimeout(50);
211cb0ef41Sopenharmony_ciperformance.measure('one', 'one');
221cb0ef41Sopenharmony_ciconst entries = performance.getEntriesByType('measure');
231cb0ef41Sopenharmony_ciassert.deepStrictEqual(entries.map((x) => x.name), ['one', 'two', 'three']);
241cb0ef41Sopenharmony_ciconst allEntries = performance.getEntries();
251cb0ef41Sopenharmony_ciassert.deepStrictEqual(allEntries.map((x) => x.name), ['one', 'one', 'two', 'two', 'three', 'three']);
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciperformance.mark('a');
281cb0ef41Sopenharmony_ciawait setTimeout(50);
291cb0ef41Sopenharmony_ciperformance.measure('a', 'a');
301cb0ef41Sopenharmony_ciawait setTimeout(50);
311cb0ef41Sopenharmony_ciperformance.mark('a');
321cb0ef41Sopenharmony_ciawait setTimeout(50);
331cb0ef41Sopenharmony_ciperformance.measure('a', 'one');
341cb0ef41Sopenharmony_ciconst entriesByName = performance.getEntriesByName('a');
351cb0ef41Sopenharmony_ciassert.deepStrictEqual(entriesByName.map((x) => x.entryType), ['measure', 'mark', 'measure', 'mark']);
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci// getEntriesBy[Name|Type](undefined)
381cb0ef41Sopenharmony_ciperformance.mark(undefined);
391cb0ef41Sopenharmony_ciassert.strictEqual(performance.getEntriesByName(undefined).length, 1);
401cb0ef41Sopenharmony_ciassert.strictEqual(performance.getEntriesByType(undefined).length, 0);
411cb0ef41Sopenharmony_ciassert.throws(() => performance.getEntriesByName(), {
421cb0ef41Sopenharmony_ci  name: 'TypeError',
431cb0ef41Sopenharmony_ci  message: 'The "name" argument must be specified',
441cb0ef41Sopenharmony_ci  code: 'ERR_MISSING_ARGS'
451cb0ef41Sopenharmony_ci});
461cb0ef41Sopenharmony_ciassert.throws(() => performance.getEntriesByType(), {
471cb0ef41Sopenharmony_ci  name: 'TypeError',
481cb0ef41Sopenharmony_ci  message: 'The "type" argument must be specified',
491cb0ef41Sopenharmony_ci  code: 'ERR_MISSING_ARGS'
501cb0ef41Sopenharmony_ci});
51