| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
| <script src="file:///gen/device/vr/public/mojom/vr_service.mojom.js"></script> |
| <script src="../external/wpt/resources/chromium/webxr-test.js"></script> |
| <script src="../xr/resources/xr-test-utils.js"></script> |
| <canvas id="webgl-canvas"></canvas> |
| <script> |
| promise_test((t) => { |
| let watcherDone = new Event("watcherdone"); |
| let eventWatcher = new EventWatcher(t, navigator.xr, ["devicechange", |
| "watcherdone"]); |
| |
| // The event should fire when a listener is added even if the devices are not |
| // explicity queried with navigator.xr.requestDevice(). |
| // Note: This behaviour is chrome specific, the spec does not explicitly |
| // state when devicechange events should occur. |
| function onDeviceChange() { |
| navigator.xr.dispatchEvent(watcherDone); |
| }; |
| |
| navigator.xr.addEventListener("devicechange", onDeviceChange, false); |
| |
| let promise = eventWatcher.wait_for(["devicechange", "watcherdone"]); |
| |
| // Timeout here is required because addEventListener sends a call to mojo to |
| // register the listener on the backend, which doesn't go through until the |
| // javascript pauses. |
| setTimeout(() => { |
| XRTest.simulateDeviceConnection({ supportsImmersive:true }); |
| }, 100); |
| |
| return promise; |
| |
| }, "Test devicechange fires when devices are connected."); |
| |
| </script> |