Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc0c7a62 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Stop controller from steal preference clicks

Test: atest
Fixes: 150175360
Change-Id: Ia22058df0ddbd1a274a508e2600d12aa1b67a343
parent 490eba35
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public class ConversationPromotePreferenceController extends NotificationPrefere

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (mChannel == null) {
        if (mChannel == null || !KEY.equals(preference.getKey())) {
            return false;
        }
        mChannel.setDemoted(false);
+18 −0
Original line number Diff line number Diff line
@@ -20,9 +20,11 @@ import static android.app.NotificationManager.IMPORTANCE_DEFAULT;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -122,4 +124,20 @@ public class ConversationPromotePreferenceControllerTest {

        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();
    }
}