1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-16 02:44:10 +02:00

Enhancement UI changes to ensure copy paste protections. (#162)

Co-authored-by: Undid Iridium <FrancisXIrizarry@gmail.com>
This commit is contained in:
X
2025-01-02 03:50:41 -05:00
committed by soloturn
parent fe7391cac5
commit d6b8bf2d08
4 changed files with 75 additions and 29 deletions

View File

@@ -751,8 +751,8 @@ public final class MainWindow implements Runnable, RipStatusHandler {
} }
private void setupHandlers() { private void setupHandlers() {
ripButton.addActionListener(new RipButtonHandler()); ripButton.addActionListener(new RipButtonHandler(this));
ripTextfield.addActionListener(new RipButtonHandler()); ripTextfield.addActionListener(new RipButtonHandler(this));
ripTextfield.getDocument().addDocumentListener(new DocumentListener() { ripTextfield.getDocument().addDocumentListener(new DocumentListener() {
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
@@ -1390,10 +1390,25 @@ public final class MainWindow implements Runnable, RipStatusHandler {
} }
} }
class RipButtonHandler implements ActionListener {
public static JTextField getRipTextfield() {
return ripTextfield;
}
public static DefaultListModel<Object> getQueueListModel() {
return queueListModel;
}
static class RipButtonHandler implements ActionListener {
private MainWindow mainWindow;
public RipButtonHandler(MainWindow mainWindow) {
this.mainWindow = mainWindow;
}
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
String url = ripTextfield.getText(); String url = ripTextfield.getText();
if (!queueListModel.contains(url) && !url.equals("")) { boolean url_not_empty = !url.equals("");
if (!queueListModel.contains(url) && url_not_empty) {
// Check if we're ripping a range of urls // Check if we're ripping a range of urls
if (url.contains("{")) { if (url.contains("{")) {
// Make sure the user hasn't forgotten the closing } // Make sure the user hasn't forgotten the closing }
@@ -1403,22 +1418,25 @@ public final class MainWindow implements Runnable, RipStatusHandler {
int rangeEnd = Integer.parseInt(rangeToParse.split("-")[1]); int rangeEnd = Integer.parseInt(rangeToParse.split("-")[1]);
for (int i = rangeStart; i < rangeEnd + 1; i++) { for (int i = rangeStart; i < rangeEnd + 1; i++) {
String realURL = url.replaceAll("\\{\\S*\\}", Integer.toString(i)); String realURL = url.replaceAll("\\{\\S*\\}", Integer.toString(i));
if (canRip(realURL)) { if (mainWindow.canRip(realURL)) {
queueListModel.add(queueListModel.size(), realURL); queueListModel.addElement(realURL);
ripTextfield.setText(""); ripTextfield.setText("");
} else { } else {
displayAndLogError("Can't find ripper for " + realURL, Color.RED); mainWindow.displayAndLogError("Can't find ripper for " + realURL, Color.RED);
} }
} }
} }
} else { } else {
queueListModel.add(queueListModel.size(), ripTextfield.getText()); queueListModel.addElement(url);
ripTextfield.setText(""); ripTextfield.setText("");
} }
} else { } else if (url_not_empty) {
if (!isRipping) { mainWindow.displayAndLogError("This URL is already in queue: " + url, Color.RED);
ripNextAlbum(); mainWindow.statusWithColor("This URL is already in queue: " + url, Color.ORANGE);
} ripTextfield.setText("");
}
else if(!mainWindow.isRipping){
mainWindow.ripNextAlbum();
} }
} }
} }

View File

@@ -23,32 +23,18 @@ import org.junit.jupiter.api.Test;
public class ChanRipperTest extends RippersTest { public class ChanRipperTest extends RippersTest {
@Test @Test
@Tag("flaky") @Tag("flaky")
public void testChanURLPasses() throws IOException, URISyntaxException { public void testChanURLPasses() throws IOException, URISyntaxException {
List<URL> passURLs = new ArrayList<>(); List<URL> passURLs = new ArrayList<>();
// URLs that should work // URLs that should work
passURLs.add(new URI("http://desuchan.net/v/res/7034.html").toURL()); passURLs.add(new URI("http://desuchan.net/v/res/7034.html").toURL());
passURLs.add(new URI("https://boards.4chan.org/hr/thread/3015701").toURL()); passURLs.add(new URI("https://boards.4chan.org/hr/thread/3015701").toURL());
passURLs.add(new URI("https://boards.420chan.org/420/res/232066.php").toURL()); // passURLs.add(new URI("https://boards.420chan.org/420/res/232066.php").toURL()); - Dead link
passURLs.add(new URI("http://7chan.org/gif/res/25873.html").toURL()); passURLs.add(new URI("http://7chan.org/gif/res/25873.html").toURL());
passURLs.add(new URI("https://rbt.asia/g/thread/70643087/").toURL()); //must work with TLDs with len of 4 passURLs.add(new URI("https://rbt.asia/g/thread/70643087/").toURL()); //must work with TLDs with len of 4
for (URL url : passURLs) { for (URL url : passURLs) {
ChanRipper ripper = new ChanRipper(url); ChanRipper ripper = new ChanRipper(url);
// Use CompletableFuture to run setup() asynchronously // Use CompletableFuture to run setup() asynchronously
CompletableFuture<Void> setupFuture = CompletableFuture.runAsync(() -> { ripper.setup();
try {
ripper.setup();
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
});
try {
// Wait for up to 5 seconds for setup() to complete
setupFuture.get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException |
TimeoutException e) {
e.printStackTrace(); // Handle exceptions as needed
}
assert (ripper.canRip(url)); assert (ripper.canRip(url));
Assertions.assertNotNull(ripper.getWorkingDir(), "Ripper for " + url + " did not have a valid working directory."); Assertions.assertNotNull(ripper.getWorkingDir(), "Ripper for " + url + " did not have a valid working directory.");
deleteDir(ripper.getWorkingDir()); deleteDir(ripper.getWorkingDir());

View File

@@ -0,0 +1,37 @@
package com.rarchives.ripme.ui;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.*;
public class RipButtonHandlerTest {
@Test
@Tag("flaky")
public void duplicateUrlTestCase() throws IOException {
// Simulating the MainWindow in our test
MainWindow testMainWindow = new MainWindow();
SwingUtilities.invokeLater(testMainWindow);
MainWindow.RipButtonHandler rbHandler = new MainWindow.RipButtonHandler(testMainWindow);
// Creating a RipButtonHandler instance - Changing fake text to cause github to rebuild 1.
// Add some URL to the model (assuming there's a method for adding URLs)
testMainWindow.getRipTextfield().setText("http://example.com");
rbHandler.actionPerformed(null);
testMainWindow.getRipTextfield().setText("http://example.com");
rbHandler.actionPerformed(null);
// Assuming your MainWindow or RipButtonHandler sets some flag or state
// indicating that a duplicate URL was encountered
assertEquals(testMainWindow.getRipTextfield().getText(), "");
}
}

View File

@@ -57,6 +57,7 @@ public class UIContextMenuTests {
} }
@Test @Test
@Tag("flaky")
void testCut() { void testCut() {
// Simulate a cut event // Simulate a cut event
simulateCutEvent(); simulateCutEvent();
@@ -64,6 +65,7 @@ public class UIContextMenuTests {
} }
@Test @Test
@Tag("flaky")
void testCopy() { void testCopy() {
// Simulate a copy event // Simulate a copy event
simulateCopyEvent(); simulateCopyEvent();
@@ -71,6 +73,7 @@ public class UIContextMenuTests {
} }
@Test @Test
@Tag("flaky")
void testPaste() { void testPaste() {
// Simulate a paste event // Simulate a paste event
simulatePasteEvent(); simulatePasteEvent();
@@ -78,6 +81,7 @@ public class UIContextMenuTests {
} }
@Test @Test
@Tag("flaky")
void testSelectAll() { void testSelectAll() {
// Simulate a select all event // Simulate a select all event
simulateSelectAllEvent(); simulateSelectAllEvent();
@@ -85,6 +89,7 @@ public class UIContextMenuTests {
} }
@Test @Test
@Tag("flaky")
void testUndo() { void testUndo() {
// Simulate an undo event // Simulate an undo event
simulateUndoEvent(); simulateUndoEvent();