Loading tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java +17 −30 Original line number Diff line number Diff line Loading @@ -15,8 +15,9 @@ */ package com.android.launcher3.ui.widget; import static com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; Loading @@ -24,43 +25,37 @@ import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.ContentResolver; import android.content.ContentValues; import android.content.pm.PackageInstaller; import android.content.pm.PackageInstaller.SessionParams; import android.content.pm.PackageManager; import android.database.Cursor; import android.os.Bundle; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import com.android.launcher3.LauncherAppWidgetHost; import com.android.launcher3.LauncherAppWidgetInfo; import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.LauncherSettings; import com.android.launcher3.Workspace; import com.android.launcher3.compat.AppWidgetManagerCompat; import com.android.launcher3.compat.PackageInstallerCompat; import com.android.launcher3.tapl.Workspace; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.ui.TestViewHelpers; import com.android.launcher3.util.ContentWriter; import com.android.launcher3.util.rule.ShellCommandRule; import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.PendingAddWidgetInfo; import com.android.launcher3.widget.PendingAppWidgetHostView; import com.android.launcher3.widget.WidgetHostViewLoader; import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.Set; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.uiautomator.UiSelector; import java.util.concurrent.Callable; /** * Tests for bind widget flow. * Loading Loading @@ -131,16 +126,14 @@ public class BindWidgetTest extends AbstractLauncherUiTest { setupContents(item); // Since there is no widget to verify, just wait until the workspace is ready. // TODO: fix LauncherInstrumentation#LAUNCHER_PKG mLauncher.getWorkspace(); final Workspace workspace = mLauncher.getWorkspace(); // Item deleted from db mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id), null, null, null, null, null); assertEquals(0, mCursor.getCount()); // The view does not exist assertFalse(mDevice.findObject(new UiSelector().description(info.label)).exists()); assertTrue("Widget exists", workspace.tryGetWidget(info.label, 0) == null); } @Test Loading Loading @@ -189,12 +182,8 @@ public class BindWidgetTest extends AbstractLauncherUiTest { setupContents(item); // Since there is no widget to verify, just wait until the workspace is ready. // TODO: fix LauncherInstrumentation#LAUNCHER_PKG mLauncher.getWorkspace(); // The view does not exist assertFalse(mDevice.findObject( new UiSelector().className(PendingAppWidgetHostView.class)).exists()); assertTrue("Pending widget exists", mLauncher.getWorkspace().tryGetPendingWidget(0) == null); // Item deleted from db mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id), null, null, null, null, null); Loading Loading @@ -258,12 +247,12 @@ public class BindWidgetTest extends AbstractLauncherUiTest { * widget class is displayed on the homescreen. */ private void setupContents(LauncherAppWidgetInfo item) { int screenId = Workspace.FIRST_SCREEN_ID; int screenId = FIRST_SCREEN_ID; // Update the screen id counter for the provider. LauncherSettings.Settings.call(mResolver, LauncherSettings.Settings.METHOD_NEW_SCREEN_ID); if (screenId > Workspace.FIRST_SCREEN_ID) { screenId = Workspace.FIRST_SCREEN_ID; if (screenId > FIRST_SCREEN_ID) { screenId = FIRST_SCREEN_ID; } // Insert the item Loading @@ -283,15 +272,13 @@ public class BindWidgetTest extends AbstractLauncherUiTest { } private void verifyWidgetPresent(LauncherAppWidgetProviderInfo info) { UiSelector selector = new UiSelector().packageName(mTargetContext.getPackageName()) .className(LauncherAppWidgetHostView.class).description(info.label); assertTrue(mDevice.findObject(selector).waitForExists(DEFAULT_UI_TIMEOUT)); assertTrue("Widget is not present", mLauncher.getWorkspace().tryGetWidget(info.label, DEFAULT_UI_TIMEOUT) != null); } private void verifyPendingWidgetPresent() { UiSelector selector = new UiSelector().packageName(mTargetContext.getPackageName()) .className(PendingAppWidgetHostView.class); assertTrue(mDevice.findObject(selector).waitForExists(DEFAULT_UI_TIMEOUT)); assertTrue("Pending widget is not present", mLauncher.getWorkspace().tryGetPendingWidget(DEFAULT_UI_TIMEOUT) != null); } /** Loading tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java +12 −29 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ import android.view.View; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; import com.android.launcher3.ItemInfo; Loading Loading @@ -81,15 +80,10 @@ public class RequestPinItemTest extends AbstractLauncherUiTest { @Test public void testPinWidgetNoConfig() throws Throwable { runTest("pinWidgetNoConfig", true, new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View view) { return info instanceof LauncherAppWidgetInfo && runTest("pinWidgetNoConfig", true, (info, view) -> info instanceof LauncherAppWidgetInfo && ((LauncherAppWidgetInfo) info).appWidgetId == mAppWidgetId && ((LauncherAppWidgetInfo) info).providerName.getClassName() .equals(AppWidgetNoConfig.class.getName()); } }); .equals(AppWidgetNoConfig.class.getName())); } @Test Loading @@ -99,28 +93,19 @@ public class RequestPinItemTest extends AbstractLauncherUiTest { RequestPinItemActivity.class, "setRemoteViewColor").putExtra( RequestPinItemActivity.EXTRA_PARAM + "0", Color.RED); runTest("pinWidgetNoConfig", true, new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View view) { return info instanceof LauncherAppWidgetInfo && runTest("pinWidgetNoConfig", true, (info, view) -> info instanceof LauncherAppWidgetInfo && ((LauncherAppWidgetInfo) info).appWidgetId == mAppWidgetId && ((LauncherAppWidgetInfo) info).providerName.getClassName() .equals(AppWidgetNoConfig.class.getName()); } }, command); .equals(AppWidgetNoConfig.class.getName()), command); } @Test public void testPinWidgetWithConfig() throws Throwable { runTest("pinWidgetWithConfig", true, new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View view) { return info instanceof LauncherAppWidgetInfo && runTest("pinWidgetWithConfig", true, (info, view) -> info instanceof LauncherAppWidgetInfo && ((LauncherAppWidgetInfo) info).appWidgetId == mAppWidgetId && ((LauncherAppWidgetInfo) info).providerName.getClassName() .equals(AppWidgetWithConfig.class.getName()); } }); .equals(AppWidgetWithConfig.class.getName())); } @Test Loading Loading @@ -174,9 +159,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest { // call the requested method to start the flow mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent( RequestPinItemActivity.class, activityMethod)); UiObject2 widgetCell = mDevice.wait( Until.findObject(By.clazz(WidgetCell.class)), DEFAULT_ACTIVITY_TIMEOUT); assertNotNull(widgetCell); mLauncher.getWidgetCell(); // Accept confirmation: BlockingBroadcastReceiver resultReceiver = new BlockingBroadcastReceiver(mCallbackAction); Loading tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +21 −11 Original line number Diff line number Diff line Loading @@ -502,6 +502,13 @@ public final class LauncherInstrumentation { } } @NonNull public WidgetCell getWidgetCell() { try (LauncherInstrumentation.Closable c = addContextLayer("want to get widget cell")) { return new WidgetCell(this); } } /** * Gets the Overview object if the current state is showing the overview panel. Fails if the * launcher is not in that state. Loading @@ -515,17 +522,6 @@ public final class LauncherInstrumentation { } } /** * Gets the Base overview object if either Launcher is in overview state or the fallback * overview activity is showing. Fails otherwise. * * @return BaseOverview object. */ @NonNull public BaseOverview getBaseOverview() { return new BaseOverview(this); } /** * Gets the All Apps object if the current state is showing the all apps panel opened by swiping * from workspace. Fails if the launcher is not in that state. Please don't call this method if Loading Loading @@ -616,6 +612,16 @@ public final class LauncherInstrumentation { return waitForObjectBySelector(getLauncherObjectSelector(resName)); } @NonNull UiObject2 waitForLauncherObject(BySelector selector) { return waitForObjectBySelector(selector.pkg(getLauncherPackageName())); } @NonNull UiObject2 tryWaitForLauncherObject(BySelector selector, long timeout) { return tryWaitForObjectBySelector(selector.pkg(getLauncherPackageName()), timeout); } @NonNull UiObject2 waitForFallbackLauncherObject(String resName) { return waitForObjectBySelector(getFallbackLauncherObjectSelector(resName)); Loading @@ -627,6 +633,10 @@ public final class LauncherInstrumentation { return object; } private UiObject2 tryWaitForObjectBySelector(BySelector selector, long timeout) { return mDevice.wait(Until.findObject(selector), timeout); } BySelector getLauncherObjectSelector(String resName) { return By.res(getLauncherPackageName(), resName); } Loading tests/tapl/com/android/launcher3/tapl/Widget.java 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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.tapl; import androidx.test.uiautomator.UiObject2; public class Widget { Widget(LauncherInstrumentation launcher, UiObject2 widget) { } } tests/tapl/com/android/launcher3/tapl/WidgetCell.java 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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.tapl; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; public class WidgetCell { WidgetCell(LauncherInstrumentation launcher) { final UiObject2 widgetCell = launcher.waitForLauncherObject(By.clazz( "com.android.launcher3.widget.WidgetCell")); launcher.assertNotNull("Can't find widget cell object", widgetCell); } } Loading
tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java +17 −30 Original line number Diff line number Diff line Loading @@ -15,8 +15,9 @@ */ package com.android.launcher3.ui.widget; import static com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; Loading @@ -24,43 +25,37 @@ import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.ContentResolver; import android.content.ContentValues; import android.content.pm.PackageInstaller; import android.content.pm.PackageInstaller.SessionParams; import android.content.pm.PackageManager; import android.database.Cursor; import android.os.Bundle; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import com.android.launcher3.LauncherAppWidgetHost; import com.android.launcher3.LauncherAppWidgetInfo; import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.LauncherSettings; import com.android.launcher3.Workspace; import com.android.launcher3.compat.AppWidgetManagerCompat; import com.android.launcher3.compat.PackageInstallerCompat; import com.android.launcher3.tapl.Workspace; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.ui.TestViewHelpers; import com.android.launcher3.util.ContentWriter; import com.android.launcher3.util.rule.ShellCommandRule; import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.PendingAddWidgetInfo; import com.android.launcher3.widget.PendingAppWidgetHostView; import com.android.launcher3.widget.WidgetHostViewLoader; import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.Set; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.uiautomator.UiSelector; import java.util.concurrent.Callable; /** * Tests for bind widget flow. * Loading Loading @@ -131,16 +126,14 @@ public class BindWidgetTest extends AbstractLauncherUiTest { setupContents(item); // Since there is no widget to verify, just wait until the workspace is ready. // TODO: fix LauncherInstrumentation#LAUNCHER_PKG mLauncher.getWorkspace(); final Workspace workspace = mLauncher.getWorkspace(); // Item deleted from db mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id), null, null, null, null, null); assertEquals(0, mCursor.getCount()); // The view does not exist assertFalse(mDevice.findObject(new UiSelector().description(info.label)).exists()); assertTrue("Widget exists", workspace.tryGetWidget(info.label, 0) == null); } @Test Loading Loading @@ -189,12 +182,8 @@ public class BindWidgetTest extends AbstractLauncherUiTest { setupContents(item); // Since there is no widget to verify, just wait until the workspace is ready. // TODO: fix LauncherInstrumentation#LAUNCHER_PKG mLauncher.getWorkspace(); // The view does not exist assertFalse(mDevice.findObject( new UiSelector().className(PendingAppWidgetHostView.class)).exists()); assertTrue("Pending widget exists", mLauncher.getWorkspace().tryGetPendingWidget(0) == null); // Item deleted from db mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id), null, null, null, null, null); Loading Loading @@ -258,12 +247,12 @@ public class BindWidgetTest extends AbstractLauncherUiTest { * widget class is displayed on the homescreen. */ private void setupContents(LauncherAppWidgetInfo item) { int screenId = Workspace.FIRST_SCREEN_ID; int screenId = FIRST_SCREEN_ID; // Update the screen id counter for the provider. LauncherSettings.Settings.call(mResolver, LauncherSettings.Settings.METHOD_NEW_SCREEN_ID); if (screenId > Workspace.FIRST_SCREEN_ID) { screenId = Workspace.FIRST_SCREEN_ID; if (screenId > FIRST_SCREEN_ID) { screenId = FIRST_SCREEN_ID; } // Insert the item Loading @@ -283,15 +272,13 @@ public class BindWidgetTest extends AbstractLauncherUiTest { } private void verifyWidgetPresent(LauncherAppWidgetProviderInfo info) { UiSelector selector = new UiSelector().packageName(mTargetContext.getPackageName()) .className(LauncherAppWidgetHostView.class).description(info.label); assertTrue(mDevice.findObject(selector).waitForExists(DEFAULT_UI_TIMEOUT)); assertTrue("Widget is not present", mLauncher.getWorkspace().tryGetWidget(info.label, DEFAULT_UI_TIMEOUT) != null); } private void verifyPendingWidgetPresent() { UiSelector selector = new UiSelector().packageName(mTargetContext.getPackageName()) .className(PendingAppWidgetHostView.class); assertTrue(mDevice.findObject(selector).waitForExists(DEFAULT_UI_TIMEOUT)); assertTrue("Pending widget is not present", mLauncher.getWorkspace().tryGetPendingWidget(DEFAULT_UI_TIMEOUT) != null); } /** Loading
tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java +12 −29 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ import android.view.View; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; import com.android.launcher3.ItemInfo; Loading Loading @@ -81,15 +80,10 @@ public class RequestPinItemTest extends AbstractLauncherUiTest { @Test public void testPinWidgetNoConfig() throws Throwable { runTest("pinWidgetNoConfig", true, new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View view) { return info instanceof LauncherAppWidgetInfo && runTest("pinWidgetNoConfig", true, (info, view) -> info instanceof LauncherAppWidgetInfo && ((LauncherAppWidgetInfo) info).appWidgetId == mAppWidgetId && ((LauncherAppWidgetInfo) info).providerName.getClassName() .equals(AppWidgetNoConfig.class.getName()); } }); .equals(AppWidgetNoConfig.class.getName())); } @Test Loading @@ -99,28 +93,19 @@ public class RequestPinItemTest extends AbstractLauncherUiTest { RequestPinItemActivity.class, "setRemoteViewColor").putExtra( RequestPinItemActivity.EXTRA_PARAM + "0", Color.RED); runTest("pinWidgetNoConfig", true, new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View view) { return info instanceof LauncherAppWidgetInfo && runTest("pinWidgetNoConfig", true, (info, view) -> info instanceof LauncherAppWidgetInfo && ((LauncherAppWidgetInfo) info).appWidgetId == mAppWidgetId && ((LauncherAppWidgetInfo) info).providerName.getClassName() .equals(AppWidgetNoConfig.class.getName()); } }, command); .equals(AppWidgetNoConfig.class.getName()), command); } @Test public void testPinWidgetWithConfig() throws Throwable { runTest("pinWidgetWithConfig", true, new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View view) { return info instanceof LauncherAppWidgetInfo && runTest("pinWidgetWithConfig", true, (info, view) -> info instanceof LauncherAppWidgetInfo && ((LauncherAppWidgetInfo) info).appWidgetId == mAppWidgetId && ((LauncherAppWidgetInfo) info).providerName.getClassName() .equals(AppWidgetWithConfig.class.getName()); } }); .equals(AppWidgetWithConfig.class.getName())); } @Test Loading Loading @@ -174,9 +159,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest { // call the requested method to start the flow mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent( RequestPinItemActivity.class, activityMethod)); UiObject2 widgetCell = mDevice.wait( Until.findObject(By.clazz(WidgetCell.class)), DEFAULT_ACTIVITY_TIMEOUT); assertNotNull(widgetCell); mLauncher.getWidgetCell(); // Accept confirmation: BlockingBroadcastReceiver resultReceiver = new BlockingBroadcastReceiver(mCallbackAction); Loading
tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +21 −11 Original line number Diff line number Diff line Loading @@ -502,6 +502,13 @@ public final class LauncherInstrumentation { } } @NonNull public WidgetCell getWidgetCell() { try (LauncherInstrumentation.Closable c = addContextLayer("want to get widget cell")) { return new WidgetCell(this); } } /** * Gets the Overview object if the current state is showing the overview panel. Fails if the * launcher is not in that state. Loading @@ -515,17 +522,6 @@ public final class LauncherInstrumentation { } } /** * Gets the Base overview object if either Launcher is in overview state or the fallback * overview activity is showing. Fails otherwise. * * @return BaseOverview object. */ @NonNull public BaseOverview getBaseOverview() { return new BaseOverview(this); } /** * Gets the All Apps object if the current state is showing the all apps panel opened by swiping * from workspace. Fails if the launcher is not in that state. Please don't call this method if Loading Loading @@ -616,6 +612,16 @@ public final class LauncherInstrumentation { return waitForObjectBySelector(getLauncherObjectSelector(resName)); } @NonNull UiObject2 waitForLauncherObject(BySelector selector) { return waitForObjectBySelector(selector.pkg(getLauncherPackageName())); } @NonNull UiObject2 tryWaitForLauncherObject(BySelector selector, long timeout) { return tryWaitForObjectBySelector(selector.pkg(getLauncherPackageName()), timeout); } @NonNull UiObject2 waitForFallbackLauncherObject(String resName) { return waitForObjectBySelector(getFallbackLauncherObjectSelector(resName)); Loading @@ -627,6 +633,10 @@ public final class LauncherInstrumentation { return object; } private UiObject2 tryWaitForObjectBySelector(BySelector selector, long timeout) { return mDevice.wait(Until.findObject(selector), timeout); } BySelector getLauncherObjectSelector(String resName) { return By.res(getLauncherPackageName(), resName); } Loading
tests/tapl/com/android/launcher3/tapl/Widget.java 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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.tapl; import androidx.test.uiautomator.UiObject2; public class Widget { Widget(LauncherInstrumentation launcher, UiObject2 widget) { } }
tests/tapl/com/android/launcher3/tapl/WidgetCell.java 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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.tapl; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; public class WidgetCell { WidgetCell(LauncherInstrumentation launcher) { final UiObject2 widgetCell = launcher.waitForLauncherObject(By.clazz( "com.android.launcher3.widget.WidgetCell")); launcher.assertNotNull("Can't find widget cell object", widgetCell); } }