mobile/android/base/tests/BaseRobocopTest.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.tests;
michael@0 6
michael@0 7 import java.util.Map;
michael@0 8
michael@0 9 import org.mozilla.gecko.Assert;
michael@0 10 import org.mozilla.gecko.FennecInstrumentationTestRunner;
michael@0 11 import org.mozilla.gecko.FennecMochitestAssert;
michael@0 12 import org.mozilla.gecko.FennecNativeDriver;
michael@0 13 import org.mozilla.gecko.FennecTalosAssert;
michael@0 14
michael@0 15 import android.app.Activity;
michael@0 16 import android.test.ActivityInstrumentationTestCase2;
michael@0 17
michael@0 18 public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2<Activity> {
michael@0 19 public enum Type {
michael@0 20 MOCHITEST,
michael@0 21 TALOS
michael@0 22 }
michael@0 23
michael@0 24 protected Assert mAsserter;
michael@0 25 protected String mLogFile;
michael@0 26
michael@0 27 protected Map<String, String> mConfig;
michael@0 28 protected String mRootPath;
michael@0 29
michael@0 30 /**
michael@0 31 * The browser is started at the beginning of this test. A single test is a
michael@0 32 * class inheriting from <code>BaseRobocopTest</code> that contains test
michael@0 33 * methods.
michael@0 34 * <p>
michael@0 35 * If a test should not start the browser at the beginning of a test,
michael@0 36 * specify a different activity class to the one-argument constructor. To do
michael@0 37 * as little as possible, specify <code>Activity.class</code>.
michael@0 38 */
michael@0 39 @SuppressWarnings("unchecked")
michael@0 40 public BaseRobocopTest() {
michael@0 41 this((Class<Activity>) TestConstants.BROWSER_INTENT_CLASS);
michael@0 42 }
michael@0 43
michael@0 44 /**
michael@0 45 * Start the given activity class at the beginning of this test.
michael@0 46 * <p>
michael@0 47 * <b>You should use the no-argument constructor in almost all cases.</b>
michael@0 48 *
michael@0 49 * @param activityClass to start before this test.
michael@0 50 */
michael@0 51 protected BaseRobocopTest(Class<Activity> activityClass) {
michael@0 52 super(activityClass);
michael@0 53 }
michael@0 54
michael@0 55 /**
michael@0 56 * Returns the test type: mochitest or talos.
michael@0 57 * <p>
michael@0 58 * By default tests are mochitests, but a test can override this method in
michael@0 59 * order to change its type. Most Robocop tests are mochitests.
michael@0 60 */
michael@0 61 protected Type getTestType() {
michael@0 62 return Type.MOCHITEST;
michael@0 63 }
michael@0 64
michael@0 65 @Override
michael@0 66 protected void setUp() throws Exception {
michael@0 67 // Load config file from root path (set up by Python script).
michael@0 68 mRootPath = FennecInstrumentationTestRunner.getFennecArguments().getString("deviceroot");
michael@0 69 String configFile = FennecNativeDriver.getFile(mRootPath + "/robotium.config");
michael@0 70 mConfig = FennecNativeDriver.convertTextToTable(configFile);
michael@0 71 mLogFile = (String) mConfig.get("logfile");
michael@0 72
michael@0 73 // Initialize the asserter.
michael@0 74 if (getTestType() == Type.TALOS) {
michael@0 75 mAsserter = new FennecTalosAssert();
michael@0 76 } else {
michael@0 77 mAsserter = new FennecMochitestAssert();
michael@0 78 }
michael@0 79 mAsserter.setLogFile(mLogFile);
michael@0 80 mAsserter.setTestName(this.getClass().getName());
michael@0 81 }
michael@0 82 }

mercurial