WorkerTestUtils.webidl (1809B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 callback WorkerTestCallback = undefined (); 6 7 [Exposed=Worker, Pref="dom.workers.testing.enabled"] 8 namespace WorkerTestUtils { 9 [Throws] 10 unsigned long currentTimerNestingLevel(); 11 [Throws] 12 boolean IsRunningInBackground(); 13 14 // Mint a (ThreadSafe)StrongWorkerRef and hold it until we see an observer 15 // notification with the given string topic on the main thread. The 16 // StrongWorkerRef will prevent the worker from moving from the Canceling to 17 // the Killing state and thereby prevent it from shutting down. 18 [Throws] 19 undefined holdStrongWorkerRefUntilMainThreadObserverNotified(UTF8String topic); 20 21 // Create a monitor that blocks the worker entirely until we see an observer 22 // notification with the given string topic on the main thread. This is a 23 // much more drastic variant of 24 // holdStrongWorkerRefUntilMainThreadObserverNotified for when the goal is to 25 // avoid letting WorkerRefs be notified. A callback should be passed to be 26 // synchronously invoked once the observer has been registered in order to 27 // communicate that the test can move forward. 28 [Throws] 29 undefined blockUntilMainThreadObserverNotified(UTF8String topic, 30 WorkerTestCallback whenObserving); 31 32 // Dispatch a runnable to the main thread to notify the observer service with 33 // the given topic. This is primarily intended for use with 34 // `holdStrongWorkerRefUntilMainThreadObserverNotified` but might be useful in 35 // other situations to cut down on test boilerplate. 36 [Throws] 37 undefined notifyObserverOnMainThread(UTF8String topic); 38 };