OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.android_webview.test; | 5 package org.chromium.android_webview.test; |
6 | 6 |
7 import android.os.Build; | 7 import android.os.Build; |
8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
9 import android.view.KeyEvent; | 9 import android.view.KeyEvent; |
10 import android.view.View; | 10 import android.view.View; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 183 } |
184 | 184 |
185 @MediumTest | 185 @MediumTest |
186 @Feature({"AndroidWebView"}) | 186 @Feature({"AndroidWebView"}) |
187 public void testOnShowCustomViewAndPlayWithHtmlControl_videoInsideDiv() thro
ws Throwable { | 187 public void testOnShowCustomViewAndPlayWithHtmlControl_videoInsideDiv() thro
ws Throwable { |
188 doTestOnShowCustomViewAndPlayWithHtmlControl(VIDEO_INSIDE_DIV_TEST_URL); | 188 doTestOnShowCustomViewAndPlayWithHtmlControl(VIDEO_INSIDE_DIV_TEST_URL); |
189 } | 189 } |
190 | 190 |
191 public void doTestOnShowCustomViewAndPlayWithHtmlControl(String videoTestUrl
) throws Throwable { | 191 public void doTestOnShowCustomViewAndPlayWithHtmlControl(String videoTestUrl
) throws Throwable { |
192 doOnShowCustomViewTest(videoTestUrl); | 192 doOnShowCustomViewTest(videoTestUrl); |
193 assertTrue(DOMUtils.isVideoPaused(getWebContentsOnUiThread(), VIDEO_ID))
; | 193 assertTrue(DOMUtils.isMediaPaused(getWebContentsOnUiThread(), VIDEO_ID))
; |
194 | 194 |
195 tapPlayButton(); | 195 tapPlayButton(); |
196 assertTrue(DOMUtils.waitForVideoPlay(getWebContentsOnUiThread(), VIDEO_I
D)); | 196 assertTrue(DOMUtils.waitForMediaPlay(getWebContentsOnUiThread(), VIDEO_I
D)); |
197 } | 197 } |
198 | 198 |
199 @MediumTest | 199 @MediumTest |
200 @Feature({"AndroidWebView"}) | 200 @Feature({"AndroidWebView"}) |
201 public void testHolePunchingSurfaceNotCreatedForClearVideo() | 201 public void testHolePunchingSurfaceNotCreatedForClearVideo() |
202 throws Throwable { | 202 throws Throwable { |
203 loadTestPage(VIDEO_TEST_URL); | 203 loadTestPage(VIDEO_TEST_URL); |
204 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); | 204 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); |
205 | 205 |
206 // Play and verify that a surface view for hole punching is not created. | 206 // Play and verify that a surface view for hole punching is not created. |
207 // Note that VIDEO_TEST_URL contains clear video. | 207 // Note that VIDEO_TEST_URL contains clear video. |
208 tapPlayButton(); | 208 tapPlayButton(); |
209 assertTrue(DOMUtils.waitForVideoPlay(getWebContentsOnUiThread(), VIDEO_I
D)); | 209 assertTrue(DOMUtils.waitForMediaPlay(getWebContentsOnUiThread(), VIDEO_I
D)); |
210 // Wait to ensure that the surface view is not added asynchronously. | 210 // Wait to ensure that the surface view is not added asynchronously. |
211 VideoSurfaceViewUtils.waitAndAssertContainsZeroVideoHoleSurfaceViews(thi
s, | 211 VideoSurfaceViewUtils.waitAndAssertContainsZeroVideoHoleSurfaceViews(thi
s, |
212 mTestContainerView); | 212 mTestContainerView); |
213 } | 213 } |
214 | 214 |
215 @MediumTest | 215 @MediumTest |
216 @Feature({"AndroidWebView"}) | 216 @Feature({"AndroidWebView"}) |
217 public void testOnShowCustomViewTransfersHolePunchingSurfaceForVideoInsideDi
v() | 217 public void testOnShowCustomViewTransfersHolePunchingSurfaceForVideoInsideDi
v() |
218 throws Throwable { | 218 throws Throwable { |
219 getInstrumentation().runOnMainSync(new Runnable() { | 219 getInstrumentation().runOnMainSync(new Runnable() { |
220 @Override | 220 @Override |
221 public void run() { | 221 public void run() { |
222 mTestContainerView.getAwContents().getSettings().setForceVideoOv
erlayForTests(true); | 222 mTestContainerView.getAwContents().getSettings().setForceVideoOv
erlayForTests(true); |
223 } | 223 } |
224 }); | 224 }); |
225 | 225 |
226 loadTestPage(VIDEO_INSIDE_DIV_TEST_URL); | 226 loadTestPage(VIDEO_INSIDE_DIV_TEST_URL); |
227 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); | 227 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); |
228 | 228 |
229 // Play and verify that there is a surface view for hole punching. | 229 // Play and verify that there is a surface view for hole punching. |
230 tapPlayButton(); | 230 tapPlayButton(); |
231 assertTrue(DOMUtils.waitForVideoPlay(getWebContentsOnUiThread(), VIDEO_I
D)); | 231 assertTrue(DOMUtils.waitForMediaPlay(getWebContentsOnUiThread(), VIDEO_I
D)); |
232 VideoSurfaceViewUtils.pollAndAssertContainsOneVideoHoleSurfaceView(this, | 232 VideoSurfaceViewUtils.pollAndAssertContainsOneVideoHoleSurfaceView(this, |
233 mTestContainerView); | 233 mTestContainerView); |
234 | 234 |
235 // Enter fullscreen and verify that the hole punching surface is transfe
rred. Note | 235 // Enter fullscreen and verify that the hole punching surface is transfe
rred. Note |
236 // that VIDEO_INSIDE_DIV_TEST_URL goes fullscreen on a <div> element, so
in fullscreen | 236 // that VIDEO_INSIDE_DIV_TEST_URL goes fullscreen on a <div> element, so
in fullscreen |
237 // the video will still be embedded in the page and the hole punching su
rface required. | 237 // the video will still be embedded in the page and the hole punching su
rface required. |
238 // We need to transfer the external surface so that scrolling is synchro
nized with the | 238 // We need to transfer the external surface so that scrolling is synchro
nized with the |
239 // new container view. | 239 // new container view. |
240 DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID)
; | 240 DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID)
; |
241 mContentsClient.waitForCustomViewShown(); | 241 mContentsClient.waitForCustomViewShown(); |
(...skipping 13 matching lines...) Expand all Loading... |
255 public void run() { | 255 public void run() { |
256 mTestContainerView.getAwContents().getSettings().setForceVideoOv
erlayForTests(true); | 256 mTestContainerView.getAwContents().getSettings().setForceVideoOv
erlayForTests(true); |
257 } | 257 } |
258 }); | 258 }); |
259 | 259 |
260 loadTestPage(VIDEO_TEST_URL); | 260 loadTestPage(VIDEO_TEST_URL); |
261 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); | 261 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); |
262 | 262 |
263 // Play and verify that there is a surface view for hole punching. | 263 // Play and verify that there is a surface view for hole punching. |
264 tapPlayButton(); | 264 tapPlayButton(); |
265 assertTrue(DOMUtils.waitForVideoPlay(getWebContentsOnUiThread(), VIDEO_I
D)); | 265 assertTrue(DOMUtils.waitForMediaPlay(getWebContentsOnUiThread(), VIDEO_I
D)); |
266 VideoSurfaceViewUtils.pollAndAssertContainsOneVideoHoleSurfaceView(this, | 266 VideoSurfaceViewUtils.pollAndAssertContainsOneVideoHoleSurfaceView(this, |
267 mTestContainerView); | 267 mTestContainerView); |
268 | 268 |
269 // Enter fullscreen and verify that the surface view is removed. Note th
at | 269 // Enter fullscreen and verify that the surface view is removed. Note th
at |
270 // VIDEO_TEST_URL goes fullscreen on the <video> element, so in fullscre
en | 270 // VIDEO_TEST_URL goes fullscreen on the <video> element, so in fullscre
en |
271 // the video will not be embedded in the page and the external surface | 271 // the video will not be embedded in the page and the external surface |
272 // not longer required. | 272 // not longer required. |
273 DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID)
; | 273 DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID)
; |
274 mContentsClient.waitForCustomViewShown(); | 274 mContentsClient.waitForCustomViewShown(); |
275 View customView = mContentsClient.getCustomView(); | 275 View customView = mContentsClient.getCustomView(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 View customView = mContentsClient.getCustomView(); | 328 View customView = mContentsClient.getCustomView(); |
329 | 329 |
330 // No power save blocker is active before playback starts. | 330 // No power save blocker is active before playback starts. |
331 assertKeepScreenOnActive(customView, false); | 331 assertKeepScreenOnActive(customView, false); |
332 | 332 |
333 // Play and verify that there is an active power save blocker. | 333 // Play and verify that there is an active power save blocker. |
334 tapPlayButton(); | 334 tapPlayButton(); |
335 assertWaitForKeepScreenOnActive(customView, true); | 335 assertWaitForKeepScreenOnActive(customView, true); |
336 | 336 |
337 // Stop the video and verify that the power save blocker is gone. | 337 // Stop the video and verify that the power save blocker is gone. |
338 DOMUtils.pauseVideo(getWebContentsOnUiThread(), VIDEO_ID); | 338 DOMUtils.pauseMedia(getWebContentsOnUiThread(), VIDEO_ID); |
339 assertWaitForKeepScreenOnActive(customView, false); | 339 assertWaitForKeepScreenOnActive(customView, false); |
340 } | 340 } |
341 | 341 |
342 @MediumTest | 342 @MediumTest |
343 @Feature({"AndroidWebView"}) | 343 @Feature({"AndroidWebView"}) |
344 public void testPowerSaveBlockerIsEnabledDuringEmbeddedPlayback() | 344 public void testPowerSaveBlockerIsEnabledDuringEmbeddedPlayback() |
345 throws Throwable { | 345 throws Throwable { |
346 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); | 346 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); |
347 loadTestPage(VIDEO_INSIDE_DIV_TEST_URL); | 347 loadTestPage(VIDEO_INSIDE_DIV_TEST_URL); |
348 | 348 |
349 // No power save blocker is active before playback starts. | 349 // No power save blocker is active before playback starts. |
350 assertKeepScreenOnActive(mTestContainerView, false); | 350 assertKeepScreenOnActive(mTestContainerView, false); |
351 | 351 |
352 // Play and verify that there is an active power save blocker. | 352 // Play and verify that there is an active power save blocker. |
353 tapPlayButton(); | 353 tapPlayButton(); |
354 assertWaitForKeepScreenOnActive(mTestContainerView, true); | 354 assertWaitForKeepScreenOnActive(mTestContainerView, true); |
355 | 355 |
356 // Stop the video and verify that the power save blocker is gone. | 356 // Stop the video and verify that the power save blocker is gone. |
357 DOMUtils.pauseVideo(getWebContentsOnUiThread(), VIDEO_ID); | 357 DOMUtils.pauseMedia(getWebContentsOnUiThread(), VIDEO_ID); |
358 assertWaitForKeepScreenOnActive(mTestContainerView, false); | 358 assertWaitForKeepScreenOnActive(mTestContainerView, false); |
359 } | 359 } |
360 | 360 |
361 @MediumTest | 361 @MediumTest |
362 @Feature({"AndroidWebView"}) | 362 @Feature({"AndroidWebView"}) |
363 public void testPowerSaveBlockerIsTransferredToFullscreen() | 363 public void testPowerSaveBlockerIsTransferredToFullscreen() |
364 throws Throwable { | 364 throws Throwable { |
365 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); | 365 assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); |
366 loadTestPage(VIDEO_INSIDE_DIV_TEST_URL); | 366 loadTestPage(VIDEO_INSIDE_DIV_TEST_URL); |
367 | 367 |
368 // Play and verify that there is an active power save blocker. | 368 // Play and verify that there is an active power save blocker. |
369 tapPlayButton(); | 369 tapPlayButton(); |
370 assertWaitForKeepScreenOnActive(mTestContainerView, true); | 370 assertWaitForKeepScreenOnActive(mTestContainerView, true); |
371 | 371 |
372 // Enter fullscreen and verify that the power save blocker is | 372 // Enter fullscreen and verify that the power save blocker is |
373 // still there. | 373 // still there. |
374 DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID)
; | 374 DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID)
; |
375 mContentsClient.waitForCustomViewShown(); | 375 mContentsClient.waitForCustomViewShown(); |
376 View customView = mContentsClient.getCustomView(); | 376 View customView = mContentsClient.getCustomView(); |
377 assertKeepScreenOnActive(customView, true); | 377 assertKeepScreenOnActive(customView, true); |
378 | 378 |
379 // Pause the video and the power save blocker is gone. | 379 // Pause the video and the power save blocker is gone. |
380 DOMUtils.pauseVideo(getWebContentsOnUiThread(), VIDEO_ID); | 380 DOMUtils.pauseMedia(getWebContentsOnUiThread(), VIDEO_ID); |
381 assertWaitForKeepScreenOnActive(customView, false); | 381 assertWaitForKeepScreenOnActive(customView, false); |
382 | 382 |
383 // Exit fullscreen and the power save blocker is still gone. | 383 // Exit fullscreen and the power save blocker is still gone. |
384 DOMUtils.exitFullscreen(getWebContentsOnUiThread()); | 384 DOMUtils.exitFullscreen(getWebContentsOnUiThread()); |
385 mContentsClient.waitForCustomViewHidden(); | 385 mContentsClient.waitForCustomViewHidden(); |
386 assertKeepScreenOnActive(mTestContainerView, false); | 386 assertKeepScreenOnActive(mTestContainerView, false); |
387 } | 387 } |
388 | 388 |
389 @MediumTest | 389 @MediumTest |
390 @Feature({"AndroidWebView"}) | 390 @Feature({"AndroidWebView"}) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 */ | 428 */ |
429 private void assertWaitForKeepScreenOnActive(final View view, final boolean
expected) | 429 private void assertWaitForKeepScreenOnActive(final View view, final boolean
expected) |
430 throws InterruptedException { | 430 throws InterruptedException { |
431 // We need to poll because it takes time to synchronize the state betwee
n the android | 431 // We need to poll because it takes time to synchronize the state betwee
n the android |
432 // views and Javascript. | 432 // views and Javascript. |
433 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | 433 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
434 @Override | 434 @Override |
435 public boolean isSatisfied() { | 435 public boolean isSatisfied() { |
436 try { | 436 try { |
437 return getKeepScreenOn(view) == expected | 437 return getKeepScreenOn(view) == expected |
438 && DOMUtils.isVideoPaused(getWebContentsOnUiThread()
, VIDEO_ID) | 438 && DOMUtils.isMediaPaused(getWebContentsOnUiThread()
, VIDEO_ID) |
439 != expected; | 439 != expected; |
440 } catch (InterruptedException | TimeoutException e) { | 440 } catch (InterruptedException | TimeoutException e) { |
441 fail(e.getMessage()); | 441 fail(e.getMessage()); |
442 return false; | 442 return false; |
443 } | 443 } |
444 } | 444 } |
445 })); | 445 })); |
446 } | 446 } |
447 | 447 |
448 private void assertKeepScreenOnActive(final View view, final boolean expecte
d) | 448 private void assertKeepScreenOnActive(final View view, final boolean expecte
d) |
449 throws Exception { | 449 throws Exception { |
450 assertTrue(getKeepScreenOn(view) == expected | 450 assertTrue(getKeepScreenOn(view) == expected |
451 && DOMUtils.isVideoPaused(getWebContentsOnUiThread(), VIDEO_ID)
!= expected); | 451 && DOMUtils.isMediaPaused(getWebContentsOnUiThread(), VIDEO_ID)
!= expected); |
452 } | 452 } |
453 | 453 |
454 private boolean getKeepScreenOn(View view) { | 454 private boolean getKeepScreenOn(View view) { |
455 // The power save blocker is added to a child anchor view, | 455 // The power save blocker is added to a child anchor view, |
456 // so we need to traverse the hierarchy. | 456 // so we need to traverse the hierarchy. |
457 if (view instanceof ViewGroup) { | 457 if (view instanceof ViewGroup) { |
458 ViewGroup viewGroup = (ViewGroup) view; | 458 ViewGroup viewGroup = (ViewGroup) view; |
459 for (int i = 0; i < viewGroup.getChildCount(); i++) { | 459 for (int i = 0; i < viewGroup.getChildCount(); i++) { |
460 if (getKeepScreenOn(viewGroup.getChildAt(i))) { | 460 if (getKeepScreenOn(viewGroup.getChildAt(i))) { |
461 return true; | 461 return true; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 public WebContents call() throws Exception { | 550 public WebContents call() throws Exception { |
551 return mContentViewCore.getWebContents(); | 551 return mContentViewCore.getWebContents(); |
552 } | 552 } |
553 }); | 553 }); |
554 } catch (Exception e) { | 554 } catch (Exception e) { |
555 fail(e.getMessage()); | 555 fail(e.getMessage()); |
556 return null; | 556 return null; |
557 } | 557 } |
558 } | 558 } |
559 } | 559 } |
OLD | NEW |