|
21 | 21 |
|
22 | 22 | #include <QCheckBox> |
23 | 23 | #include <QClipboard> |
| 24 | +#include <QDialog> |
24 | 25 | #include <QListWidget> |
25 | 26 | #include <QMenu> |
26 | 27 | #include <QMenuBar> |
@@ -2504,6 +2505,68 @@ void TestGui::testMenuActionStates() |
2504 | 2505 | QVERIFY(isActionEnabled("actionPasswordGenerator")); |
2505 | 2506 | } |
2506 | 2507 |
|
| 2508 | +void TestGui::testDeleteEntryDuringModalDialog() |
| 2509 | +{ |
| 2510 | + // Delete key in native file dialogs on macOS |
| 2511 | + // should not delete password entries |
| 2512 | + |
| 2513 | + // Add canned entries for consistent testing |
| 2514 | + addCannedEntries(); |
| 2515 | + |
| 2516 | + auto* entryView = m_dbWidget->findChild<EntryView*>("entryView"); |
| 2517 | + auto* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete"); |
| 2518 | + |
| 2519 | + // Count initial entries |
| 2520 | + int initialEntryCount = entryView->model()->rowCount(); |
| 2521 | + QVERIFY(initialEntryCount > 0); |
| 2522 | + |
| 2523 | + // Select the first entry |
| 2524 | + clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton); |
| 2525 | + entryView->setFocus(); |
| 2526 | + QApplication::processEvents(); |
| 2527 | + |
| 2528 | + // Create and show a modal dialog to simulate the file save dialog |
| 2529 | + QDialog modalDialog(m_mainWindow.data()); |
| 2530 | + modalDialog.setModal(true); |
| 2531 | + |
| 2532 | + // Use a timer to trigger the delete action while modal dialog is shown |
| 2533 | + bool deleteTriggered = false; |
| 2534 | + QTimer::singleShot(50, [&]() { |
| 2535 | + // Verify modal dialog is active |
| 2536 | + QVERIFY(QApplication::activeModalWidget() == &modalDialog); |
| 2537 | + |
| 2538 | + // Trigger delete action while modal is open |
| 2539 | + entryDeleteAction->trigger(); |
| 2540 | + deleteTriggered = true; |
| 2541 | + |
| 2542 | + // Close the modal dialog |
| 2543 | + modalDialog.accept(); |
| 2544 | + }); |
| 2545 | + |
| 2546 | + // Show modal dialog (blocks until closed) |
| 2547 | + modalDialog.exec(); |
| 2548 | + |
| 2549 | + QVERIFY(deleteTriggered); |
| 2550 | + QApplication::processEvents(); |
| 2551 | + |
| 2552 | + // Verify entry count unchanged - delete should have been blocked |
| 2553 | + QCOMPARE(entryView->model()->rowCount(), initialEntryCount); |
| 2554 | + |
| 2555 | + // Now verify normal deletion still works after modal closes |
| 2556 | + clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton); |
| 2557 | + entryView->setFocus(); |
| 2558 | + QApplication::processEvents(); |
| 2559 | + |
| 2560 | + if (!config()->get(Config::Security_NoConfirmMoveEntryToRecycleBin).toBool()) { |
| 2561 | + MessageBox::setNextAnswer(MessageBox::Move); |
| 2562 | + } |
| 2563 | + entryDeleteAction->trigger(); |
| 2564 | + QApplication::processEvents(); |
| 2565 | + |
| 2566 | + // Verify entry was deleted normally |
| 2567 | + QCOMPARE(entryView->model()->rowCount(), initialEntryCount - 1); |
| 2568 | +} |
| 2569 | + |
2507 | 2570 | void TestGui::addCannedEntries() |
2508 | 2571 | { |
2509 | 2572 | // Find buttons |
|
0 commit comments