1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.messaging.util; 18 19 import android.test.suitebuilder.annotation.SmallTest; 20 21 import com.android.messaging.BugleTestCase; 22 23 /* 24 * Class for testing YouTubeUtil. 25 */ 26 @SmallTest 27 public class YouTubeUtilTest extends BugleTestCase { 28 public void testGetYoutubePreviewImageLink() { 29 final String videoId = "dQw4w9WgXcQ"; 30 final String videoThumbnailUrl = YouTubeUtil.YOUTUBE_STATIC_THUMBNAIL_PREFIX + videoId 31 + YouTubeUtil.YOUTUBE_STATIC_THUMBNAIL_END; 32 33 // Check known valid youtube links to videos 34 assertEquals( 35 YouTubeUtil.getYoutubePreviewImageLink("http://www.youtube.com/watch?v=" + videoId), 36 videoThumbnailUrl); 37 assertEquals( 38 YouTubeUtil.getYoutubePreviewImageLink("https://www.youtube.com/watch?v=" + videoId 39 + "&feature=youtu.be"), videoThumbnailUrl); 40 assertEquals( 41 YouTubeUtil.getYoutubePreviewImageLink("www.youtube.com/watch?v=" + videoId), 42 videoThumbnailUrl); 43 assertEquals( 44 YouTubeUtil.getYoutubePreviewImageLink("http://www.youtube.com/embed/" + videoId), 45 videoThumbnailUrl); 46 assertEquals(YouTubeUtil.getYoutubePreviewImageLink("http://www.youtube.com/v/" + videoId), 47 videoThumbnailUrl); 48 assertEquals( 49 YouTubeUtil.getYoutubePreviewImageLink("https://youtube.googleapis.com/v/" 50 + videoId), videoThumbnailUrl); 51 assertEquals( 52 YouTubeUtil.getYoutubePreviewImageLink("http://www.youtube.com/apiplayer?video_id=" 53 + videoId), videoThumbnailUrl); 54 // This is the type of links that are used as shares from YouTube and will be the most 55 // likely case that we see 56 assertEquals(YouTubeUtil.getYoutubePreviewImageLink("http://youtu.be/" + videoId), 57 videoThumbnailUrl); 58 59 // Try links that shouldn't work 60 assertNull(YouTubeUtil.getYoutubePreviewImageLink("http://www.youtube.com")); 61 } 62 }