michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import java.util.Map; michael@0: michael@0: import org.mozilla.gecko.Assert; michael@0: import org.mozilla.gecko.FennecInstrumentationTestRunner; michael@0: import org.mozilla.gecko.FennecMochitestAssert; michael@0: import org.mozilla.gecko.FennecNativeDriver; michael@0: import org.mozilla.gecko.FennecTalosAssert; michael@0: michael@0: import android.app.Activity; michael@0: import android.test.ActivityInstrumentationTestCase2; michael@0: michael@0: public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2 { michael@0: public enum Type { michael@0: MOCHITEST, michael@0: TALOS michael@0: } michael@0: michael@0: protected Assert mAsserter; michael@0: protected String mLogFile; michael@0: michael@0: protected Map mConfig; michael@0: protected String mRootPath; michael@0: michael@0: /** michael@0: * The browser is started at the beginning of this test. A single test is a michael@0: * class inheriting from BaseRobocopTest that contains test michael@0: * methods. michael@0: *

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

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

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