1const run_test = isolated => { 2 // Multiplier to convert the clamped timestamps to microseconds. 3 const multiplier = 1000; 4 const windowOrigin = performance.timeOrigin; 5 // Clamp to at least 5 microseconds in isolated contexts and at least 100 in 6 // non-isolated ones. 7 const resolution = isolated ? 5 : 100; 8 9 const create_worker = () => { 10 return new Promise(resolve => { 11 const workerScript = 'postMessage({timeOrigin: performance.timeOrigin})'; 12 const blob = new Blob([workerScript]); 13 const worker = new Worker(URL.createObjectURL(blob)); 14 worker.addEventListener('message', event => { 15 resolve(event.data.timeOrigin); 16 }); 17 }); 18 }; 19 promise_test(async t => { 20 assert_equals(self.crossOriginIsolated, isolated, 21 "crossOriginIsolated is properly set"); 22 let prev = windowOrigin; 23 let current; 24 for (let i = 1; i < 100; ++i) { 25 current = await create_worker(); 26 assert_true(current === prev || current - prev > resolution / 1000); 27 prev = current; 28 } 29 }, 'timeOrigins are clamped.'); 30}; 31