diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-04 07:44:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-04 07:44:42 -0500 |
commit | dae007fd1634bcf1545e67abaa7746fa95f10e94 (patch) | |
tree | af4ee95a6116796e9fb432ad330649f708f50210 /components/script | |
parent | 73c9847ef81e838c970e44c1645209134fddd32e (diff) | |
parent | ada0256030904412727d85af036dcfd8605dcb97 (diff) | |
download | servo-dae007fd1634bcf1545e67abaa7746fa95f10e94.tar.gz servo-dae007fd1634bcf1545e67abaa7746fa95f10e94.zip |
Auto merge of #13612 - szeged:test-api-impl, r=jdm
WebBluetooth Test API and tests
<!-- Please describe your changes on the following line: -->
This patch depends on the [devices mock device support PR](https://github.com/servo/devices/pull/17).
After it lands, the Cargo files can be updated.
1. Adjust to the changes in [devices mock device support PR](https://github.com/servo/devices/pull/17).
2. WebBluetooth Test API implementation. Based on : https://webbluetoothcg.github.io/web-bluetooth/tests.html
3. Wpt tests for the already landed WebBluetooth functions.
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
<!-- Either: -->
- [x] There are tests for these changes
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13612)
<!-- Reviewable:end -->
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) |