Merge "[2/n] Implement OpenTransparentActivityTest flicker test" into udc-qpr-dev

This commit is contained in:
Massimo Carli
2023-07-18 08:59:08 +00:00
committed by Android (Google) Code Review
9 changed files with 351 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
/*
* Copyright (C) 2023 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.wm.shell.flicker.appcompat
import android.platform.test.annotations.Postsubmit
import android.tools.common.Rotation
import android.tools.common.flicker.assertions.FlickerTest
import android.tools.common.traces.component.ComponentNameMatcher
import android.tools.device.flicker.junit.FlickerParametersRunnerFactory
import android.tools.device.flicker.legacy.FlickerBuilder
import android.tools.device.flicker.legacy.LegacyFlickerTest
import android.tools.device.flicker.legacy.LegacyFlickerTestFactory
import androidx.test.filters.RequiresDevice
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
/**
* Test launching app in size compat mode.
*
* To run this test: `atest WMShellFlickerTestsOther:OpenTransparentActivityTest`
*
* Actions:
* ```
* Launch a letteboxed app and then a transparent activity from it. We test the bounds
* are the same.
* ```
*
* Notes:
* ```
* Some default assertions (e.g., nav bar, status bar and screen covered)
* are inherited [BaseTest]
* ```
*/
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
class OpenTransparentActivityTest(flicker: LegacyFlickerTest) : TransparentBaseAppCompat(flicker) {
/** {@inheritDoc} */
override val transition: FlickerBuilder.() -> Unit
get() = {
setup {
letterboxTranslucentLauncherApp.launchViaIntent(wmHelper)
}
transitions {
waitAndGetLaunchTransparent()?.click() ?: error("Launch Transparent not found")
}
teardown {
letterboxTranslucentApp.exit(wmHelper)
letterboxTranslucentLauncherApp.exit(wmHelper)
}
}
/**
* Checks the transparent activity is launched on top of the opaque one
*/
@Postsubmit
@Test
fun translucentActivityIsLaunchedOnTopOfOpaqueActivity() {
flicker.assertWm {
this.isAppWindowOnTop(letterboxTranslucentLauncherApp)
.then()
.isAppWindowOnTop(letterboxTranslucentApp)
}
}
/**
* Checks that the activity is letterboxed
*/
@Postsubmit
@Test
fun translucentActivityIsLetterboxed() {
flicker.assertLayers { isVisible(ComponentNameMatcher.LETTERBOX) }
}
/**
* Checks that the translucent activity inherits bounds from the opaque one.
*/
@Postsubmit
@Test
fun translucentActivityInheritsBoundsFromOpaqueActivity() {
flicker.assertLayersEnd {
this.visibleRegion(letterboxTranslucentApp)
.coversExactly(visibleRegion(letterboxTranslucentLauncherApp).region)
}
}
/**
* Checks that the translucent activity has rounded corners
*/
@Postsubmit
@Test
fun translucentActivityHasRoundedCorners() {
flicker.assertLayersEnd {
this.hasRoundedCorners(letterboxTranslucentApp)
}
}
companion object {
/**
* Creates the test configurations.
*
* See [FlickerTestFactory.rotationTests] for configuring screen orientation and
* navigation modes.
*/
@Parameterized.Parameters(name = "{0}")
@JvmStatic
fun getParams(): Collection<FlickerTest> {
return LegacyFlickerTestFactory
.nonRotationTests(supportedRotations = listOf(Rotation.ROTATION_90))
}
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (C) 2023 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.wm.shell.flicker.appcompat
import android.content.Context
import android.tools.device.flicker.legacy.FlickerTestData
import android.tools.device.flicker.legacy.LegacyFlickerTest
import android.tools.device.helpers.FIND_TIMEOUT
import android.tools.device.traces.parsers.toFlickerComponent
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.helpers.LetterboxAppHelper
import com.android.server.wm.flicker.testapp.ActivityOptions
import com.android.wm.shell.flicker.BaseTest
import org.junit.Assume
import org.junit.Before
import org.junit.Rule
abstract class TransparentBaseAppCompat(flicker: LegacyFlickerTest) : BaseTest(flicker) {
protected val context: Context = instrumentation.context
protected val letterboxTranslucentLauncherApp = LetterboxAppHelper(
instrumentation,
launcherName = ActivityOptions.LaunchTransparentActivity.LABEL,
component = ActivityOptions.LaunchTransparentActivity.COMPONENT.toFlickerComponent()
)
protected val letterboxTranslucentApp = LetterboxAppHelper(
instrumentation,
launcherName = ActivityOptions.TransparentActivity.LABEL,
component = ActivityOptions.TransparentActivity.COMPONENT.toFlickerComponent()
)
@JvmField
@Rule
val letterboxRule: LetterboxRule = LetterboxRule()
@Before
fun before() {
Assume.assumeTrue(tapl.isTablet && letterboxRule.isIgnoreOrientationRequest)
}
protected fun FlickerTestData.waitAndGetLaunchTransparent(): UiObject2? =
device.wait(
Until.findObject(By.text("Launch Transparent")),
FIND_TIMEOUT
)
protected fun FlickerTestData.goBack() = device.pressBack()
}

View File

@@ -102,6 +102,24 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".LaunchTransparentActivity"
android:resizeableActivity="false"
android:screenOrientation="portrait"
android:theme="@android:style/Theme"
android:taskAffinity="com.android.server.wm.flicker.testapp.LaunchTransparentActivity"
android:label="LaunchTransparentActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".TransparentActivity"
android:theme="@style/TransparentTheme"
android:taskAffinity="com.android.server.wm.flicker.testapp.TransparentActivity"
android:label="TransparentActivity"
android:exported="false">
</activity>
<activity android:name=".LaunchNewActivity"
android:taskAffinity="com.android.server.wm.flicker.testapp.LaunchNewActivity"
android:theme="@style/CutoutShortEdges"

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2023 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.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2023 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/black">
<Button
android:id="@+id/button_launch_transparent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Launch Transparent" />
<Button
android:id="@+id/button_request_permission"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Request Permission" />
</LinearLayout>

View File

@@ -43,6 +43,13 @@
<item name="android:windowSoftInputMode">stateUnchanged</item>
</style>
<style name="TransparentTheme" parent="@android:style/Theme.DeviceDefault">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
<style name="no_starting_window" parent="@android:style/Theme.DeviceDefault">
<item name="android:windowDisablePreview">true</item>
</style>

View File

@@ -73,6 +73,18 @@ public class ActivityOptions {
FLICKER_APP_PACKAGE + ".NonResizeablePortraitActivity");
}
public static class TransparentActivity {
public static final String LABEL = "TransparentActivity";
public static final ComponentName COMPONENT = new ComponentName(FLICKER_APP_PACKAGE,
FLICKER_APP_PACKAGE + ".TransparentActivity");
}
public static class LaunchTransparentActivity {
public static final String LABEL = "LaunchTransparentActivity";
public static final ComponentName COMPONENT = new ComponentName(FLICKER_APP_PACKAGE,
FLICKER_APP_PACKAGE + ".LaunchTransparentActivity");
}
public static class DialogThemedActivity {
public static final String LABEL = "DialogThemedActivity";
public static final ComponentName COMPONENT = new ComponentName(FLICKER_APP_PACKAGE,

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2023 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.server.wm.flicker.testapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class LaunchTransparentActivity extends Activity {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_transparent_launch);
findViewById(R.id.button_launch_transparent)
.setOnClickListener(v -> launchTransparentActivity());
}
private void launchTransparentActivity() {
startActivity(new Intent(this, TransparentActivity.class));
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright (C) 2023 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.server.wm.flicker.testapp;
import android.app.Activity;
import android.os.Bundle;
public class TransparentActivity extends Activity {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_transparent);
}
}