// Copyright 2015 The Chromium Authors
// 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;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.LargeTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.TabTitleObserver;
import org.chromium.content_public.browser.test.util.DOMUtils;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.concurrent.TimeoutException;
/** Simple tests of html5 video. */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class VideoTest {
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Test
@Feature({"Media", "Media-Video", "Main"})
@LargeTest
public void testLoadMediaUrl() throws TimeoutException {
EmbeddedTestServer testServer =
EmbeddedTestServer.createAndStartServer(
ApplicationProvider.getApplicationContext());
Tab tab = mActivityTestRule.getActivity().getActivityTab();
TabTitleObserver titleObserver = new TabTitleObserver(tab, "ready_to_play");
mActivityTestRule.loadUrl(
testServer.getURL("/chrome/test/data/android/media/video-play.html"));
titleObserver.waitForTitleUpdate(5);
Assert.assertEquals("ready_to_play", ChromeTabUtils.getTitleOnUiThread(tab));
titleObserver = new TabTitleObserver(tab, "ended");
DOMUtils.clickNode(tab.getWebContents(), "button1");
// Now the video will play for 5 secs.
// Makes sure that the video ends and title was changed.
titleObserver.waitForTitleUpdate(15);
Assert.assertEquals("ended", ChromeTabUtils.getTitleOnUiThread(tab));
}
@Before
public void setUp() throws InterruptedException {
mActivityTestRule.startMainActivityOnBlankPage();
}
}