From: David ‘Bombe’ Roden Date: Sun, 13 Nov 2016 08:41:13 +0000 (+0100) Subject: Treat cancelled fetch request as failure X-Git-Tag: 0.9.7^2~440 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1cd71a1c2a94f889d63d6ec3168d76da0a8b116b;p=Sone.git Treat cancelled fetch request as failure --- diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 48df732..82cc94b 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -178,7 +178,11 @@ public class FreenetInterface { @Override public boolean snoopMetadata(Metadata meta, ClientContext context) { String mimeType = meta.getMIMEType(); - return (mimeType == null) || backgroundFetchCallback.cancelForMimeType(uri, mimeType); + boolean cancel = (mimeType == null) || backgroundFetchCallback.cancelForMimeType(uri, mimeType); + if (cancel) { + backgroundFetchCallback.failed(uri); + } + return cancel; } }; FetchContext fetchContext = client.getFetchContext(); diff --git a/src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java b/src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java index 195876f..cf69136 100644 --- a/src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java +++ b/src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java @@ -440,27 +440,32 @@ public class FreenetInterfaceTest { @Test public void requestIsNotCancelledForImageMimeType() { verifySnoopCancelsRequestForMimeType("image/png", false); + verify(backgroundFetchCallback, never()).failed(uri); } @Test public void requestIsCancelledForNullMimeType() { verifySnoopCancelsRequestForMimeType(null, true); verify(backgroundFetchCallback, never()).cancelForMimeType(eq(uri), ArgumentMatchers.any()); + verify(backgroundFetchCallback).failed(uri); } @Test public void requestIsCancelledForVideoMimeType() { verifySnoopCancelsRequestForMimeType("video/mkv", true); + verify(backgroundFetchCallback).failed(uri); } @Test public void requestIsCancelledForAudioMimeType() { verifySnoopCancelsRequestForMimeType("audio/mpeg", true); + verify(backgroundFetchCallback).failed(uri); } @Test public void requestIsCancelledForTextMimeType() { verifySnoopCancelsRequestForMimeType("text/plain", true); + verify(backgroundFetchCallback).failed(uri); } private void verifySnoopCancelsRequestForMimeType(String mimeType, boolean cancel) {