| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser; | |
| 6 | |
| 7 import android.app.Activity; | |
| 8 import android.content.Intent; | |
| 9 import android.provider.Browser; | |
| 10 import android.support.test.filters.MediumTest; | |
| 11 import android.support.test.rule.UiThreadTestRule; | |
| 12 | |
| 13 import org.junit.After; | |
| 14 import org.junit.Assert; | |
| 15 import org.junit.Before; | |
| 16 import org.junit.Rule; | |
| 17 import org.junit.Test; | |
| 18 import org.junit.runner.RunWith; | |
| 19 | |
| 20 import org.chromium.base.ApplicationStatus; | |
| 21 import org.chromium.base.test.util.CommandLineFlags; | |
| 22 import org.chromium.chrome.browser.tab.Tab; | |
| 23 import org.chromium.chrome.test.ChromeActivityTestRule; | |
| 24 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | |
| 25 import org.chromium.content.browser.test.util.Criteria; | |
| 26 import org.chromium.content.browser.test.util.CriteriaHelper; | |
| 27 import org.chromium.content.browser.test.util.DOMUtils; | |
| 28 import org.chromium.content.common.ContentSwitches; | |
| 29 import org.chromium.content_public.browser.WebContents; | |
| 30 import org.chromium.net.test.EmbeddedTestServer; | |
| 31 /** | |
| 32 * Tests for FullscreenWebContentsActivity. | |
| 33 */ | |
| 34 @RunWith(ChromeJUnit4ClassRunner.class) | |
| 35 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, | |
| 36 ContentSwitches.DISABLE_GESTURE_REQUIREMENT_FOR_MEDIA_PLAYBACK, | |
| 37 "enable-features=" + ChromeFeatureList.FULLSCREEN_ACTIVITY}) | |
| 38 public class FullscreenWebContentsActivityTest { | |
| 39 private static final String TEST_PATH = "/content/test/data/media/video-play
er.html"; | |
| 40 private static final String VIDEO_ID = "video"; | |
| 41 | |
| 42 @Rule | |
| 43 public UiThreadTestRule mUiThreadTestRule = new UiThreadTestRule(); | |
| 44 @Rule | |
| 45 public ChromeActivityTestRule<ChromeTabbedActivity> mActivityTestRule = | |
| 46 new ChromeActivityTestRule<>(ChromeTabbedActivity.class); | |
| 47 | |
| 48 private EmbeddedTestServer mTestServer; | |
| 49 private ChromeTabbedActivity mActivity; | |
| 50 | |
| 51 @Before | |
| 52 public void setUp() throws InterruptedException { | |
| 53 mTestServer = EmbeddedTestServer.createAndStartServer( | |
| 54 mActivityTestRule.getInstrumentation().getContext()); | |
| 55 mActivityTestRule.startMainActivityWithURL(mTestServer.getURL(TEST_PATH)
); | |
| 56 mActivity = mActivityTestRule.getActivity(); | |
| 57 } | |
| 58 | |
| 59 @After | |
| 60 public void tearDown() throws Exception { | |
| 61 mTestServer.stopAndDestroyServer(); | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * Manually moves a Tab from a ChromeTabbedActivity to a FullscreenWebConten
tsActivity and back. | |
| 66 */ | |
| 67 @Test | |
| 68 @MediumTest | |
| 69 public void testTransfer() throws Throwable { | |
| 70 final Tab tab = mActivityTestRule.getActivity().getActivityTab(); | |
| 71 | |
| 72 moveTabToActivity(mActivity, tab, FullscreenWebContentsActivity.class); | |
| 73 waitForActivity(FullscreenWebContentsActivity.class); | |
| 74 | |
| 75 final FullscreenWebContentsActivity fullscreenActivity = | |
| 76 (FullscreenWebContentsActivity) ApplicationStatus.getLastTracked
FocusedActivity(); | |
| 77 Assert.assertEquals(tab.getId(), fullscreenActivity.getActivityTab().get
Id()); | |
| 78 | |
| 79 moveTabToActivity(fullscreenActivity, tab, ChromeTabbedActivity.class); | |
| 80 waitForActivity(ChromeTabbedActivity.class); | |
| 81 } | |
| 82 | |
| 83 /** | |
| 84 * Manually moves the Tab to an Activity. | |
| 85 */ | |
| 86 private void moveTabToActivity(final Activity fromActivity, final Tab tab, | |
| 87 final Class<? extends ChromeActivity> targetClass) throws Throwable
{ | |
| 88 mUiThreadTestRule.runOnUiThread(new Runnable() { | |
| 89 @Override | |
| 90 public void run() { | |
| 91 Intent intent = new Intent(fromActivity, targetClass); | |
| 92 intent.putExtra( | |
| 93 IntentHandler.EXTRA_PARENT_COMPONENT, fromActivity.getCo
mponentName()); | |
| 94 intent.putExtra(Browser.EXTRA_APPLICATION_ID, fromActivity.getPa
ckageName()); | |
| 95 | |
| 96 if (targetClass == FullscreenWebContentsActivity.class) { | |
| 97 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 98 } | |
| 99 | |
| 100 tab.detachAndStartReparenting(intent, null, null); | |
| 101 } | |
| 102 }); | |
| 103 } | |
| 104 | |
| 105 /** | |
| 106 * Waits for an Activity of the given class to be started and for it to have
a Tab. | |
| 107 */ | |
| 108 private static void waitForActivity(final Class<? extends ChromeActivity> ac
tivityClass) { | |
| 109 CriteriaHelper.pollUiThread(new Criteria() { | |
| 110 @Override | |
| 111 public boolean isSatisfied() { | |
| 112 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedA
ctivity(); | |
| 113 if (lastActivity.getClass() != activityClass) return false; | |
| 114 | |
| 115 return ((ChromeActivity) lastActivity).getActivityTab() != null; | |
| 116 } | |
| 117 }); | |
| 118 } | |
| 119 | |
| 120 /** | |
| 121 * Toggles fullscreen to check FullscreenWebContentsActivity has been starte
d. | |
| 122 */ | |
| 123 @Test | |
| 124 @MediumTest | |
| 125 public void testFullscreen() throws Throwable { | |
| 126 enterFullscreen(); | |
| 127 // TODO(peconn): Test leaving fullscreen by pressing Back | |
| 128 // TODO(peconn): Test leaving fullscreen by DOMUtils.exitFullscreen(WebC
ontents) | |
| 129 } | |
| 130 | |
| 131 /** | |
| 132 * Clicks on the fullscreen button in the webpage and waits for the | |
| 133 * FullscreenWebContentsActivity to be started. | |
| 134 */ | |
| 135 private void enterFullscreen() throws Throwable { | |
| 136 // Start playback to guarantee it's properly loaded. | |
| 137 WebContents webContents = mActivity.getCurrentContentViewCore().getWebCo
ntents(); | |
| 138 Assert.assertTrue(DOMUtils.isMediaPaused(webContents, VIDEO_ID)); | |
| 139 DOMUtils.playMedia(webContents, VIDEO_ID); | |
| 140 DOMUtils.waitForMediaPlay(webContents, VIDEO_ID); | |
| 141 | |
| 142 // Trigger requestFullscreen() via a click on a button. | |
| 143 Assert.assertTrue(DOMUtils.clickNode(mActivity.getCurrentContentViewCore
(), "fullscreen")); | |
| 144 waitForActivity(FullscreenWebContentsActivity.class); | |
| 145 } | |
| 146 | |
| 147 /** | |
| 148 * Tests that no flags change on the ChromeTabbedActivity when going fullscr
een. | |
| 149 */ | |
| 150 @Test | |
| 151 @MediumTest | |
| 152 public void testFullscreenFlags() throws Throwable { | |
| 153 int old = mActivity.getTabsView().getSystemUiVisibility(); | |
| 154 | |
| 155 enterFullscreen(); | |
| 156 | |
| 157 Assert.assertEquals(old, mActivity.getTabsView().getSystemUiVisibility()
); | |
| 158 // TODO(peconn): Test again after leaving fullscreen. | |
| 159 } | |
| 160 } | |
| OLD | NEW |