Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
| 8 import android.graphics.Color; | 8 import android.graphics.Color; |
| 9 import android.graphics.Rect; | |
| 10 import android.os.Build; | |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 11 import android.test.suitebuilder.annotation.SmallTest; |
| 10 import android.view.View; | 12 import android.view.View; |
| 11 import android.webkit.WebChromeClient; | 13 import android.webkit.WebChromeClient; |
| 12 | 14 |
| 13 import org.chromium.android_webview.AwContents; | 15 import org.chromium.android_webview.AwContents; |
| 14 import org.chromium.android_webview.AwContents.VisualStateCallback; | 16 import org.chromium.android_webview.AwContents.VisualStateCallback; |
| 15 import org.chromium.android_webview.test.util.CommonResources; | 17 import org.chromium.android_webview.test.util.CommonResources; |
| 16 import org.chromium.android_webview.test.util.GraphicsTestUtils; | 18 import org.chromium.android_webview.test.util.GraphicsTestUtils; |
| 17 import org.chromium.android_webview.test.util.JavascriptEventObserver; | 19 import org.chromium.android_webview.test.util.JavascriptEventObserver; |
| 18 import org.chromium.base.test.util.Feature; | 20 import org.chromium.base.test.util.Feature; |
| 21 import org.chromium.base.test.util.MinAndroidSdkLevel; | |
| 19 import org.chromium.content.browser.ContentViewCore; | 22 import org.chromium.content.browser.ContentViewCore; |
| 20 import org.chromium.content.browser.test.util.CallbackHelper; | 23 import org.chromium.content.browser.test.util.CallbackHelper; |
| 21 import org.chromium.content.browser.test.util.DOMUtils; | 24 import org.chromium.content.browser.test.util.DOMUtils; |
| 22 import org.chromium.content_public.browser.LoadUrlParams; | 25 import org.chromium.content_public.browser.LoadUrlParams; |
| 23 | 26 |
| 24 import java.util.concurrent.CountDownLatch; | 27 import java.util.concurrent.CountDownLatch; |
| 25 import java.util.concurrent.TimeUnit; | 28 import java.util.concurrent.TimeUnit; |
| 26 import java.util.concurrent.atomic.AtomicReference; | 29 import java.util.concurrent.atomic.AtomicReference; |
| 27 | 30 |
| 28 /** | 31 /** |
| 29 * Visual state related tests. | 32 * Visual state related tests. |
| 30 */ | 33 */ |
| 34 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT) | |
| 31 public class VisualStateTest extends AwTestBase { | 35 public class VisualStateTest extends AwTestBase { |
| 32 | 36 |
| 33 private static final String WAIT_FOR_JS_TEST_URL = | 37 private static final String WAIT_FOR_JS_TEST_URL = |
| 34 "file:///android_asset/visual_state_waits_for_js_test.html"; | 38 "file:///android_asset/visual_state_waits_for_js_test.html"; |
| 35 private static final String FULLSCREEN_TEST_URL = | 39 private static final String FULLSCREEN_TEST_URL = |
| 36 "file:///android_asset/visual_state_during_fullscreen_test.html"; | 40 "file:///android_asset/visual_state_during_fullscreen_test.html"; |
| 37 private static final String UPDATE_COLOR_CONTROL_ID = "updateColorControl"; | 41 private static final String UPDATE_COLOR_CONTROL_ID = "updateColorControl"; |
| 38 private static final String ENTER_FULLSCREEN_CONTROL_ID = "enterFullscreenCo ntrol"; | 42 private static final String ENTER_FULLSCREEN_CONTROL_ID = "enterFullscreenCo ntrol"; |
| 39 | 43 |
| 40 private TestAwContentsClient mContentsClient = new TestAwContentsClient(); | 44 private TestAwContentsClient mContentsClient = new TestAwContentsClient(); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 318 |
| 315 loadUrlSync(awContents, awContentsClient.getOnPageFinishedHelper(), FULL SCREEN_TEST_URL); | 319 loadUrlSync(awContents, awContentsClient.getOnPageFinishedHelper(), FULL SCREEN_TEST_URL); |
| 316 | 320 |
| 317 assertTrue(readyToEnterFullscreenSignal.await( | 321 assertTrue(readyToEnterFullscreenSignal.await( |
| 318 AwTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); | 322 AwTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); |
| 319 DOMUtils.clickNode(VisualStateTest.this, contentViewCore, ENTER_FULLSCRE EN_CONTROL_ID); | 323 DOMUtils.clickNode(VisualStateTest.this, contentViewCore, ENTER_FULLSCRE EN_CONTROL_ID); |
| 320 | 324 |
| 321 assertTrue(testFinishedSignal.await(AwTestBase.WAIT_TIMEOUT_MS, TimeUnit .MILLISECONDS)); | 325 assertTrue(testFinishedSignal.await(AwTestBase.WAIT_TIMEOUT_MS, TimeUnit .MILLISECONDS)); |
| 322 } | 326 } |
| 323 | 327 |
| 328 @Feature({"AndroidWebView"}) | |
| 329 @SmallTest | |
| 330 public void testVisualStateCallbackWhenContainerViewDetached() | |
| 331 throws Throwable { | |
| 332 final CountDownLatch readyToEnterFullscreenSignal = new CountDownLatch(1 ); | |
| 333 final CountDownLatch hasCustomViewSignal = new CountDownLatch(1); | |
| 334 final CountDownLatch testFinishedSignal = new CountDownLatch(1); | |
| 335 | |
| 336 final AtomicReference<AwContents> awContentsRef = new AtomicReference<>( ); | |
|
hush (inactive)
2015/03/04 18:39:08
Why not "AtomicReference<AwContents>" on the right
boliu
2015/03/04 19:16:43
http://docs.oracle.com/javase/7/docs/technotes/gui
hush (inactive)
2015/03/04 19:39:54
Okay.
| |
| 337 final AtomicReference<View> customViewRef = new AtomicReference<>(); | |
| 338 | |
| 339 final TestAwContentsClient awContentsClient = new TestAwContentsClient() { | |
| 340 @Override | |
| 341 public void onPageFinished(String url) { | |
| 342 super.onPageFinished(url); | |
| 343 readyToEnterFullscreenSignal.countDown(); | |
| 344 } | |
| 345 | |
| 346 @Override | |
| 347 public void onShowCustomView( | |
| 348 final View customView, WebChromeClient.CustomViewCallback ca llback) { | |
| 349 // Please note that we don't attach the custom view to the windo w here | |
| 350 // (awContentsClient is an instance of TestAwContentsClient, not | |
| 351 // FullScreenVideoTestAwContentsClient). | |
| 352 customView.setClipBounds(new Rect(0, 0, 100, 100)); | |
| 353 customView.measure(100, 100); | |
| 354 customView.layout(0, 0, 100, 100); | |
| 355 customViewRef.set(customView); | |
| 356 hasCustomViewSignal.countDown(); | |
| 357 } | |
| 358 }; | |
| 359 final AwTestContainerView testView = createAwTestContainerViewOnMainSync (awContentsClient); | |
| 360 final AwContents awContents = testView.getAwContents(); | |
| 361 awContentsRef.set(awContents); | |
| 362 final ContentViewCore contentViewCore = testView.getContentViewCore(); | |
| 363 enableJavaScriptOnUiThread(awContents); | |
| 364 awContents.getSettings().setFullscreenSupported(true); | |
| 365 | |
| 366 // JS will notify this observer once it has entered fullscreen. | |
| 367 final JavascriptEventObserver jsObserver = new JavascriptEventObserver() ; | |
| 368 runTestOnUiThread(new Runnable() { | |
| 369 @Override | |
| 370 public void run() { | |
| 371 jsObserver.register(contentViewCore, "jsObserver"); | |
| 372 } | |
| 373 }); | |
| 374 | |
| 375 loadUrlSync(awContents, awContentsClient.getOnPageFinishedHelper(), FULL SCREEN_TEST_URL); | |
| 376 | |
| 377 assertTrue(readyToEnterFullscreenSignal.await( | |
| 378 AwTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); | |
| 379 DOMUtils.clickNode(VisualStateTest.this, contentViewCore, ENTER_FULLSCRE EN_CONTROL_ID); | |
| 380 | |
| 381 assertTrue(hasCustomViewSignal.await(AwTestBase.WAIT_TIMEOUT_MS, TimeUni t.MILLISECONDS)); | |
| 382 assertTrue(jsObserver.waitForEvent(WAIT_TIMEOUT_MS)); | |
| 383 | |
| 384 runTestOnUiThread(new Runnable() { | |
| 385 @Override | |
| 386 public void run() { | |
| 387 awContents.insertVisualStateCallback(20, new VisualStateCallback () { | |
| 388 @Override | |
| 389 public void onComplete(long id) { | |
| 390 assertFalse(customViewRef.get().isAttachedToWindow()); | |
| 391 // NOTE: We cannot use drawAwContents here because the w eb contents | |
| 392 // are rendered into the custom view while in fullscreen . | |
| 393 Bitmap redScreenshot = GraphicsTestUtils.drawView( | |
| 394 customViewRef.get(), 100, 100); | |
| 395 assertEquals(Color.RED, redScreenshot.getPixel(50, 50)); | |
| 396 testFinishedSignal.countDown(); | |
| 397 } | |
| 398 }); | |
| 399 } | |
| 400 }); | |
| 401 | |
| 402 assertTrue(testFinishedSignal.await(AwTestBase.WAIT_TIMEOUT_MS, TimeUnit .MILLISECONDS)); | |
| 403 } | |
| 404 | |
| 324 private static final LoadUrlParams createTestPageUrl(String backgroundColor) { | 405 private static final LoadUrlParams createTestPageUrl(String backgroundColor) { |
| 325 return LoadUrlParams.createLoadDataParams( | 406 return LoadUrlParams.createLoadDataParams( |
| 326 "<html><body bgcolor=" + backgroundColor + "></body></html>", "t ext/html", false); | 407 "<html><body bgcolor=" + backgroundColor + "></body></html>", "t ext/html", false); |
| 327 } | 408 } |
| 328 } | 409 } |
| OLD | NEW |