Chromium Code Reviews| Index: content/public/android/javatests/src/org/chromium/content/browser/VSyncPausedTest.java |
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/VSyncPausedTest.java b/content/public/android/javatests/src/org/chromium/content/browser/VSyncPausedTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c57f432fa68caea59bd63d7622dcf67be23cd8af |
| --- /dev/null |
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/VSyncPausedTest.java |
| @@ -0,0 +1,96 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.content.browser; |
| + |
| +import android.support.test.filters.MediumTest; |
| + |
| +import org.junit.Assert; |
| +import org.junit.Before; |
| +import org.junit.Rule; |
| +import org.junit.Test; |
| +import org.junit.runner.RunWith; |
| + |
| +import org.chromium.base.ThreadUtils; |
| +import org.chromium.base.test.BaseJUnit4ClassRunner; |
| +import org.chromium.base.test.util.CallbackHelper; |
| +import org.chromium.base.test.util.UrlUtils; |
| +import org.chromium.content.browser.test.util.JavaScriptUtils; |
| +import org.chromium.content_public.browser.WebContentsObserver; |
| +import org.chromium.content_shell_apk.ContentShellActivity; |
| +import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| + |
| +import java.util.concurrent.TimeUnit; |
| +import java.util.concurrent.TimeoutException; |
| + |
| +/** |
| + * Tests pausing the VSync loop for a WindowAndroid. |
| + */ |
| +@RunWith(BaseJUnit4ClassRunner.class) |
| +public class VSyncPausedTest { |
| + @Rule |
| + public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule(); |
| + |
| + private static final String VSYNC_HTML = "content/test/data/android/vsync.html"; |
| + private static final String CALL_RAF = "window.requestAnimationFrame(onAnimationFrame);"; |
| + |
| + private CallbackHelper mOnTitleUpdatedHelper; |
| + private String mTitle; |
| + |
| + private WebContentsObserver mObserver; |
| + private ContentShellActivity mActivity; |
| + |
| + @Before |
| + public void setUp() throws Exception { |
| + mActivity = mActivityTestRule.launchContentShellWithUrl( |
| + UrlUtils.getIsolatedTestFileUrl(VSYNC_HTML)); |
| + mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| + mObserver = new WebContentsObserver(mActivity.getActiveWebContents()) { |
| + @Override |
| + public void titleWasSet(String title) { |
| + mTitle = title; |
| + mOnTitleUpdatedHelper.notifyCalled(); |
| + } |
| + }; |
| + mOnTitleUpdatedHelper = new CallbackHelper(); |
| + } |
| + |
| + @Test |
| + @MediumTest |
| + public void testPauseVSync() throws Throwable { |
| + int callCount = mOnTitleUpdatedHelper.getCallCount(); |
| + JavaScriptUtils.executeJavaScriptAndWaitForResult( |
| + mActivity.getActiveWebContents(), CALL_RAF); |
| + mOnTitleUpdatedHelper.waitForCallback(callCount); |
| + Assert.assertEquals("1", mTitle); |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + mActivity.getActiveShell().getContentViewCore().getWindowAndroid().setVSyncPaused( |
| + true); |
| + } |
| + }); |
| + // There may be a VSync already propagating before we pause VSync, so we need a short delay |
| + // to let it finish propagating and prevent flakes. |
| + Thread.sleep(100); |
|
boliu
2017/03/16 02:28:52
err, no sleeps, which is a recipe for flakes
mayb
mthiesse
2017/03/16 15:36:06
Found a better solution.
|
| + callCount = mOnTitleUpdatedHelper.getCallCount(); |
| + JavaScriptUtils.executeJavaScriptAndWaitForResult( |
| + mActivity.getActiveWebContents(), CALL_RAF); |
| + try { |
| + mOnTitleUpdatedHelper.waitForCallback(callCount, 1, 1, TimeUnit.SECONDS); |
| + } catch (TimeoutException e) { |
| + // Timeout is expected. |
| + } |
| + Assert.assertEquals("1", mTitle); |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + mActivity.getActiveShell().getContentViewCore().getWindowAndroid().setVSyncPaused( |
| + false); |
| + } |
| + }); |
| + mOnTitleUpdatedHelper.waitForCallback(callCount); |
| + Assert.assertEquals("2", mTitle); |
| + } |
| +} |