Commit 5e5e78b2 authored by Brian Sheedy's avatar Brian Sheedy Committed by Commit Bot

Revert "Add test support for WebVR auto presentation"

This reverts commit 8a3c2e92.

Reason for revert: Causing compile issues.

Original change's description:
> Add test support for WebVR auto presentation
> 
> Adds test utility code that allows Chrome to think it's received an intent
> from a trusted app. This allows us to test Chrome's ability to auto present
> WebVR content when given a link from a trusted app (or test its rejection
> if the app is not trusted). Also adds one test using the new code.
> 
> Also contains a drive-by fix for flakiness in
> WebVrTransitionTest#testNfcFiresVrdisplayactivate caused by a race
> condition when adding the vrdisplayactivate listener.
> 
> Bug: 746086
> Change-Id: Ic6b55df18d915a4e36b36ca43bd11f4c773f6d33
> Reviewed-on: https://chromium-review.googlesource.com/578527
> Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
> Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
> Reviewed-by: Andrew Grieve <agrieve@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#488408}

TBR=mthiesse@chromium.org,agrieve@chromium.org,ymalik@chromium.org,bsheedy@chromium.org

Change-Id: I232fc7dd751f948caf5a20cd8de248560d87a529
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 746086
Reviewed-on: https://chromium-review.googlesource.com/580208Reviewed-by: default avatarSelim Gurun <sgurun@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488439}
parent 4bdde14d
......@@ -556,7 +556,6 @@ if (enable_vr) {
"javatests/src/org/chromium/chrome/browser/vr_shell/EmulatedVrController.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/mock/MockVrCoreVersionCheckerImpl.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/mock/MockVrDaydreamApi.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/mock/MockVrIntentHandler.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/nfc_apk/SimNfcActivity.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/util/CardboardUtils.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/util/NfcSimUtils.java",
......@@ -591,7 +590,6 @@ if (enable_vr) {
"//third_party/android_support_test_runner:runner_java",
"//third_party/android_tools:android_support_v7_appcompat_java",
"//third_party/android_tools:android_support_v7_recyclerview_java",
"//third_party/custom_tabs_client:custom_tabs_support_java",
"//third_party/gvr-android-sdk:controller_test_api_java",
"//third_party/gvr-android-sdk:gvr_common_java",
"//third_party/junit",
......
......@@ -35,17 +35,11 @@ public interface VrDaydreamApi {
*/
Intent createVrIntent(final ComponentName componentName);
/**
* Launch the given PendingIntent in VR mode.
* @return false if unable to acquire DaydreamApi instance.
*/
boolean launchInVr(final PendingIntent pendingIntent);
/**
* Launch the given Intent in VR mode.
* @return false if unable to acquire DaydreamApi instance.
*/
boolean launchInVr(final Intent intent);
boolean launchInVr(final PendingIntent pendingIntent);
/**
* @param requestCode The requestCode used by startActivityForResult.
......
......@@ -67,15 +67,6 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
return true;
}
@Override
public boolean launchInVr(final Intent intent) {
DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return false;
daydreamApi.launchInVr(intent);
daydreamApi.close();
return true;
}
@Override
public boolean exitFromVr(int requestCode, final Intent intent) {
Activity activity = WindowAndroid.activityFromContext(mContext);
......
// Copyright 2017 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.chrome.browser.vr_shell;
import android.content.Intent;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.IntentHandler;
// TODO(bsheedy): Move more VR intent related code into here even if it doesn't need
// to be overridden for testing
/**
* Handles VR intent checking for VrShellDelegate.
*/
public class VrIntentHandler {
private static VrIntentHandler sInstance;
private static final String DAYDREAM_HOME_PACKAGE = "com.google.android.vr.home";
/**
* Determines whether the given intent is a VR intent from Daydream Home.
* @param intent The intent to check
* @return Whether the intent is a VR intent and originated from Daydream Home
*/
public boolean isTrustedDaydreamIntent(Intent intent) {
return VrShellDelegate.isVrIntent(intent)
&& IntentHandler.isIntentFromTrustedApp(intent, DAYDREAM_HOME_PACKAGE);
}
/**
* Gets the static VrIntentHandler instance.
* @return The VrIntentHandler instance
*/
public static VrIntentHandler getInstance() {
if (sInstance == null) {
sInstance = new VrIntentHandler();
}
return sInstance;
}
@VisibleForTesting
public static void setInstanceForTesting(VrIntentHandler handler) {
sInstance = handler;
}
}
......@@ -46,6 +46,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
......@@ -94,7 +95,8 @@ public class VrShellDelegate
@IntDef({VR_NOT_AVAILABLE, VR_CARDBOARD, VR_DAYDREAM})
private @interface VrSupportLevel {}
public static final String DAYDREAM_VR_EXTRA = "android.intent.extra.VR_LAUNCH";
private static final String DAYDREAM_VR_EXTRA = "android.intent.extra.VR_LAUNCH";
private static final String DAYDREAM_HOME_PACKAGE = "com.google.android.vr.home";
static final String VR_FRE_INTENT_EXTRA = "org.chromium.chrome.browser.vr_shell.VR_FRE";
// Linter and formatter disagree on how the line below should be formatted.
......@@ -841,6 +843,11 @@ public class VrShellDelegate
sBlackOverlayView = null;
}
private static boolean isTrustedDaydreamIntent(Intent intent) {
return isVrIntent(intent)
&& IntentHandler.isIntentFromTrustedApp(intent, DAYDREAM_HOME_PACKAGE);
}
private void onAutopresentIntent() {
// Autopresent intents are only expected from trusted first party apps while
// we're not in vr.
......@@ -871,7 +878,7 @@ public class VrShellDelegate
VrShellDelegate instance = getInstance(activity);
if (instance == null) return;
instance.onVrIntent();
if (VrIntentHandler.getInstance().isTrustedDaydreamIntent(intent)) {
if (isTrustedDaydreamIntent(intent)) {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEBVR_AUTOPRESENT)
|| !activitySupportsPresentation(activity)
|| !isVrShellEnabled(instance.mVrSupportLevel)) {
......@@ -886,7 +893,7 @@ public class VrShellDelegate
* This is called when ChromeTabbedActivity gets a new intent before native is initialized.
*/
public static void maybeHandleVrIntentPreNative(ChromeActivity activity, Intent intent) {
if (VrIntentHandler.getInstance().isTrustedDaydreamIntent(intent)) {
if (isTrustedDaydreamIntent(intent)) {
// We add a black overlay view so that we can show black while the VR UI is loading.
// Note that this alone isn't sufficient to prevent 2D UI from showing when
// auto-presenting WebVR. See comment about the custom animation in {@link
......
......@@ -1307,7 +1307,6 @@ chrome_vr_java_sources = [
"java/src/org/chromium/chrome/browser/vr_shell/VrCoreVersionCheckerImpl.java",
"java/src/org/chromium/chrome/browser/vr_shell/VrDaydreamApiImpl.java",
"java/src/org/chromium/chrome/browser/vr_shell/VrExternalNavigationDelegate.java",
"java/src/org/chromium/chrome/browser/vr_shell/VrIntentHandler.java",
"java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java",
"java/src/org/chromium/chrome/browser/vr_shell/VrWindowAndroid.java",
"java/src/org/chromium/chrome/browser/vr_shell/OnDispatchTouchEventCallback.java",
......
......@@ -5,8 +5,6 @@
package org.chromium.chrome.browser.vr_shell;
import static org.chromium.chrome.browser.vr_shell.VrTestRule.PAGE_LOAD_TIMEOUT_S;
import static org.chromium.chrome.browser.vr_shell.VrTestRule.POLL_CHECK_INTERVAL_SHORT_MS;
import static org.chromium.chrome.browser.vr_shell.VrTestRule.POLL_TIMEOUT_LONG_MS;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_DON_ENABLED;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM;
......@@ -21,16 +19,12 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.vr_shell.mock.MockVrIntentHandler;
import org.chromium.chrome.browser.vr_shell.util.NfcSimUtils;
import org.chromium.chrome.browser.vr_shell.util.VrTransitionUtils;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.WebContents;
/**
* End-to-end tests for transitioning between WebVR's magic window and
......@@ -65,12 +59,11 @@ public class WebVrTransitionTest {
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@RetryOnFailure(message = "crbug.com/736527")
public void testNfcFiresVrdisplayactivate() throws InterruptedException {
mVrTestRule.loadUrlAndAwaitInitialization(
VrTestRule.getHtmlTestFile("test_nfc_fires_vrdisplayactivate"),
PAGE_LOAD_TIMEOUT_S);
mVrTestRule.runJavaScriptOrFail(
"addListener()", POLL_TIMEOUT_LONG_MS, mVrTestRule.getFirstTabWebContents());
NfcSimUtils.simNfcScan(mVrTestRule.getActivity());
mVrTestRule.waitOnJavaScriptStep(mVrTestRule.getFirstTabWebContents());
mVrTestRule.endTest(mVrTestRule.getFirstTabWebContents());
......@@ -91,31 +84,4 @@ public class WebVrTransitionTest {
mVrTestRule.getFirstTabCvc(), mVrTestRule.getFirstTabWebContents());
mVrTestRule.endTest(mVrTestRule.getFirstTabWebContents());
}
/**
* Tests that an intent from a trusted app such as Daydream Home allows WebVR content
* to auto present without the need for a user gesture.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testTrustedIntentAllowsAutoPresent() throws InterruptedException {
VrIntentHandler.setInstanceForTesting(new MockVrIntentHandler(
true /* useMockImplementation */, true /* treatIntentsAsTrusted */));
VrTransitionUtils.sendDaydreamAutopresentIntent(
mVrTestRule.getHtmlTestFile("test_webvr_autopresent"), mVrTestRule.getActivity());
// Wait until the link is opened in a new tab
final ChromeActivity act = mVrTestRule.getActivity();
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
return act.getTabModelSelector().getTotalTabCount() == 2;
}
}, POLL_TIMEOUT_LONG_MS, POLL_CHECK_INTERVAL_SHORT_MS);
WebContents wc = mVrTestRule.getActivity().getActivityTab().getWebContents();
mVrTestRule.waitOnJavaScriptStep(wc);
mVrTestRule.endTest(wc);
}
}
......@@ -42,11 +42,6 @@ public class MockVrDaydreamApi implements VrDaydreamApi {
return true;
}
@Override
public boolean launchInVr(final Intent intent) {
return true;
}
@Override
public boolean exitFromVr(int requestCode, final Intent intent) {
return true;
......
// Copyright 2017 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.chrome.browser.vr_shell.mock;
import android.content.Intent;
import org.chromium.chrome.browser.vr_shell.VrIntentHandler;
/**
* Mock version of VrIntentHandler for testing.
*/
public class MockVrIntentHandler extends VrIntentHandler {
private boolean mUseMockImplementation;
private boolean mTreatIntentsAsTrusted;
public MockVrIntentHandler(boolean useMockImplementation, boolean treatIntentsAsTrusted) {
mUseMockImplementation = useMockImplementation;
mTreatIntentsAsTrusted = treatIntentsAsTrusted;
}
@Override
public boolean isTrustedDaydreamIntent(Intent intent) {
if (mUseMockImplementation) {
return mTreatIntentsAsTrusted;
}
return super.isTrustedDaydreamIntent(intent);
}
public void setUseMockImplementation(boolean enabled) {
mUseMockImplementation = enabled;
}
public void setTreatIntentsAsTrusted(boolean trusted) {
mTreatIntentsAsTrusted = trusted;
}
}
......@@ -7,17 +7,9 @@ package org.chromium.chrome.browser.vr_shell.util;
import static org.chromium.chrome.browser.vr_shell.VrTestRule.POLL_CHECK_INTERVAL_SHORT_MS;
import static org.chromium.chrome.browser.vr_shell.VrTestRule.POLL_TIMEOUT_LONG_MS;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.support.customtabs.CustomTabsIntent;
import com.google.vr.ndk.base.DaydreamApi;
import org.junit.Assert;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.vr_shell.VrClassesWrapperImpl;
import org.chromium.chrome.browser.vr_shell.VrShellDelegate;
import org.chromium.chrome.browser.vr_shell.VrTestRule;
import org.chromium.content.browser.ContentViewCore;
......@@ -138,31 +130,4 @@ public class VrTransitionUtils {
});
return isBackButtonEnabled.get();
}
/**
* Sends an intent to Chrome telling it to autopresent the given URL. This
* is expected to fail unless the trusted intent check is disabled in VrShellDelegate.
*
* @param url String containing the URL to open
* @param activity The activity to launch the intent from
*/
public static void sendDaydreamAutopresentIntent(String url, final Activity activity) {
// Create an intent that will launch Chrome at the specified URL with autopresent
final Intent intent =
activity.getPackageManager().getLaunchIntentForPackage(activity.getPackageName());
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.putExtra(VrShellDelegate.DAYDREAM_VR_EXTRA, true);
DaydreamApi.setupVrIntent(intent);
intent.removeCategory("com.google.intent.category.DAYDREAM");
CustomTabsIntent.setAlwaysUseBrowserUI(intent);
final VrClassesWrapperImpl wrapper = new VrClassesWrapperImpl();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
wrapper.createVrDaydreamApi(activity).launchInVr(intent);
}
});
}
}
......@@ -13,10 +13,8 @@ vrdisplayactivate event
<script src="../resources/webvr_e2e.js"></script>
<script>
var t = async_test("NFC scan fires the vrdisplayactivate event");
function addListener() {
window.addEventListener("vrdisplayactivate", () => {t.done();}, false);
}
// NFC scan triggered after page loaded and listener added
window.addEventListener("vrdisplayactivate", () => {t.done();}, false);
// NFC scan triggered after page load
</script>
</body>
</html>
<!doctype html>
<!--
Tests that an intent from a trusted app allows a page to auto present without
the need for a user gesture.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../resources/webvr_e2e.css">
</head>
<body>
<canvas id="webgl-canvas"></canvas>
<script src="../../../../../../third_party/WebKit/LayoutTests/resources/testharness.js"></script>
<script src="../resources/webvr_e2e.js"></script>
<script src="../resources/webvr_boilerplate.js"></script>
<script>
var t = async_test("Trusted intents allow auto present");
// We need to wait for vrDisplay to be non-null before adding the
// listener, so poll it
function pollVrDisplay() {
if (vrDisplay == null) {
window.setTimeout(pollVrDisplay, 100);
return
}
window.addEventListener("vrdisplayactivate", () => {
vrDisplay.requestPresent([{source: webglCanvas}]).then( () => {
// Do nothing
}, () => {
t.step( () => {
assert_unreached("requestPresent promise rejected");
});
}).then( () => {
t.done();
});
}, false);
}
window.setTimeout(pollVrDisplay, 100);
</script>
</body>
</html>
......@@ -87,6 +87,7 @@ gl.enable(gl.DEPTH_TEST);
gl.enable(gl.CULL_FACE);
window.addEventListener("resize", onResize, false);
window.addEventListener("vrdisplaypresentchange", onVrPresentChange, false);
window.addEventListener('vrdisplayactivate', onVrRequestPresent, false);
window.requestAnimationFrame(onAnimationFrame);
webglCanvas.onclick = onVrRequestPresent;
onResize();
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