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

Commit f7652a6f authored by An An Yu's avatar An An Yu
Browse files

[AE Flicker Test] From a split A|B, let A launch C with

alwaysExpand=true, expect C to overlay split A|B.

Test: atest MainActivityStartsSecondaryWithAlwaysExpand

Bug: 238043427

Change-Id: I9e4f06a8ed01352d5442f7d31f0a41fcc0d05c8c
parent 87710579
Loading
Loading
Loading
Loading
+140 −0
Original line number Diff line number Diff line
/*
 * 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.activityembedding

import android.platform.test.annotations.Presubmit
import android.tools.device.flicker.junit.FlickerParametersRunnerFactory
import android.tools.device.flicker.legacy.FlickerBuilder
import android.tools.device.flicker.legacy.FlickerTest
import android.tools.device.flicker.legacy.FlickerTestFactory
import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.helpers.ActivityEmbeddingAppHelper
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized
import android.tools.common.datatypes.Rect

/**
 * Test launching an activity with AlwaysExpand rule.
 *
 * Setup: Launch A|B in split with B being the secondary activity.
 * Transitions:
 * A start C with alwaysExpand=true, expect C to launch in fullscreen and cover split A|B.
 *
 * To run this test: `atest FlickerTests:MainActivityStartsSecondaryWithAlwaysExpandTest`
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class MainActivityStartsSecondaryWithAlwaysExpandTest(flicker: FlickerTest) :
  ActivityEmbeddingTestBase(flicker) {

  /** {@inheritDoc} */
  override val transition: FlickerBuilder.() -> Unit = {
    setup {
      tapl.setExpectedRotationCheckEnabled(false)
      // Launch a split
      testApp.launchViaIntent(wmHelper)
      testApp.launchSecondaryActivity(wmHelper)
      startDisplayBounds =
        wmHelper.currentState.layerState.physicalDisplayBounds ?: error("Display not found")
    }
    transitions {
      // Launch C with alwaysExpand
      testApp.launchAlwaysExpandActivity(wmHelper)
    }
    teardown {
      tapl.goHome()
      testApp.exit(wmHelper)
    }
  }

  /** Transition begins with a split. */
  @Presubmit
  @Test
  fun startsWithSplit() {
    flicker.assertWmStart {
      this.isAppWindowVisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
    }
    flicker.assertWmStart {
      this.isAppWindowVisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
    }
  }


  /** Main activity should become invisible after being covered by always expand activity. */
  @Presubmit
  @Test
  fun mainActivityLayerBecomesInvisible() {
    flicker.assertLayers {
      isVisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
        .then()
        .isInvisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
    }
  }

  /** Secondary activity should become invisible after being covered by always expand activity. */
  @Presubmit
  @Test
  fun secondaryActivityLayerBecomesInvisible() {
    flicker.assertLayers {
      isVisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
        .then()
        .isInvisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
    }
  }

  /** At the end of transition always expand activity is in fullscreen. */
  @Presubmit
  @Test
  fun endsWithAlwaysExpandActivityCoveringFullScreen() {
    flicker.assertWmEnd {
      this.visibleRegion(ActivityEmbeddingAppHelper.ALWAYS_EXPAND_ACTIVITY_COMPONENT)
        .coversExactly(startDisplayBounds)
    }
  }

  /** Always expand activity is on top of the split. */
  @Presubmit
  @Test
  fun endsWithAlwaysExpandActivityOnTop() {
    flicker.assertWmEnd {
      this.isAppWindowOnTop(
        ActivityEmbeddingAppHelper.ALWAYS_EXPAND_ACTIVITY_COMPONENT)
    }
  }

  companion object {
    /** {@inheritDoc} */
    private var startDisplayBounds = Rect.EMPTY
    /**
     * Creates the test configurations.
     *
     * See [FlickerTestFactory.nonRotationTests] for configuring screen orientation and
     * navigation modes.
     */
    @Parameterized.Parameters(name = "{0}")
    @JvmStatic
    fun getParams(): Collection<FlickerTest> {
      return FlickerTestFactory.nonRotationTests()
    }
  }
}
+26 −0
Original line number Diff line number Diff line
@@ -77,6 +77,29 @@ constructor(
            .waitForAndVerify()
     }

    /**
     * Clicks the button to launch a secondary activity with alwaysExpand enabled, which will launch
     * a fullscreen window on top of the visible region.
     */
    fun launchAlwaysExpandActivity(wmHelper: WindowManagerStateHelper) {
        val launchButton =
                uiDevice.wait(
                        Until.findObject(
                                By.res(getPackage(),
                                        "launch_always_expand_activity_button")),
                        FIND_TIMEOUT
                )
        require(launchButton != null) {
            "Can't find launch always expand activity button on screen."
        }
        launchButton.click()
        wmHelper
                .StateSyncBuilder()
                .withActivityState(ALWAYS_EXPAND_ACTIVITY_COMPONENT, PlatformConsts.STATE_RESUMED)
                .withActivityState(MAIN_ACTIVITY_COMPONENT, PlatformConsts.STATE_PAUSED)
                .waitForAndVerify()
    }

    /**
     * Clicks the button to launch the placeholder primary activity, which should launch the
     * placeholder secondary activity based on the placeholder rule.
@@ -105,6 +128,9 @@ constructor(
        val SECONDARY_ACTIVITY_COMPONENT =
            ActivityOptions.ActivityEmbedding.SecondaryActivity.COMPONENT.toFlickerComponent()

        val ALWAYS_EXPAND_ACTIVITY_COMPONENT =
            ActivityOptions.ActivityEmbedding.AlwaysExpandActivity.COMPONENT.toFlickerComponent()

        val PLACEHOLDER_PRIMARY_COMPONENT =
            ActivityOptions.ActivityEmbedding.PlaceholderPrimaryActivity.COMPONENT
                .toFlickerComponent()
+7 −0
Original line number Diff line number Diff line
@@ -197,6 +197,13 @@
            android:theme="@style/CutoutShortEdges"
            android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout"
            android:exported="false"/>
        <activity
            android:name=".ActivityEmbeddingAlwaysExpandActivity"
            android:label="ActivityEmbedding AlwaysExpand"
            android:taskAffinity="com.android.server.wm.flicker.testapp.ActivityEmbedding"
            android:theme="@style/CutoutShortEdges"
            android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout"
            android:exported="false"/>
        <activity
            android:name=".ActivityEmbeddingPlaceholderPrimaryActivity"
            android:label="ActivityEmbedding Placeholder Primary"
+8 −0
Original line number Diff line number Diff line
@@ -37,4 +37,12 @@
        android:onClick="launchPlaceholderSplit"
        android:text="Launch Placeholder Split" />

    <Button
        android:id="@+id/launch_always_expand_activity_button"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:layout_centerHorizontal="true"
        android:onClick="launchAlwaysExpandActivity"
        android:text="Launch Always Expand Activity" />

</LinearLayout>
+33 −0
Original line number Diff line number Diff line
/*
 * 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.graphics.Color;
import android.os.Bundle;

/**
 * Activity with alwaysExpand=true (launched via R.id.launch_always_expand_activity_button)
 */
public class ActivityEmbeddingAlwaysExpandActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_embedding_base_layout);
    findViewById(R.id.root_activity_layout).setBackgroundColor(Color.GREEN);
  }

}
Loading