diff --git a/crates/web-sys/tests/all/history.rs b/crates/web-sys/tests/all/history.rs new file mode 100644 index 00000000..8af76f98 --- /dev/null +++ b/crates/web-sys/tests/all/history.rs @@ -0,0 +1,44 @@ +use super::websys_project; + +#[test] +fn history() { + websys_project() + .file( + "src/lib.rs", + r#" + #![feature(use_extern_macros)] + extern crate wasm_bindgen; + use wasm_bindgen::prelude::*; + extern crate web_sys; + + #[wasm_bindgen] + pub fn test_history(history: &web_sys::History) { + assert_eq!(history.length().unwrap(), 2); + + assert!(history.go(1).is_ok()); + assert!(history.back().is_ok()); + assert!(history.forward().is_ok()); + assert!(history.go(-1).is_ok()); + + history.set_scroll_restoration(web_sys::ScrollRestoration::Manual).expect("failure to set scroll restoration"); + assert_eq!(history.scroll_restoration().unwrap(), web_sys::ScrollRestoration::Manual); + + history.set_scroll_restoration(web_sys::ScrollRestoration::Auto).expect("failure to set scroll restoration"); + assert_eq!(history.scroll_restoration().unwrap(), web_sys::ScrollRestoration::Auto); + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + window.history.pushState({}, "I am a title", "part/of/some/url"); + wasm.test_history(window.history); + } + "#, + ) + .test(); +} diff --git a/crates/web-sys/tests/all/main.rs b/crates/web-sys/tests/all/main.rs index 01052ba7..d0200b0a 100644 --- a/crates/web-sys/tests/all/main.rs +++ b/crates/web-sys/tests/all/main.rs @@ -5,6 +5,7 @@ mod event; mod headers; mod response; mod element; +mod history; fn websys_project() -> Project { project() diff --git a/crates/web-sys/webidls/available/History.webidl b/crates/web-sys/webidls/enabled/History.webidl similarity index 100% rename from crates/web-sys/webidls/available/History.webidl rename to crates/web-sys/webidls/enabled/History.webidl