Chromium Code Reviews| 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.test.suitebuilder.annotation.MediumTest; | 7 import android.test.suitebuilder.annotation.MediumTest; |
| 8 import android.view.View; | 8 import android.view.View; |
| 9 import android.view.ViewGroup; | 9 import android.view.ViewGroup; |
| 10 | 10 |
| 11 import org.chromium.android_webview.test.util.JavascriptEventObserver; | 11 import org.chromium.android_webview.test.util.JavascriptEventObserver; |
| 12 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
| 13 import org.chromium.content.browser.ContentVideoView; | |
| 13 import org.chromium.content.browser.ContentViewCore; | 14 import org.chromium.content.browser.ContentViewCore; |
| 14 import org.chromium.content.browser.test.util.Criteria; | 15 import org.chromium.content.browser.test.util.Criteria; |
| 15 import org.chromium.content.browser.test.util.CriteriaHelper; | 16 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 16 import org.chromium.content.browser.test.util.DOMUtils; | 17 import org.chromium.content.browser.test.util.DOMUtils; |
| 17 import org.chromium.content.browser.test.util.TouchCommon; | 18 import org.chromium.content.browser.test.util.TouchCommon; |
| 18 | 19 |
| 19 import java.util.concurrent.TimeoutException; | 20 import java.util.concurrent.TimeoutException; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * Test the fullscreen API (WebChromeClient::onShow/HideCustomView). | 23 * Test the fullscreen API (WebChromeClient::onShow/HideCustomView). |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 50 mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity()) ; | 51 mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity()) ; |
| 51 mTestContainerView = | 52 mTestContainerView = |
| 52 createAwTestContainerViewOnMainSync(mContentsClient); | 53 createAwTestContainerViewOnMainSync(mContentsClient); |
| 53 mContentViewCore = mTestContainerView.getContentViewCore(); | 54 mContentViewCore = mTestContainerView.getContentViewCore(); |
| 54 enableJavaScriptOnUiThread(mTestContainerView.getAwContents()); | 55 enableJavaScriptOnUiThread(mTestContainerView.getAwContents()); |
| 55 mTestContainerView.getAwContents().getSettings().setFullscreenSupported( true); | 56 mTestContainerView.getAwContents().getSettings().setFullscreenSupported( true); |
| 56 } | 57 } |
| 57 | 58 |
| 58 @MediumTest | 59 @MediumTest |
| 59 @Feature({"AndroidWebView"}) | 60 @Feature({"AndroidWebView"}) |
| 61 @DisableHardwareAccelerationForTest | |
| 62 public void testFullscreenVideoInSoftwareModeDoesNotDeadlock() throws Throwa ble { | |
| 63 // Although fullscreen video is not supported without hardware accelerat ion | |
| 64 // we should not deadlock if apps try to use it. | |
| 65 loadTestPageAndClickFullscreen(VIDEO_TEST_URL); | |
| 66 mContentsClient.waitForCustomViewShown(); | |
| 67 getInstrumentation().runOnMainSync(new Runnable() { | |
| 68 @Override | |
| 69 public void run() { | |
| 70 mContentsClient.getExitCallback().onCustomViewHidden(); | |
| 71 } | |
| 72 }); | |
| 73 mContentsClient.waitForCustomViewHidden(); | |
| 74 } | |
| 75 | |
| 76 @MediumTest | |
| 77 @Feature({"AndroidWebView"}) | |
| 78 @DisableHardwareAccelerationForTest | |
| 79 public void testFullscreenForNonVideoElementIsSupportedInSoftwareMode() thro ws Throwable { | |
| 80 // Fullscreen for non-video elements is supported and works as expected. Note that | |
| 81 // this test is the same as testOnShowAndHideCustomViewWithCallback_vide oInsideDiv below. | |
| 82 doTestOnShowAndHideCustomViewWithCallback(VIDEO_INSIDE_DIV_TEST_URL); | |
| 83 } | |
| 84 | |
| 85 @MediumTest | |
| 86 @Feature({"AndroidWebView"}) | |
| 60 public void testOnShowAndHideCustomViewWithCallback_video() throws Throwable { | 87 public void testOnShowAndHideCustomViewWithCallback_video() throws Throwable { |
| 61 doTestOnShowAndHideCustomViewWithCallback(VIDEO_TEST_URL); | 88 doTestOnShowAndHideCustomViewWithCallback(VIDEO_TEST_URL); |
| 62 } | 89 } |
| 63 | 90 |
| 64 @MediumTest | 91 @MediumTest |
| 65 @Feature({"AndroidWebView"}) | 92 @Feature({"AndroidWebView"}) |
| 66 public void testOnShowAndHideCustomViewWithCallback_videoInsideDiv() throws Throwable { | 93 public void testOnShowAndHideCustomViewWithCallback_videoInsideDiv() throws Throwable { |
| 67 doTestOnShowAndHideCustomViewWithCallback(VIDEO_INSIDE_DIV_TEST_URL); | 94 doTestOnShowAndHideCustomViewWithCallback(VIDEO_INSIDE_DIV_TEST_URL); |
| 68 } | 95 } |
| 69 | 96 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 ViewGroup viewGroup = (ViewGroup) view; | 315 ViewGroup viewGroup = (ViewGroup) view; |
| 289 for (int i = 0; i < viewGroup.getChildCount(); i++) { | 316 for (int i = 0; i < viewGroup.getChildCount(); i++) { |
| 290 if (getKeepScreenOn(viewGroup.getChildAt(i))) { | 317 if (getKeepScreenOn(viewGroup.getChildAt(i))) { |
| 291 return true; | 318 return true; |
| 292 } | 319 } |
| 293 } | 320 } |
| 294 } | 321 } |
| 295 return view.getKeepScreenOn(); | 322 return view.getKeepScreenOn(); |
| 296 } | 323 } |
| 297 | 324 |
| 325 private void assertContainsContentVideoView() | |
| 326 throws InterruptedException { | |
| 327 // We need to poll because the ContentVideoView is added to the customVi ew asynchronously | |
| 328 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | |
| 329 @Override | |
| 330 public boolean isSatisfied() { | |
| 331 return containsVideoView(mContentsClient.getCustomView()); | |
|
boliu
2014/10/22 02:01:02
Need to do this on the UI thread.
Ignacio Solla
2014/10/22 09:32:16
Why? I'm happy to change it but I'd like to unders
boliu
2014/10/22 15:53:45
Because AwContents/ContentViewCore, and the entire
Ignacio Solla
2014/10/27 11:42:06
OK done. (I was thinking that read-only operation
| |
| 332 } | |
| 333 })); | |
| 334 } | |
| 335 | |
| 336 private void assertIsFullscreen() throws InterruptedException { | |
| 337 // We need to poll because the Javascript state is updated asynchronousl y | |
| 338 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | |
| 339 @Override | |
| 340 public boolean isSatisfied() { | |
| 341 try { | |
| 342 return DOMUtils.isFullscreen(mContentViewCore.getWebContents ()); | |
|
boliu
2014/10/22 02:01:02
I didn't find this DOMUtils method?! I assume it n
Ignacio Solla
2014/10/22 09:32:16
To avoid conflicts, I have set the diffbase of thi
boliu
2014/10/22 15:53:45
Ok. isFullscreen itself looks thread safe. mConten
Ignacio Solla
2014/10/27 11:42:06
Ok, I'm calling mContentViewCore.getWebContents()
boliu
2014/10/27 16:49:44
Why? I don't see it just glancing at the code. Thr
Ignacio Solla
2014/10/27 16:59:52
See:
https://code.google.com/p/chromium/codesearch
| |
| 343 } catch (InterruptedException | TimeoutException e) { | |
| 344 fail(e.getMessage()); | |
| 345 return false; | |
| 346 } | |
| 347 } | |
| 348 })); | |
| 349 } | |
| 350 | |
| 351 private boolean containsVideoView(View view) { | |
|
boliu
2014/10/22 02:01:02
nit: move this next to assertContainsContentVideoV
Ignacio Solla
2014/10/22 09:32:16
Done.
| |
| 352 if (view instanceof ContentVideoView) { | |
| 353 return true; | |
| 354 } | |
| 355 if (view instanceof ViewGroup) { | |
| 356 ViewGroup viewGroup = (ViewGroup) view; | |
| 357 for (int i = 0; i < viewGroup.getChildCount(); i++) { | |
| 358 if (containsVideoView(viewGroup.getChildAt(i))) { | |
| 359 return true; | |
| 360 } | |
| 361 } | |
| 362 } | |
| 363 return false; | |
| 364 } | |
| 365 | |
| 298 private JavascriptEventObserver registerObserver(final String observerName) { | 366 private JavascriptEventObserver registerObserver(final String observerName) { |
| 299 final JavascriptEventObserver observer = new JavascriptEventObserver(); | 367 final JavascriptEventObserver observer = new JavascriptEventObserver(); |
| 300 getInstrumentation().runOnMainSync(new Runnable() { | 368 getInstrumentation().runOnMainSync(new Runnable() { |
| 301 @Override | 369 @Override |
| 302 public void run() { | 370 public void run() { |
| 303 observer.register(mContentViewCore, observerName); | 371 observer.register(mContentViewCore, observerName); |
| 304 } | 372 } |
| 305 }); | 373 }); |
| 306 return observer; | 374 return observer; |
| 307 } | 375 } |
| 308 | 376 |
| 309 private void doOnShowAndHideCustomViewTest(String videoTestUrl, final Runnab le existFullscreen) | 377 private void doOnShowAndHideCustomViewTest(String videoTestUrl, final Runnab le existFullscreen) |
| 310 throws Throwable { | 378 throws Throwable { |
| 311 doOnShowCustomViewTest(videoTestUrl); | 379 doOnShowCustomViewTest(videoTestUrl); |
| 312 getInstrumentation().runOnMainSync(existFullscreen); | 380 getInstrumentation().runOnMainSync(existFullscreen); |
| 313 mContentsClient.waitForCustomViewHidden(); | 381 mContentsClient.waitForCustomViewHidden(); |
| 314 } | 382 } |
| 315 | 383 |
| 316 private void doOnShowCustomViewTest(String videoTestUrl) throws Exception { | 384 private void doOnShowCustomViewTest(String videoTestUrl) throws Exception { |
| 317 loadTestPageAndClickFullscreen(videoTestUrl); | 385 loadTestPageAndClickFullscreen(videoTestUrl); |
| 318 mContentsClient.waitForCustomViewShown(); | 386 mContentsClient.waitForCustomViewShown(); |
| 319 assertTrue(DOMUtils.isFullscreen(mContentViewCore.getWebContents())); | 387 assertIsFullscreen(); |
| 388 if (videoTestUrl.equals(VIDEO_TEST_URL)) { | |
| 389 // We only create a ContentVideoView (ie. a hardware accelerated sur face) when going | |
| 390 // fullscreen on a video element. | |
| 391 assertContainsContentVideoView(); | |
| 392 } | |
| 320 } | 393 } |
| 321 | 394 |
| 322 private void loadTestPageAndClickFullscreen(String videoTestUrl) throws Exce ption { | 395 private void loadTestPageAndClickFullscreen(String videoTestUrl) throws Exce ption { |
| 323 loadTestPage(videoTestUrl); | 396 loadTestPage(videoTestUrl); |
| 324 DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID) ; | 397 DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID) ; |
|
boliu
2014/10/22 02:01:02
UI thread.
Ignacio Solla
2014/10/22 09:32:16
We're already dispatching the click event on the U
boliu
2014/10/22 15:53:45
Ahh crap I didn't read that far. I'm pretty sure t
Ignacio Solla
2014/10/27 11:42:06
clickNode cannot be called on the instrumentation
boliu
2014/10/27 16:49:44
This change has to wait for that to be fixed then.
Ignacio Solla
2014/10/27 16:59:52
eh, this change is not changing this line of code
| |
| 325 } | 398 } |
| 326 | 399 |
| 327 private void loadTestPage(String videoTestUrl) throws Exception { | 400 private void loadTestPage(String videoTestUrl) throws Exception { |
| 328 loadUrlSync(mTestContainerView.getAwContents(), | 401 loadUrlSync(mTestContainerView.getAwContents(), |
| 329 mContentsClient.getOnPageFinishedHelper(), videoTestUrl); | 402 mContentsClient.getOnPageFinishedHelper(), videoTestUrl); |
| 330 } | 403 } |
| 331 } | 404 } |
| OLD | NEW |