Commit e556124a authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Video Tutorials : Added tests for video player view binder

Bug: 1142645
Change-Id: I8c26e00a7239f2f37180ddbb37f52e92b9973bd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2497433
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarCalder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821017}
parent a5e4729d
...@@ -172,6 +172,7 @@ if (is_android) { ...@@ -172,6 +172,7 @@ if (is_android) {
"android/java/src/org/chromium/chrome/browser/video_tutorials/iph/VideoIPHTest.java", "android/java/src/org/chromium/chrome/browser/video_tutorials/iph/VideoIPHTest.java",
"android/java/src/org/chromium/chrome/browser/video_tutorials/languages/LanguagePickerTest.java", "android/java/src/org/chromium/chrome/browser/video_tutorials/languages/LanguagePickerTest.java",
"android/java/src/org/chromium/chrome/browser/video_tutorials/list/TutorialListCoordinatorTest.java", "android/java/src/org/chromium/chrome/browser/video_tutorials/list/TutorialListCoordinatorTest.java",
"android/java/src/org/chromium/chrome/browser/video_tutorials/player/VideoPlayerViewBinderTest.java",
] ]
deps = [ deps = [
":java", ":java",
...@@ -180,6 +181,7 @@ if (is_android) { ...@@ -180,6 +181,7 @@ if (is_android) {
"//chrome/browser/video_tutorials:java", "//chrome/browser/video_tutorials:java",
"//chrome/browser/video_tutorials:test_support_java", "//chrome/browser/video_tutorials:test_support_java",
"//chrome/test/android:chrome_java_test_support", "//chrome/test/android:chrome_java_test_support",
"//components/thin_webview:java",
"//content/public/test/android:content_java_test_support", "//content/public/test/android:content_java_test_support",
"//third_party/android_deps:androidx_annotation_annotation_java", "//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/android_deps:androidx_recyclerview_recyclerview_java", "//third_party/android_deps:androidx_recyclerview_recyclerview_java",
...@@ -190,6 +192,7 @@ if (is_android) { ...@@ -190,6 +192,7 @@ if (is_android) {
"//third_party/hamcrest:hamcrest_core_java", "//third_party/hamcrest:hamcrest_core_java",
"//third_party/junit", "//third_party/junit",
"//third_party/mockito:mockito_java", "//third_party/mockito:mockito_java",
"//ui/android:ui_java",
"//ui/android:ui_java_test_support", "//ui/android:ui_java_test_support",
] ]
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<FrameLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loading_root"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/background_dark"> android:background="@android:color/background_dark">
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.video_tutorials.player;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.test.filters.SmallTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.chromium.base.test.UiThreadTest;
import org.chromium.chrome.browser.video_tutorials.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.components.thinwebview.ThinWebView;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
import org.chromium.ui.test.util.DummyUiActivity;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Tests for {@link VideoPlayerViewBinder}.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
public class VideoPlayerViewBinderTest {
@Rule
public ActivityTestRule<DummyUiActivity> mActivityTestRule =
new ActivityTestRule<>(DummyUiActivity.class);
private Activity mActivity;
private View mMainView;
private View mLoadingView;
private View mLanguagePickerView;
private View mControls;
private PropertyModel mModel;
private PropertyModelChangeProcessor mMCP;
@Mock
private ThinWebView mThinWebView;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mModel = new PropertyModel(VideoPlayerProperties.ALL_KEYS);
mActivity = mActivityTestRule.getActivity();
TestThreadUtils.runOnUiThreadBlocking(() -> {
FrameLayout thinWebViewLayout = new FrameLayout(mActivity);
Mockito.when(mThinWebView.getView()).thenReturn(thinWebViewLayout);
VideoPlayerView videoPlayerView = new VideoPlayerView(mActivity, mModel, mThinWebView);
mMainView = videoPlayerView.getView();
mActivity.setContentView(mMainView);
mLanguagePickerView = mMainView.findViewById(R.id.language_picker);
mLoadingView = mMainView.findViewById(R.id.loading_root);
mControls = mMainView.findViewById(R.id.player_root);
mLanguagePickerView.setVisibility(View.GONE);
mLoadingView.setVisibility(View.GONE);
mControls.setVisibility(View.GONE);
mMCP = PropertyModelChangeProcessor.create(
mModel, videoPlayerView, new VideoPlayerViewBinder());
});
}
@After
public void tearDown() throws Exception {
mMCP.destroy();
}
@Test
@UiThreadTest
@SmallTest
public void testLoadingAnimation() {
mModel.set(VideoPlayerProperties.SHOW_LOADING_SCREEN, true);
assertEquals(View.VISIBLE, mLoadingView.getVisibility());
mModel.set(VideoPlayerProperties.SHOW_LOADING_SCREEN, false);
assertEquals(View.GONE, mLoadingView.getVisibility());
}
@Test
@UiThreadTest
@SmallTest
public void testLanguagePickerVisibility() {
mModel.set(VideoPlayerProperties.SHOW_LANGUAGE_PICKER, true);
assertEquals(View.VISIBLE, mLanguagePickerView.getVisibility());
}
@Test
@UiThreadTest
@SmallTest
public void testControlsVisibility() {
mModel.set(VideoPlayerProperties.SHOW_MEDIA_CONTROLS, true);
assertEquals(View.VISIBLE, mControls.getVisibility());
}
@Test
@UiThreadTest
@SmallTest
public void testTryNowButton() {
View tryNowButton = mControls.findViewById(R.id.try_now);
mModel.set(VideoPlayerProperties.SHOW_TRY_NOW, true);
assertEquals(View.VISIBLE, tryNowButton.getVisibility());
AtomicBoolean buttonClicked = new AtomicBoolean();
mModel.set(VideoPlayerProperties.CALLBACK_TRY_NOW, () -> buttonClicked.set(true));
tryNowButton.performClick();
assertTrue(buttonClicked.get());
}
@Test
@UiThreadTest
@SmallTest
public void testWatchNextButton() {
View watchNextButton = mControls.findViewById(R.id.watch_next);
mModel.set(VideoPlayerProperties.SHOW_WATCH_NEXT, true);
assertEquals(View.VISIBLE, watchNextButton.getVisibility());
AtomicBoolean buttonClicked = new AtomicBoolean();
mModel.set(VideoPlayerProperties.CALLBACK_WATCH_NEXT, () -> buttonClicked.set(true));
watchNextButton.performClick();
assertTrue(buttonClicked.get());
}
@Test
@UiThreadTest
@SmallTest
public void testChangeLanguageButton() {
TextView changeLanguage = mControls.findViewById(R.id.change_language);
String languageName = "XYZ";
mModel.set(VideoPlayerProperties.SHOW_CHANGE_LANGUAGE, true);
mModel.set(VideoPlayerProperties.CHANGE_LANGUAGE_BUTTON_TEXT, languageName);
assertEquals(View.VISIBLE, changeLanguage.getVisibility());
assertTrue(TextUtils.equals(languageName, changeLanguage.getText()));
AtomicBoolean buttonClicked = new AtomicBoolean();
mModel.set(VideoPlayerProperties.CALLBACK_CHANGE_LANGUAGE, () -> buttonClicked.set(true));
changeLanguage.performClick();
assertTrue(buttonClicked.get());
}
@Test
@UiThreadTest
@SmallTest
public void testShareButton() {
View shareButton = mControls.findViewById(R.id.share_button);
AtomicBoolean buttonClicked = new AtomicBoolean();
mModel.set(VideoPlayerProperties.CALLBACK_SHARE, () -> buttonClicked.set(true));
shareButton.performClick();
assertTrue(buttonClicked.get());
}
@Test
@UiThreadTest
@SmallTest
public void testCloseButton() {
View closeButton = mControls.findViewById(R.id.close_button);
AtomicBoolean buttonClicked = new AtomicBoolean();
mModel.set(VideoPlayerProperties.CALLBACK_CLOSE, () -> buttonClicked.set(true));
closeButton.performClick();
assertTrue(buttonClicked.get());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment