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