Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / workers / resources / worker-util.js
blob4566343dcb3d12304cbf1f9d7db3d7b7b67ce800
1 // Useful utilities for worker tests
3 function log(message)
5 document.getElementById("result").innerHTML += message + "<br>";
8 function waitUntilWorkerThreadsExit(callback)
10 waitUntilThreadCountMatches(callback, 0);
13 function waitUntilThreadCountMatches(callback, count)
15 // When running in a browser, just wait for one second then call the callback.
16 if (!window.testRunner) {
17 setTimeout(function() { gc(); callback(); }, 1000);
18 return;
21 if (internals.workerThreadCount == count) {
22 // Worker threads have exited.
23 callback();
24 } else {
25 // Poll until worker threads have been GC'd/exited.
26 // Force a GC with a bunch of allocations to try to scramble the stack and force worker objects to be collected.
27 gc(true);
28 setTimeout(function() { waitUntilThreadCountMatches(callback, count); }, 10);
32 function ensureThreadCountMatches(callback, count)
34 // Just wait until the thread count matches, then wait another 100ms to see if it changes, then fire the callback.
35 waitUntilThreadCountMatches(function() {
36 setTimeout(function() { waitUntilThreadCountMatches(callback, count); }, 100);
37 }, count);
40 function done()
42 if (window.debug)
43 debug('<br><span class="pass">TEST COMPLETE</span>');
44 else
45 log("DONE");
47 // Call notifyDone via the queue so any pending console messages/exceptions are written out first.
48 setTimeout(function() {
49 if (window.testRunner)
50 testRunner.notifyDone();
51 }, 0);