WebXR - DOM overlay and hit test - add test case
Add test case for the DOM overlay and hit test API interaction - hit
test results should be suppressed if the input source is interacting with
cross-origin content.
Change-Id: Ib7af656c19177ef725205e8bd27bac57b81b9cce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2103302
Reviewed-by: Klaus Weidner <klausw@chromium.org>
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750411}
diff --git a/webxr/dom-overlay/ar_dom_overlay_hit_test.https.html b/webxr/dom-overlay/ar_dom_overlay_hit_test.https.html
new file mode 100644
index 0000000..406efe8
--- /dev/null
+++ b/webxr/dom-overlay/ar_dom_overlay_hit_test.https.html
@@ -0,0 +1,113 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/webxr_util.js"></script>
+<script src="../resources/webxr_test_constants.js"></script>
+<script src="../resources/webxr_test_constants_fake_world.js"></script>
+<script src="../resources/webxr_test_asserts.js"></script>
+
+<style type="text/css">
+ div {
+ padding: 10px;
+ min-width: 10px;
+ min-height: 10px;
+ }
+ iframe {
+ border: 0;
+ width: 20px;
+ height: 20px;
+ }
+</style>
+<div id="div_overlay">
+ <div id="inner_b">
+ </div>
+ <!-- This SVG iframe is treated as cross-origin content. -->
+ <iframe id="iframe" src='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect height="20" width="20" fill="red" fill-opacity="0.3"/></svg>'>
+ </iframe>
+ <canvas>
+ </canvas>
+</div>
+
+<script>
+
+const fakeDeviceInitParams = {
+ supportedModes: ["immersive-ar"],
+ views: VALID_VIEWS,
+ viewerOrigin: IDENTITY_TRANSFORM,
+ supportedFeatures: ALL_FEATURES,
+};
+
+const hitTestOptionsInit = {
+ profile: "generic-touchscreen",
+ offsetRay: new XRRay(),
+};
+
+const SCREEN_POINTER_TRANSFORM = {
+ position: [0, 0, 0], // middle of the screen
+ orientation: [0, 0, 0, 1] // forward-facing
+};
+
+const screen_controller_init = {
+ handedness: "none",
+ targetRayMode: "screen",
+ pointerOrigin: SCREEN_POINTER_TRANSFORM, // aka input_from_pointer
+ profiles: ["generic-touchscreen",]
+};
+
+const testCrossOriginContent = function(overlayElement, session, fakeDeviceController, t) {
+ const iframe = document.getElementById('iframe');
+ const inner_b = document.getElementById('inner_b');
+
+ const input_source =
+ fakeDeviceController.simulateInputSourceConnection(screen_controller_init);
+ return session.requestReferenceSpace('viewer').then(function(viewerSpace) {
+ return session.requestHitTestSourceForTransientInput(hitTestOptionsInit)
+ .then((hitTestSource) => {
+ // Press the primary input button and then release it a short time later.
+ session.requestAnimationFrame((time, xrFrame) => {
+ input_source.setOverlayPointerPosition(iframe.offsetLeft + 1,
+ iframe.offsetTop + 1);
+ input_source.startSelection();
+
+ session.requestAnimationFrame((time, xrFrame) => {
+ input_source.endSelection();
+
+ // There should be no results for transient input for cross origin content:
+ const results = xrFrame.getHitTestResultsForTransientInput(hitTestSource);
+ t.step(() => {
+ assert_true(results.length === 0, "Hit test results should be suppressed for cross-origin content");
+ });
+
+ session.requestAnimationFrame((time, xrFrame) => {
+ // Need to process one more frame to allow select to propagate
+
+ session.requestAnimationFrame((time, xrFrame) => {
+ input_source.setOverlayPointerPosition(inner_b.offsetLeft + 1,
+ inner_b.offsetTop + 1);
+ input_source.startSelection();
+
+ session.requestAnimationFrame((time, xrFrame) => {
+ input_source.endSelection();
+
+ const results = xrFrame.getHitTestResultsForTransientInput(hitTestSource);
+ t.step(() => {
+ assert_true(results.length === 1, "Hit test results should not be for cross-origin content");
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+};
+
+xr_session_promise_test(
+ "Ensures DOM Overlay interactions on cross origin iframe do not cause hit test results to come up",
+ testCrossOriginContent.bind(this, document.getElementById('div_overlay')),
+ fakeDeviceInitParams, 'immersive-ar', {
+ requiredFeatures: ['dom-overlay', 'hit-test'],
+ domOverlay: { root: document.getElementById('div_overlay') }
+ });
+
+</script>