Commit 139eab66 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Fix two VR test issues

Fixes two VR test failures:
1. MockVrDaydreamApi not working properly.
2. DeepLinkedApp tests getting stuck in relaunch loops due to
    the relaunch logic not working properly with the DON flow
    skipped.

Bug: 825248

Change-Id: Iee43fc55f8160bb4fdbbc4f60de8b67f64a3d8e9
Reviewed-on: https://chromium-review.googlesource.com/978887
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545852}
parent 454ac851
......@@ -51,6 +51,12 @@ public class VrMainActivity extends Activity {
int uiMode = config.uiMode & Configuration.UI_MODE_TYPE_MASK;
needsRelaunch = uiMode != Configuration.UI_MODE_TYPE_VR_HEADSET;
}
// The check for relaunching does not work properly if the DON flow is skipped, which
// is the case during tests. So, allow intents to specify that relaunching is not
// necessary.
if (getIntent().getBooleanExtra(VrIntentUtils.AVOID_RELAUNCH_EXTRA, false)) {
needsRelaunch = false;
}
if (needsRelaunch) {
VrIntentUtils.launchInVr(getIntent(), this);
finish();
......
......@@ -24,6 +24,10 @@ public class VrIntentUtils {
// The Daydream Home app adds this extra to auto-present intents.
public static final String AUTOPRESENT_WEVBVR_EXTRA = "browser.vr.AUTOPRESENT_WEBVR";
public static final String DAYDREAM_CATEGORY = "com.google.intent.category.DAYDREAM";
// Tells Chrome not to relaunch itself when receiving a VR intent. This is used by tests since
// the relaunch logic does not work properly with the DON flow skipped.
public static final String AVOID_RELAUNCH_EXTRA =
"org.chromium.chrome.browser.vr_shell.AVOID_RELAUNCH";
static final String VR_FRE_INTENT_EXTRA = "org.chromium.chrome.browser.vr_shell.VR_FRE";
static final String VR_FRE_CALLER_INTENT_EXTRA =
......
......@@ -29,7 +29,6 @@ import org.junit.runner.RunWith;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
......@@ -90,7 +89,7 @@ public class VrShellTransitionTest {
}
private void enterExitVrShell(boolean supported) {
MockVrDaydreamApi mockApi = new MockVrDaydreamApi();
MockVrDaydreamApi mockApi = new MockVrDaydreamApi(mTestRule.getActivity());
if (!supported) {
VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApi);
}
......@@ -152,7 +151,8 @@ public class VrShellTransitionTest {
public void testVrIntentStartsVrShell() {
// Send a VR intent, which will open the link in a CTA.
String url = VrTestFramework.getHtmlTestFile("test_navigation_2d_page");
VrTransitionUtils.sendVrLaunchIntent(url, mTestRule.getActivity(), false /* autopresent */);
VrTransitionUtils.sendVrLaunchIntent(
url, mTestRule.getActivity(), false /* autopresent */, true /* avoidRelaunch */);
// Wait until a CTA is opened due to the intent
final AtomicReference<ChromeTabbedActivity> cta =
......@@ -341,7 +341,6 @@ public class VrShellTransitionTest {
@Test
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@MediumTest
@DisabledTest(message = "crbug.com/825248")
public void testEnterVrInOverviewMode() throws InterruptedException, TimeoutException {
final ChromeTabbedActivity activity = mTestRule.getActivity();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
......@@ -354,8 +353,7 @@ public class VrShellTransitionTest {
Assert.assertTrue(activity.isInOverviewMode());
MockVrDaydreamApi mockApi = new MockVrDaydreamApi();
mockApi.setForwardSetupIntent(true);
MockVrDaydreamApi mockApi = new MockVrDaydreamApi(mTestRule.getActivity());
VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApi);
Assert.assertTrue(VrTransitionUtils.forceEnterVr());
VrTransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS);
......@@ -393,12 +391,8 @@ public class VrShellTransitionTest {
TransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS);
Assert.assertTrue(VrShellDelegateUtils.getDelegateInstance().isVrEntryComplete());
MockVrDaydreamApi mockApi = new MockVrDaydreamApi() {
@Override
public Boolean isDaydreamCurrentViewer() {
return true;
}
};
MockVrDaydreamApi mockApi = new MockVrDaydreamApi(mTestRule.getActivity());
mockApi.setExitFromVrReturnValue(false);
VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApi);
ThreadUtils.runOnUiThreadBlocking(() -> {
Intent preferencesIntent = PreferencesLauncher.createIntentForSettingsPage(
......@@ -409,17 +403,10 @@ public class VrShellTransitionTest {
CriteriaHelper.pollUiThread(() -> { return mockApi.getExitFromVrCalled(); });
Assert.assertFalse(mockApi.getLaunchVrHomescreenCalled());
MockVrDaydreamApi mockApiWithDoff = new MockVrDaydreamApi() {
@Override
public boolean exitFromVr(int requestCode, final Intent intent) {
return true;
}
mockApi.close();
@Override
public Boolean isDaydreamCurrentViewer() {
return true;
}
};
MockVrDaydreamApi mockApiWithDoff = new MockVrDaydreamApi(mTestRule.getActivity());
mockApiWithDoff.setExitFromVrReturnValue(true);
VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApiWithDoff);
......
......@@ -433,10 +433,9 @@ public class WebVrInputTest {
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
@CommandLineFlags
.Remove({"enable-webvr"})
@CommandLineFlags.Add({"enable-features=WebXR"})
public void testAppButtonNoopsWhenBrowsingDisabled_WebXr()
@CommandLineFlags.Remove({"enable-webvr"})
@CommandLineFlags.Add({"enable-features=WebXR"})
public void testAppButtonNoopsWhenBrowsingDisabled_WebXr()
throws InterruptedException, ExecutionException {
appButtonNoopsTestImpl(
XrTestFramework.getHtmlTestFile("generic_webxr_page"), mXrTestFramework);
......@@ -465,7 +464,7 @@ public class WebVrInputTest {
framework.loadUrlAndAwaitInitialization(url, PAGE_LOAD_TIMEOUT_S);
TransitionUtils.enterPresentationOrFail(framework);
MockVrDaydreamApi mockApi = new MockVrDaydreamApi();
MockVrDaydreamApi mockApi = new MockVrDaydreamApi(mTestRule.getActivity());
VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApi);
EmulatedVrController controller = new EmulatedVrController(mTestRule.getActivity());
......@@ -495,8 +494,8 @@ public class WebVrInputTest {
// Send an autopresent intent, which will open the link in a CCT
VrTransitionUtils.sendVrLaunchIntent(
VrTestFramework.getHtmlTestFile("test_webvr_autopresent"),
mTestRule.getActivity(), true /* autopresent */);
VrTestFramework.getHtmlTestFile("test_webvr_autopresent"), mTestRule.getActivity(),
true /* autopresent */, true /* avoidRelaunch */);
// Wait until a CCT is opened due to the intent
final AtomicReference<CustomTabActivity> cct = new AtomicReference<CustomTabActivity>();
......@@ -533,7 +532,7 @@ public class WebVrInputTest {
"vrDisplay.isPresenting", POLL_TIMEOUT_LONG_MS, wc));
// Verify that pressing the app button does nothing
MockVrDaydreamApi mockApi = new MockVrDaydreamApi();
MockVrDaydreamApi mockApi = new MockVrDaydreamApi(cct.get());
VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApi);
EmulatedVrController controller = new EmulatedVrController(cct.get());
......
......@@ -324,8 +324,8 @@ public class WebVrTransitionTest {
// Send an autopresent intent, which will open the link in a CCT
VrTransitionUtils.sendVrLaunchIntent(
VrTestFramework.getHtmlTestFile("test_webvr_autopresent"),
mTestRule.getActivity(), true /* autopresent */);
VrTestFramework.getHtmlTestFile("test_webvr_autopresent"), mTestRule.getActivity(),
true /* autopresent */, true /* avoidRelaunch */);
// Wait until a CCT is opened due to the intent
final AtomicReference<CustomTabActivity> cct = new AtomicReference<CustomTabActivity>();
......
......@@ -5,68 +5,57 @@
package org.chromium.chrome.browser.vr_shell.mock;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import com.google.vr.ndk.base.DaydreamApi;
import org.chromium.chrome.browser.vr_shell.VrDaydreamApi;
import org.chromium.chrome.browser.vr_shell.VrDaydreamApiImpl;
// TODO(bsheedy): Make Mockito work in instrumentation tests and replace uses of this class with
// Mockito spies.
/**
* Mock implementation of VR Shell's VrDaydreamApi
* "Mock" implementation of VR Shell's VrDaydreamApi that mostly does the same thing as the normal
* VrDaydreamApiImpl, but allows checking whether methods were called and modifying return values.
*/
public class MockVrDaydreamApi implements VrDaydreamApi {
public class MockVrDaydreamApi extends VrDaydreamApiImpl {
private boolean mLaunchInVrCalled;
private boolean mExitFromVrCalled;
private boolean mLaunchVrHomescreenCalled;
private boolean mForwardSetupIntent;
@Override
public boolean isDaydreamReadyDevice() {
return false;
}
@Override
public boolean registerDaydreamIntent(final PendingIntent pendingIntent) {
return false;
}
private boolean mDoNotForwardLaunchRequests;
private Boolean mExitFromVrReturnValue;
@Override
public boolean unregisterDaydreamIntent() {
return false;
}
@Override
public Intent createVrIntent(final ComponentName componentName) {
return new Intent();
public MockVrDaydreamApi(Context context) {
super(context);
}
@Override
public boolean launchInVr(final PendingIntent pendingIntent) {
mLaunchInVrCalled = true;
return true;
if (mDoNotForwardLaunchRequests) return true;
return super.launchInVr(pendingIntent);
}
@Override
public boolean launchInVr(final Intent intent) {
return true;
mLaunchInVrCalled = true;
if (mDoNotForwardLaunchRequests) return true;
return super.launchInVr(intent);
}
@Override
public boolean exitFromVr(int requestCode, final Intent intent) {
mExitFromVrCalled = true;
return false;
if (mExitFromVrReturnValue == null) return super.exitFromVr(requestCode, intent);
return mExitFromVrReturnValue.booleanValue();
}
@Override
public Boolean isDaydreamCurrentViewer() {
return false;
public void setExitFromVrReturnValue(Boolean value) {
mExitFromVrReturnValue = value;
}
@Override
public boolean launchVrHomescreen() {
mLaunchVrHomescreenCalled = true;
return true;
return super.launchVrHomescreen();
}
public boolean getLaunchInVrCalled() {
......@@ -80,32 +69,4 @@ public class MockVrDaydreamApi implements VrDaydreamApi {
public boolean getLaunchVrHomescreenCalled() {
return mLaunchVrHomescreenCalled;
}
@Override
public boolean bootsToVr() {
return false;
}
@Override
public Intent setupVrIntent(Intent intent) {
if (mForwardSetupIntent) {
return DaydreamApi.setupVrIntent(intent);
}
return null;
}
public void setForwardSetupIntent(boolean forward) {
mForwardSetupIntent = forward;
}
@Override
public void launchGvrSettings() {}
@Override
public boolean isInVrSession() {
return true;
}
@Override
public void close() {}
}
......@@ -200,7 +200,7 @@ public class TransitionUtils {
* @param autopresent If this intent is expected to auto-present WebVR
*/
public static void sendVrLaunchIntent(
String url, final Activity activity, boolean autopresent) {
String url, final Activity activity, boolean autopresent, boolean avoidRelaunch) {
// Create an intent that will launch Chrome at the specified URL.
final Intent intent =
new Intent(ContextUtils.getApplicationContext(), VrMainActivity.class);
......@@ -213,6 +213,7 @@ public class TransitionUtils {
intent.removeCategory(VrIntentUtils.DAYDREAM_CATEGORY);
intent.putExtra(VrIntentUtils.AUTOPRESENT_WEVBVR_EXTRA, true);
}
if (avoidRelaunch) intent.putExtra(VrIntentUtils.AVOID_RELAUNCH_EXTRA, true);
final VrClassesWrapperImpl wrapper = new VrClassesWrapperImpl();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment