/* 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.gecko.tests; import java.util.Map; import org.mozilla.gecko.Assert; import org.mozilla.gecko.FennecInstrumentationTestRunner; import org.mozilla.gecko.FennecMochitestAssert; import org.mozilla.gecko.FennecNativeDriver; import org.mozilla.gecko.FennecTalosAssert; import android.app.Activity; import android.test.ActivityInstrumentationTestCase2; import android.util.Log; public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2 { public enum Type { MOCHITEST, TALOS } private static final String DEFAULT_ROOT_PATH = "/mnt/sdcard/tests"; protected Assert mAsserter; protected String mLogFile; protected Map mConfig; protected String mRootPath; /** * The browser is started at the beginning of this test. A single test is a * class inheriting from BaseRobocopTest that contains test * methods. *

* If a test should not start the browser at the beginning of a test, * specify a different activity class to the one-argument constructor. To do * as little as possible, specify Activity.class. */ @SuppressWarnings("unchecked") public BaseRobocopTest() { this((Class) TestConstants.BROWSER_INTENT_CLASS); } /** * Start the given activity class at the beginning of this test. *

* You should use the no-argument constructor in almost all cases. * * @param activityClass to start before this test. */ protected BaseRobocopTest(Class activityClass) { super(activityClass); } /** * Returns the test type: mochitest or talos. *

* By default tests are mochitests, but a test can override this method in * order to change its type. Most Robocop tests are mochitests. */ protected Type getTestType() { return Type.MOCHITEST; } @Override protected void setUp() throws Exception { // Load config file from root path (set up by Python script). mRootPath = FennecInstrumentationTestRunner.getFennecArguments().getString("deviceroot"); if (mRootPath == null) { Log.w("Robocop", "Did not find deviceroot in arguments; falling back to: " + DEFAULT_ROOT_PATH); mRootPath = DEFAULT_ROOT_PATH; } String configFile = FennecNativeDriver.getFile(mRootPath + "/robotium.config"); mConfig = FennecNativeDriver.convertTextToTable(configFile); mLogFile = (String) mConfig.get("logfile"); // Initialize the asserter. if (getTestType() == Type.TALOS) { mAsserter = new FennecTalosAssert(); } else { mAsserter = new FennecMochitestAssert(); } mAsserter.setLogFile(mLogFile); mAsserter.setTestName(this.getClass().getName()); } }