michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: package org.mozilla.gecko.background.helpers; michael@0: michael@0: import junit.framework.AssertionFailedError; michael@0: michael@0: import org.mozilla.gecko.background.testhelpers.WaitHelper; michael@0: michael@0: import android.app.Activity; michael@0: import android.content.Context; michael@0: import android.test.ActivityInstrumentationTestCase2; michael@0: michael@0: /** michael@0: * AndroidSyncTestCase provides helper methods for testing. michael@0: */ michael@0: public class AndroidSyncTestCase extends ActivityInstrumentationTestCase2 { michael@0: protected static String LOG_TAG = "AndroidSyncTestCase"; michael@0: michael@0: public AndroidSyncTestCase() { michael@0: super(Activity.class); michael@0: WaitHelper.resetTestWaiter(); michael@0: } michael@0: michael@0: public Context getApplicationContext() { michael@0: return this.getInstrumentation().getTargetContext().getApplicationContext(); michael@0: } michael@0: michael@0: public static void performWait(Runnable runnable) { michael@0: try { michael@0: WaitHelper.getTestWaiter().performWait(runnable); michael@0: } catch (WaitHelper.InnerError e) { michael@0: AssertionFailedError inner = new AssertionFailedError("Caught error in performWait"); michael@0: inner.initCause(e.innerError); michael@0: throw inner; michael@0: } michael@0: } michael@0: michael@0: public static void performNotify() { michael@0: WaitHelper.getTestWaiter().performNotify(); michael@0: } michael@0: michael@0: public static void performNotify(Throwable e) { michael@0: WaitHelper.getTestWaiter().performNotify(e); michael@0: } michael@0: michael@0: public static void performNotify(String reason, Throwable e) { michael@0: AssertionFailedError er = new AssertionFailedError(reason + ": " + e.getMessage()); michael@0: er.initCause(e); michael@0: WaitHelper.getTestWaiter().performNotify(er); michael@0: } michael@0: }