Shift+Delete can remove a deck while the tablet pane loads

Aperta
#23,738 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile

Direzione di ricerca

The reproduction is the included DeckPickerStartupShortcutDeletionTest.kt, which pauses InitialActivity.getStartupFailureType while DeckPicker is in tablet mode. Start in DeckPicker's onKeyUp handling of KEYCODE_DEL with META_SHIFT_ON, and check what it does before the study options fragment exists. Done when the test passes: Shift+Delete shows the confirmation dialog naming the deck and the deck is not deleted before that.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

code-scan

Assisted-by: GPT-6.2-Sol xhigh

[EXISTING] Shift+Delete can remove a deck while the tablet pane loads
Subject: [EXISTING] Shift+Delete can remove a deck while the tablet pane loads

Pressing Shift+Delete before the tablet study pane loads removes the selected deck and its cards without confirmation.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerStartupShortcutDeletionTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerStartupShortcutDeletionTest.kt
new file mode 100644
index 0000000000..a4125cc520
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerStartupShortcutDeletionTest.kt
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki
+
+import android.content.Intent
+import android.content.SharedPreferences
+import android.view.KeyEvent
+import androidx.appcompat.app.AlertDialog
+import androidx.core.content.edit
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.anki.common.preferences.sharedPrefs
+import com.ichi2.anki.dialogs.DeckPickerConfirmDeleteDeckDialog
+import com.ichi2.anki.dialogs.utils.message
+import com.ichi2.testutils.BackupManagerTestUtilities
+import io.mockk.every
+import io.mockk.mockkObject
+import io.mockk.unmockkObject
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.Robolectric
+import org.robolectric.annotation.Config
+import java.util.concurrent.CountDownLatch
+import java.util.concurrent.TimeUnit.SECONDS
+import kotlin.test.assertContains
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+import kotlin.test.assertTrue
+
+@RunWith(AndroidJUnit4::class)
+@Config(qualifiers = "xlarge")
+class DeckPickerStartupShortcutDeletionTest : RobolectricTest() {
+    @Test
+    fun `Shift Delete asks before deleting while the tablet pane is loading`() {
+        val deckName = "Selected deck"
+        val target = addDeck(deckName, setAsSelected = true)
+        addNoteToDeck(target)
+        setIntroductionSlidesShown(true)
+        BackupManagerTestUtilities.setupSpaceForBackup(targetContext)
+        targetContext.sharedPrefs().edit { putBoolean("backupPromptDisabled", true) }
+        val startupStarted = CountDownLatch(1)
+        val finishStartup = CountDownLatch(1)
+
+        mockkObject(InitialActivity)
+        try {
+            every { InitialActivity.getStartupFailureType(any<SharedPreferences>(), any<() -> Boolean>()) } answers {
+                startupStarted.countDown()
+                check(finishStartup.await(30, SECONDS)) { "Startup was not released" }
+                callOriginal()
+            }
+            val controller = Robolectric.buildActivity(DeckPicker::class.java, Intent()).setup()
+            saveControllerForCleanup(controller)
+            val picker = controller.get()
+            try {
+                assertTrue(startupStarted.await(10, SECONDS))
+                assertTrue(picker.fragmented)
+                assertNull(picker.supportFragmentManager.findFragmentById(R.id.studyoptions_fragment))
+
+                picker.onKeyUp(
+                    KeyEvent.KEYCODE_DEL,
+                    KeyEvent(0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL, 0, KeyEvent.META_SHIFT_ON),
+                )
+
+                fun confirmation() =
+                    picker.supportFragmentManager.fragments
+                        .filterIsInstance<DeckPickerConfirmDeleteDeckDialog>()
+                        .firstOrNull { it.dialog?.isShowing == true }
+
+                advanceRobolectricLooperUntil { confirmation() != null || col.decks.getLegacy(target) == null }
+                assertNotNull(col.decks.getLegacy(target), "The selected deck was deleted before its name was shown")
+                val dialog = assertNotNull(confirmation()).requireDialog() as AlertDialog
+                assertContains(dialog.message, deckName)
+            } finally {
+                finishStartup.countDown()
+                picker.viewModel.awaitStartup()
+            }
+        } finally {
+            finishStartup.countDown()
+            unmockkObject(InitialActivity)
+        }
+    }
+}

⚠️ This issue existed before the PR and should likely be split off into a separate issue.

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23697#pullrequestreview-6048764417

Lingua principale
Kotlin
Stelle
12.3k
Fork
3.1k
Merge medio
2g 1h
PR unite (30g)
311

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ankidroid/Anki-Android

Tutte le issue di ankidroid/Anki-Android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.