Revert to Fix AddConfigWidgetTest
- we were checking the widget being valid and bound after we are accepting the config - solution is to revert back to test before and check post result after be check if widget is valid and bound. making sure that ShellCommandRule is checking for success, refactor for AddConfigWidgetTest with extra launcher wait condition. Test: none Bug: 276794291 Flag: not needed Change-Id: I4a6caf0851a947da03711b2a5d5bc9f736a47f95
This commit is contained in:
@@ -15,25 +15,27 @@
|
||||
*/
|
||||
package com.android.launcher3.ui.widget;
|
||||
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
|
||||
import static com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
|
||||
import com.android.launcher3.tapl.Widget;
|
||||
import com.android.launcher3.tapl.WidgetResizeFrame;
|
||||
import com.android.launcher3.tapl.Widgets;
|
||||
import com.android.launcher3.testcomponent.WidgetConfigActivity;
|
||||
import com.android.launcher3.ui.AbstractLauncherUiTest;
|
||||
import com.android.launcher3.ui.TestViewHelpers;
|
||||
import com.android.launcher3.util.Wait;
|
||||
import com.android.launcher3.util.rule.ScreenRecordRule.ScreenRecord;
|
||||
import com.android.launcher3.util.rule.ShellCommandRule;
|
||||
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
|
||||
@@ -50,7 +52,6 @@ import org.junit.runner.RunWith;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class AddConfigWidgetTest extends AbstractLauncherUiTest {
|
||||
|
||||
private static final String WIDGET_PROVIDER_INFO = "b/276794291";
|
||||
@Rule
|
||||
public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
|
||||
|
||||
@@ -88,33 +89,51 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
|
||||
clearHomescreen();
|
||||
mDevice.pressHome();
|
||||
|
||||
final Widgets widgets = mLauncher.getWorkspace().openAllWidgets();
|
||||
|
||||
// Drag widget to homescreen
|
||||
WidgetConfigStartupMonitor monitor = new WidgetConfigStartupMonitor();
|
||||
WidgetResizeFrame resizeFrame =
|
||||
widgets.getWidget(mWidgetInfo.getLabel(mTargetContext.getPackageManager()))
|
||||
.dragConfigWidgetToWorkspace(acceptConfig);
|
||||
mLauncher.getWorkspace()
|
||||
.openAllWidgets()
|
||||
.getWidget(mWidgetInfo.getLabel(mTargetContext.getPackageManager()))
|
||||
.dragToWorkspace(true, false);
|
||||
// Widget id for which the config activity was opened
|
||||
mWidgetId = monitor.getWidgetId();
|
||||
|
||||
Log.e(WIDGET_PROVIDER_INFO,
|
||||
"InstalledProviders count: " + mAppWidgetManager.getInstalledProviders().size());
|
||||
|
||||
// Verify that the widget id is valid and bound
|
||||
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
|
||||
|
||||
setResult(acceptConfig);
|
||||
if (acceptConfig) {
|
||||
assertNotNull("Widget resize frame not shown after widget added", resizeFrame);
|
||||
resizeFrame.dismiss();
|
||||
|
||||
final Widget widget =
|
||||
mLauncher.getWorkspace().tryGetWidget(mWidgetInfo.label, DEFAULT_UI_TIMEOUT);
|
||||
assertNotNull("Widget not found on the workspace", widget);
|
||||
Wait.atMost("", new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
|
||||
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
|
||||
} else {
|
||||
final Widget widget =
|
||||
mLauncher.getWorkspace().tryGetWidget(mWidgetInfo.label, DEFAULT_UI_TIMEOUT);
|
||||
assertNull("Widget unexpectedly found on the workspace", widget);
|
||||
// Verify that the widget id is deleted.
|
||||
Wait.atMost("", () -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null,
|
||||
DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
|
||||
}
|
||||
}
|
||||
|
||||
private void setResult(boolean success) {
|
||||
getInstrumentation().getTargetContext().sendBroadcast(
|
||||
WidgetConfigActivity.getCommandIntent(WidgetConfigActivity.class,
|
||||
success ? "clickOK" : "clickCancel"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition for searching widget id
|
||||
*/
|
||||
private class WidgetSearchCondition implements Wait.Condition, ItemOperator {
|
||||
|
||||
@Override
|
||||
public boolean isTrue() throws Throwable {
|
||||
return mMainThreadExecutor.submit(mActivityMonitor.itemExists(this)).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean evaluate(ItemInfo info, View view) {
|
||||
return info instanceof LauncherAppWidgetInfo
|
||||
&& ((LauncherAppWidgetInfo) info).providerName.getClassName().equals(
|
||||
mWidgetInfo.provider.getClassName())
|
||||
&& ((LauncherAppWidgetInfo) info).appWidgetId == mWidgetId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user