1 // Copyright 2018 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.chrome.browser.vr.util;
6 
7 import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_CHECK_INTERVAL_SHORT_MS;
8 import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_TIMEOUT_LONG_MS;
9 
10 import org.chromium.base.test.util.CriteriaHelper;
11 import org.chromium.chrome.browser.vr.TestVrShellDelegate;
12 import org.chromium.chrome.browser.vr.VrShellDelegate;
13 import org.chromium.content_public.browser.test.util.TestThreadUtils;
14 
15 /**
16  * Class containing utility functions for transitioning between different
17  * states in VR, such as fullscreen, WebVR presentation, and the VR browser.
18  *
19  * Methods in this class are applicable to any form of VR, e.g. they will work for both WebXR for VR
20  * and the VR Browser.
21  *
22  * All the transitions in this class are performed directly through Chrome,
23  * as opposed to NFC tag simulation which involves receiving an intent from
24  * an outside application (VR Services).
25  */
26 public class VrTransitionUtils {
27     /**
28      * Forces Chrome out of VR mode.
29      */
forceExitVr()30     public static void forceExitVr() {
31         TestThreadUtils.runOnUiThreadBlocking(() -> { VrShellDelegate.forceExitVrImmediately(); });
32     }
33 
34     /**
35      * Waits until Chrome believes it is in VR.
36      *
37      * @param timeout How long to wait for VR entry before timing out and failing.
38      */
waitForVrEntry(final int timeout)39     public static void waitForVrEntry(final int timeout) {
40         // Relatively long timeout because sometimes GVR takes a while to enter VR
41         CriteriaHelper.pollUiThread(() -> {
42             return VrShellDelegateUtils.getDelegateInstance().isVrEntryComplete();
43         }, "VR not entered in allotted time", timeout, POLL_CHECK_INTERVAL_SHORT_MS);
44     }
45 
46     /**
47      * Waits for the black overlay that shows during VR Browser entry to be gone.
48      */
waitForOverlayGone()49     public static void waitForOverlayGone() {
50         CriteriaHelper.pollUiThread(
51                 ()
52                         -> { return !TestVrShellDelegate.getInstance().isBlackOverlayVisible(); },
53                 "Black overlay did not disappear in allotted time", POLL_TIMEOUT_LONG_MS,
54                 POLL_CHECK_INTERVAL_SHORT_MS);
55     }
56 }
57