Bug 701076 - [hookup to make] Robotium integration into birch tree. r=blassey,bear

This commit is contained in:
Joel Maher 2011-12-30 15:57:34 -05:00
parent c431dbcb94
commit 7b015f4b69
9 changed files with 216 additions and 16 deletions

View File

@ -62,6 +62,7 @@ ifeq (android,$(MOZ_WIDGET_TOOLKIT))
mobile/sutagent/android/watcher \
mobile/sutagent/android/ffxcp \
mobile/sutagent/android/fencp \
mobile/robocop \
$(NULL)
endif
endif

View File

@ -130,15 +130,12 @@ classes.dex: $(_JAVA_TESTS)
robocop.ap_: AndroidManifest.xml
$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -I . -S res -F $@ -J ./
robocop-unsigned-unaligned.apk: robocop.ap_ classes.dex
$(APKBUILDER) $@ -v $(APKBUILDER_FLAGS) -z robocop.ap_ -f classes.dex
robocop-unaligned.apk: robocop-unsigned-unaligned.apk
cp robocop-unsigned-unaligned.apk $@
jarsigner -keystore ~/.android/debug.keystore -storepass android -keypass android $@ androiddebugkey
robocop.apk: robocop-unaligned.apk
$(ZIPALIGN) -f -v 4 robocop-unaligned.apk $@
robocop.apk: robocop.ap_ classes.dex
$(APKBUILDER) robocop-raw.apk -v $(APKBUILDER_FLAGS) -z robocop.ap_ -f classes.dex
ifdef JARSIGNER
$(JARSIGNER) robocop-raw.apk
endif
$(ZIPALIGN) -f -v 4 robocop-raw.apk $@
cp $(TESTPATH)/robocop.ini robocop.ini
cp $(srcdir)/parse_ids.py parse_ids.py

View File

@ -51,6 +51,7 @@ DIRS = \
chrome \
ssltunnel \
specialpowers \
roboextender \
$(NULL)
@ -82,6 +83,7 @@ _SERV_FILES = \
$(topsrcdir)/build/mobile/devicemanagerADB.py \
$(topsrcdir)/build/mobile/devicemanagerSUT.py \
$(topsrcdir)/build/automationutils.py \
$(topsrcdir)/build/manifestparser.py \
$(topsrcdir)/build/mobile/remoteautomation.py \
gen_template.pl \
server.js \
@ -100,6 +102,10 @@ _SERV_FILES = \
android.json \
$(NULL)
ifeq ($(MOZ_BUILD_APP),mobile/android)
_SERV_FILES += $(topsrcdir)/mobile/android/base/tests/robocop.ini
endif
_PYWEBSOCKET_FILES = \
pywebsocket/standalone.py \
$(NULL)

View File

@ -0,0 +1,58 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation
# Portions created by the Initial Developer are Copyright (C) 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = testing/mochitest/roboextender
include $(DEPTH)/config/autoconf.mk
_TEST_FILES = \
bootstrap.js \
install.rdf \
$(NULL)
TEST_EXTENSIONS_DIR = $(DEPTH)/_tests/testing/mochitest/extensions
include $(topsrcdir)/config/rules.mk
libs:: $(_TEST_FILES)
$(MKDIR) -p $(TEST_EXTENSIONS_DIR)/roboextender@mozilla.org
$(INSTALL) $(foreach f,$^,"$f") $(TEST_EXTENSIONS_DIR)/roboextender@mozilla.org/

View File

@ -0,0 +1,60 @@
var Cc = Components.classes;
var Ci = Components.interfaces;
function loadIntoWindow(window) {}
function unloadFromWindow(window) {}
function _sendMessageToJava (aMsg) {
let bridge = Cc["@mozilla.org/android/bridge;1"].getService(Ci.nsIAndroidBridge);
return bridge.handleGeckoMessage(JSON.stringify(aMsg));
};
/*
bootstrap.js API
*/
var windowListener = {
onOpenWindow: function(aWindow) {
// Wait for the window to finish loading
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
domWindow.addEventListener("load", function() {
domWindow.removeEventListener("load", arguments.callee, false);
if (domWindow) {
domWindow.addEventListener("scroll", function(e) {
let message = {
gecko: {
type: 'robocop:scroll',
y: XPCNativeWrapper.unwrap(e.target).documentElement.scrollTop,
height: XPCNativeWrapper.unwrap(e.target).documentElement.scrollHeight,
cheight: XPCNativeWrapper.unwrap(e.target).documentElement.clientHeight,
}
};
let retVal = _sendMessageToJava(message);
});
}
}, false);
},
onCloseWindow: function(aWindow) { },
onWindowTitleChange: function(aWindow, aTitle) { }
};
function startup(aData, aReason) {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
// Load into any new windows
wm.addListener(windowListener);
}
function shutdown(aData, aReason) {
// When the application is shutting down we normally don't have to clean up any UI changes
if (aReason == APP_SHUTDOWN) return;
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
let obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
// Stop watching for new windows
wm.removeListener(windowListener);
}
function install(aData, aReason) { }
function uninstall(aData, aReason) { }

View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>roboextender@mozilla.org</em:id>
<em:type>2</em:type>
<em:name>Robocop Extender</em:name>
<em:version>1.0</em:version>
<em:bootstrap>true</em:bootstrap>
<em:creator>Joel Maher</em:creator>
<em:targetApplication>
<Description>
<em:id>toolkit@mozilla.org</em:id>
<em:minVersion>10.0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

View File

@ -49,6 +49,7 @@ from runtests import MochitestOptions
from runtests import MochitestServer
import devicemanager, devicemanagerADB, devicemanagerSUT
import manifestparser
class RemoteOptions(MochitestOptions):
@ -106,6 +107,11 @@ class RemoteOptions(MochitestOptions):
help = "name of the pidfile to generate")
defaults["pidFile"] = ""
self.add_option("--robocop", action = "store",
type = "string", dest = "robocop",
help = "use when running robotium tests on native UI")
defaults["robocop"] = ""
defaults["remoteTestRoot"] = None
defaults["logFile"] = "mochitest.log"
defaults["autorun"] = True
@ -312,7 +318,7 @@ def main():
auto = RemoteAutomation(dm_none, "fennec")
parser = RemoteOptions(auto, scriptdir)
options, args = parser.parse_args()
if (options.dm_trans == "adb"):
if (options.dm_trans == "adb" or options.robocop):
if (options.deviceIP):
dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort)
else:
@ -345,14 +351,46 @@ def main():
procName = options.app.split('/')[-1]
if (dm.processExist(procName)):
dm.killProcess(procName)
if (options.robocop):
mp = manifestparser.TestManifest(strict=False)
# TODO: pull this in dynamically
mp.read('robocop.ini')
robocop_tests = mp.active_tests(exists=False)
try:
retVal = mochitest.runTests(options)
except:
print "TEST-UNEXPECTED-ERROR | | Exception caught while running tests."
fHandle = open("robotium.config", "w")
fHandle.write("profile=%s\n" % (mochitest.remoteProfile))
fHandle.write("logfile=%s\n" % (options.remoteLogFile))
fHandle.close()
deviceRoot = dm.getDeviceRoot()
# Note, we are pushing to /sdcard since we have this location hard coded in robocop
dm.pushFile("robotium.config", "/sdcard/robotium.config")
dm.pushFile(os.path.abspath(options.robocop + "/fennec_ids.txt"), "/sdcard/fennec_ids.txt")
options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot)
manifest = mochitest.buildProfile(options)
mochitest.startWebServer(options)
if (options.dm_trans == 'adb'):
dm.checkCmd(["install", "-r", os.path.join(options.robocop, "robocop.apk")])
for test in robocop_tests:
cmd = ["shell", "am", "instrument", "-w", "-e", "class"]
cmd.append("%s.tests.%s" % (options.app, test['name']))
cmd.append("org.mozilla.roboexample.test/android.test.InstrumentationTestRunner")
retVal = dm.checkCmd(cmd)
else:
# SUTAgent needs to install robocop and not crash when we launch robocop.
retVal = dm.launchProcess(["am", "instrument", "-w", "org.mozilla.roboexample.test/android.test.InstrumentationTestRunner"])
mochitest.stopWebServer(options)
mochitest.stopWebSocketServer(options)
sys.exit(1)
else:
try:
retVal = mochitest.runTests(options)
except:
print "TEST-UNEXPECTED-ERROR | | Exception caught while running tests."
mochitest.stopWebServer(options)
mochitest.stopWebSocketServer(options)
sys.exit(1)
sys.exit(retVal)

View File

@ -74,6 +74,13 @@ RUN_MOCHITEST_REMOTE = \
--app=$(TEST_PACKAGE_NAME) --deviceIP=${TEST_DEVICE} --xre-path=${MOZ_HOST_BIN} \
$(SYMBOLS_PATH) $(TEST_PATH_ARG) $(EXTRA_TEST_ARGS)
RUN_MOCHITEST_ROBOTIUM = \
rm -f ./$@.log && \
$(PYTHON) _tests/testing/mochitest/runtestsremote.py --robocop ../../../build/mobile/robocop \
--console-level=INFO --log-file=./$@.log --file-level=INFO $(DM_FLAGS) --dm_trans=adb \
--app=$(TEST_PACKAGE_NAME) --deviceIP=${TEST_DEVICE} --xre-path=${MOZ_HOST_BIN} \
$(SYMBOLS_PATH) $(TEST_PATH_ARG) $(EXTRA_TEST_ARGS)
ifndef NO_FAIL_ON_TEST_ERRORS
define CHECK_TEST_ERROR
@errors=`grep "TEST-UNEXPECTED-" $@.log` ;\
@ -95,6 +102,14 @@ mochitest-remote:
echo "please prepare your host with environment variables for TEST_DEVICE and MOZ_HOST_BIN"; \
fi
mochitest-robotium: DM_TRANS?=adb
mochitest-robotium:
@if test -f ${MOZ_HOST_BIN}/xpcshell && [ "${TEST_DEVICE}" != "usb" -o "$(DM_TRANS)" = "adb" ]; \
then $(RUN_MOCHITEST_ROBOTIUM); \
else \
echo "please prepare your host with environment variables for TEST_DEVICE and MOZ_HOST_BIN"; \
fi
mochitest-plain:
$(RUN_MOCHITEST)
$(CHECK_TEST_ERROR)
@ -286,6 +301,11 @@ stage-android: make-stage-dir
$(NSINSTALL) $(DEPTH)/build/mobile/sutagent/android/watcher/Watcher.apk $(PKG_STAGE)/bin
$(NSINSTALL) $(DEPTH)/build/mobile/sutagent/android/fencp/FenCP.apk $(PKG_STAGE)/bin
$(NSINSTALL) $(DEPTH)/build/mobile/sutagent/android/ffxcp/FfxCP.apk $(PKG_STAGE)/bin
ifeq ($(MOZ_BUILD_APP),mobile/android)
$(NSINSTALL) $(DEPTH)/build/mobile/robocop/robocop.apk $(PKG_STAGE)/bin
$(PYTHON) $(DIST)/../build/mobile/robocop/parse_ids.py -i $(DEPTH)/mobile/android/base/R.java -o $(DEPTH)/build/mobile/robocop/fennec_ids.txt
$(NSINSTALL) $(DEPTH)/build/mobile/robocop/fennec_ids.txt $(PKG_STAGE)/bin
endif
stage-jetpack: make-stage-dir
$(NSINSTALL) $(topsrcdir)/testing/jetpack/jetpack-location.txt $(PKG_STAGE)/jetpack

View File

@ -350,6 +350,7 @@ INNER_MAKE_PACKAGE = \
cp $(_ABS_DIST)/gecko.apk $(_ABS_DIST)/gecko-unsigned-unaligned.apk && \
$(JARSIGNER) $(_ABS_DIST)/gecko.apk && \
$(ZIPALIGN) -f -v 4 $(_ABS_DIST)/gecko.apk $(PACKAGE)
INNER_UNMAKE_PACKAGE = \
mkdir $(MOZ_PKG_DIR) && \
pushd $(MOZ_PKG_DIR) && \