diff options
Diffstat (limited to 'components/servo/tests/webview.rs')
-rw-r--r-- | components/servo/tests/webview.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/components/servo/tests/webview.rs b/components/servo/tests/webview.rs new file mode 100644 index 00000000000..4ed06e412da --- /dev/null +++ b/components/servo/tests/webview.rs @@ -0,0 +1,49 @@ +/* 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/. */ + +//! WebView API unit tests. +//! +//! Since all Servo tests must run serially on the same thread, it is important +//! that tests never panic. In order to ensure this, use `anyhow::ensure!` instead +//! of `assert!` for test assertions. `ensure!` will produce a `Result::Err` in +//! place of panicking. + +mod common; + +use std::cell::Cell; +use std::rc::Rc; + +use anyhow::ensure; +use common::{ServoTest, run_api_tests}; +use servo::{WebViewBuilder, WebViewDelegate}; + +#[derive(Default)] +struct WebViewDelegateImpl { + url_changed: Cell<bool>, +} + +impl WebViewDelegate for WebViewDelegateImpl { + fn notify_url_changed(&self, _webview: servo::WebView, _url: url::Url) { + self.url_changed.set(true); + } +} + +fn test_create_webview(servo_test: &ServoTest) -> Result<(), anyhow::Error> { + let delegate = Rc::new(WebViewDelegateImpl::default()); + let webview = WebViewBuilder::new(servo_test.servo()) + .delegate(delegate.clone()) + .build(); + + servo_test.spin(move || Ok(!delegate.url_changed.get()))?; + + let url = webview.url(); + ensure!(url.is_some()); + ensure!(url.unwrap().to_string() == "about:blank"); + + Ok(()) +} + +fn main() { + run_api_tests!(test_create_webview); +} |