Skip to content

Commit 2430540

Browse files
committed
Add tests for live chat functionality in YouTube extractors
1 parent 05f6a5e commit 2430540

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
8383
public int expectedStreamSegmentsCount() { return -1; } // return 0 or greater to test (default is -1 to ignore)
8484
public List<MetaInfo> expectedMetaInfo() throws MalformedURLException { return Collections.emptyList(); } // default: no metadata info available
8585
public ContentAvailability expectedContentAvailability() { return ContentAvailability.UNKNOWN; } // default: unknown content availability
86+
public boolean expectedHasLiveChat() { return false; } // default: no live chat available
8687

8788
@Test
8889
@Override
@@ -480,4 +481,9 @@ public void testMetaInfo() throws Exception {
480481
public void testContentAvailability() throws Exception {
481482
assertEquals(expectedContentAvailability(), extractor().getContentAvailability());
482483
}
484+
485+
@Test
486+
public void testHasLiveChat() throws Exception {
487+
assertEquals(expectedHasLiveChat(), extractor().hasLiveChat());
488+
}
483489
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,4 +427,50 @@ public void testGetCommentsFormatting() throws IOException, ExtractionException
427427
assertContains("<b>", firstComment.getCommentText().getContent());
428428
}
429429
}
430+
431+
/**
432+
* Test live chat mode behavior on a regular video extractor.
433+
* Does not extend {@link Base} because these tests do not need network/mock data.
434+
*/
435+
public static class LiveChatMode {
436+
private static final String URL = "https://www.youtube.com/watch?v=D00Au7k3i6o";
437+
438+
@org.junit.jupiter.api.BeforeAll
439+
static void setUp() {
440+
org.schabi.newpipe.extractor.InitNewPipeTest.initEmpty();
441+
org.schabi.newpipe.extractor.NewPipe.init(new org.schabi.newpipe.extractor.downloader.Downloader() {
442+
@org.jetbrains.annotations.NotNull
443+
@Override
444+
public org.schabi.newpipe.extractor.downloader.Response execute(
445+
@org.jetbrains.annotations.NotNull final org.schabi.newpipe.extractor.downloader.Request request) {
446+
throw new UnsupportedOperationException("No communication expected");
447+
}
448+
});
449+
}
450+
451+
private YoutubeCommentsExtractor createExtractor() throws Exception {
452+
return (YoutubeCommentsExtractor) YouTube.getCommentsExtractor(URL);
453+
}
454+
455+
@Test
456+
void testIsLiveChatDefaultFalse() throws Exception {
457+
assertFalse(createExtractor().isLiveChat());
458+
}
459+
460+
@Test
461+
void testSetLiveChatContinuationActivatesLiveChat() throws Exception {
462+
final YoutubeCommentsExtractor extractor = createExtractor();
463+
assertFalse(extractor.isLiveChat());
464+
extractor.setLiveChatContinuation("test-continuation");
465+
assertTrue(extractor.isLiveChat());
466+
}
467+
468+
@Test
469+
void testCommentsDisabledIsFalseInLiveChatMode() throws Exception {
470+
final YoutubeCommentsExtractor extractor = createExtractor();
471+
extractor.setLiveChatContinuation("test-continuation");
472+
assertTrue(extractor.isLiveChat());
473+
assertFalse(extractor.isCommentsDisabled());
474+
}
475+
}
430476
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.schabi.newpipe.extractor.services.youtube.stream;
22

3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
35
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
46

57
import org.junit.jupiter.api.Test;
@@ -38,7 +40,15 @@ public void testUploaderName() throws Exception {
3840
@Override public String expectedOriginalUrlContains() { return URL; }
3941

4042
@Override public StreamType expectedStreamType() { return StreamType.LIVE_STREAM; }
43+
@Override public boolean expectedHasLiveChat() { return true; }
4144
@Override public String expectedUploaderName() { return "Lofi Girl"; }
45+
46+
@Test
47+
void testLiveChatContinuationNotNull() throws Exception {
48+
final String continuation = extractor().getLiveChatContinuation();
49+
assertNotNull(continuation);
50+
assertFalse(continuation.isEmpty());
51+
}
4252
@Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow"; }
4353
@Override public long expectedUploaderSubscriberCountAtLeast() { return 9_800_000; }
4454
@Override public List<String> expectedDescriptionContains() {

0 commit comments

Comments
 (0)