Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7038153 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Add test for Instrumentation.startActivitySync()

Actual support for Activity on Ravenwood will take more time,
but let's add a minimal bivalent test for
`Instrumentation.startActivitySync()` as a baseline.

Test: atest RavenwoodUiTest_device
Test: atest RavenwoodUiTest
Bug: 331434971
Flag: TEST_ONLY
Change-Id: I6e601f456fe160f307333fa53d0b55dc48e3d8a8
parent 2137b07c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
    { "name": "RavenwoodBivalentTest_device_ravenizer" },
    { "name": "RavenwoodBivalentInstTest_nonself_inst" },
    { "name": "RavenwoodBivalentInstTest_self_inst_device" },
    { "name": "RavenwoodUiTest_device" },

    // The sysui tests should match vendor/unbundled_google/packages/SystemUIGoogle/TEST_MAPPING
    {
@@ -136,6 +137,10 @@
      "name": "FrameworksUtilTestsRavenwood",
      "host": true
    },
    {
      "name": "InternalArrayUtilsTest",
      "host": true
    },
    {
      "name": "InternalTestsRavenwood",
      "host": true
@@ -184,6 +189,10 @@
      "name": "RavenwoodServicesTest",
      "host": true
    },
    {
      "name": "RavenwoodUiTest",
      "host": true
    },
    {
      "name": "UinputTestsRavenwood",
      "host": true
+59 −0
Original line number Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_base_license"],
}

java_defaults {
    name: "ravenwood-uitest-defaults",
    static_libs: [
        "androidx.annotation_annotation",
        "androidx.test.ext.junit",
        "androidx.test.rules",
        "truth",
    ],
    srcs: [
        "test/**/*.java",
    ],
    auto_gen_config: true,
}

android_ravenwood_test {
    name: "RavenwoodUiTest",
    defaults: ["ravenwood-uitest-defaults"],
    package_name: "com.android.ravenwoodtest.uitest",

    srcs: [
        ":RavenwoodUiTest-res{.aapt.srcjar}",
    ],
    resource_apk: "RavenwoodUiTest-res",
}

android_app {
    name: "RavenwoodUiTest-res",
    use_resource_processor: false,
    // Intentionally has no srcs files for faster rebuild.
    sdk_version: "current",
    uses_libs: [
        "android.test.runner",
        "android.test.base",
    ],
}

android_test {
    name: "RavenwoodUiTest_device",
    defaults: ["ravenwood-uitest-defaults"],
    test_suites: [
        "device-tests",
    ],
    static_libs: [
        "ravenwood-junit",
    ],
    uses_libs: [
        "android.test.runner",
        "android.test.base",
    ],
}
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2025 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.ravenwoodtest.uitest">

    <application android:debuggable="true" >
        <uses-library android:name="android.test.runner" />

        <activity
            android:name=".TestActivity"
            android:label="@string/activity_title"
            android:exported="true"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="com.android.ravenwoodtest.uitest"
        />
</manifest>
+21 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2025 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<resources xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string translatable="false" name="test_string">Test string</string>
    <string translatable="false" name="activity_title">RavenUiTest</string>
</resources>
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ravenwoodtest.uitest;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.platform.test.annotations.DisabledOnRavenwood;
import android.platform.test.ravenwood.RavenwoodUtils;

import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;

public class RavenwoodActivityTest {
    private static final Instrumentation sInstrumentation =
            InstrumentationRegistry.getInstrumentation();

    private static final Context sContext = sInstrumentation.getContext();

    @Test
    public void testResourcesAvailable() {
        assertEquals("Test string", sContext.getString(R.string.test_string));
    }

    @Test
    @DisabledOnRavenwood(blockedBy = Activity.class)
    public void testStartActivity() {
        Intent intent = new Intent(sContext, TestActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // This must be supplied.
        // Without FLAG_ACTIVITY_NEW_TASK, it'd fail with
        // AndroidRuntimeException: Calling startActivity() from outside of an Activity context ...

        Activity act = sInstrumentation.startActivitySync(intent);
        assertThat(act).isNotNull();
        try {
            // Check some basic states...
            assertThat(act).isInstanceOf(TestActivity.class);
            assertThat(act.getPackageName()).isEqualTo(sContext.getPackageName());
            assertThat(act.isResumed()).isTrue();
        } finally {
            RavenwoodUtils.runOnMainThreadSync(act::finish);
        }
    }
}
Loading