Skip to content

Commit

Permalink
Bug 1529082 - Move TestRunnerActivity to test_runner. r=ahal,owlish
Browse files Browse the repository at this point in the history
The fact that the test runner app is defined inside the geckoview test package
has always felt like a hack to me. I've mistakenly thought that
TestRunnerActivity was used in GeckoView's junit tests many times (even though
that's not the case).

From what I can see, there's no way to generate an AAB package for androidTest,
so to be able to run Gecko tests as AAB we finally need to define the
TestRunner as an ordinary package instead.

Differential Revision: https://phabricator.services.mozilla.com/D127320
  • Loading branch information
agi committed Nov 2, 2021
1 parent 294bf21 commit e055f12
Show file tree
Hide file tree
Showing 56 changed files with 301 additions and 71 deletions.
2 changes: 1 addition & 1 deletion layout/tools/reftest/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def run_android_test(self, **kwargs):
if not args.xrePath:
args.xrePath = os.environ.get("MOZ_HOST_BIN")
if not args.app:
args.app = "org.mozilla.geckoview.test"
args.app = "org.mozilla.geckoview.test_runner"
if not args.utilityPath:
args.utilityPath = args.xrePath
args.ignoreWindowSize = True
Expand Down
2 changes: 1 addition & 1 deletion layout/tools/reftest/mach_test_package_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_reftest_desktop(context, args):
def run_reftest_android(context, args):
from remotereftest import run_test_harness

args.app = args.app or "org.mozilla.geckoview.test"
args.app = args.app or "org.mozilla.geckoview.test_runner"
args.utilityPath = context.hostutils
args.xrePath = context.hostutils
args.httpdPath = context.module_dir
Expand Down
24 changes: 0 additions & 24 deletions mobile/android/geckoview/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,11 @@

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="androidx.multidex.MultiDexApplication">
<activity android:name=".TestRunnerActivity" android:exported="true"/>
<activity android:name=".GeckoViewTestActivity" android:exported="true"/>
<activity-alias android:name=".App" android:targetActivity=".TestRunnerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="org.mozilla.geckoview.test.XPCSHELL_TEST"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>

<!-- This is used for crash handling in GeckoSessionTestRule -->
<service
android:name=".TestCrashHandler"
Expand All @@ -50,18 +39,5 @@
<service android:name=".TestRuntimeService$instance1" android:enabled="true" android:exported="false" android:process=":runtime1" />

<service android:name=".TrackingPermissionService" android:enabled="true" android:exported="false" android:process=":tp" />

<!-- This is used to run xpcshell tests -->
<service android:name=".XpcshellTestRunnerService$i0" android:enabled="true" android:exported="true" android:process=":xpcshell0"/>
<service android:name=".XpcshellTestRunnerService$i1" android:enabled="true" android:exported="true" android:process=":xpcshell1"/>
<service android:name=".XpcshellTestRunnerService$i2" android:enabled="true" android:exported="true" android:process=":xpcshell2"/>
<service android:name=".XpcshellTestRunnerService$i3" android:enabled="true" android:exported="true" android:process=":xpcshell3"/>
<service android:name=".XpcshellTestRunnerService$i4" android:enabled="true" android:exported="true" android:process=":xpcshell4"/>
<service android:name=".XpcshellTestRunnerService$i5" android:enabled="true" android:exported="true" android:process=":xpcshell5"/>
<service android:name=".XpcshellTestRunnerService$i6" android:enabled="true" android:exported="true" android:process=":xpcshell6"/>
<service android:name=".XpcshellTestRunnerService$i7" android:enabled="true" android:exported="true" android:process=":xpcshell7"/>
<service android:name=".XpcshellTestRunnerService$i8" android:enabled="true" android:exported="true" android:process=":xpcshell8"/>
<service android:name=".XpcshellTestRunnerService$i9" android:enabled="true" android:exported="true" android:process=":xpcshell9"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ private static String getProcessName(final Context context) {

if (info.xpcshell
&& (!BuildConfig.DEBUG
|| !"org.mozilla.geckoview.test"
|| !"org.mozilla.geckoview.test_runner"
.equals(context.getApplicationContext().getPackageName()))) {
throw new IllegalArgumentException("Only the test app can run -xpcshell.");
}
Expand Down
59 changes: 59 additions & 0 deletions mobile/android/gradle.configure
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ set_config(
)


@depends(gradle_android_build_config)
def gradle_android_geckoview_test_runner_bundle(build_config):
"""Path to intermediates classes folder."""

def uncapitalize(s):
if s:
return s[0].lower() + s[1:]
else:
return s

def capitalize(s):
# str.capitalize lower cases trailing letters.
if s:
return s[0].upper() + s[1:]
else:
return s

productFlavor = uncapitalize(
"".join(capitalize(f) for f in build_config.geckoview.variant.productFlavors)
)
buildType = uncapitalize(build_config.geckoview.variant.buildType)
variant = uncapitalize(build_config.geckoview.variant.name)

return "gradle/build/mobile/android/test_runner/outputs/bundle/{}/test_runner-{}-{}.aab".format(
variant,
productFlavor,
buildType,
)


set_config(
"GRADLE_ANDROID_GECKOVIEW_TEST_RUNNER_BUNDLE",
gradle_android_geckoview_test_runner_bundle,
)


@depends(gradle_android_build_config)
def gradle_android_variant_name(build_config):
"""Like "withoutGeckoBinariesDebug"."""
Expand Down Expand Up @@ -231,6 +267,7 @@ set_config(
"mobile/android/annotations",
"mobile/android/geckoview",
"mobile/android/geckoview_example",
"mobile/android/test_runner",
"mobile/android/examples/messaging_example",
"mobile/android/examples/port_messaging_example",
],
Expand Down Expand Up @@ -283,6 +320,9 @@ def gradle_android_archive_geckoview_tasks(build_config):
"geckoview:assemble{geckoview.variant.name}AndroidTest".format(
geckoview=build_config.geckoview
),
"test_runner:assemble{geckoview_example.variant.name}".format(
geckoview_example=build_config.geckoview_example
),
"geckoview_example:assemble{geckoview_example.variant.name}".format(
geckoview_example=build_config.geckoview_example
),
Expand Down Expand Up @@ -384,6 +424,9 @@ def gradle_android_build_geckoview_example_tasks(build_config):
"geckoview:assemble{geckoview.variant.name}AndroidTest".format(
geckoview=build_config.geckoview
),
"test_runner:assemble{geckoview.variant.name}".format(
geckoview=build_config.geckoview
),
]


Expand All @@ -393,6 +436,22 @@ set_config(
)


@depends(gradle_android_build_config)
def gradle_android_install_geckoview_test_runner_tasks(build_config):
"""Gradle tasks run by |mach android install-geckoview-test_runner|."""
return [
"test_runner:install{geckoview.variant.name}".format(
geckoview=build_config.geckoview
),
]


set_config(
"GRADLE_ANDROID_INSTALL_GECKOVIEW_TEST_RUNNER_TASKS",
gradle_android_install_geckoview_test_runner_tasks,
)


@depends(gradle_android_build_config)
def gradle_android_install_geckoview_example_tasks(build_config):
"""Gradle tasks run by |mach android install-geckoview_example|."""
Expand Down
37 changes: 37 additions & 0 deletions mobile/android/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ def android_build_geckoview_example(command_context, args):
return 0


def install_app_bundle(command_context, bundle):
from mozdevice import ADBDeviceFactory

bundletool = mozpath.join(command_context._mach_context.state_dir, "bundletool.jar")
device = ADBDeviceFactory(verbose=True)
bundle_path = mozpath.join(command_context.topobjdir, bundle)
device.install_app_bundle(bundletool, bundle_path, timeout=120)


@SubCommand("android", "install-geckoview_example", """Install geckoview_example """)
@CommandArgument("args", nargs=argparse.REMAINDER)
def android_install_geckoview_example(command_context, args):
Expand All @@ -240,6 +249,34 @@ def android_install_geckoview_example(command_context, args):
return 0


@SubCommand(
"android", "install-geckoview-test_runner", """Install geckoview.test_runner """
)
@CommandArgument("args", nargs=argparse.REMAINDER)
def android_install_geckoview_test_runner(command_context, args):
gradle(
command_context,
command_context.substs["GRADLE_ANDROID_INSTALL_GECKOVIEW_TEST_RUNNER_TASKS"]
+ args,
verbose=True,
)
return 0


@SubCommand(
"android",
"install-geckoview-test_runner-aab",
"""Install geckoview.test_runner with AAB""",
)
@CommandArgument("args", nargs=argparse.REMAINDER)
def android_install_geckoview_test_runner_aab(command_context, args):
install_app_bundle(
command_context,
command_context.substs["GRADLE_ANDROID_GECKOVIEW_TEST_RUNNER_BUNDLE"],
)
return 0


@SubCommand(
"android",
"geckoview-docs",
Expand Down
63 changes: 63 additions & 0 deletions mobile/android/test_runner/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
buildDir "${topobjdir}/gradle/build/mobile/android/test_runner"

apply plugin: 'com.android.application'

apply from: "${topsrcdir}/mobile/android/gradle/product_flavors.gradle"

android {
buildToolsVersion project.ext.buildToolsVersion
compileSdkVersion project.ext.compileSdkVersion

defaultConfig {
targetSdkVersion project.ext.targetSdkVersion
minSdkVersion project.ext.minSdkVersion
manifestPlaceholders = project.ext.manifestPlaceholders

applicationId "org.mozilla.geckoview.test_runner"
versionCode 1
versionName "1.0"

multiDexEnabled true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dexOptions {
javaMaxHeapSize "32g"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

// By default the android plugins ignores folders that start with `_`, but
// we need those in web extensions.
// See also:
// - https://issuetracker.google.com/issues/36911326
// - https://stackoverflow.com/questions/9206117/how-to-workaround-autoomitting-fiiles-folders-starting-with-underscore-in
aaptOptions {
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
noCompress 'ja'
}

project.configureProductFlavors.delegate = it
project.configureProductFlavors()
}

dependencies {
implementation "androidx.annotation:annotation:1.0.0"
implementation "androidx.appcompat:appcompat:1.0.0"
implementation "androidx.preference:preference:1.0.0"

implementation project(path: ':geckoview')
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'

implementation 'androidx.multidex:multidex:2.0.0'
}
44 changes: 44 additions & 0 deletions mobile/android/test_runner/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.mozilla.geckoview.test_runner">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="androidx.multidex.MultiDexApplication">
<uses-library android:name="android.test.runner" android:required="false"/>
<activity android:name=".TestRunnerActivity" android:exported="true"/>
<activity-alias android:name=".App" android:targetActivity=".TestRunnerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="org.mozilla.geckoview.test_runner.XPCSHELL_TEST"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>

<!-- This is used to run xpcshell tests -->
<service android:name=".XpcshellTestRunnerService$i0" android:enabled="true" android:exported="true" android:process=":xpcshell0"/>
<service android:name=".XpcshellTestRunnerService$i1" android:enabled="true" android:exported="true" android:process=":xpcshell1"/>
<service android:name=".XpcshellTestRunnerService$i2" android:enabled="true" android:exported="true" android:process=":xpcshell2"/>
<service android:name=".XpcshellTestRunnerService$i3" android:enabled="true" android:exported="true" android:process=":xpcshell3"/>
<service android:name=".XpcshellTestRunnerService$i4" android:enabled="true" android:exported="true" android:process=":xpcshell4"/>
<service android:name=".XpcshellTestRunnerService$i5" android:enabled="true" android:exported="true" android:process=":xpcshell5"/>
<service android:name=".XpcshellTestRunnerService$i6" android:enabled="true" android:exported="true" android:process=":xpcshell6"/>
<service android:name=".XpcshellTestRunnerService$i7" android:enabled="true" android:exported="true" android:process=":xpcshell7"/>
<service android:name=".XpcshellTestRunnerService$i8" android:enabled="true" android:exported="true" android:process=":xpcshell8"/>
<service android:name=".XpcshellTestRunnerService$i9" android:enabled="true" android:exported="true" android:process=":xpcshell9"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

package org.mozilla.geckoview.test;
package org.mozilla.geckoview.test_runner;

import android.app.Activity;
import android.content.Intent;
Expand Down Expand Up @@ -385,8 +385,7 @@ protected void onCreate(final Bundle savedInstanceState) {
.contentBlocking(
new ContentBlocking.Settings.Builder()
.safeBrowsingProviders(google, googleLegacy)
.build())
.crashHandler(TestCrashHandler.class);
.build());

sRuntime = GeckoRuntime.create(this, runtimeSettingsBuilder.build());

Expand All @@ -400,7 +399,7 @@ public void onExtensionListUpdated() {
});

webExtensionController()
.installBuiltIn("resource://android/assets/web_extensions/test-runner-support/")
.installBuiltIn("resource://android/assets/test-runner-support/")
.accept(
extension -> {
extension.setMessageDelegate(mApiEngine, "test-runner-support");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

package org.mozilla.geckoview.test;
package org.mozilla.geckoview.test_runner;

import android.util.Log;
import androidx.annotation.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

package org.mozilla.geckoview.test;
package org.mozilla.geckoview.test_runner;

import android.app.Service;
import android.content.Intent;
Expand Down Expand Up @@ -81,7 +81,6 @@ public synchronized int onStartCommand(Intent intent, int flags, int startId) {
new ContentBlocking.Settings.Builder()
.safeBrowsingProviders(google, googleLegacy)
.build())
.crashHandler(TestCrashHandler.class)
.build();

sRuntime = GeckoRuntime.create(this, runtimeSettings);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions mobile/android/test_runner/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
7 changes: 7 additions & 0 deletions mobile/android/test_runner/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<resources>
<string name="app_name">GeckoView Test Runner</string>
</resources>
Loading

0 comments on commit e055f12

Please sign in to comment.