Skip to content

Commit d6b8bf2

Browse files
Undid-IridiumUndid Iridium
authored andcommitted
Enhancement UI changes to ensure copy paste protections. (#162)
Co-authored-by: Undid Iridium <[email protected]>
1 parent fe7391c commit d6b8bf2

File tree

4 files changed

+75
-29
lines changed

4 files changed

+75
-29
lines changed

src/main/java/com/rarchives/ripme/ui/MainWindow.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ private void changeLocale() {
751751
}
752752

753753
private void setupHandlers() {
754-
ripButton.addActionListener(new RipButtonHandler());
755-
ripTextfield.addActionListener(new RipButtonHandler());
754+
ripButton.addActionListener(new RipButtonHandler(this));
755+
ripTextfield.addActionListener(new RipButtonHandler(this));
756756
ripTextfield.getDocument().addDocumentListener(new DocumentListener() {
757757
@Override
758758
public void removeUpdate(DocumentEvent e) {
@@ -1390,10 +1390,25 @@ private boolean canRip(String urlString) {
13901390
}
13911391
}
13921392

1393-
class RipButtonHandler implements ActionListener {
1393+
1394+
public static JTextField getRipTextfield() {
1395+
return ripTextfield;
1396+
}
1397+
1398+
public static DefaultListModel<Object> getQueueListModel() {
1399+
return queueListModel;
1400+
}
1401+
static class RipButtonHandler implements ActionListener {
1402+
1403+
private MainWindow mainWindow;
1404+
1405+
public RipButtonHandler(MainWindow mainWindow) {
1406+
this.mainWindow = mainWindow;
1407+
}
13941408
public void actionPerformed(ActionEvent event) {
13951409
String url = ripTextfield.getText();
1396-
if (!queueListModel.contains(url) && !url.equals("")) {
1410+
boolean url_not_empty = !url.equals("");
1411+
if (!queueListModel.contains(url) && url_not_empty) {
13971412
// Check if we're ripping a range of urls
13981413
if (url.contains("{")) {
13991414
// Make sure the user hasn't forgotten the closing }
@@ -1403,22 +1418,25 @@ public void actionPerformed(ActionEvent event) {
14031418
int rangeEnd = Integer.parseInt(rangeToParse.split("-")[1]);
14041419
for (int i = rangeStart; i < rangeEnd + 1; i++) {
14051420
String realURL = url.replaceAll("\\{\\S*\\}", Integer.toString(i));
1406-
if (canRip(realURL)) {
1407-
queueListModel.add(queueListModel.size(), realURL);
1421+
if (mainWindow.canRip(realURL)) {
1422+
queueListModel.addElement(realURL);
14081423
ripTextfield.setText("");
14091424
} else {
1410-
displayAndLogError("Can't find ripper for " + realURL, Color.RED);
1425+
mainWindow.displayAndLogError("Can't find ripper for " + realURL, Color.RED);
14111426
}
14121427
}
14131428
}
14141429
} else {
1415-
queueListModel.add(queueListModel.size(), ripTextfield.getText());
1430+
queueListModel.addElement(url);
14161431
ripTextfield.setText("");
14171432
}
1418-
} else {
1419-
if (!isRipping) {
1420-
ripNextAlbum();
1421-
}
1433+
} else if (url_not_empty) {
1434+
mainWindow.displayAndLogError("This URL is already in queue: " + url, Color.RED);
1435+
mainWindow.statusWithColor("This URL is already in queue: " + url, Color.ORANGE);
1436+
ripTextfield.setText("");
1437+
}
1438+
else if(!mainWindow.isRipping){
1439+
mainWindow.ripNextAlbum();
14221440
}
14231441
}
14241442
}

src/test/java/com/rarchives/ripme/tst/ripper/rippers/ChanRipperTest.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,18 @@
2323
public class ChanRipperTest extends RippersTest {
2424
@Test
2525
@Tag("flaky")
26-
public void testChanURLPasses() throws IOException, URISyntaxException {
26+
public void testChanURLPasses() throws IOException, URISyntaxException {
2727
List<URL> passURLs = new ArrayList<>();
2828
// URLs that should work
2929
passURLs.add(new URI("http://desuchan.net/v/res/7034.html").toURL());
3030
passURLs.add(new URI("https://boards.4chan.org/hr/thread/3015701").toURL());
31-
passURLs.add(new URI("https://boards.420chan.org/420/res/232066.php").toURL());
31+
// passURLs.add(new URI("https://boards.420chan.org/420/res/232066.php").toURL()); - Dead link
3232
passURLs.add(new URI("http://7chan.org/gif/res/25873.html").toURL());
3333
passURLs.add(new URI("https://rbt.asia/g/thread/70643087/").toURL()); //must work with TLDs with len of 4
3434
for (URL url : passURLs) {
3535
ChanRipper ripper = new ChanRipper(url);
3636
// Use CompletableFuture to run setup() asynchronously
37-
CompletableFuture<Void> setupFuture = CompletableFuture.runAsync(() -> {
38-
try {
39-
ripper.setup();
40-
} catch (IOException | URISyntaxException e) {
41-
throw new RuntimeException(e);
42-
}
43-
});
44-
45-
try {
46-
// Wait for up to 5 seconds for setup() to complete
47-
setupFuture.get(5, TimeUnit.SECONDS);
48-
} catch (InterruptedException | ExecutionException |
49-
TimeoutException e) {
50-
e.printStackTrace(); // Handle exceptions as needed
51-
}
37+
ripper.setup();
5238
assert (ripper.canRip(url));
5339
Assertions.assertNotNull(ripper.getWorkingDir(), "Ripper for " + url + " did not have a valid working directory.");
5440
deleteDir(ripper.getWorkingDir());
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.rarchives.ripme.ui;
2+
3+
import org.junit.jupiter.api.Tag;
4+
import org.junit.jupiter.api.Test;
5+
6+
import javax.swing.*;
7+
import java.awt.event.ActionEvent;
8+
import java.io.IOException;
9+
import java.util.Collections;
10+
11+
import static org.junit.jupiter.api.Assertions.*;
12+
13+
public class RipButtonHandlerTest {
14+
15+
16+
@Test
17+
@Tag("flaky")
18+
public void duplicateUrlTestCase() throws IOException {
19+
// Simulating the MainWindow in our test
20+
MainWindow testMainWindow = new MainWindow();
21+
SwingUtilities.invokeLater(testMainWindow);
22+
23+
MainWindow.RipButtonHandler rbHandler = new MainWindow.RipButtonHandler(testMainWindow);
24+
// Creating a RipButtonHandler instance - Changing fake text to cause github to rebuild 1.
25+
26+
// Add some URL to the model (assuming there's a method for adding URLs)
27+
testMainWindow.getRipTextfield().setText("http://example.com");
28+
rbHandler.actionPerformed(null);
29+
testMainWindow.getRipTextfield().setText("http://example.com");
30+
rbHandler.actionPerformed(null);
31+
32+
// Assuming your MainWindow or RipButtonHandler sets some flag or state
33+
// indicating that a duplicate URL was encountered
34+
assertEquals(testMainWindow.getRipTextfield().getText(), "");
35+
}
36+
37+
}

src/test/java/com/rarchives/ripme/ui/UIContextMenuTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,39 @@ void tearDown() {
5757
}
5858

5959
@Test
60+
@Tag("flaky")
6061
void testCut() {
6162
// Simulate a cut event
6263
simulateCutEvent();
6364
// Add assertions if needed
6465
}
6566

6667
@Test
68+
@Tag("flaky")
6769
void testCopy() {
6870
// Simulate a copy event
6971
simulateCopyEvent();
7072
// Add assertions if needed
7173
}
7274

7375
@Test
76+
@Tag("flaky")
7477
void testPaste() {
7578
// Simulate a paste event
7679
simulatePasteEvent();
7780
// Add assertions if needed
7881
}
7982

8083
@Test
84+
@Tag("flaky")
8185
void testSelectAll() {
8286
// Simulate a select all event
8387
simulateSelectAllEvent();
8488
// Add assertions if needed
8589
}
8690

8791
@Test
92+
@Tag("flaky")
8893
void testUndo() {
8994
// Simulate an undo event
9095
simulateUndoEvent();

0 commit comments

Comments
 (0)