Bug 903528 - Part 2: Land and build Fennec JUnit 3 tests. r=rnewman

--HG--
rename : mobile/android/tests/moz.build => mobile/android/tests/browser/moz.build
This commit is contained in:
Nick Alexander 2014-02-24 18:24:46 -08:00
parent 478d42ae14
commit 8394a7f950
15 changed files with 265 additions and 0 deletions

View File

@ -0,0 +1,26 @@
#filter substitution
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="@ANDROID_BROWSER_TEST_PACKAGE_NAME@"
sharedUserId="@MOZ_ANDROID_SHARED_ID@"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="@ANDROID_BROWSER_TARGET_PACKAGE_NAME@.permissions.BROWSER_PROVIDER"/>
<uses-permission android:name="@ANDROID_BROWSER_TARGET_PACKAGE_NAME@.permissions.FORMHISTORY_PROVIDER"/>
<uses-permission android:name="@ANDROID_BROWSER_TARGET_PACKAGE_NAME@.permissions.PASSWORD_PROVIDER"/>
<application
android:icon="@drawable/icon"
android:label="@ANDROID_BROWSER_APP_DISPLAYNAME@">
<uses-library android:name="android.test.runner" />
</application>
<instrumentation
android:label="@string/app_name"
android:name="org.mozilla.browser.harness.BrowserInstrumentationTestRunner"
android:targetPackage="@ANDROID_BROWSER_TARGET_PACKAGE_NAME@" />
</manifest>

View File

@ -0,0 +1,31 @@
# 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/.
ANDROID_APK_NAME := browser-junit3-debug
ANDROID_EXTRA_JARS += \
browser-junit3.jar \
$(NULL)
PP_TARGETS += manifest
manifest := AndroidManifest.xml.in
manifest_FLAGS += \
-DANDROID_BROWSER_TARGET_PACKAGE_NAME='$(ANDROID_PACKAGE_NAME)' \
-DANDROID_BROWSER_TEST_PACKAGE_NAME='org.mozilla.gecko.browser.tests' \
-DANDROID_BROWSER_APP_DISPLAYNAME='$(MOZ_APP_DISPLAYNAME) Browser Tests' \
-DMOZ_ANDROID_SHARED_ID='$(ANDROID_PACKAGE_NAME).sharedID' \
$(NULL)
include $(topsrcdir)/config/rules.mk
tools:: $(ANDROID_APK_NAME).apk
# The test APK needs to know the contents of the target APK while not
# being linked against them. This is a best effort to avoid getting
# out of sync with base's build config.
JARS_DIR := $(DEPTH)/mobile/android/base
JAVA_BOOTCLASSPATH := $(JAVA_BOOTCLASSPATH):$(subst $(NULL) ,:,$(wildcard $(JARS_DIR)/*.jar))
# We also want to re-compile classes.dex when the associated base
# content changes.
classes.dex: $(wildcard $(JARS_DIR)/*.jar)

View File

@ -0,0 +1,17 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
jar = add_java_jar('browser-junit3')
jar.sources += [
'src/harness/BrowserInstrumentationTestRunner.java',
'src/harness/BrowserTestListener.java',
'src/tests/BrowserTestCase.java',
'src/tests/TestJarReader.java',
]
jar.generated_sources = [] # None yet -- try to keep it this way.
jar.javac_flags += ['-Xlint:all,-unchecked']

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name" />
</LinearLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Gecko Browser Tests</string>
</resources>

View File

@ -0,0 +1,33 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.browser.harness;
import android.os.Bundle;
import android.test.AndroidTestRunner;
import android.test.InstrumentationTestRunner;
import android.util.Log;
/**
* A test runner that installs a special test listener.
* <p>
* In future, this listener will turn JUnit 3 test events into log messages in
* the format that Mochitest parsers understand.
*/
public class BrowserInstrumentationTestRunner extends InstrumentationTestRunner {
private static final String LOG_TAG = "BInstTestRunner";
@Override
public void onCreate(Bundle arguments) {
Log.d(LOG_TAG, "onCreate");
super.onCreate(arguments);
}
@Override
protected AndroidTestRunner getAndroidTestRunner() {
Log.d(LOG_TAG, "getAndroidTestRunner");
AndroidTestRunner testRunner = super.getAndroidTestRunner();
testRunner.addTestListener(new BrowserTestListener());
return testRunner;
}
}

View File

@ -0,0 +1,42 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.browser.harness;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestListener;
import android.util.Log;
/**
* BrowserTestListener turns JUnit 3 test events into log messages in the format
* that Mochitest parsers understand.
* <p>
* The idea is that, on infrastructure, we'll be able to use the same test
* parsing code for Browser JUnit 3 tests as we do for Robocop tests.
* <p>
* In future, that is!
*/
public class BrowserTestListener implements TestListener {
public static final String LOG_TAG = "BTestListener";
@Override
public void startTest(Test test) {
Log.d(LOG_TAG, "startTest: " + test);
}
@Override
public void endTest(Test test) {
Log.d(LOG_TAG, "endTest: " + test);
}
@Override
public void addFailure(Test test, AssertionFailedError t) {
Log.d(LOG_TAG, "addFailure: " + test);
}
@Override
public void addError(Test test, Throwable t) {
Log.d(LOG_TAG, "addError: " + test);
}
}

View File

@ -0,0 +1,37 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.browser.tests;
import org.mozilla.gecko.AppConstants;
import android.app.Activity;
import android.content.Context;
import android.test.ActivityInstrumentationTestCase2;
/**
* BrowserTestCase provides helper methods for testing.
*/
public class BrowserTestCase extends ActivityInstrumentationTestCase2<Activity> {
private static String LOG_TAG = "BrowserTestCase";
private static final String LAUNCHER_ACTIVITY = AppConstants.ANDROID_PACKAGE_NAME + ".App";
private final static Class<Activity> sLauncherActivityClass;
static {
try {
sLauncherActivityClass = (Class<Activity>) Class.forName(LAUNCHER_ACTIVITY);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public BrowserTestCase() {
super(sLauncherActivityClass);
}
public Context getApplicationContext() {
return this.getInstrumentation().getTargetContext().getApplicationContext();
}
}

View File

@ -0,0 +1,45 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.browser.tests;
import java.io.InputStream;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.util.GeckoJarReader;
/**
* A basic jar reader test. Tests reading a png from fennec's apk, as well as
* loading some invalid jar urls.
*/
public class TestJarReader extends BrowserTestCase {
public void testJarReader() {
String appPath = getActivity().getApplication().getPackageResourcePath();
assertNotNull(appPath);
// Test reading a file from a jar url that looks correct.
String url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME;
InputStream stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
assertNotNull(stream);
// Test looking for an non-existent file in a jar.
url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME;
stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
assertNull(stream);
// Test looking for a file that doesn't exist in the APK.
url = "jar:file://" + appPath + "!/" + "BAD" + AppConstants.OMNIJAR_NAME;
stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
assertNull(stream);
// Test looking for an jar with an invalid url.
url = "jar:file://" + appPath + "!" + "!/" + AppConstants.OMNIJAR_NAME;
stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
assertNull(stream);
// Test looking for a file that doesn't exist on disk.
url = "jar:file://" + appPath + "BAD" + "!/" + AppConstants.OMNIJAR_NAME;
stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
assertNull(stream);
}
}

View File

@ -0,0 +1,9 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
TEST_DIRS += [
'junit3',
]

View File

@ -6,4 +6,5 @@
TEST_DIRS += [
'background',
'browser',
]

View File

@ -381,10 +381,15 @@ INNER_ROBOCOP_PACKAGE= \
BACKGROUND_TESTS_PATH = $(abspath $(_ABS_DIST)/../mobile/android/tests/background/junit3)
INNER_BACKGROUND_TESTS_PACKAGE= \
$(call RELEASE_SIGN_ANDROID_APK,$(BACKGROUND_TESTS_PATH)/background-junit3-debug-unsigned-unaligned.apk,$(_ABS_DIST)/background-junit3.apk)
BROWSER_TESTS_PATH = $(abspath $(_ABS_DIST)/../mobile/android/tests/browser/junit3)
INNER_BROWSER_TESTS_PACKAGE= \
$(call RELEASE_SIGN_ANDROID_APK,$(BROWSER_TESTS_PATH)/browser-junit3-debug-unsigned-unaligned.apk,$(_ABS_DIST)/browser-junit3.apk)
endif
else
INNER_ROBOCOP_PACKAGE=echo 'Testing is disabled - No Android Robocop for you'
INNER_BACKGROUND_TESTS_PACKAGE=echo 'Testing is disabled - No Android Background JUnit 3 tests for you'
INNER_BROWSER_TESTS_PACKAGE=echo 'Testing is disabled - No Android Browser JUnit 3tests for you'
endif
# Create geckoview_library/geckoview_{assets,library}.zip for third-party GeckoView consumers.
@ -477,6 +482,7 @@ INNER_MAKE_PACKAGE = \
$(ZIPALIGN) -f -v 4 $(_ABS_DIST)/gecko.apk $(PACKAGE) && \
$(INNER_ROBOCOP_PACKAGE) && \
$(INNER_BACKGROUND_TESTS_PACKAGE) && \
$(INNER_BROWSER_TESTS_PACKAGE) && \
$(INNER_MAKE_GECKOVIEW_LIBRARY)
# Language repacks root the resources contained in assets/omni.ja