Skip to content
Permalink
Browse files

Improve session test lifecycle code

  • Loading branch information...
Manishearth committed Jul 23, 2019
1 parent 518a55c commit d996d3c1ebb07a7fe32f22c51c08664b00ceb106
@@ -7,13 +7,19 @@ use crate::dom::bindings::codegen::Bindings::FakeXRDeviceBinding::{
};
use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::refcounted::TrustedPromise;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use euclid::{Point2D, Rect, Size2D};
use euclid::{RigidTransform3D, Rotation3D, Transform3D, Vector3D};
use ipc_channel::ipc::IpcSender;
use ipc_channel::router::ROUTER;
use profile_traits::ipc;
use std::rc::Rc;
use webxr_api::{MockDeviceMsg, View, Views};

#[dom_struct]
@@ -139,4 +145,27 @@ impl FakeXRDeviceMethods for FakeXRDevice {
.send(MockDeviceMsg::SetViewerOrigin(get_origin(origin)?));
Ok(())
}

/// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md
fn Disconnect(&self) -> Rc<Promise> {
let global = self.global();
let p = Promise::new(&global);
let mut trusted = Some(TrustedPromise::new(p.clone()));
let (task_source, canceller) = global
.as_window()
.task_manager()
.dom_manipulation_task_source_with_canceller();
let (sender, receiver) = ipc::channel(global.time_profiler_chan().clone()).unwrap();
ROUTER.add_route(
receiver.to_opaque(),
Box::new(move |_| {
let trusted = trusted
.take()
.expect("disconnect callback called multiple times");
let _ = task_source.queue_with_canceller(trusted.resolve_task(()), &canceller);
}),
);
self.disconnect(sender);
p
}
}
@@ -26,6 +26,9 @@ interface FakeXRDevice {

// Promise<FakeXRInputController>
// simulateInputSourceConnection(FakeXRInputSourceInit);

// behaves as if device was disconnected
Promise<void> disconnect();
};

// https://immersive-web.github.io/webxr/#dom-xrwebgllayer-getviewport
@@ -178,9 +178,7 @@ impl XRTestMethods for XRTest {
let mut rooted_devices: Vec<_> =
devices.iter().map(|x| DomRoot::from_ref(&**x)).collect();
devices.clear();
for device in rooted_devices.drain(..) {
device.disconnect(sender.clone());
}

let mut trusted = Some(TrustedPromise::new(p.clone()));
let (task_source, canceller) = global
.as_window()
@@ -201,9 +199,9 @@ impl XRTestMethods for XRTest {
}),
);

// XXXManishearth this is a hack, it will need to be replaced when
// we improve how mock messaging works
p.resolve_native(&())
for device in rooted_devices.drain(..) {
device.disconnect(sender.clone());
}
};
p
}
@@ -1,4 +1,5 @@
[xrDevice_disconnect_ends.https.html]
expected: TIMEOUT
[Immersive session ends when device is disconnected]
expected: FAIL
expected: TIMEOUT

0 comments on commit d996d3c

Please sign in to comment.
You can’t perform that action at this time.