Files
servo/components/script/dom/bluetooth/testrunner.rs
Euclid Ye cae0752676 cargo: Rename workspace-local library starting with b to servo_* (#43552)
Follow up of #43526. This addresses Nico's comment:
https://github.com/servo/servo/pull/43526#issuecomment-4104953308

- `bluetooth_traits` -> `servo_bluetooth_traits`
- `base` -> `servo_base`
- `bluetooth` -> `servo_bluetooth`
- `background_hang_monitor` -> `servo_background_hang_monitor`

Testing: This should not change any behaviour.

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2026-03-23 08:26:49 +00:00

56 lines
2.0 KiB
Rust

/* 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 https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use profile_traits::generic_channel;
use servo_base::generic_channel::GenericSender;
use servo_bluetooth_traits::BluetoothRequest;
use crate::conversions::Convert;
use crate::dom::bindings::codegen::Bindings::TestRunnerBinding::TestRunnerMethods;
use crate::dom::bindings::error::ErrorResult;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::script_runtime::CanGc;
// https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner
#[dom_struct]
pub(crate) struct TestRunner {
reflector_: Reflector,
}
impl TestRunner {
pub(crate) fn new_inherited() -> TestRunner {
TestRunner {
reflector_: Reflector::new(),
}
}
pub(crate) fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot<TestRunner> {
reflect_dom_object(Box::new(TestRunner::new_inherited()), global, can_gc)
}
fn get_bluetooth_thread(&self) -> GenericSender<BluetoothRequest> {
self.global().as_window().bluetooth_thread()
}
}
impl TestRunnerMethods<crate::DomTypeHolder> for TestRunner {
// https://webbluetoothcg.github.io/web-bluetooth/tests#setBluetoothMockDataSet
#[expect(non_snake_case)]
fn SetBluetoothMockDataSet(&self, dataSetName: DOMString) -> ErrorResult {
let (sender, receiver) =
generic_channel::channel(self.global().time_profiler_chan().clone()).unwrap();
self.get_bluetooth_thread()
.send(BluetoothRequest::Test(String::from(dataSetName), sender))
.unwrap();
match receiver.recv().unwrap() {
Ok(()) => Ok(()),
Err(error) => Err(error.convert()),
}
}
}