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 -->
This commit is contained in:
bors-servo 2016-11-04 07:44:42 -05:00 committed by GitHub
commit dae007fd16
253 changed files with 5456 additions and 24 deletions

View file

@ -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;

View file

@ -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))
},
}
}
}

View file

@ -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);
};

View file

@ -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;
};

View file

@ -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)