11cb0ef41Sopenharmony_ci<!doctype html> 21cb0ef41Sopenharmony_ci<html> 31cb0ef41Sopenharmony_ci<head> 41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 61cb0ef41Sopenharmony_ci</head> 71cb0ef41Sopenharmony_ci<body> 81cb0ef41Sopenharmony_ci<script> 91cb0ef41Sopenharmony_ciconst windowOrigin = performance.timeOrigin; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_citest(() => { 121cb0ef41Sopenharmony_ci // Use a 30ms cushion when comparing with Date() to account for inaccuracy. 131cb0ef41Sopenharmony_ci const startTime = Date.now(); 141cb0ef41Sopenharmony_ci assert_greater_than_equal(startTime + 30, windowOrigin, 'Date.now() should be at least as large as the window timeOrigin.'); 151cb0ef41Sopenharmony_ci const startNow = performance.now(); 161cb0ef41Sopenharmony_ci assert_less_than_equal(startTime, windowOrigin + startNow + 30, 'Date.now() should be close to window timeOrigin.'); 171cb0ef41Sopenharmony_ci}, 'Window timeOrigin is close to Date.now() when there is no system clock adjustment.'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciconst workerScript = 'postMessage({timeOrigin: performance.timeOrigin})'; 201cb0ef41Sopenharmony_ciconst blob = new Blob([workerScript]); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciasync_test(function(t) { 231cb0ef41Sopenharmony_ci const beforeWorkerCreation = performance.now(); 241cb0ef41Sopenharmony_ci const worker = new Worker(URL.createObjectURL(blob)); 251cb0ef41Sopenharmony_ci worker.addEventListener('message', t.step_func_done(function(event) { 261cb0ef41Sopenharmony_ci const workerOrigin = event.data.timeOrigin; 271cb0ef41Sopenharmony_ci assert_greater_than_equal(workerOrigin, windowOrigin + beforeWorkerCreation, 'Worker timeOrigin should be greater than the window timeOrigin.'); 281cb0ef41Sopenharmony_ci const afterWorkerCreation = performance.now(); 291cb0ef41Sopenharmony_ci assert_less_than_equal(workerOrigin - windowOrigin, afterWorkerCreation, 'Window and worker timeOrigins should be close.'); 301cb0ef41Sopenharmony_ci })); 311cb0ef41Sopenharmony_ci}, 'Window and worker timeOrigins are close when created one after another.'); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciasync_test(function(t) { 341cb0ef41Sopenharmony_ci this.step_timeout(function() { 351cb0ef41Sopenharmony_ci const workerCreation = performance.now(); 361cb0ef41Sopenharmony_ci const worker = new Worker(URL.createObjectURL(blob)); 371cb0ef41Sopenharmony_ci worker.addEventListener('message', t.step_func_done(function(event) { 381cb0ef41Sopenharmony_ci const workerOrigin = event.data.timeOrigin; 391cb0ef41Sopenharmony_ci assert_greater_than_equal(workerOrigin - windowOrigin, 200, 'We waited 200ms to spawn the second worker, so its timeOrigin should be greater than that of the window.'); 401cb0ef41Sopenharmony_ci })); 411cb0ef41Sopenharmony_ci }, 200); 421cb0ef41Sopenharmony_ci}, 'Window and worker timeOrigins differ when worker is created after a delay.'); 431cb0ef41Sopenharmony_ci</script> 441cb0ef41Sopenharmony_ci</body> 451cb0ef41Sopenharmony_ci</html>