mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-06-08 09:28:51 +00:00
72 lines
2.0 KiB
Java
72 lines
2.0 KiB
Java
/* 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.goanna;
|
|
|
|
import org.mozilla.goanna.AppConstants;
|
|
import org.mozilla.goanna.menu.GoannaMenu;
|
|
import org.mozilla.goanna.util.ThreadUtils;
|
|
|
|
public class TestGoannaMenu extends BrowserTestCase {
|
|
|
|
private volatile Exception exception;
|
|
private void setException(Exception e) {
|
|
this.exception = e;
|
|
}
|
|
|
|
public void testMenuThreading() throws InterruptedException {
|
|
final GoannaMenu menu = new GoannaMenu(getActivity());
|
|
final Object semaphore = new Object();
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
menu.add("test1");
|
|
} catch (Exception e) {
|
|
setException(e);
|
|
}
|
|
|
|
synchronized (semaphore) {
|
|
semaphore.notify();
|
|
}
|
|
}
|
|
});
|
|
synchronized (semaphore) {
|
|
semaphore.wait();
|
|
}
|
|
|
|
// No exception thrown if called on UI thread.
|
|
assertNull(exception);
|
|
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
menu.add("test2");
|
|
} catch (Exception e) {
|
|
setException(e);
|
|
}
|
|
|
|
synchronized (semaphore) {
|
|
semaphore.notify();
|
|
}
|
|
}
|
|
}).start();
|
|
|
|
synchronized (semaphore) {
|
|
semaphore.wait();
|
|
}
|
|
|
|
if (AppConstants.RELEASE_BUILD) {
|
|
// No exception thrown: release build.
|
|
assertNull(exception);
|
|
return;
|
|
}
|
|
|
|
assertNotNull(exception);
|
|
assertEquals(exception.getClass(), IllegalThreadStateException.class);
|
|
}
|
|
}
|