Merge "Fix switch listener on app notif page" into sc-dev am: bef076df47
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15273047 Change-Id: I4928c1a96fafefa6039a89f6c03e832c9cffd1e0
This commit is contained in:
@@ -53,6 +53,7 @@ import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -550,12 +551,10 @@ public class AppStateNotificationBridgeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchOnClickListener() {
|
||||
ViewGroup parent = mock(ViewGroup.class);
|
||||
public void testSwitchOnChangeListener() {
|
||||
Switch toggle = mock(Switch.class);
|
||||
when(toggle.isChecked()).thenReturn(true);
|
||||
when(toggle.isEnabled()).thenReturn(true);
|
||||
when(parent.findViewById(anyInt())).thenReturn(toggle);
|
||||
|
||||
AppEntry entry = mock(AppEntry.class);
|
||||
entry.info = new ApplicationInfo();
|
||||
@@ -563,10 +562,9 @@ public class AppStateNotificationBridgeTest {
|
||||
entry.info.uid = 1356;
|
||||
entry.extraInfo = new NotificationsSentState();
|
||||
|
||||
ViewGroup.OnClickListener listener = mBridge.getSwitchOnClickListener(entry);
|
||||
listener.onClick(parent);
|
||||
CompoundButton.OnCheckedChangeListener listener = mBridge.getSwitchOnCheckedListener(entry);
|
||||
listener.onCheckedChanged(toggle, true);
|
||||
|
||||
verify(toggle).toggle();
|
||||
verify(mBackend).setNotificationsEnabledForPackage(
|
||||
entry.info.packageName, entry.info.uid, true);
|
||||
assertThat(((NotificationsSentState) entry.extraInfo).blocked).isFalse();
|
||||
|
@@ -35,6 +35,8 @@ import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ApplicationViewHolderTest {
|
||||
|
||||
@@ -123,13 +125,16 @@ public class ApplicationViewHolderTest {
|
||||
|
||||
@Test
|
||||
public void updateSwitch() {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mView = ApplicationViewHolder.newView(new FrameLayout(mContext), true);
|
||||
mHolder = new ApplicationViewHolder(mView);
|
||||
mHolder.updateSwitch(v -> {
|
||||
} /* listener */, true, true);
|
||||
mHolder.updateSwitch((buttonView, isChecked) -> latch.countDown(), true, true);
|
||||
|
||||
assertThat(mHolder.mSwitch.isChecked()).isTrue();
|
||||
assertThat(mHolder.mSwitch.isEnabled()).isTrue();
|
||||
assertThat(mHolder.mWidgetContainer.hasOnClickListeners()).isTrue();
|
||||
assertThat(mHolder.mSwitch.isFocusable()).isTrue();
|
||||
assertThat(mHolder.mSwitch.isClickable()).isTrue();
|
||||
mHolder.mSwitch.callOnClick();
|
||||
assertThat(latch.getCount()).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user