mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1062377 - Add JUnit test for new GeckoBackgroundThread; r=rnewman
This commit is contained in:
parent
269c3dabc8
commit
bb7aa8e680
@ -182,6 +182,7 @@ public final class ThreadUtils {
|
||||
return isOnThread(getUiThread());
|
||||
}
|
||||
|
||||
@RobocopTarget
|
||||
public static boolean isOnBackgroundThread() {
|
||||
if (sBackgroundThread == null) {
|
||||
return false;
|
||||
@ -190,6 +191,7 @@ public final class ThreadUtils {
|
||||
return isOnThread(sBackgroundThread);
|
||||
}
|
||||
|
||||
@RobocopTarget
|
||||
public static boolean isOnThread(Thread thread) {
|
||||
return (Thread.currentThread().getId() == thread.getId());
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ jar.sources += [
|
||||
'src/harness/BrowserInstrumentationTestRunner.java',
|
||||
'src/harness/BrowserTestListener.java',
|
||||
'src/TestDistribution.java',
|
||||
'src/TestGeckoBackgroundThread.java',
|
||||
'src/TestGeckoMenu.java',
|
||||
'src/TestGeckoProfilesProvider.java',
|
||||
'src/TestGeckoSharedPrefs.java',
|
||||
'src/TestImageDownloader.java',
|
||||
'src/TestJarReader.java',
|
||||
|
@ -0,0 +1,55 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
public class TestGeckoBackgroundThread extends BrowserTestCase {
|
||||
|
||||
private boolean finishedTest;
|
||||
private boolean ranFirstRunnable;
|
||||
|
||||
public void testGeckoBackgroundThread() throws InterruptedException {
|
||||
|
||||
final Thread testThread = Thread.currentThread();
|
||||
|
||||
ThreadUtils.postToBackgroundThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Must *not* be on thread that posted the Runnable.
|
||||
assertFalse(ThreadUtils.isOnThread(testThread));
|
||||
|
||||
// Must be on background thread.
|
||||
assertTrue(ThreadUtils.isOnBackgroundThread());
|
||||
|
||||
ranFirstRunnable = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Post a second Runnable to make sure it still runs on the background thread,
|
||||
// and it only runs after the first Runnable has run.
|
||||
ThreadUtils.postToBackgroundThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Must still be on background thread.
|
||||
assertTrue(ThreadUtils.isOnBackgroundThread());
|
||||
|
||||
// This Runnable must be run after the first Runnable had finished.
|
||||
assertTrue(ranFirstRunnable);
|
||||
|
||||
synchronized (TestGeckoBackgroundThread.this) {
|
||||
finishedTest = true;
|
||||
TestGeckoBackgroundThread.this.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
synchronized (this) {
|
||||
while (!finishedTest) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user