Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/VSyncPausedTest.java

Issue 2754493002: Expose VSync pausing through WindowAndroid and pause VSync during webVR presentation (Closed)
Patch Set: remove log Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/public/android/BUILD.gn ('k') | content/test/data/android/vsync.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.content.browser;
6
7 import android.support.test.filters.MediumTest;
8
9 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14
15 import org.chromium.base.ThreadUtils;
16 import org.chromium.base.test.BaseJUnit4ClassRunner;
17 import org.chromium.base.test.util.CallbackHelper;
18 import org.chromium.base.test.util.UrlUtils;
19 import org.chromium.content.browser.test.util.JavaScriptUtils;
20 import org.chromium.content_public.browser.WebContentsObserver;
21 import org.chromium.content_shell_apk.ContentShellActivity;
22 import org.chromium.content_shell_apk.ContentShellActivityTestRule;
23
24 import java.util.concurrent.TimeUnit;
25 import java.util.concurrent.TimeoutException;
26
27 /**
28 * Tests pausing the VSync loop for a WindowAndroid.
29 */
30 @RunWith(BaseJUnit4ClassRunner.class)
31 public class VSyncPausedTest {
32 @Rule
33 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi vityTestRule();
34
35 private static final String VSYNC_HTML = "content/test/data/android/vsync.ht ml";
36 private static final String CALL_RAF = "window.requestAnimationFrame(onAnima tionFrame);";
37
38 private CallbackHelper mOnTitleUpdatedHelper;
39 private String mTitle;
40
41 private WebContentsObserver mObserver;
42 private ContentShellActivity mActivity;
43
44 @Before
45 public void setUp() throws Exception {
46 mActivity = mActivityTestRule.launchContentShellWithUrl(
47 UrlUtils.getIsolatedTestFileUrl(VSYNC_HTML));
48 mActivityTestRule.waitForActiveShellToBeDoneLoading();
49 mObserver = new WebContentsObserver(mActivity.getActiveWebContents()) {
50 @Override
51 public void titleWasSet(String title) {
52 mTitle = title;
53 mOnTitleUpdatedHelper.notifyCalled();
54 }
55 };
56 mOnTitleUpdatedHelper = new CallbackHelper();
57 }
58
59 @Test
60 @MediumTest
61 public void testPauseVSync() throws Throwable {
62 int callCount = mOnTitleUpdatedHelper.getCallCount();
63 JavaScriptUtils.executeJavaScriptAndWaitForResult(
64 mActivity.getActiveWebContents(), CALL_RAF);
65 mOnTitleUpdatedHelper.waitForCallback(callCount);
66 Assert.assertEquals("1", mTitle);
67 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
68 @Override
69 public void run() {
70 mActivity.getActiveShell().getContentViewCore().getWindowAndroid ().setVSyncPaused(
71 true);
72 }
73 });
74 // There may be a VSync already propagating before we pause VSync, so we need a short delay
75 // to let it finish propagating and prevent flakes.
76 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.
77 callCount = mOnTitleUpdatedHelper.getCallCount();
78 JavaScriptUtils.executeJavaScriptAndWaitForResult(
79 mActivity.getActiveWebContents(), CALL_RAF);
80 try {
81 mOnTitleUpdatedHelper.waitForCallback(callCount, 1, 1, TimeUnit.SECO NDS);
82 } catch (TimeoutException e) {
83 // Timeout is expected.
84 }
85 Assert.assertEquals("1", mTitle);
86 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
87 @Override
88 public void run() {
89 mActivity.getActiveShell().getContentViewCore().getWindowAndroid ().setVSyncPaused(
90 false);
91 }
92 });
93 mOnTitleUpdatedHelper.waitForCallback(callCount);
94 Assert.assertEquals("2", mTitle);
95 }
96 }
OLDNEW
« no previous file with comments | « content/public/android/BUILD.gn ('k') | content/test/data/android/vsync.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698