1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-15 10:24:04 +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() {
ripButton.addActionListener(new RipButtonHandler());
ripTextfield.addActionListener(new RipButtonHandler());
ripButton.addActionListener(new RipButtonHandler(this));
ripTextfield.addActionListener(new RipButtonHandler(this));
ripTextfield.getDocument().addDocumentListener(new DocumentListener() {
@Override
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) {
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
if (url.contains("{")) {
// 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]);
for (int i = rangeStart; i < rangeEnd + 1; i++) {
String realURL = url.replaceAll("\\{\\S*\\}", Integer.toString(i));
if (canRip(realURL)) {
queueListModel.add(queueListModel.size(), realURL);
if (mainWindow.canRip(realURL)) {
queueListModel.addElement(realURL);
ripTextfield.setText("");
} else {
displayAndLogError("Can't find ripper for " + realURL, Color.RED);
mainWindow.displayAndLogError("Can't find ripper for " + realURL, Color.RED);
}
}
}
} else {
queueListModel.add(queueListModel.size(), ripTextfield.getText());
queueListModel.addElement(url);
ripTextfield.setText("");
}
} else {
if (!isRipping) {
ripNextAlbum();
}
} else if (url_not_empty) {
mainWindow.displayAndLogError("This URL is already in queue: " + url, Color.RED);
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 {
@Test
@Tag("flaky")
public void testChanURLPasses() throws IOException, URISyntaxException {
public void testChanURLPasses() throws IOException, URISyntaxException {
List<URL> passURLs = new ArrayList<>();
// URLs that should work
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.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("https://rbt.asia/g/thread/70643087/").toURL()); //must work with TLDs with len of 4
for (URL url : passURLs) {
ChanRipper ripper = new ChanRipper(url);
// Use CompletableFuture to run setup() asynchronously
CompletableFuture<Void> setupFuture = CompletableFuture.runAsync(() -> {
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
}
ripper.setup();
assert (ripper.canRip(url));
Assertions.assertNotNull(ripper.getWorkingDir(), "Ripper for " + url + " did not have a valid working directory.");
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
@Tag("flaky")
void testCut() {
// Simulate a cut event
simulateCutEvent();
@@ -64,6 +65,7 @@ public class UIContextMenuTests {
}
@Test
@Tag("flaky")
void testCopy() {
// Simulate a copy event
simulateCopyEvent();
@@ -71,6 +73,7 @@ public class UIContextMenuTests {
}
@Test
@Tag("flaky")
void testPaste() {
// Simulate a paste event
simulatePasteEvent();
@@ -78,6 +81,7 @@ public class UIContextMenuTests {
}
@Test
@Tag("flaky")
void testSelectAll() {
// Simulate a select all event
simulateSelectAllEvent();
@@ -85,6 +89,7 @@ public class UIContextMenuTests {
}
@Test
@Tag("flaky")
void testUndo() {
// Simulate an undo event
simulateUndoEvent();