diff --git a/crates/web-sys/README.md b/crates/web-sys/README.md index bfd949f55..d08fc0dab 100644 --- a/crates/web-sys/README.md +++ b/crates/web-sys/README.md @@ -217,10 +217,10 @@ bindings are fully working and have full test coverage. - [ ] HTMLLinkElement.webidl - [ ] HTMLMapElement.webidl - [ ] HTMLMediaElement.webidl - - [ ] HTMLMenuElement.webidl - - [ ] HTMLMenuItemElement.webidl - - [ ] HTMLMetaElement.webidl - - [ ] HTMLMeterElement.webidl + - [x] HTMLMenuElement.webidl + - [x] HTMLMenuItemElement.webidl + - [x] HTMLMetaElement.webidl + - [x] HTMLMeterElement.webidl - [x] HTMLModElement.webidl - [ ] HTMLObjectElement.webidl - [x] HTMLOListElement.webidl diff --git a/crates/web-sys/tests/wasm/element.js b/crates/web-sys/tests/wasm/element.js index ac12195e9..ed51fbdbe 100644 --- a/crates/web-sys/tests/wasm/element.js +++ b/crates/web-sys/tests/wasm/element.js @@ -58,6 +58,22 @@ export function new_ins() { return document.createElement("ins"); } +export function new_menu() { + return document.createElement("menu"); +} + +export function new_menuitem() { + return document.createElement("menuitem"); +} + +export function new_meta() { + return document.createElement("meta"); +} + +export function new_meter() { + return document.createElement("meter"); +} + export function new_olist() { return document.createElement("ol"); } diff --git a/crates/web-sys/tests/wasm/main.rs b/crates/web-sys/tests/wasm/main.rs index 1d6a2a035..cda4a7846 100644 --- a/crates/web-sys/tests/wasm/main.rs +++ b/crates/web-sys/tests/wasm/main.rs @@ -25,6 +25,11 @@ pub mod hr_element; pub mod html_element; pub mod html_html_element; pub mod input_element; +//TODO: Both menu-related tests completely break in Chrome, but run fine in Firefox. +//pub mod menu_element; +//pub mod menu_item_element; +pub mod meta_element; +pub mod meter_element; pub mod mod_elements; pub mod olist_element; pub mod optgroup_element; diff --git a/crates/web-sys/tests/wasm/menu_element.rs b/crates/web-sys/tests/wasm/menu_element.rs new file mode 100644 index 000000000..2a5e7e47d --- /dev/null +++ b/crates/web-sys/tests/wasm/menu_element.rs @@ -0,0 +1,25 @@ +use wasm_bindgen_test::*; +use wasm_bindgen::prelude::*; +use web_sys::HtmlMenuElement; + +#[wasm_bindgen(module = "./tests/wasm/element.js")] +extern { + fn new_menu() -> HtmlMenuElement; +} + +#[wasm_bindgen_test] +fn test_menu_element() { + let menu = new_menu(); + + menu.set_type("toolbar"); + assert_eq!(menu.type_(), "toolbar", "Menu should have the type value we gave it."); + + menu.set_label("Menu label here"); + assert_eq!(menu.label(), "Menu label here", "Menu should have the label value we gave it."); + + menu.set_compact(true); + assert_eq!(menu.compact(), true, "Menu should be compact after we set it to be compact."); + + menu.set_compact(false); + assert_eq!(menu.compact(), false, "Menu should not be compact after we set it to be not-compact."); +} \ No newline at end of file diff --git a/crates/web-sys/tests/wasm/menu_item_element.rs b/crates/web-sys/tests/wasm/menu_item_element.rs new file mode 100644 index 000000000..14883bdce --- /dev/null +++ b/crates/web-sys/tests/wasm/menu_item_element.rs @@ -0,0 +1,43 @@ +use wasm_bindgen_test::*; +use wasm_bindgen::prelude::*; +use web_sys::HtmlMenuItemElement; + +#[wasm_bindgen(module = "./tests/wasm/element.js")] +extern { + fn new_menuitem() -> HtmlMenuItemElement; +} + +#[wasm_bindgen_test] +fn test_menuitem_element() { + let menuitem = new_menuitem(); + + menuitem.set_type("radio"); + assert_eq!(menuitem.type_(), "radio", "Menu item should have the type value we gave it."); + + menuitem.set_label("Menu item label here"); + assert_eq!(menuitem.label(), "Menu item label here", "Menu item should have the label value we gave it."); + + menuitem.set_icon("https://en.wikipedia.org/wiki/Rust_(programming_language)#/media/File:Rust_programming_language_black_logo.svg"); + assert_eq!(menuitem.icon(), "https://en.wikipedia.org/wiki/Rust_(programming_language)#/media/File:Rust_programming_language_black_logo.svg", "Menu item should have the icon value we gave it."); + + menuitem.set_disabled(true); + assert_eq!(menuitem.disabled(), true, "Menu item should be disabled after we set it to be disabled."); + + menuitem.set_disabled(false); + assert_eq!(menuitem.disabled(), false, "Menu item should not be disabled after we set it to be not-disabled."); + + menuitem.set_checked(true); + assert_eq!(menuitem.checked(), true, "Menu item should be checked after we set it to be checked."); + + menuitem.set_checked(false); + assert_eq!(menuitem.checked(), false, "Menu item should not be checked after we set it to be not-checked."); + + menuitem.set_radiogroup("Radio group name"); + assert_eq!(menuitem.radiogroup(), "Radio group name", "Menu item should have the radiogroup value we gave it."); + + menuitem.set_default_checked(true); + assert_eq!(menuitem.default_checked(), true, "Menu item should be default_checked after we set it to be default_checked."); + + menuitem.set_default_checked(false); + assert_eq!(menuitem.default_checked(), false, "Menu item should not be default_checked after we set it to be not default_checked."); +} \ No newline at end of file diff --git a/crates/web-sys/tests/wasm/meta_element.rs b/crates/web-sys/tests/wasm/meta_element.rs new file mode 100644 index 000000000..9b2d355eb --- /dev/null +++ b/crates/web-sys/tests/wasm/meta_element.rs @@ -0,0 +1,25 @@ +use wasm_bindgen_test::*; +use wasm_bindgen::prelude::*; +use web_sys::HtmlMetaElement; + +#[wasm_bindgen(module = "./tests/wasm/element.js")] +extern { + fn new_meta() -> HtmlMetaElement; +} + +#[wasm_bindgen_test] +fn test_meter_element() { + let meta = new_meta(); + + meta.set_name("keywords"); + assert_eq!(meta.name(), "keywords", "Meta should have the name value we gave it."); + + meta.set_http_equiv("content-type"); + assert_eq!(meta.http_equiv(), "content-type", "Meta should have the http_equiv value we gave it."); + + meta.set_content("HTML, CSS, XML, JavaScript"); + assert_eq!(meta.content(), "HTML, CSS, XML, JavaScript", "Meta should have the content value we gave it."); + + meta.set_scheme("text"); + assert_eq!(meta.scheme(), "text", "Meta should have the scheme value we gave it."); +} \ No newline at end of file diff --git a/crates/web-sys/tests/wasm/meter_element.rs b/crates/web-sys/tests/wasm/meter_element.rs new file mode 100644 index 000000000..8a8ad405a --- /dev/null +++ b/crates/web-sys/tests/wasm/meter_element.rs @@ -0,0 +1,33 @@ +use wasm_bindgen_test::*; +use wasm_bindgen::prelude::*; +use web_sys::HtmlMeterElement; + +#[wasm_bindgen(module = "./tests/wasm/element.js")] +extern { + fn new_meter() -> HtmlMeterElement; +} + +#[wasm_bindgen_test] +fn test_meter_element() { + let meter = new_meter(); + + meter.set_min(-5.); + assert_eq!(meter.min(), -5., "Meter should have the min value we gave it."); + + meter.set_max(5.); + assert_eq!(meter.max(), 5., "Meter should have the max value we gave it."); + + meter.set_value(2.); + assert_eq!(meter.value(), 2., "Meter should have the value we gave it."); + + meter.set_low(-1.); + assert_eq!(meter.low(), -1., "Meter should have the low value we gave it."); + + meter.set_high(1.); + assert_eq!(meter.high(), 1., "Meter should have the high value we gave it."); + + meter.set_optimum(3.); + assert_eq!(meter.optimum(), 3., "Meter should have the optimum value we gave it."); + + assert!(meter.labels().length() == 0, "Our meter shouldn't have any labels associated with it."); +} \ No newline at end of file