OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.pm.ActivityInfo; | 7 import android.content.pm.ActivityInfo; |
8 import android.graphics.Rect; | 8 import android.graphics.Rect; |
9 import android.support.test.InstrumentationRegistry; | 9 import android.support.test.InstrumentationRegistry; |
10 import android.support.test.filters.MediumTest; | 10 import android.support.test.filters.MediumTest; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 @Before | 129 @Before |
130 public void setUp() throws Exception { | 130 public void setUp() throws Exception { |
131 mActivityTestRule.launchContentShellWithUrlSync(TEST_URL); | 131 mActivityTestRule.launchContentShellWithUrlSync(TEST_URL); |
132 } | 132 } |
133 | 133 |
134 @Test | 134 @Test |
135 @MediumTest | 135 @MediumTest |
136 @Feature({"VideoFullscreenOrientationLock"}) | 136 @Feature({"VideoFullscreenOrientationLock"}) |
137 public void testEnterExitFullscreenWithControlsButton() throws Exception { | 137 public void testEnterExitFullscreenWithControlsButton() throws Exception { |
138 if (DeviceFormFactor.isTablet(InstrumentationRegistry.getInstrumentation
().getContext())) { | 138 if (DeviceFormFactor.isTablet()) { |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 // Start playback to guarantee it's properly loaded. | 142 // Start playback to guarantee it's properly loaded. |
143 Assert.assertTrue(DOMUtils.isMediaPaused(mActivityTestRule.getWebContent
s(), VIDEO_ID)); | 143 Assert.assertTrue(DOMUtils.isMediaPaused(mActivityTestRule.getWebContent
s(), VIDEO_ID)); |
144 DOMUtils.playMedia(mActivityTestRule.getWebContents(), VIDEO_ID); | 144 DOMUtils.playMedia(mActivityTestRule.getWebContents(), VIDEO_ID); |
145 DOMUtils.waitForMediaPlay(mActivityTestRule.getWebContents(), VIDEO_ID); | 145 DOMUtils.waitForMediaPlay(mActivityTestRule.getWebContents(), VIDEO_ID); |
146 | 146 |
147 // Simulate click on fullscreen button. | 147 // Simulate click on fullscreen button. |
148 Assert.assertTrue(clickFullscreenButton()); | 148 Assert.assertTrue(clickFullscreenButton()); |
149 waitForContentsFullscreenState(true); | 149 waitForContentsFullscreenState(true); |
150 | 150 |
151 // Should be locked to landscape now, `waitUntilLockedToLandscape` will
throw otherwise. | 151 // Should be locked to landscape now, `waitUntilLockedToLandscape` will
throw otherwise. |
152 waitUntilLockedToLandscape(); | 152 waitUntilLockedToLandscape(); |
153 | 153 |
154 // Because of the fullscreen animation, the click on the exit fullscreen
button will fail | 154 // Because of the fullscreen animation, the click on the exit fullscreen
button will fail |
155 // roughly 10% of the time. Settling down the UI reduces the flake to 0%
. | 155 // roughly 10% of the time. Settling down the UI reduces the flake to 0%
. |
156 UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation()); | 156 UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation()); |
157 | 157 |
158 // Leave fullscreen by clicking back on the button. | 158 // Leave fullscreen by clicking back on the button. |
159 Assert.assertTrue(clickFullscreenButton()); | 159 Assert.assertTrue(clickFullscreenButton()); |
160 waitForContentsFullscreenState(false); | 160 waitForContentsFullscreenState(false); |
161 waitUntilUnlocked(); | 161 waitUntilUnlocked(); |
162 } | 162 } |
163 | 163 |
164 @Test | 164 @Test |
165 @MediumTest | 165 @MediumTest |
166 @Feature({"VideoFullscreenOrientationLock"}) | 166 @Feature({"VideoFullscreenOrientationLock"}) |
167 public void testEnterExitFullscreenWithAPI() throws Exception { | 167 public void testEnterExitFullscreenWithAPI() throws Exception { |
168 if (DeviceFormFactor.isTablet(InstrumentationRegistry.getInstrumentation
().getContext())) { | 168 if (DeviceFormFactor.isTablet()) { |
169 return; | 169 return; |
170 } | 170 } |
171 | 171 |
172 // Start playback to guarantee it's properly loaded. | 172 // Start playback to guarantee it's properly loaded. |
173 Assert.assertTrue(DOMUtils.isMediaPaused(mActivityTestRule.getWebContent
s(), VIDEO_ID)); | 173 Assert.assertTrue(DOMUtils.isMediaPaused(mActivityTestRule.getWebContent
s(), VIDEO_ID)); |
174 DOMUtils.playMedia(mActivityTestRule.getWebContents(), VIDEO_ID); | 174 DOMUtils.playMedia(mActivityTestRule.getWebContents(), VIDEO_ID); |
175 DOMUtils.waitForMediaPlay(mActivityTestRule.getWebContents(), VIDEO_ID); | 175 DOMUtils.waitForMediaPlay(mActivityTestRule.getWebContents(), VIDEO_ID); |
176 | 176 |
177 // Trigger requestFullscreen() via a click on a button. | 177 // Trigger requestFullscreen() via a click on a button. |
178 Assert.assertTrue(DOMUtils.clickNode(mActivityTestRule.getContentViewCor
e(), "fullscreen")); | 178 Assert.assertTrue(DOMUtils.clickNode(mActivityTestRule.getContentViewCor
e(), "fullscreen")); |
179 waitForContentsFullscreenState(true); | 179 waitForContentsFullscreenState(true); |
180 | 180 |
181 // Should be locked to landscape now, `waitUntilLockedToLandscape` will
throw otherwise. | 181 // Should be locked to landscape now, `waitUntilLockedToLandscape` will
throw otherwise. |
182 waitUntilLockedToLandscape(); | 182 waitUntilLockedToLandscape(); |
183 | 183 |
184 // Leave fullscreen from API. | 184 // Leave fullscreen from API. |
185 DOMUtils.exitFullscreen(mActivityTestRule.getWebContents()); | 185 DOMUtils.exitFullscreen(mActivityTestRule.getWebContents()); |
186 waitForContentsFullscreenState(false); | 186 waitForContentsFullscreenState(false); |
187 waitUntilUnlocked(); | 187 waitUntilUnlocked(); |
188 } | 188 } |
189 | 189 |
190 @Test | 190 @Test |
191 @MediumTest | 191 @MediumTest |
192 @Feature({"VideoFullscreenOrientationLock"}) | 192 @Feature({"VideoFullscreenOrientationLock"}) |
193 public void testExitFullscreenByRemovingVideo() throws Exception { | 193 public void testExitFullscreenByRemovingVideo() throws Exception { |
194 if (DeviceFormFactor.isTablet(InstrumentationRegistry.getInstrumentation
().getContext())) { | 194 if (DeviceFormFactor.isTablet()) { |
195 return; | 195 return; |
196 } | 196 } |
197 | 197 |
198 // Start playback to guarantee it's properly loaded. | 198 // Start playback to guarantee it's properly loaded. |
199 Assert.assertTrue(DOMUtils.isMediaPaused(mActivityTestRule.getWebContent
s(), VIDEO_ID)); | 199 Assert.assertTrue(DOMUtils.isMediaPaused(mActivityTestRule.getWebContent
s(), VIDEO_ID)); |
200 DOMUtils.playMedia(mActivityTestRule.getWebContents(), VIDEO_ID); | 200 DOMUtils.playMedia(mActivityTestRule.getWebContents(), VIDEO_ID); |
201 DOMUtils.waitForMediaPlay(mActivityTestRule.getWebContents(), VIDEO_ID); | 201 DOMUtils.waitForMediaPlay(mActivityTestRule.getWebContents(), VIDEO_ID); |
202 | 202 |
203 // Trigger requestFullscreen() via a click on a button. | 203 // Trigger requestFullscreen() via a click on a button. |
204 Assert.assertTrue(DOMUtils.clickNode(mActivityTestRule.getContentViewCor
e(), "fullscreen")); | 204 Assert.assertTrue(DOMUtils.clickNode(mActivityTestRule.getContentViewCor
e(), "fullscreen")); |
205 waitForContentsFullscreenState(true); | 205 waitForContentsFullscreenState(true); |
206 | 206 |
207 // Should be locked to landscape now, `waitUntilLockedToLandscape` will
throw otherwise. | 207 // Should be locked to landscape now, `waitUntilLockedToLandscape` will
throw otherwise. |
208 waitUntilLockedToLandscape(); | 208 waitUntilLockedToLandscape(); |
209 | 209 |
210 // Leave fullscreen by removing video element from page. | 210 // Leave fullscreen by removing video element from page. |
211 JavaScriptUtils.executeJavaScriptAndWaitForResult( | 211 JavaScriptUtils.executeJavaScriptAndWaitForResult( |
212 mActivityTestRule.getWebContents(), "document.body.innerHTML = '
';"); | 212 mActivityTestRule.getWebContents(), "document.body.innerHTML = '
';"); |
213 waitForContentsFullscreenState(false); | 213 waitForContentsFullscreenState(false); |
214 waitUntilUnlocked(); | 214 waitUntilUnlocked(); |
215 } | 215 } |
216 | 216 |
217 @Test | 217 @Test |
218 @MediumTest | 218 @MediumTest |
219 @Feature({"VideoFullscreenOrientationLock"}) | 219 @Feature({"VideoFullscreenOrientationLock"}) |
220 public void testExitFullscreenWithNavigation() throws Exception { | 220 public void testExitFullscreenWithNavigation() throws Exception { |
221 if (DeviceFormFactor.isTablet(InstrumentationRegistry.getInstrumentation
().getContext())) { | 221 if (DeviceFormFactor.isTablet()) { |
222 return; | 222 return; |
223 } | 223 } |
224 | 224 |
225 // Start playback to guarantee it's properly loaded. | 225 // Start playback to guarantee it's properly loaded. |
226 Assert.assertTrue(DOMUtils.isMediaPaused(mActivityTestRule.getWebContent
s(), VIDEO_ID)); | 226 Assert.assertTrue(DOMUtils.isMediaPaused(mActivityTestRule.getWebContent
s(), VIDEO_ID)); |
227 DOMUtils.playMedia(mActivityTestRule.getWebContents(), VIDEO_ID); | 227 DOMUtils.playMedia(mActivityTestRule.getWebContents(), VIDEO_ID); |
228 DOMUtils.waitForMediaPlay(mActivityTestRule.getWebContents(), VIDEO_ID); | 228 DOMUtils.waitForMediaPlay(mActivityTestRule.getWebContents(), VIDEO_ID); |
229 | 229 |
230 // Trigger requestFullscreen() via a click on a button. | 230 // Trigger requestFullscreen() via a click on a button. |
231 Assert.assertTrue(DOMUtils.clickNode(mActivityTestRule.getContentViewCor
e(), "fullscreen")); | 231 Assert.assertTrue(DOMUtils.clickNode(mActivityTestRule.getContentViewCor
e(), "fullscreen")); |
232 waitForContentsFullscreenState(true); | 232 waitForContentsFullscreenState(true); |
233 | 233 |
234 // Should be locked to landscape now, `waitUntilLockedToLandscape` will
throw otherwise. | 234 // Should be locked to landscape now, `waitUntilLockedToLandscape` will
throw otherwise. |
235 waitUntilLockedToLandscape(); | 235 waitUntilLockedToLandscape(); |
236 | 236 |
237 // Leave fullscreen by navigating page. | 237 // Leave fullscreen by navigating page. |
238 JavaScriptUtils.executeJavaScriptAndWaitForResult( | 238 JavaScriptUtils.executeJavaScriptAndWaitForResult( |
239 mActivityTestRule.getWebContents(), "location.reload();"); | 239 mActivityTestRule.getWebContents(), "location.reload();"); |
240 waitForContentsFullscreenState(false); | 240 waitForContentsFullscreenState(false); |
241 waitUntilUnlocked(); | 241 waitUntilUnlocked(); |
242 } | 242 } |
243 } | 243 } |
OLD | NEW |