Merge "Stop controller from steal preference clicks" into rvc-dev

This commit is contained in:
Julia Reynolds
2020-02-26 04:32:52 +00:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 1 deletions

View File

@@ -62,7 +62,7 @@ public class ConversationPromotePreferenceController extends NotificationPrefere
@Override @Override
public boolean handlePreferenceTreeClick(Preference preference) { public boolean handlePreferenceTreeClick(Preference preference) {
if (mChannel == null) { if (mChannel == null || !KEY.equals(preference.getKey())) {
return false; return false;
} }
mChannel.setDemoted(false); mChannel.setDemoted(false);

View File

@@ -20,9 +20,11 @@ import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -122,4 +124,20 @@ public class ConversationPromotePreferenceControllerTest {
verify(mFragment).getActivity(); verify(mFragment).getActivity();
} }
@Test
public void testHandlePreferenceClick_wrongKey() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("wrong");
assertFalse(mController.handlePreferenceTreeClick(pref));
verify(mBackend, never()).updateChannel(eq(null), anyInt(), any());
verify(mFragment, never()).getActivity();
}
} }