Update various tests to prepare for the new picker UI
- Switched the tests that probe old picker to use disabled flag - Added some more tests for new code - A test to use the tap to add listener to add widget to homescreen - Updated compose unit test to cover for expanding an item Bug: 408283627 Flag: EXEMPT independent module Test: Test changes Change-Id: I238896ec6e24596db93953a22bb43f6c7abbb9d1
This commit is contained in:
1 parent
0fed92d45c
commit
afa97055fa
7 files changed
+233
-4
No files matched your search
+23
-1
@@ -61,6 +61,27 @@ filegroup {
|
||||
],
|
||||
}
|
||||
|
||||
filegroup {
|
||||
name: "launcher-compose-test-helpers-src",
|
||||
srcs: [
|
||||
"compose/tests/com/android/launcher3/helper/TestHelper.kt",
|
||||
],
|
||||
}
|
||||
|
||||
filegroup {
|
||||
name: "launcher-compose-ui-tests-src",
|
||||
srcs: [], // Placeholder for compose/tests/com/android/launcher3/ui/.. tests.
|
||||
}
|
||||
|
||||
// Tests for features that are enabled only when compose dependency is enabled & run as part of
|
||||
// Launcher3Tests
|
||||
filegroup {
|
||||
name: "launcher-compose-unit-tests-src",
|
||||
srcs: [
|
||||
"compose/tests/com/android/launcher3/widget/AddWidgetConfigTest.kt",
|
||||
],
|
||||
}
|
||||
|
||||
filegroup {
|
||||
name: "launcher-compose-tests-src",
|
||||
srcs: [
|
||||
@@ -260,7 +281,8 @@ launcher_compose_tests_java_defaults {
|
||||
soong_config_variables: {
|
||||
release_enable_compose_in_launcher: {
|
||||
srcs: [
|
||||
":launcher-compose-tests-src",
|
||||
":launcher-compose-test-helpers-src",
|
||||
":launcher-compose-unit-tests-src",
|
||||
],
|
||||
// Compose dependencies
|
||||
static_libs: [
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.launcher3.widget
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.view.View
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.LargeTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.android.launcher3.AbstractFloatingView
|
||||
import com.android.launcher3.Launcher
|
||||
import com.android.launcher3.model.data.ItemInfo
|
||||
import com.android.launcher3.model.data.LauncherAppWidgetInfo
|
||||
import com.android.launcher3.testcomponent.WidgetConfigActivity
|
||||
import com.android.launcher3.util.BaseLauncherActivityTest
|
||||
import com.android.launcher3.util.BlockingBroadcastReceiver
|
||||
import com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator
|
||||
import com.android.launcher3.util.Wait
|
||||
import com.android.launcher3.util.rule.ShellCommandRule
|
||||
import com.android.launcher3.util.ui.PortraitLandscapeRunner.PortraitLandscape
|
||||
import com.android.launcher3.util.ui.TestViewHelpers
|
||||
import com.android.launcher3.util.workspace.FavoriteItemsTransaction
|
||||
import com.android.launcher3.widgetpicker.listeners.WidgetPickerAddItemListener
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* Test verifies that when adding a widget to homescreen using [WidgetPickerAddItemListener], if the
|
||||
* widget has a configuration activity, it is shown correctly.
|
||||
*/
|
||||
@LargeTest
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AddWidgetConfigTest : BaseLauncherActivityTest<Launcher>() {
|
||||
@get:Rule val grantWidgetRule: ShellCommandRule = ShellCommandRule.grantWidgetBind()
|
||||
|
||||
private lateinit var widgetInfo: LauncherAppWidgetProviderInfo
|
||||
private lateinit var appWidgetManager: AppWidgetManager
|
||||
|
||||
private var widgetId = 0
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
widgetInfo = TestViewHelpers.findWidgetProvider(/* hasConfigureScreen= */ true)
|
||||
appWidgetManager = AppWidgetManager.getInstance(targetContext())
|
||||
}
|
||||
|
||||
@Test
|
||||
@PortraitLandscape
|
||||
@Throws(Throwable::class)
|
||||
fun testWidgetConfig() {
|
||||
runTest(acceptConfig = true)
|
||||
}
|
||||
|
||||
@Test
|
||||
@PortraitLandscape
|
||||
@Throws(Throwable::class)
|
||||
fun testConfigCancelled() {
|
||||
runTest(acceptConfig = false)
|
||||
}
|
||||
|
||||
/** @param acceptConfig accept the config activity */
|
||||
@Throws(Throwable::class)
|
||||
private fun runTest(acceptConfig: Boolean) {
|
||||
FavoriteItemsTransaction(targetContext()).commit()
|
||||
loadLauncherSync()
|
||||
|
||||
// Add widget to home screen
|
||||
val monitor = WidgetConfigStartupMonitor()
|
||||
launcherActivity.executeOnLauncher({ l: Launcher ->
|
||||
val addItemListener = WidgetPickerAddItemListener(widgetInfo)
|
||||
addItemListener.init(l, /* isHomeStarted= */ true)
|
||||
})
|
||||
|
||||
uiDevice.waitForIdle()
|
||||
|
||||
// Widget id for which the config activity was opened
|
||||
widgetId = monitor.widgetId
|
||||
|
||||
// Verify that the widget id is valid and bound
|
||||
assertThat(appWidgetManager.getAppWidgetInfo(widgetId)).isNotNull()
|
||||
setResult(acceptConfig)
|
||||
|
||||
if (acceptConfig) {
|
||||
launcherActivity.getOnceNotNull("Widget was not added") { l: Launcher ->
|
||||
// Close the resize frame before searching for widget
|
||||
AbstractFloatingView.closeAllOpenViews(l)
|
||||
l.workspace.mapOverItems(WidgetSearchCondition())
|
||||
}
|
||||
assertThat(appWidgetManager.getAppWidgetInfo(widgetId)).isNotNull()
|
||||
} else {
|
||||
// Verify that the widget id is deleted.
|
||||
Wait.atMost(
|
||||
"no widget with id",
|
||||
{ appWidgetManager.getAppWidgetInfo(widgetId) == null },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setResult(success: Boolean) {
|
||||
InstrumentationRegistry.getInstrumentation()
|
||||
.targetContext
|
||||
.sendBroadcast(
|
||||
WidgetConfigActivity.getCommandIntent(
|
||||
WidgetConfigActivity::class.java,
|
||||
if (success) "clickOK" else "clickCancel",
|
||||
)
|
||||
)
|
||||
uiDevice.waitForIdle()
|
||||
}
|
||||
|
||||
/** Condition for searching widget id */
|
||||
private inner class WidgetSearchCondition : ItemOperator {
|
||||
override fun evaluate(info: ItemInfo?, view: View): Boolean {
|
||||
return info is LauncherAppWidgetInfo &&
|
||||
info.providerName == widgetInfo.provider &&
|
||||
info.appWidgetId == widgetId
|
||||
}
|
||||
}
|
||||
|
||||
/** Broadcast receiver for receiving widget config activity status. */
|
||||
private class WidgetConfigStartupMonitor :
|
||||
BlockingBroadcastReceiver(WidgetConfigActivity::class.java.name) {
|
||||
@get:Throws(InterruptedException::class)
|
||||
val widgetId: Int
|
||||
get() {
|
||||
val intent = checkNotNull(blockingGetExtraIntent())
|
||||
assertThat(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE).isEqualTo(intent.action)
|
||||
val widgetId =
|
||||
intent.getIntExtra(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
LauncherAppWidgetInfo.NO_ID,
|
||||
)
|
||||
assertThat(widgetId).isNotEqualTo(LauncherAppWidgetInfo.NO_ID)
|
||||
return widgetId
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -212,4 +212,34 @@ class LandingScreenSinglePaneTest {
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertIsNotDisplayed()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun clickingOnAppHeaderShowsWidgetsForThatApp() = testScope.runTest {
|
||||
composeTestRule.setContent { SinglePaneTestContent() }
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
composeTestRule.onNode(hasTextExactly(PERSONAL_LABEL)).assertExists().performClick()
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Click on the an app header
|
||||
val appTitle = PERSONAL_TEST_APPS[0].title!!.toString()
|
||||
composeTestRule.onNode(hasText(appTitle)).assertExists().performClick()
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Verify the widget for that selected app is displayed
|
||||
composeTestRule.onNode(
|
||||
hasContentDescription(
|
||||
PERSONAL_TEST_APPS[0].widgets[0].label,
|
||||
substring = true
|
||||
)
|
||||
)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
}
|
||||
@@ -64,9 +64,6 @@ filegroup {
|
||||
// Library with all the dependencies for building quickstep
|
||||
android_library {
|
||||
name: "Launcher3TestLib",
|
||||
defaults: [
|
||||
"launcher_compose_tests_defaults",
|
||||
],
|
||||
srcs: [],
|
||||
asset_dirs: ["assets"],
|
||||
resource_dirs: ["res"],
|
||||
|
||||
@@ -27,12 +27,15 @@ import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Process;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.LargeTest;
|
||||
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
import com.android.launcher3.Flags;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
|
||||
@@ -60,6 +63,9 @@ import org.junit.runner.RunWith;
|
||||
@LargeTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class AddConfigWidgetTest extends BaseLauncherActivityTest<Launcher> {
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule =
|
||||
new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
|
||||
|
||||
@Rule
|
||||
public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
|
||||
@@ -77,12 +83,14 @@ public class AddConfigWidgetTest extends BaseLauncherActivityTest<Launcher> {
|
||||
|
||||
@Test
|
||||
@PortraitLandscape
|
||||
@DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR)
|
||||
public void testWidgetConfig() throws Throwable {
|
||||
runTest(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@PortraitLandscape
|
||||
@DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR)
|
||||
public void testConfigCancelled() throws Throwable {
|
||||
runTest(false);
|
||||
}
|
||||
|
||||
@@ -17,12 +17,15 @@ package com.android.launcher3.widget;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.PlatinumTest;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.LargeTest;
|
||||
|
||||
import com.android.launcher3.Flags;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.tapl.Widget;
|
||||
import com.android.launcher3.tapl.WidgetResizeFrame;
|
||||
@@ -44,12 +47,16 @@ import org.junit.runner.RunWith;
|
||||
@LargeTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TaplAddWidgetTest extends AbstractLauncherUiTest<Launcher, View> {
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule =
|
||||
new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
|
||||
|
||||
@Rule
|
||||
public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
|
||||
|
||||
@Test
|
||||
@PortraitLandscape
|
||||
@DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR)
|
||||
public void testDragIcon() throws Throwable {
|
||||
commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext));
|
||||
|
||||
@@ -81,6 +88,7 @@ public class TaplAddWidgetTest extends AbstractLauncherUiTest<Launcher, View> {
|
||||
*/
|
||||
@Test
|
||||
@PortraitLandscape
|
||||
@DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR)
|
||||
public void testDragCustomShortcut() throws Throwable {
|
||||
// TODO(b/322820039): Enable test for tablets - the picker UI has changed and test needs to
|
||||
// be updated to look for appropriate UI elements.
|
||||
@@ -99,6 +107,7 @@ public class TaplAddWidgetTest extends AbstractLauncherUiTest<Launcher, View> {
|
||||
*/
|
||||
@PlatinumTest(focusArea = "launcher")
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR)
|
||||
public void testResizeWidget() throws Throwable {
|
||||
commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext));
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.MediumTest;
|
||||
|
||||
@@ -34,12 +37,17 @@ import org.junit.Test;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.android.launcher3.Flags;
|
||||
|
||||
/**
|
||||
* Make sure the basic interactions with the WidgetPicker works.
|
||||
*/
|
||||
@MediumTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WidgetPickerTest extends BaseLauncherActivityTest<Launcher> {
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule =
|
||||
new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
|
||||
|
||||
@Rule
|
||||
public TestRule screenRecordRule = new ScreenRecordRule();
|
||||
@@ -58,6 +66,7 @@ public class WidgetPickerTest extends BaseLauncherActivityTest<Launcher> {
|
||||
@Test
|
||||
@ScreenRecord
|
||||
@PortraitLandscape
|
||||
@DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR)
|
||||
public void testWidgets() {
|
||||
loadLauncherSync();
|
||||
// Test opening widgets.
|
||||
|
||||
Reference in new issue
Block a user