diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/mod.rs | 1 | ||||
-rw-r--r-- | components/script/dom/testrunner.rs | 53 | ||||
-rw-r--r-- | components/script/dom/webidls/TestRunner.webidl | 16 | ||||
-rw-r--r-- | components/script/dom/webidls/Window.webidl | 7 | ||||
-rw-r--r-- | components/script/dom/window.rs | 8 |
5 files changed, 85 insertions, 0 deletions
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 14498823424..d419d41ec61 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -399,6 +399,7 @@ pub mod testbinding; pub mod testbindingiterable; pub mod testbindingpairiterable; pub mod testbindingproxy; +pub mod testrunner; pub mod text; pub mod textdecoder; pub mod textencoder; diff --git a/components/script/dom/testrunner.rs b/components/script/dom/testrunner.rs new file mode 100644 index 00000000000..f96ab6dbf65 --- /dev/null +++ b/components/script/dom/testrunner.rs @@ -0,0 +1,53 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use bluetooth_traits::BluetoothMethodMsg; +use dom::bindings::codegen::Bindings::TestRunnerBinding; +use dom::bindings::codegen::Bindings::TestRunnerBinding::TestRunnerMethods; +use dom::bindings::error::{Error, ErrorResult}; +use dom::bindings::js::Root; +use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; +use dom::bindings::str::DOMString; +use dom::globalscope::GlobalScope; +use ipc_channel::ipc::{self, IpcSender}; + +// https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner + #[dom_struct] +pub struct TestRunner { + reflector_: Reflector, +} + +impl TestRunner { + pub fn new_inherited() -> TestRunner { + TestRunner { + reflector_: Reflector::new(), + } + } + + pub fn new(global: &GlobalScope) -> Root<TestRunner> { + reflect_dom_object(box TestRunner::new_inherited(), + global, + TestRunnerBinding::Wrap) + } + + fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> { + self.global().as_window().bluetooth_thread() + } +} + +impl TestRunnerMethods for TestRunner { + // https://webbluetoothcg.github.io/web-bluetooth/tests#setBluetoothMockDataSet + fn SetBluetoothMockDataSet(&self, dataSetName: DOMString) -> ErrorResult { + let (sender, receiver) = ipc::channel().unwrap(); + self.get_bluetooth_thread().send(BluetoothMethodMsg::Test(String::from(dataSetName), sender)).unwrap(); + match receiver.recv().unwrap().into() { + Ok(()) => { + Ok(()) + }, + Err(error) => { + Err(Error::from(error)) + }, + } + } +} diff --git a/components/script/dom/webidls/TestRunner.webidl b/components/script/dom/webidls/TestRunner.webidl new file mode 100644 index 00000000000..0326c14dbec --- /dev/null +++ b/components/script/dom/webidls/TestRunner.webidl @@ -0,0 +1,16 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner + +// callback BluetoothManualChooserEventsCallback = void(sequence<DOMString> events); + +[Pref="dom.bluetooth.testing.enabled", Exposed=Window] +interface TestRunner { + [Throws] + void setBluetoothMockDataSet(DOMString dataSetName); + // void setBluetoothManualChooser(); + // void getBluetoothManualChooserEvents(BluetoothManualChooserEventsCallback callback); + // void sendBluetoothManualChooserEvent(DOMString event, DOMString argument); +}; diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index ad3494b6f5f..5e7e08d4b18 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -185,3 +185,10 @@ Window implements WindowLocalStorage; // http://w3c.github.io/animation-timing/#framerequestcallback callback FrameRequestCallback = void (DOMHighResTimeStamp time); + +// https://webbluetoothcg.github.io/web-bluetooth/tests#test-interfaces +partial interface Window { + [Pref="dom.bluetooth.testing.enabled", Exposed=Window] + readonly attribute TestRunner testRunner; + //readonly attribute EventSender eventSender; +}; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index c77ed80cff9..3d3d7dde2a7 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -45,6 +45,7 @@ use dom::performance::Performance; use dom::promise::Promise; use dom::screen::Screen; use dom::storage::Storage; +use dom::testrunner::TestRunner; use euclid::{Point2D, Rect, Size2D}; use fetch; use ipc_channel::ipc::{self, IpcSender}; @@ -239,6 +240,8 @@ pub struct Window { /// All the MediaQueryLists we need to update media_query_lists: WeakMediaQueryListVec, + + test_runner: MutNullableHeap<JS<TestRunner>>, } impl Window { @@ -881,6 +884,10 @@ impl WindowMethods for Window { fn Fetch(&self, input: RequestOrUSVString, init: &RequestInit) -> Rc<Promise> { fetch::Fetch(&self.upcast(), input, init) } + + fn TestRunner(&self) -> Root<TestRunner> { + self.test_runner.or_init(|| TestRunner::new(self.upcast())) + } } impl Window { @@ -1588,6 +1595,7 @@ impl Window { error_reporter: error_reporter, scroll_offsets: DOMRefCell::new(HashMap::new()), media_query_lists: WeakMediaQueryListVec::new(), + test_runner: Default::default(), }; WindowBinding::Wrap(runtime.cx(), win) |