chromium/device/vr/public/mojom/browser_test_interfaces.mojom

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module device_test.mojom;

import "device/vr/public/mojom/openxr_interaction_profile_type.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
import "ui/gfx/mojom/transform.mojom";

struct Color {
  uint8 r;
  uint8 g;
  uint8 b;
  uint8 a;
};

enum Eye {
  LEFT = 1,
  RIGHT = 2,
  NONE = 3
};

struct ViewData {
  Color color;
  Eye eye;
  gfx.mojom.Rect viewport;
};

struct PoseFrameData {
  gfx.mojom.Transform? device_to_origin;
};

// Each component is the tangent of the up/down/left/right view frustum.
struct ProjectionRaw {
  float left;
  float right;
  float top;
  float bottom;
};

struct DeviceConfig {
  float interpupillary_distance; // Distance between the eyes.

  ProjectionRaw projection_left;
  ProjectionRaw projection_right;
};

struct ControllerAxisData {
  float x;
  float y;
  uint8 axis_type; // Corresponds to OpenVR's EVRControllerAxisType
};

enum TrackedDeviceClass {
  kTrackedDeviceInvalid,
  kTrackedDeviceHmd,
  kTrackedDeviceController,
  kTrackedDeviceGenericTracker,
  kTrackedDeviceTrackingReference,
  kTrackedDeviceDisplayRedirect
};

enum ControllerRole {
  kControllerRoleInvalid, // Test hook should ignore this controller.
  kControllerRoleLeft,
  kControllerRoleRight,
  kControllerRoleVoice // Simulates voice input such as saying "select" in WMR.
};

struct ControllerFrameData {
  uint32 packet_number;
  uint64 buttons_pressed;
  uint64 buttons_touched;
  uint64 supported_buttons;
  array<ControllerAxisData, 5> axis_data;
  PoseFrameData pose_data;
  ControllerRole role = kControllerRoleInvalid;
  bool is_valid;
};

// Event type is used by test to simulate runtime events.
enum EventType {
  kSessionLost,
  kVisibilityVisibleBlurred,
  kInstanceLost,
  kInteractionProfileChanged,
  kNoEvent
};

// EventData is used by test to pass all event related data.
struct EventData {
  EventType type = kNoEvent;
  device.mojom.OpenXrInteractionProfileType interaction_profile = kInvalid;
};

// Tests may implement this, and register it to control behavior of devices for
// tests.  The test interface lives in the browser process, and may be consumed
// by the device utility process.
// It is only implemented when running in browser tests.
// In general, methods here should be sync so that we can better mimic the
// underlying runtimes, who may make these queries/notifications synchronously.
interface XRTestHook {
  // Notifies the test anytime the XR runtime receives a frame with the data
  // that was submitted. Should only be called once per frame.
  // frame_data is an array of all the views that are active in the frame. This
  // is generally the left and right eye view, but may contain additional
  // secondary views as well if secondary view configurations are enabled.
  [Sync] OnFrameSubmitted(array<ViewData> frame_data) => ();

  // Called by the XR runtime to retrieve the XR device's configuration set by
  // the test.
  [Sync] WaitGetDeviceConfig() => (DeviceConfig config);

  // Called by the XR runtime to retrieve the XR device's pose while in a
  // presenting/exclusive session.
  [Sync] WaitGetPresentingPose() => (PoseFrameData data);

  // Called by the XR runtime to retrieve the XR device's pose while in a
  // magic window/non-exclusive session.
  [Sync] WaitGetMagicWindowPose() => (PoseFrameData data);

  // Called by the XR runtime to retrieve the ControllerRole of the device
  // that the test has registered at the given index, i.e. which hand the
  // controller is mapped to.
  [Sync] WaitGetControllerRoleForTrackedDeviceIndex(uint32 index) =>
      (ControllerRole role);

  // Called by the XR runtime to retrieve the class of the device that the test
  // has registered at the given index, e.g. whether it is a controller or
  // headset.
  [Sync] WaitGetTrackedDeviceClass(uint32 index) =>
      (TrackedDeviceClass device_class);

  // Called by the XR runtime anytime it updates its controller data to retrieve
  // the controller data of the device that the test has registered at the
  // given index, e.g. its current position and pressed buttons.
  [Sync] WaitGetControllerData(uint32 index) => (ControllerFrameData data);

  // Called by the OpenXR test to simulate runtime events.
  [Sync] WaitGetEventData() => (EventData data);

  // Used to indicate if the Fake Runtime would allow creating any session.
  [Sync] WaitGetCanCreateSession() => (bool can_create_session);
};

// Interface exposed by IsolatedXRService to allow browser tests to hook VR APIs
// It is always hosted in the XRDevice process, but only has effects while
// running in browser tests with mock implementations of runtimes.
interface XRServiceTestHook {
  // We want to ensure that the test hook is set before attempting to request a
  // session, so that we can deterministically guarantee that we're using the
  // test runtime (and when), and not accidentally getting the product runtime
  // or returning garbage data from the test runtime. Thus this method needs to
  // remain sync, since this is a different mojo pipe than is used to create the
  // session, so ordering of the method calls would not otherwise be guaranteed.
  // This allows the tests to be written in a more straightforward and easily
  // debuggable manner, rather than relying on waiting for the async callback to
  // continue with the test.
  [Sync] SetTestHook(pending_remote<XRTestHook>? hook) => ();

  // Called by tests to trigger a termination of the Device Service Process
  // To test that the product can properly handle the service either crashing
  // or (more expectedly) being terminated by some other running process.
  [Sync] TerminateDeviceServiceProcessForTesting() => ();
};