mobile/android/tests/browser/junit3/src/tests/TestGeckoMenu.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 package org.mozilla.gecko.browser.tests;
     7 import org.mozilla.gecko.AppConstants;
     8 import org.mozilla.gecko.menu.GeckoMenu;
     9 import org.mozilla.gecko.util.ThreadUtils;
    11 public class TestGeckoMenu extends BrowserTestCase {
    13     private volatile Exception exception;
    14     private void setException(Exception e) {
    15         this.exception = e;
    16     }
    18     public void testMenuThreading() throws InterruptedException {
    19         final GeckoMenu menu = new GeckoMenu(getActivity());
    20         final Object semaphore = new Object();
    22         ThreadUtils.postToUiThread(new Runnable() {
    23             @Override
    24             public void run() {
    25                 try {
    26                     menu.add("test1");
    27                 } catch (Exception e) {
    28                     setException(e);
    29                 }
    31                 synchronized (semaphore) {
    32                     semaphore.notify();
    33                 }
    34             }
    35         });
    36         synchronized (semaphore) {
    37             semaphore.wait();
    38         }
    40         // No exception thrown if called on UI thread.
    41         assertNull(exception);
    43         new Thread(new Runnable() {
    44             @Override
    45             public void run() {
    46                 try {
    47                     menu.add("test2");
    48                 } catch (Exception e) {
    49                     setException(e);
    50                 }
    52                 synchronized (semaphore) {
    53                     semaphore.notify();
    54                 }
    55             }
    56         }).start();
    58         synchronized (semaphore) {
    59             semaphore.wait();
    60         }
    62         if (AppConstants.RELEASE_BUILD) {
    63             // No exception thrown: release build.
    64             assertNull(exception);
    65             return;
    66         }
    68         assertNotNull(exception);
    69         assertEquals(exception.getClass(), IllegalThreadStateException.class);
    70     }
    71 }

mercurial