From 97786c5695d578fd39d1a6fd864b4fe6e9c51cbb Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Fri, 29 May 2015 17:18:07 -0700 Subject: [PATCH] Bug 1169476 -- Implement |mach robocop --serve|. r=gbrown This adds a flag to |mach robocop| that does everything to run a Robocop test except launch the actual test. Instead of launching the test, it starts the mochi.test server and launches Fennec with a test profile; then it sits and waits forever. This allows regular Java IDEs (IntelliJ, but previously Eclipse) to run Robocop tests like regular instrumentation tests, "injecting" them into the prepared testing environment. It's quite nice! --HG-- extra : rebase_source : a5ab08222110a20291aebe70ef1fda0d340dbe7d extra : source : e91ac9a35f86928fcd519911476ee7d68d06f921 --- build/mobile/remoteautomation.py | 8 +- build/mobile/robocop/AndroidManifest.xml.in | 14 ++- ...LaunchFennecWithConfigurationActivity.java | 40 ++++++++ build/mobile/robocop/Makefile.in | 1 + .../browser/robocop/BaseRobocopTest.java | 92 ++++++++++++++++--- .../tests/browser/robocop/BaseTest.java | 32 ------- .../android/tests/browser/robocop/UITest.java | 36 -------- testing/mochitest/mach_commands.py | 8 +- testing/mochitest/runtestsremote.py | 47 +++++++--- 9 files changed, 180 insertions(+), 98 deletions(-) create mode 100644 build/mobile/robocop/LaunchFennecWithConfigurationActivity.java diff --git a/build/mobile/remoteautomation.py b/build/mobile/remoteautomation.py index 692fe2ca1b08..e99a2c090820 100644 --- a/build/mobile/remoteautomation.py +++ b/build/mobile/remoteautomation.py @@ -24,6 +24,10 @@ fennecLogcatFilters = [ "The character encoding of the HTML document was not dec class RemoteAutomation(Automation): _devicemanager = None + # Part of a hack for Robocop: "am COMMAND" is handled specially if COMMAND + # is in this set. See usages below. + _specialAmCommands = ('instrument', 'start') + def __init__(self, deviceManager, appName = '', remoteLog = None, processArgs=None): self._devicemanager = deviceManager @@ -237,7 +241,7 @@ class RemoteAutomation(Automation): # Hack for robocop, if app & testURL == None and extraArgs contains the rest of the stuff, lets # assume extraArgs is all we need - if app == "am" and extraArgs[0] == "instrument": + if app == "am" and extraArgs[0] in RemoteAutomation._specialAmCommands: return app, extraArgs cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs) @@ -275,7 +279,7 @@ class RemoteAutomation(Automation): else: raise Exception("unable to launch process") self.procName = cmd[0].split('/')[-1] - if cmd[0] == 'am' and cmd[1] == "instrument": + if cmd[0] == 'am' and cmd[1] in RemoteAutomation._specialAmCommands: self.procName = app print "Robocop process name: "+self.procName diff --git a/build/mobile/robocop/AndroidManifest.xml.in b/build/mobile/robocop/AndroidManifest.xml.in index dd81d83619a8..914f4dd31f19 100644 --- a/build/mobile/robocop/AndroidManifest.xml.in +++ b/build/mobile/robocop/AndroidManifest.xml.in @@ -8,7 +8,11 @@ android:versionCode="1" android:versionName="1.0" > - + + + + + + + + diff --git a/build/mobile/robocop/LaunchFennecWithConfigurationActivity.java b/build/mobile/robocop/LaunchFennecWithConfigurationActivity.java new file mode 100644 index 000000000000..208b2c7bd0ab --- /dev/null +++ b/build/mobile/robocop/LaunchFennecWithConfigurationActivity.java @@ -0,0 +1,40 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.gecko; + +import java.util.Map; + +import org.mozilla.gecko.tests.BaseRobocopTest; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; + +/** + * An Activity that extracts Robocop settings from robotium.config, launches + * Fennec with the Robocop testing parameters, and finishes itself. + *

+ * This is intended to be used by local testers using |mach robocop --serve|. + */ +public class LaunchFennecWithConfigurationActivity extends Activity { + @Override + public void onCreate(Bundle arguments) { + super.onCreate(arguments); + } + + @Override + public void onResume() { + super.onResume(); + + final String configFile = FennecNativeDriver.getFile(BaseRobocopTest.DEFAULT_ROOT_PATH + "/robotium.config"); + final Map config = FennecNativeDriver.convertTextToTable(configFile); + final Intent intent = BaseRobocopTest.createActivityIntent(config); + + intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS); + + this.finish(); + this.startActivity(intent); + } +} diff --git a/build/mobile/robocop/Makefile.in b/build/mobile/robocop/Makefile.in index 60635269fb85..e7f5adcdb922 100644 --- a/build/mobile/robocop/Makefile.in +++ b/build/mobile/robocop/Makefile.in @@ -24,6 +24,7 @@ _JAVA_HARNESS := \ FennecTalosAssert.java \ FennecNativeDriver.java \ FennecNativeElement.java \ + LaunchFennecWithConfigurationActivity.java \ RoboCopException.java \ RobocopShare1.java \ RobocopShare2.java \ diff --git a/mobile/android/tests/browser/robocop/BaseRobocopTest.java b/mobile/android/tests/browser/robocop/BaseRobocopTest.java index 5bcdba9a3b48..1785e0f8ca15 100644 --- a/mobile/android/tests/browser/robocop/BaseRobocopTest.java +++ b/mobile/android/tests/browser/robocop/BaseRobocopTest.java @@ -4,7 +4,15 @@ package org.mozilla.gecko.tests; -import java.util.Map; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.PowerManager; +import android.test.ActivityInstrumentationTestCase2; +import android.text.TextUtils; +import android.util.Log; + +import com.jayway.android.robotium.solo.Solo; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -13,32 +21,32 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.mozilla.gecko.Actions; import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.Assert; +import org.mozilla.gecko.BrowserApp; import org.mozilla.gecko.Driver; import org.mozilla.gecko.FennecInstrumentationTestRunner; import org.mozilla.gecko.FennecMochitestAssert; import org.mozilla.gecko.FennecNativeActions; import org.mozilla.gecko.FennecNativeDriver; import org.mozilla.gecko.FennecTalosAssert; +import org.mozilla.gecko.GeckoAppShell; +import org.mozilla.gecko.GeckoEvent; import org.mozilla.gecko.updater.UpdateServiceHelper; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.res.Resources; -import android.os.PowerManager; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import com.jayway.android.robotium.solo.Solo; +import java.util.Map; @SuppressWarnings("unchecked") public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2 { + public static final String LOGTAG = "BaseTest"; + public enum Type { MOCHITEST, TALOS } - private static final String DEFAULT_ROOT_PATH = "/mnt/sdcard/tests"; + public static final String DEFAULT_ROOT_PATH = "/mnt/sdcard/tests"; + + // How long to wait for a Robocop:Quit message to actually kill Fennec. + private static final int ROBOCOP_QUIT_WAIT_MS = 180000; /** * The Java Class instance that launches the browser. @@ -76,8 +84,6 @@ public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2BaseRobocopTest that contains test @@ -112,6 +118,30 @@ public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2 config) { + final Intent intent = new Intent(Intent.ACTION_MAIN); + intent.putExtra("args", "-no-remote -profile " + config.get("profile")); + // Don't show the first run experience. + intent.putExtra(BrowserApp.EXTRA_SKIP_STARTPANE, true); + + final String envString = config.get("envvars"); + if (!TextUtils.isEmpty(envString)) { + final String[] envStrings = envString.split(","); + + for (int iter = 0; iter < envStrings.length; iter++) { + intent.putExtra("env" + iter, envStrings[iter]); + } + } + + return intent; + } + @Override protected void setUp() throws Exception { // Disable the updater. @@ -152,7 +182,43 @@ public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2