Skip to content

Commit 0ffc634

Browse files
committed
Remove YouTube stream tests mocks and their use
The cpn parameter is randomly generated so its value in the mocks is almost never valid. YouTube stream tests will now use an online version only.
1 parent 749ab51 commit 0ffc634

67 files changed

Lines changed: 54 additions & 13785 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

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

33
import org.junit.BeforeClass;
4-
import org.schabi.newpipe.downloader.DownloaderFactory;
4+
import org.schabi.newpipe.downloader.DownloaderTestImpl;
55
import org.schabi.newpipe.extractor.NewPipe;
66
import org.schabi.newpipe.extractor.StreamingService;
77
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
@@ -10,7 +10,6 @@
1010
import org.schabi.newpipe.extractor.stream.StreamExtractor;
1111
import org.schabi.newpipe.extractor.stream.StreamType;
1212

13-
import java.util.Arrays;
1413
import java.util.Collections;
1514
import java.util.List;
1615
import java.util.Random;
@@ -19,19 +18,22 @@
1918

2019
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2120

21+
// We cannot use mocks for this test class because of the content playback nonce field sent in POST
22+
// bodies requests, which is generated randomly.
23+
2224
public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtractorTest {
23-
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/";
2425
private static final String ID = "rwcfPqbAx-0";
2526
private static final int TIMESTAMP = 196;
26-
private static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID + "&t=" + TIMESTAMP;
27+
private static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID + "&t="
28+
+ TIMESTAMP;
2729
private static StreamExtractor extractor;
2830

2931
@BeforeClass
3032
public static void setUp() throws Exception {
3133
YoutubeParsingHelper.resetClientVersionAndKey();
3234
YoutubeParsingHelper.setNumberGenerator(new Random(1));
3335
YoutubeStreamExtractor.resetDeobfuscationCode();
34-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "ageRestricted"));
36+
NewPipe.init(DownloaderTestImpl.getInstance());
3537
extractor = YouTube.getStreamExtractor(URL);
3638
extractor.fetchPage();
3739
}

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

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

33
import org.junit.BeforeClass;
4-
import org.schabi.newpipe.downloader.DownloaderFactory;
4+
import org.schabi.newpipe.downloader.DownloaderTestImpl;
55
import org.schabi.newpipe.extractor.NewPipe;
66
import org.schabi.newpipe.extractor.StreamingService;
77
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
@@ -19,12 +19,13 @@
1919

2020
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2121

22+
// We cannot use mocks for this test class because of the content playback nonce field sent in POST
23+
// bodies requests, which is generated randomly.
24+
2225
/**
2326
* Test for {@link YoutubeStreamLinkHandlerFactory}
2427
*/
25-
2628
public class YoutubeStreamExtractorControversialTest extends DefaultStreamExtractorTest {
27-
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/";
2829
private static final String ID = "T4XJQO3qol8";
2930
private static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID;
3031
private static StreamExtractor extractor;
@@ -34,7 +35,7 @@ public static void setUp() throws Exception {
3435
YoutubeParsingHelper.resetClientVersionAndKey();
3536
YoutubeParsingHelper.setNumberGenerator(new Random(1));
3637
YoutubeStreamExtractor.resetDeobfuscationCode();
37-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "controversial"));
38+
NewPipe.init(DownloaderTestImpl.getInstance());
3839
extractor = YouTube.getStreamExtractor(URL);
3940
extractor.fetchPage();
4041
}

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

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
/*
2+
* Created by Christian Schabesberger on 30.12.15.
3+
*
4+
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
5+
* YoutubeVideoExtractorDefault.java is part of NewPipe Extractor.
6+
*
7+
* NewPipe Extractor is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* NewPipe Extractor is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
121
package org.schabi.newpipe.extractor.services.youtube.stream;
222

323
import org.junit.BeforeClass;
424
import org.junit.Ignore;
525
import org.junit.Test;
6-
import org.schabi.newpipe.downloader.DownloaderFactory;
726
import org.schabi.newpipe.downloader.DownloaderTestImpl;
827
import org.schabi.newpipe.extractor.MetaInfo;
928
import org.schabi.newpipe.extractor.NewPipe;
@@ -34,27 +53,10 @@
3453
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
3554
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
3655

37-
/*
38-
* Created by Christian Schabesberger on 30.12.15.
39-
*
40-
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
41-
* YoutubeVideoExtractorDefault.java is part of NewPipe.
42-
*
43-
* NewPipe is free software: you can redistribute it and/or modify
44-
* it under the terms of the GNU General Public License as published by
45-
* the Free Software Foundation, either version 3 of the License, or
46-
* (at your option) any later version.
47-
*
48-
* NewPipe is distributed in the hope that it will be useful,
49-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
50-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51-
* GNU General Public License for more details.
52-
*
53-
* You should have received a copy of the GNU General Public License
54-
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
55-
*/
56+
// We cannot use mocks for this test class because of the content playback nonce field sent in POST
57+
// bodies requests, which is generated randomly.
58+
5659
public class YoutubeStreamExtractorDefaultTest {
57-
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/";
5860
static final String BASE_URL = "https://www.youtube.com/watch?v=";
5961
public static final String YOUTUBE_LICENCE = "YouTube licence";
6062

@@ -64,7 +66,7 @@ public static void setUp() throws IOException {
6466
YoutubeParsingHelper.resetClientVersionAndKey();
6567
YoutubeParsingHelper.setNumberGenerator(new Random(1));
6668
YoutubeStreamExtractor.resetDeobfuscationCode();
67-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable"));
69+
NewPipe.init(DownloaderTestImpl.getInstance());
6870
}
6971

7072
@Test(expected = GeographicRestrictionException.class)
@@ -121,7 +123,7 @@ public static void setUp() throws Exception {
121123
YoutubeParsingHelper.resetClientVersionAndKey();
122124
YoutubeParsingHelper.setNumberGenerator(new Random(1));
123125
YoutubeStreamExtractor.resetDeobfuscationCode();
124-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "pewdiwpie"));
126+
NewPipe.init(DownloaderTestImpl.getInstance());
125127
extractor = YouTube.getStreamExtractor(URL);
126128
extractor.fetchPage();
127129
}
@@ -165,7 +167,7 @@ public static void setUp() throws Exception {
165167
YoutubeParsingHelper.resetClientVersionAndKey();
166168
YoutubeParsingHelper.setNumberGenerator(new Random(1));
167169
YoutubeStreamExtractor.resetDeobfuscationCode();
168-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "unboxing"));
170+
NewPipe.init(DownloaderTestImpl.getInstance());
169171
extractor = YouTube.getStreamExtractor(URL);
170172
extractor.fetchPage();
171173
}
@@ -219,7 +221,7 @@ public static void setUp() throws Exception {
219221
YoutubeParsingHelper.resetClientVersionAndKey();
220222
YoutubeParsingHelper.setNumberGenerator(new Random(1));
221223
YoutubeStreamExtractor.resetDeobfuscationCode();
222-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "ratingsDisabled"));
224+
NewPipe.init(DownloaderTestImpl.getInstance());
223225
extractor = YouTube.getStreamExtractor(URL);
224226
extractor.fetchPage();
225227
}
@@ -257,7 +259,7 @@ public static void setUp() throws Exception {
257259
YoutubeParsingHelper.resetClientVersionAndKey();
258260
YoutubeParsingHelper.setNumberGenerator(new Random(1));
259261
YoutubeStreamExtractor.resetDeobfuscationCode();
260-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "streamSegmentsTagesschau"));
262+
NewPipe.init(DownloaderTestImpl.getInstance());
261263
extractor = YouTube.getStreamExtractor(URL);
262264
extractor.fetchPage();
263265
}
@@ -319,7 +321,7 @@ public static void setUp() throws Exception {
319321
YoutubeParsingHelper.resetClientVersionAndKey();
320322
YoutubeParsingHelper.setNumberGenerator(new Random(1));
321323
YoutubeStreamExtractor.resetDeobfuscationCode();
322-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "streamSegmentsMaiLab"));
324+
NewPipe.init(DownloaderTestImpl.getInstance());
323325
extractor = YouTube.getStreamExtractor(URL);
324326
extractor.fetchPage();
325327
}
@@ -387,7 +389,7 @@ public static class PublicBroadcasterTest extends DefaultStreamExtractorTest {
387389
public static void setUp() throws Exception {
388390
YoutubeParsingHelper.resetClientVersionAndKey();
389391
YoutubeParsingHelper.setNumberGenerator(new Random(1));
390-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "publicBroadcast"));
392+
NewPipe.init(DownloaderTestImpl.getInstance());
391393
extractor = YouTube.getStreamExtractor(URL);
392394
YoutubeStreamExtractor.resetDeobfuscationCode();
393395
extractor.fetchPage();

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.junit.BeforeClass;
44
import org.junit.Test;
5-
import org.schabi.newpipe.downloader.DownloaderFactory;
5+
import org.schabi.newpipe.downloader.DownloaderTestImpl;
66
import org.schabi.newpipe.extractor.NewPipe;
77
import org.schabi.newpipe.extractor.StreamingService;
88
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
@@ -19,8 +19,10 @@
1919

2020
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2121

22+
// We cannot use mocks for this test because of the content playback nonce field sent in POST bodies
23+
// requests, which is generated randomly.
24+
2225
public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractorTest {
23-
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/";
2426
private static final String ID = "5qap5aO4i9A";
2527
private static final int TIMESTAMP = 1737;
2628
private static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID + "&t=" + TIMESTAMP;
@@ -31,7 +33,7 @@ public static void setUp() throws Exception {
3133
YoutubeParsingHelper.resetClientVersionAndKey();
3234
YoutubeParsingHelper.setNumberGenerator(new Random(1));
3335
YoutubeStreamExtractor.resetDeobfuscationCode();
34-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "live"));
36+
NewPipe.init(DownloaderTestImpl.getInstance());
3537
extractor = YouTube.getStreamExtractor(URL);
3638
extractor.fetchPage();
3739
}

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

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

33
import org.junit.BeforeClass;
4-
import org.schabi.newpipe.downloader.DownloaderFactory;
4+
import org.schabi.newpipe.downloader.DownloaderTestImpl;
55
import org.schabi.newpipe.extractor.NewPipe;
66
import org.schabi.newpipe.extractor.StreamingService;
77
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
@@ -19,18 +19,20 @@
1919
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2020
import static org.schabi.newpipe.extractor.stream.StreamExtractor.Privacy.UNLISTED;
2121

22+
// We cannot use mocks for this test because of the content playback nonce field sent in POST bodies
23+
// requests, which is generated randomly.
24+
2225
public class YoutubeStreamExtractorUnlistedTest extends DefaultStreamExtractorTest {
23-
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/";
24-
static final String ID = "udsB8KnIJTg";
25-
static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID;
26+
private static final String ID = "udsB8KnIJTg";
27+
private static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID;
2628
private static StreamExtractor extractor;
2729

2830
@BeforeClass
2931
public static void setUp() throws Exception {
3032
YoutubeParsingHelper.resetClientVersionAndKey();
3133
YoutubeParsingHelper.setNumberGenerator(new Random(1));
3234
YoutubeStreamExtractor.resetDeobfuscationCode();
33-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "unlisted"));
35+
NewPipe.init(DownloaderTestImpl.getInstance());
3436
extractor = YouTube.getStreamExtractor(URL);
3537
extractor.fetchPage();
3638
}

0 commit comments

Comments
 (0)