Added a test for the cold open Camera, then open App scenario. Refactored to use the same resolveInfo for the Camera launcher name and component.

Test: atest FlickerTests:OpenAppAfterCameraTest
Change-Id: I245fab20a81085e421ecb12b5ec94f386114ebd5
This commit is contained in:
Alexandra-Natalia
2022-07-22 14:41:13 +00:00
parent 9a0c9f236f
commit f435b0024d
2 changed files with 151 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2022 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.helpers
import android.app.Instrumentation
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.provider.MediaStore
import com.android.server.wm.traces.common.ComponentMatcher
import com.android.server.wm.traces.common.IComponentMatcher
class CameraAppHelper @JvmOverloads constructor(
instrumentation: Instrumentation,
private val pkgManager: PackageManager = instrumentation.context.packageManager
) : StandardAppHelper(instrumentation, getCameraLauncherName(pkgManager),
getCameraComponent(pkgManager)){
companion object{
private fun getCameraIntent(): Intent {
return Intent(MediaStore.ACTION_IMAGE_CAPTURE)
}
private fun getResolveInfo(pkgManager: PackageManager): ResolveInfo {
val intent = getCameraIntent()
return pkgManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)
?: error("unable to resolve camera activity")
}
private fun getCameraComponent(pkgManager: PackageManager): IComponentMatcher {
val resolveInfo = getResolveInfo(pkgManager)
return ComponentMatcher(resolveInfo.activityInfo.packageName,
className = resolveInfo.activityInfo.name)
}
private fun getCameraLauncherName(pkgManager: PackageManager): String {
val resolveInfo = getResolveInfo(pkgManager)
return resolveInfo.activityInfo.name
}
}
}

View File

@@ -0,0 +1,97 @@
/*
* Copyright (C) 2022 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.launch
import android.platform.test.annotations.FlakyTest
import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresDevice
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.annotation.Group1
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.CameraAppHelper
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized
/**
* Test launching an app after cold opening camera
*
* To run this test: `atest FlickerTests:OpenAppAfterCameraTest`
*
* Notes:
* Some default assertions are inherited [OpenAppTransition]
*/
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group1
open class OpenAppAfterCameraTest(
testSpec: FlickerTestParameter
) : OpenAppFromLauncherTransition(testSpec) {
private val cameraApp = CameraAppHelper(instrumentation) /** {@inheritDoc} */
override val transition: FlickerBuilder.() -> Unit
get() = {
super.transition(this)
setup {
eachRun {
// 1. Open camera - cold -> close it first
cameraApp.exit(wmHelper)
cameraApp.launchViaIntent(wmHelper)
// 2. Press home button (button nav mode) / swipe up to home (gesture nav mode)
tapl.goHome()
}
}
teardown {
eachRun {
testApp.exit(wmHelper)
}
}
transitions {
testApp.launchViaIntent(wmHelper)
}
}
/** {@inheritDoc} */
@FlakyTest(bugId = 206753786)
@Test
override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd()
/** {@inheritDoc} */
@Presubmit
@Test
override fun appLayerReplacesLauncher() = super.appLayerReplacesLauncher()
companion object {
/**
* Creates the test configurations.
*
* See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring
* repetitions, screen orientation and navigation modes.
*/
@Parameterized.Parameters(name = "{0}")
@JvmStatic
fun getParams(): Collection<FlickerTestParameter> {
return FlickerTestParameterFactory.getInstance()
.getConfigNonRotationTests()
}
}
}