1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/BaseRobocopTest.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.tests; 1.9 + 1.10 +import java.util.Map; 1.11 + 1.12 +import org.mozilla.gecko.Assert; 1.13 +import org.mozilla.gecko.FennecInstrumentationTestRunner; 1.14 +import org.mozilla.gecko.FennecMochitestAssert; 1.15 +import org.mozilla.gecko.FennecNativeDriver; 1.16 +import org.mozilla.gecko.FennecTalosAssert; 1.17 + 1.18 +import android.app.Activity; 1.19 +import android.test.ActivityInstrumentationTestCase2; 1.20 + 1.21 +public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2<Activity> { 1.22 + public enum Type { 1.23 + MOCHITEST, 1.24 + TALOS 1.25 + } 1.26 + 1.27 + protected Assert mAsserter; 1.28 + protected String mLogFile; 1.29 + 1.30 + protected Map<String, String> mConfig; 1.31 + protected String mRootPath; 1.32 + 1.33 + /** 1.34 + * The browser is started at the beginning of this test. A single test is a 1.35 + * class inheriting from <code>BaseRobocopTest</code> that contains test 1.36 + * methods. 1.37 + * <p> 1.38 + * If a test should not start the browser at the beginning of a test, 1.39 + * specify a different activity class to the one-argument constructor. To do 1.40 + * as little as possible, specify <code>Activity.class</code>. 1.41 + */ 1.42 + @SuppressWarnings("unchecked") 1.43 + public BaseRobocopTest() { 1.44 + this((Class<Activity>) TestConstants.BROWSER_INTENT_CLASS); 1.45 + } 1.46 + 1.47 + /** 1.48 + * Start the given activity class at the beginning of this test. 1.49 + * <p> 1.50 + * <b>You should use the no-argument constructor in almost all cases.</b> 1.51 + * 1.52 + * @param activityClass to start before this test. 1.53 + */ 1.54 + protected BaseRobocopTest(Class<Activity> activityClass) { 1.55 + super(activityClass); 1.56 + } 1.57 + 1.58 + /** 1.59 + * Returns the test type: mochitest or talos. 1.60 + * <p> 1.61 + * By default tests are mochitests, but a test can override this method in 1.62 + * order to change its type. Most Robocop tests are mochitests. 1.63 + */ 1.64 + protected Type getTestType() { 1.65 + return Type.MOCHITEST; 1.66 + } 1.67 + 1.68 + @Override 1.69 + protected void setUp() throws Exception { 1.70 + // Load config file from root path (set up by Python script). 1.71 + mRootPath = FennecInstrumentationTestRunner.getFennecArguments().getString("deviceroot"); 1.72 + String configFile = FennecNativeDriver.getFile(mRootPath + "/robotium.config"); 1.73 + mConfig = FennecNativeDriver.convertTextToTable(configFile); 1.74 + mLogFile = (String) mConfig.get("logfile"); 1.75 + 1.76 + // Initialize the asserter. 1.77 + if (getTestType() == Type.TALOS) { 1.78 + mAsserter = new FennecTalosAssert(); 1.79 + } else { 1.80 + mAsserter = new FennecMochitestAssert(); 1.81 + } 1.82 + mAsserter.setLogFile(mLogFile); 1.83 + mAsserter.setTestName(this.getClass().getName()); 1.84 + } 1.85 +}