bug 790102 - Frequent trobocheck, trobopan talosError: 'GeckoEventExpecter: blockForEvent timeout: Gecko:Ready [browser_output.txt]', add helper function to block for gecko:ready r=gbrown
authorBrad Lassey <blassey@mozilla.com>
Thu, 25 Oct 2012 15:41:26 -0400
changeset 111571 13455917d72ccf9ec930df70d21388fe80d32473
parent 111570 f258c53b90ea8477749ce81904a94bf932c636fc
child 111572 a63eeede2d15cc6ed00eedb512ae2fecd3e7b522
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersgbrown
bugs790102
milestone19.0a1
bug 790102 - Frequent trobocheck, trobopan talosError: 'GeckoEventExpecter: blockForEvent timeout: Gecko:Ready [browser_output.txt]', add helper function to block for gecko:ready r=gbrown
mobile/android/base/tests/BaseTest.java.in
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -10,17 +10,17 @@ import android.content.ContentValues;
 import android.content.Intent;
 import android.content.res.AssetManager;
 import android.database.Cursor;
 import android.os.SystemClock;
 import android.test.ActivityInstrumentationTestCase2;
 import java.io.File;
 import java.io.InputStream;
 import java.io.IOException;
-
+import java.lang.reflect.Method;
 import java.util.HashMap;
 
 /**
  *  A convenient base class suitable for most Robocop tests.
  */
 abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
     public static final int TEST_MOCHITEST = 0;
     public static final int TEST_TALOS = 1;
@@ -35,16 +35,33 @@ abstract class BaseTest extends Activity
     protected Driver mDriver;
     protected Assert mAsserter;
     protected Actions mActions;
     protected String mBaseUrl;
     protected String mRawBaseUrl;
     private String mLogFile;
     protected String mProfile;
 
+    protected void blockForGeckoReady() {
+        try {
+            Actions.EventExpecter geckoReadyExpector = mActions.expectGeckoEvent("Gecko:Ready");
+            ClassLoader classLoader = getActivity().getClassLoader();
+            Class appsCls = classLoader.loadClass("org.mozilla.gecko.GeckoApp");
+            Class launchStateCls = classLoader.loadClass("org.mozilla.gecko.GeckoApp$LaunchState");
+            Method checkLaunchState =  appsCls.getMethod("checkLaunchState", launchStateCls);
+            Object states[] =  launchStateCls.getEnumConstants();
+            Boolean ret = (Boolean)checkLaunchState.invoke(null, states[3]);
+            if (!ret.booleanValue()) {
+	        geckoReadyExpector.blockForEvent();
+            }
+        } catch (Exception e) {
+            mAsserter.dumpLog("Exception in blockForGeckoReady", e);
+        }
+    }
+
     static {
         try {
             mLauncherActivityClass = (Class<Activity>)Class.forName(LAUNCH_ACTIVITY_FULL_CLASSNAME);
         } catch (ClassNotFoundException e) {
             throw new RuntimeException(e);
         }
     }