| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.chrome.browser.vr_shell; | 5 package org.chromium.chrome.browser.vr_shell; |
| 6 | 6 |
| 7 import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_D
AYDREAM; | 7 import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_D
AYDREAM; |
| 8 import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_D
AYDREAM_VIEW; | 8 import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_D
AYDREAM_VIEW; |
| 9 import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_N
ON_DAYDREAM; | 9 import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_N
ON_DAYDREAM; |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 public class VrShellTest extends ChromeTabbedActivityTestBase { | 39 public class VrShellTest extends ChromeTabbedActivityTestBase { |
| 40 private static final String GOLDEN_DIR = | 40 private static final String GOLDEN_DIR = |
| 41 "chrome/test/data/android/render_tests"; | 41 "chrome/test/data/android/render_tests"; |
| 42 | 42 |
| 43 private VrShellDelegate mDelegate; | 43 private VrShellDelegate mDelegate; |
| 44 private ViewRenderer mViewRenderer; | 44 private ViewRenderer mViewRenderer; |
| 45 | 45 |
| 46 @Override | 46 @Override |
| 47 protected void setUp() throws Exception { | 47 protected void setUp() throws Exception { |
| 48 super.setUp(); | 48 super.setUp(); |
| 49 mDelegate = getActivity().getVrShellDelegate(); | 49 mDelegate = VrShellDelegate.getInstanceForTesting(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 @Override | 52 @Override |
| 53 public void startMainActivity() throws InterruptedException { | 53 public void startMainActivity() throws InterruptedException { |
| 54 startMainActivityOnBlankPage(); | 54 startMainActivityOnBlankPage(); |
| 55 mViewRenderer = new ViewRenderer(getActivity(), | 55 mViewRenderer = new ViewRenderer(getActivity(), |
| 56 GOLDEN_DIR, this.getClass().getSimpleName()); | 56 GOLDEN_DIR, this.getClass().getSimpleName()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 private void enterExitVrMode(boolean supported) { | 59 private void enterExitVrMode(boolean supported) { |
| 60 MockVrDaydreamApi mockApi = new MockVrDaydreamApi(); | 60 MockVrDaydreamApi mockApi = new MockVrDaydreamApi(); |
| 61 if (!supported) { | 61 if (!supported) { |
| 62 mDelegate.overrideDaydreamApiForTesting(mockApi); | 62 mDelegate.overrideDaydreamApiForTesting(mockApi); |
| 63 } | 63 } |
| 64 VrUtils.forceEnterVr(mDelegate); | 64 VrUtils.forceEnterVr(); |
| 65 if (supported) { | 65 if (supported) { |
| 66 VrUtils.waitForVrSupported(mDelegate); | 66 VrUtils.waitForVrSupported(); |
| 67 assertTrue(mDelegate.isInVR()); | 67 assertTrue(VrShellDelegate.isInVR()); |
| 68 } else { | 68 } else { |
| 69 assertFalse(mockApi.getLaunchInVrCalled()); | 69 assertFalse(mockApi.getLaunchInVrCalled()); |
| 70 assertFalse(mDelegate.isInVR()); | 70 assertFalse(VrShellDelegate.isInVR()); |
| 71 } | 71 } |
| 72 VrUtils.forceExitVr(mDelegate); | 72 VrUtils.forceExitVr(mDelegate); |
| 73 assertFalse(mDelegate.isInVR()); | 73 assertFalse(VrShellDelegate.isInVR()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 private void enterExitVrModeImage(boolean supported) throws IOException { | 76 private void enterExitVrModeImage(boolean supported) throws IOException { |
| 77 int prevOrientation = getActivity().getRequestedOrientation(); | 77 int prevOrientation = getActivity().getRequestedOrientation(); |
| 78 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LA
NDSCAPE); | 78 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LA
NDSCAPE); |
| 79 getInstrumentation().waitForIdleSync(); | 79 getInstrumentation().waitForIdleSync(); |
| 80 mViewRenderer.renderAndCompare( | 80 mViewRenderer.renderAndCompare( |
| 81 getActivity().getWindow().getDecorView().getRootView(), | 81 getActivity().getWindow().getDecorView().getRootView(), |
| 82 "blank_page"); | 82 "blank_page"); |
| 83 | 83 |
| 84 VrUtils.forceEnterVr(mDelegate); | 84 VrUtils.forceEnterVr(); |
| 85 // Currently, screenshots only show the static UI overlay, not the | 85 // Currently, screenshots only show the static UI overlay, not the |
| 86 // actual content. Thus, 1:1 pixel checking is reliable until a | 86 // actual content. Thus, 1:1 pixel checking is reliable until a |
| 87 // way to take screenshots of VR content is added, in which case | 87 // way to take screenshots of VR content is added, in which case |
| 88 // % similarity or some other method will need to be used. We're | 88 // % similarity or some other method will need to be used. We're |
| 89 // assuming that if the UI overlay is visible, then the device has | 89 // assuming that if the UI overlay is visible, then the device has |
| 90 // successfully entered VR mode. | 90 // successfully entered VR mode. |
| 91 if (supported) { | 91 if (supported) { |
| 92 VrUtils.waitForVrSupported(mDelegate); | 92 VrUtils.waitForVrSupported(); |
| 93 mViewRenderer.renderAndCompare( | 93 mViewRenderer.renderAndCompare( |
| 94 getActivity().getWindow().getDecorView().getRootView(), | 94 getActivity().getWindow().getDecorView().getRootView(), |
| 95 "vr_entered"); | 95 "vr_entered"); |
| 96 } else { | 96 } else { |
| 97 // TODO(bsheedy): Find a good way to wait before taking a screenshot | 97 // TODO(bsheedy): Find a good way to wait before taking a screenshot |
| 98 // when running on an unsupported device | 98 // when running on an unsupported device |
| 99 mViewRenderer.renderAndCompare( | 99 mViewRenderer.renderAndCompare( |
| 100 getActivity().getWindow().getDecorView().getRootView(), | 100 getActivity().getWindow().getDecorView().getRootView(), |
| 101 "blank_page"); | 101 "blank_page"); |
| 102 } | 102 } |
| 103 | 103 |
| 104 VrUtils.forceExitVr(mDelegate); | 104 VrUtils.forceExitVr(mDelegate); |
| 105 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LA
NDSCAPE); | 105 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LA
NDSCAPE); |
| 106 getInstrumentation().waitForIdleSync(); | 106 getInstrumentation().waitForIdleSync(); |
| 107 mViewRenderer.renderAndCompare( | 107 mViewRenderer.renderAndCompare( |
| 108 getActivity().getWindow().getDecorView().getRootView(), | 108 getActivity().getWindow().getDecorView().getRootView(), |
| 109 "blank_page"); | 109 "blank_page"); |
| 110 | 110 |
| 111 getActivity().setRequestedOrientation(prevOrientation); | 111 getActivity().setRequestedOrientation(prevOrientation); |
| 112 } | 112 } |
| 113 | 113 |
| 114 private void enterVrModeNfc(boolean supported) { | 114 private void enterVrModeNfc(boolean supported) { |
| 115 getInstrumentation().waitForIdleSync(); | 115 getInstrumentation().waitForIdleSync(); |
| 116 VrUtils.simNfc(getActivity()); | 116 VrUtils.simNfc(getActivity()); |
| 117 if (supported) { | 117 if (supported) { |
| 118 VrUtils.waitForVrSupported(mDelegate); | 118 VrUtils.waitForVrSupported(); |
| 119 assertTrue(mDelegate.isInVR()); | 119 assertTrue(VrShellDelegate.isInVR()); |
| 120 } else { | 120 } else { |
| 121 assertFalse(mDelegate.isInVR()); | 121 assertFalse(VrShellDelegate.isInVR()); |
| 122 } | 122 } |
| 123 VrUtils.forceExitVr(mDelegate); | 123 VrUtils.forceExitVr(mDelegate); |
| 124 // TODO(bsheedy): Figure out why NFC tests cause the next test to fail | 124 // TODO(bsheedy): Figure out why NFC tests cause the next test to fail |
| 125 // to enter VR unless we sleep for some amount of time after exiting VR | 125 // to enter VR unless we sleep for some amount of time after exiting VR |
| 126 // in the NFC test | 126 // in the NFC test |
| 127 } | 127 } |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * Verifies that browser successfully enters VR mode when Daydream headset | 130 * Verifies that browser successfully enters VR mode when Daydream headset |
| 131 * NFC tag is scanned on a Daydream-ready device. Requires that the phone | 131 * NFC tag is scanned on a Daydream-ready device. Requires that the phone |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 }); | 240 }); |
| 241 | 241 |
| 242 CriteriaHelper.pollUiThread(Criteria.equals(testWidth, new Callable<Inte
ger>() { | 242 CriteriaHelper.pollUiThread(Criteria.equals(testWidth, new Callable<Inte
ger>() { |
| 243 @Override | 243 @Override |
| 244 public Integer call() { | 244 public Integer call() { |
| 245 return cvc.getViewportWidthPix(); | 245 return cvc.getViewportWidthPix(); |
| 246 } | 246 } |
| 247 })); | 247 })); |
| 248 } | 248 } |
| 249 } | 249 } |
| OLD | NEW |