|
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/. */ |
|
4 |
|
5 package org.mozilla.gecko.tests; |
|
6 |
|
7 import java.util.Map; |
|
8 |
|
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; |
|
14 |
|
15 import android.app.Activity; |
|
16 import android.test.ActivityInstrumentationTestCase2; |
|
17 |
|
18 public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2<Activity> { |
|
19 public enum Type { |
|
20 MOCHITEST, |
|
21 TALOS |
|
22 } |
|
23 |
|
24 protected Assert mAsserter; |
|
25 protected String mLogFile; |
|
26 |
|
27 protected Map<String, String> mConfig; |
|
28 protected String mRootPath; |
|
29 |
|
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 } |
|
43 |
|
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 } |
|
54 |
|
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 } |
|
64 |
|
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"); |
|
72 |
|
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 } |