Bug 916507 - Part 2: Remove reflection from BaseTest. r=nalexander

This commit is contained in:
Michael Comella 2013-11-13 14:53:21 -08:00
parent 3aca959578
commit 9ea21fd958
2 changed files with 5 additions and 20 deletions

View File

@ -17,7 +17,6 @@ import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;

View File

@ -2,7 +2,9 @@ package org.mozilla.gecko.tests;
import com.jayway.android.robotium.solo.Condition; import com.jayway.android.robotium.solo.Condition;
import com.jayway.android.robotium.solo.Solo; import com.jayway.android.robotium.solo.Solo;
import org.mozilla.gecko.*; import org.mozilla.gecko.*;
import org.mozilla.gecko.GeckoThread.LaunchState;
import android.app.Activity; import android.app.Activity;
import android.app.Instrumentation; import android.app.Instrumentation;
@ -37,7 +39,6 @@ import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -79,13 +80,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
protected void blockForGeckoReady() { protected void blockForGeckoReady() {
try { try {
Actions.EventExpecter geckoReadyExpector = mActions.expectGeckoEvent("Gecko:Ready"); Actions.EventExpecter geckoReadyExpector = mActions.expectGeckoEvent("Gecko:Ready");
ClassLoader classLoader = getActivity().getClassLoader(); if (!GeckoThread.checkLaunchState(LaunchState.GeckoRunning)) {
Class appsCls = classLoader.loadClass("org.mozilla.gecko.GeckoThread");
Class launchStateCls = classLoader.loadClass("org.mozilla.gecko.GeckoThread$LaunchState");
Method checkLaunchState = appsCls.getMethod("checkLaunchState", launchStateCls);
Object states[] = launchStateCls.getEnumConstants();
Boolean ret = (Boolean)checkLaunchState.invoke(null, states[3]);
if (!ret.booleanValue()) {
geckoReadyExpector.blockForEvent(); geckoReadyExpector.blockForEvent();
} }
geckoReadyExpector.unregisterListener(); geckoReadyExpector.unregisterListener();
@ -256,12 +251,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
*/ */
protected final void loadUrl(final String url) { protected final void loadUrl(final String url) {
try { try {
ClassLoader classLoader = getActivity().getClassLoader(); Tabs.getInstance().loadUrl(url);
Class tabsClass = classLoader.loadClass("org.mozilla.gecko.Tabs");
Method getInstance = tabsClass.getMethod("getInstance");
Method loadUrl = tabsClass.getMethod("loadUrl", String.class);
Object tabs = getInstance.invoke(null);
loadUrl.invoke(tabs, new Object[] { url });
} catch (Exception e) { } catch (Exception e) {
mAsserter.dumpLog("Exception in loadUrl", e); mAsserter.dumpLog("Exception in loadUrl", e);
throw new RuntimeException(e); throw new RuntimeException(e);
@ -728,11 +718,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
// Determine device type // Determine device type
type = "phone"; type = "phone";
try { try {
ClassLoader classLoader = getActivity().getClassLoader(); if (GeckoAppShell.isTablet()) {
Class appsCls = classLoader.loadClass("org.mozilla.gecko.GeckoAppShell");
Method isTabletMethod = appsCls.getMethod("isTablet", (Class[]) null);
boolean isTablet = (Boolean)isTabletMethod.invoke(null);
if (isTablet) {
type = "tablet"; type = "tablet";
} }
} catch (Exception e) { } catch (Exception e) {