mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-28 15:56:49 +00:00
Adding some tests for request pin shortcut/widget flow
Bug: 33584624 Change-Id: I49df36f60d2ae071b9d2c77c9c3300e010cd3bb9
This commit is contained in:
@@ -18,10 +18,7 @@ package com.android.launcher3.ui.widget;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.UiObject2;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
@@ -41,8 +38,6 @@ import com.android.launcher3.util.Wait;
|
||||
import com.android.launcher3.widget.WidgetCell;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Test to verify widget configuration is properly shown.
|
||||
@@ -50,9 +45,6 @@ import java.util.concurrent.TimeUnit;
|
||||
@LargeTest
|
||||
public class AddConfigWidgetTest extends LauncherInstrumentationTestCase {
|
||||
|
||||
public static final long DEFAULT_ACTIVITY_TIMEOUT = TimeUnit.SECONDS.toMillis(10);
|
||||
public static final long DEFAULT_BROADCAST_TIMEOUT_SECS = 5;
|
||||
|
||||
private LauncherAppWidgetProviderInfo mWidgetInfo;
|
||||
private SimpleActivityMonitor mActivityMonitor;
|
||||
private MainThreadExecutor mMainThreadExecutor;
|
||||
@@ -69,6 +61,8 @@ public class AddConfigWidgetTest extends LauncherInstrumentationTestCase {
|
||||
.registerActivityLifecycleCallbacks(mActivityMonitor);
|
||||
mMainThreadExecutor = new MainThreadExecutor();
|
||||
mAppWidgetManager = AppWidgetManager.getInstance(mTargetContext);
|
||||
|
||||
grantWidgetPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,12 +120,11 @@ public class AddConfigWidgetTest extends LauncherInstrumentationTestCase {
|
||||
// Verify that the widget id is valid and bound
|
||||
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
|
||||
|
||||
setResult(acceptConfig);
|
||||
if (acceptConfig) {
|
||||
setResult(Activity.RESULT_OK);
|
||||
assertTrue(Wait.atMost(new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT));
|
||||
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
|
||||
} else {
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
// Verify that the widget id is deleted.
|
||||
assertTrue(Wait.atMost(new Condition() {
|
||||
@Override
|
||||
@@ -142,10 +135,11 @@ public class AddConfigWidgetTest extends LauncherInstrumentationTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private void setResult(int resultCode) {
|
||||
String action = WidgetConfigActivity.class.getName() + WidgetConfigActivity.SUFFIX_FINISH;
|
||||
private void setResult(boolean success) {
|
||||
|
||||
getInstrumentation().getTargetContext().sendBroadcast(
|
||||
new Intent(action).putExtra(WidgetConfigActivity.EXTRA_CODE, resultCode));
|
||||
WidgetConfigActivity.getCommandIntent(WidgetConfigActivity.class,
|
||||
success ? "clickOK" : "clickCancel"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,28 +179,17 @@ public class AddConfigWidgetTest extends LauncherInstrumentationTestCase {
|
||||
/**
|
||||
* Broadcast receiver for receiving widget config activity status.
|
||||
*/
|
||||
private class WidgetConfigStartupMonitor extends BroadcastReceiver {
|
||||
private class WidgetConfigStartupMonitor extends BlockingBroadcastReceiver {
|
||||
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
private Intent mIntent;
|
||||
|
||||
WidgetConfigStartupMonitor() {
|
||||
getInstrumentation().getTargetContext().registerReceiver(this,
|
||||
new IntentFilter(WidgetConfigActivity.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mIntent = intent.getParcelableExtra(Intent.EXTRA_INTENT);
|
||||
latch.countDown();
|
||||
public WidgetConfigStartupMonitor() {
|
||||
super(WidgetConfigActivity.class.getName());
|
||||
}
|
||||
|
||||
public int getWidgetId() throws InterruptedException {
|
||||
latch.await(DEFAULT_BROADCAST_TIMEOUT_SECS, TimeUnit.SECONDS);
|
||||
getInstrumentation().getTargetContext().unregisterReceiver(this);
|
||||
assertNotNull(mIntent);
|
||||
assertEquals(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE, mIntent.getAction());
|
||||
int widgetId = mIntent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
Intent intent = blockingGetExtraIntent();
|
||||
assertNotNull(intent);
|
||||
assertEquals(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE, intent.getAction());
|
||||
int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
LauncherAppWidgetInfo.NO_ID);
|
||||
assertNotSame(widgetId, LauncherAppWidgetInfo.NO_ID);
|
||||
return widgetId;
|
||||
|
||||
Reference in New Issue
Block a user