1# XR Browser Test Details 2 3[TOC] 4 5## Test Input Architecture 6 7### Overview 8 9When a [`MockXRDeviceHookBase`][xr hook base] is constructed, it sets itself as 10the current test hook in [`XRServiceTestHook::SetTestHook()`][xr service hook]. 11This then causes the provided test hook to be set as the current hook for each 12runtime. What specifically each runtime does after that differs (covered in each 13runtime's specific section), but the important part is that the runtimes will 14start calling into the test via Mojo to get controller and headset data instead 15of attempting to use the real implementation. 16 17[xr hook base]: https://chromium.googlesource.com/chromium/src/+/master/chrome/browser/vr/test/mock_xr_device_hook_base.h 18[xr service hook]: https://chromium.googlesource.com/chromium/src/+/HEAD/content/services/isolated_xr_device/xr_service_test_hook.cc 19 20### WMR 21 22WMR is handled by mock implementations of the wrapper classes that surround all 23calls to the WMR API. The real wrappers are found in 24[`//device/vr/windows_mixed_reality/wrappers/`][real wmr wrappers] while the 25mocks are in 26[`//device/vr/windows_mixed_reality/wrappers/test/`][mock wmr wrappers]. 27 28[real wmr wrappers]: https://chromium.googlesource.com/chromium/src/+/HEAD/device/vr/windows_mixed_reality/wrappers 29[mock wmr wrappers]: https://chromium.googlesource.com/chromium/src/+/HEAD/device/vr/windows_mixed_reality/wrappers/test/ 30 31When [`XRServiceTestHook::SetTestHook()`][xr service hook] is called, it in turn 32calls [`MixedRealityDeviceStatics::SetTestHook()`][wmr statics]. This stores the 33reference to the hook for later use. 34 35[wmr statics]: https://chromium.googlesource.com/chromium/src/+/HEAD/device/vr/windows_mixed_reality/mixed_reality_statics.h 36 37When any of several WMR wrappers are created through the factories in 38[`//device/vr/windows_mixed_reality/wrappers/wmr_wrapper_factories.h`][wmr factories], 39they check [`MixedRealityDeviceStatics::ShouldUseMocks()`][wmr statics]. The 40first time this is called, it returns true if the hook has already been set, or 41false otherwise. Subsequent calls will always return the same value as the first 42call did. This means that usage of the real and mock wrappers are impossible to 43accidentally mix. **Note** This also means that it's currently impossible to 44switch to or from the mock wrappers during a test after the runtime has been 45attempted to be started. 46 47[wmr factories]: https://chromium.googlesource.com/chromium/src/+/HEAD/device/vr/windows_mixed_reality/wrappers/wmr_wrapper_factories.h 48 49When the mock wrappers are in use, any calls made to them that would require 50data from the headset or controllers calls into the test via the test hook. 51Since multiple wrapper classes could potentially be using the hook at once, the 52hook is actually provided by acquiring a [`LockedVRTestHook`][locked hook] via 53[`MixedRealityDeviceStatics::GetLockedTestHook()`][wmr statics]. This is 54effectively a reference to the currently set 55[`MockXRDeviceHookBase`][xr hook base] that automatically acquires and releases 56a static lock on construction and destruction, making usage of the hook thread 57safe. 58 59[locked hook]:https://chromium.googlesource.com/chromium/src/+/HEAD/device/vr/test/locked_vr_test_hook.h 60