11cb0ef41Sopenharmony_ciconst run_test = isolated => {
21cb0ef41Sopenharmony_ci  // Multiplier to convert the clamped timestamps to microseconds.
31cb0ef41Sopenharmony_ci  const multiplier = 1000;
41cb0ef41Sopenharmony_ci  const windowOrigin = performance.timeOrigin;
51cb0ef41Sopenharmony_ci  // Clamp to at least 5 microseconds in isolated contexts and at least 100 in
61cb0ef41Sopenharmony_ci  // non-isolated ones.
71cb0ef41Sopenharmony_ci  const resolution = isolated ? 5 : 100;
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci  const create_worker = () => {
101cb0ef41Sopenharmony_ci    return new Promise(resolve => {
111cb0ef41Sopenharmony_ci      const workerScript = 'postMessage({timeOrigin: performance.timeOrigin})';
121cb0ef41Sopenharmony_ci      const blob = new Blob([workerScript]);
131cb0ef41Sopenharmony_ci      const worker = new Worker(URL.createObjectURL(blob));
141cb0ef41Sopenharmony_ci      worker.addEventListener('message', event => {
151cb0ef41Sopenharmony_ci        resolve(event.data.timeOrigin);
161cb0ef41Sopenharmony_ci      });
171cb0ef41Sopenharmony_ci    });
181cb0ef41Sopenharmony_ci  };
191cb0ef41Sopenharmony_ci  promise_test(async t => {
201cb0ef41Sopenharmony_ci    assert_equals(self.crossOriginIsolated, isolated,
211cb0ef41Sopenharmony_ci      "crossOriginIsolated is properly set");
221cb0ef41Sopenharmony_ci    let prev = windowOrigin;
231cb0ef41Sopenharmony_ci    let current;
241cb0ef41Sopenharmony_ci    for (let i = 1; i < 100; ++i) {
251cb0ef41Sopenharmony_ci      current = await create_worker();
261cb0ef41Sopenharmony_ci      assert_true(current === prev || current - prev > resolution / 1000);
271cb0ef41Sopenharmony_ci      prev = current;
281cb0ef41Sopenharmony_ci    }
291cb0ef41Sopenharmony_ci  }, 'timeOrigins are clamped.');
301cb0ef41Sopenharmony_ci};
31