diff options
Diffstat (limited to 'vendor/web-sys/tests/wasm')
54 files changed, 2871 insertions, 0 deletions
diff --git a/vendor/web-sys/tests/wasm/anchor_element.rs b/vendor/web-sys/tests/wasm/anchor_element.rs new file mode 100644 index 000000000..7f09c2501 --- /dev/null +++ b/vendor/web-sys/tests/wasm/anchor_element.rs @@ -0,0 +1,72 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlAnchorElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_a() -> HtmlAnchorElement; +} + +#[wasm_bindgen_test] +fn test_anchor_element() { + let element = new_a(); + assert_eq!(element.target(), "", "Shouldn't have a target"); + element.set_target("_blank"); + assert_eq!(element.target(), "_blank", "Should have a target"); + + assert_eq!(element.download(), "", "Shouldn't have a download"); + element.set_download("boop.png"); + assert_eq!(element.download(), "boop.png", "Should have a download"); + + assert_eq!(element.ping(), "", "Shouldn't have a ping"); + element.set_ping("boop"); + assert_eq!(element.ping(), "boop", "Should have a ping"); + + assert_eq!(element.rel(), "", "Shouldn't have a rel"); + element.set_rel("boop"); + assert_eq!(element.rel(), "boop", "Should have a rel"); + + assert_eq!( + element.referrer_policy(), + "", + "Shouldn't have a referrer_policy" + ); + element.set_referrer_policy("origin"); + assert_eq!( + element.referrer_policy(), + "origin", + "Should have a referrer_policy" + ); + + assert_eq!(element.hreflang(), "", "Shouldn't have a hreflang"); + element.set_hreflang("en-us"); + assert_eq!(element.hreflang(), "en-us", "Should have a hreflang"); + + assert_eq!(element.type_(), "", "Shouldn't have a type"); + element.set_type("text/plain"); + assert_eq!(element.type_(), "text/plain", "Should have a type"); + + assert_eq!(element.text().unwrap(), "", "Shouldn't have a text"); + element.set_text("Click me!").unwrap(); + assert_eq!(element.text().unwrap(), "Click me!", "Should have a text"); + + assert_eq!(element.coords(), "", "Shouldn't have a coords"); + element.set_coords("1,2,3"); + assert_eq!(element.coords(), "1,2,3", "Should have a coords"); + + assert_eq!(element.charset(), "", "Shouldn't have a charset"); + element.set_charset("thing"); + assert_eq!(element.charset(), "thing", "Should have a charset"); + + assert_eq!(element.name(), "", "Shouldn't have a name"); + element.set_name("thing"); + assert_eq!(element.name(), "thing", "Should have a name"); + + assert_eq!(element.rev(), "", "Shouldn't have a rev"); + element.set_rev("thing"); + assert_eq!(element.rev(), "thing", "Should have a rev"); + + assert_eq!(element.shape(), "", "Shouldn't have a shape"); + element.set_shape("thing"); + assert_eq!(element.shape(), "thing", "Should have a shape"); +} diff --git a/vendor/web-sys/tests/wasm/blob.js b/vendor/web-sys/tests/wasm/blob.js new file mode 100644 index 000000000..9fdd18bf4 --- /dev/null +++ b/vendor/web-sys/tests/wasm/blob.js @@ -0,0 +1,3 @@ +export function new_blob() { + return new Blob([ 1, 2, 3 ]); +} diff --git a/vendor/web-sys/tests/wasm/blob.rs b/vendor/web-sys/tests/wasm/blob.rs new file mode 100644 index 000000000..726ffc715 --- /dev/null +++ b/vendor/web-sys/tests/wasm/blob.rs @@ -0,0 +1,64 @@ +use js_sys::{Array, ArrayBuffer}; +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::JsFuture; +use wasm_bindgen_test::*; +use web_sys::Blob; + +#[wasm_bindgen(module = "/tests/wasm/blob.js")] +extern "C" { + fn new_blob() -> Blob; +} + +#[wasm_bindgen_test] +fn test_blob_from_js() { + let blob = new_blob(); + assert!(blob.is_instance_of::<Blob>()); + assert_eq!(blob.size(), 3.0); +} + +#[wasm_bindgen_test] +fn test_blob_from_bytes() { + let bytes = Array::new(); + bytes.push(&1.into()); + bytes.push(&2.into()); + bytes.push(&3.into()); + + let blob = Blob::new_with_u8_array_sequence(&bytes.into()).unwrap(); + assert!(blob.is_instance_of::<Blob>()); + assert_eq!(blob.size(), 3.0); +} + +#[wasm_bindgen_test] +fn test_blob_empty() { + let blob = Blob::new().unwrap(); + assert!(blob.is_instance_of::<Blob>()); + assert_eq!(blob.size(), 0.0); +} + +#[wasm_bindgen_test] +async fn test_blob_array_buffer() { + let bytes = Array::new(); + bytes.push(&1.into()); + bytes.push(&2.into()); + bytes.push(&3.into()); + + let blob = Blob::new_with_u8_array_sequence(&bytes.into()).unwrap(); + + let buffer: ArrayBuffer = JsFuture::from(blob.array_buffer()).await.unwrap().into(); + + assert!(blob.is_instance_of::<Blob>()); + assert!(buffer.is_instance_of::<ArrayBuffer>()); + assert_eq!(blob.size(), buffer.byte_length() as f64); +} + +#[wasm_bindgen_test] +async fn test_blob_text() { + let strings = Array::new(); + strings.push(&"hello".into()); + + let blob = Blob::new_with_str_sequence(&strings.into()).unwrap(); + let string = JsFuture::from(blob.text()).await.unwrap(); + + assert!(blob.is_instance_of::<Blob>()); + assert_eq!(string, "hello") +} diff --git a/vendor/web-sys/tests/wasm/body_element.rs b/vendor/web-sys/tests/wasm/body_element.rs new file mode 100644 index 000000000..daf5769ff --- /dev/null +++ b/vendor/web-sys/tests/wasm/body_element.rs @@ -0,0 +1,37 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlBodyElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_body() -> HtmlBodyElement; +} + +#[wasm_bindgen_test] +fn test_body_element() { + let element = new_body(); + assert_eq!(element.text(), "", "Shouldn't have a text"); + element.set_text("boop"); + assert_eq!(element.text(), "boop", "Should have a text"); + + // Legacy color setting + assert_eq!(element.link(), "", "Shouldn't have a link"); + element.set_link("blue"); + assert_eq!(element.link(), "blue", "Should have a link"); + + assert_eq!(element.v_link(), "", "Shouldn't have a v_link"); + element.set_v_link("purple"); + assert_eq!(element.v_link(), "purple", "Should have a v_link"); + + assert_eq!(element.a_link(), "", "Shouldn't have a a_link"); + element.set_a_link("purple"); + assert_eq!(element.a_link(), "purple", "Should have a a_link"); + + assert_eq!(element.bg_color(), "", "Shouldn't have a bg_color"); + element.set_bg_color("yellow"); + assert_eq!(element.bg_color(), "yellow", "Should have a bg_color"); + + assert_eq!(element.background(), "", "Shouldn't have a background"); + element.set_background("image"); + assert_eq!(element.background(), "image", "Should have a background"); +} diff --git a/vendor/web-sys/tests/wasm/br_element.rs b/vendor/web-sys/tests/wasm/br_element.rs new file mode 100644 index 000000000..e3c4c667c --- /dev/null +++ b/vendor/web-sys/tests/wasm/br_element.rs @@ -0,0 +1,17 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlBrElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_br() -> HtmlBrElement; +} + +#[wasm_bindgen_test] +fn test_br_element() { + let element = new_br(); + // Legacy clear method + assert_eq!(element.clear(), "", "Shouldn't have a clear"); + element.set_clear("boop"); + assert_eq!(element.clear(), "boop", "Should have a clear"); +} diff --git a/vendor/web-sys/tests/wasm/button_element.rs b/vendor/web-sys/tests/wasm/button_element.rs new file mode 100644 index 000000000..d94160aac --- /dev/null +++ b/vendor/web-sys/tests/wasm/button_element.rs @@ -0,0 +1,122 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::{HtmlButtonElement, HtmlFormElement, Node}; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_button() -> HtmlButtonElement; + fn new_form() -> HtmlFormElement; +} + +#[wasm_bindgen_test] +fn test_button_element() { + let element = new_button(); + let location = web_sys::window().unwrap().location().href().unwrap(); + assert!(!element.autofocus(), "Shouldn't have autofocus"); + element.set_autofocus(true); + assert!(element.autofocus(), "Should have autofocus"); + + assert!(!element.disabled(), "Shouldn't be disabled"); + element.set_disabled(true); + assert!(element.disabled(), "Should be disabled"); + + match element.form() { + None => assert!(true, "Shouldn't have a form"), + _ => assert!(false, "Shouldn't have a form"), + }; + + assert_eq!( + element.form_action(), + location, + "Should have the pages location" + ); + element.set_form_action("http://boop.com/"); + assert_eq!( + element.form_action(), + "http://boop.com/", + "Should have a form_action" + ); + + assert_eq!(element.form_enctype(), "", "Should have no enctype"); + element.set_form_enctype("text/plain"); + assert_eq!( + element.form_enctype(), + "text/plain", + "Should have a plain text enctype" + ); + + assert_eq!(element.form_method(), "", "Should have no method"); + element.set_form_method("POST"); + assert_eq!(element.form_method(), "post", "Should have a POST method"); + + assert!(!element.form_no_validate(), "Should validate"); + element.set_form_no_validate(true); + assert!(element.form_no_validate(), "Should not validate"); + + assert_eq!(element.form_target(), "", "Should have no target"); + element.set_form_target("_blank"); + assert_eq!( + element.form_target(), + "_blank", + "Should have a _blank target" + ); + + assert_eq!(element.name(), "", "Shouldn't have a name"); + element.set_name("button-name"); + assert_eq!(element.name(), "button-name", "Should have a name"); + + assert_eq!(element.type_(), "submit", "Shouldn't have a type"); + element.set_type("reset"); + assert_eq!(element.type_(), "reset", "Should have a reset type"); + + assert_eq!(element.value(), "", "Shouldn't have a value"); + element.set_value("value1"); + assert_eq!(element.value(), "value1", "Should have a value"); + + assert_eq!(element.will_validate(), false, "Shouldn't validate"); + assert_eq!( + element.validation_message().unwrap(), + "", + "Shouldn't have a value" + ); + assert_eq!(element.check_validity(), true, "Should be valid"); + assert_eq!(element.report_validity(), true, "Should be valid"); + element.set_custom_validity("Boop"); // Method exists but doesn't impact validity + assert_eq!(element.check_validity(), true, "Should be valid"); + assert_eq!(element.report_validity(), true, "Should be valid"); + + assert_eq!( + element.labels().length(), + 0, + "Should return a node list with no elements" + ); +} + +#[wasm_bindgen_test] +fn test_button_element_in_form() { + let button = new_button(); + button.set_type("reset"); + let form = new_form(); + form.set_name("test-form"); + + // TODO: implement `Clone` for types in `web_sys` to make this easier. + let button = JsValue::from(button); + let as_node = Node::from(button.clone()); + Node::from(JsValue::from(form)) + .append_child(&as_node) + .unwrap(); + + let element = HtmlButtonElement::from(button); + match element.form() { + None => assert!(false, "Should have a form"), + Some(form) => { + assert!(true, "Should have a form"); + assert_eq!( + form.name(), + "test-form", + "Form should have a name of test-form" + ); + } + }; + assert_eq!(element.type_(), "reset", "Should have a type"); +} diff --git a/vendor/web-sys/tests/wasm/console.rs b/vendor/web-sys/tests/wasm/console.rs new file mode 100644 index 000000000..b83638569 --- /dev/null +++ b/vendor/web-sys/tests/wasm/console.rs @@ -0,0 +1,8 @@ +use wasm_bindgen_test::*; +use web_sys::console; + +#[wasm_bindgen_test] +fn test_console() { + console::time_with_label("test label"); + console::time_end_with_label("test label"); +} diff --git a/vendor/web-sys/tests/wasm/div_element.rs b/vendor/web-sys/tests/wasm/div_element.rs new file mode 100644 index 000000000..8b95f082d --- /dev/null +++ b/vendor/web-sys/tests/wasm/div_element.rs @@ -0,0 +1,16 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlDivElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_div() -> HtmlDivElement; +} + +#[wasm_bindgen_test] +fn test_div_element() { + let element = new_div(); + assert_eq!(element.align(), "", "Shouldn't have a align"); + element.set_align("right"); + assert_eq!(element.align(), "right", "Should have a align"); +} diff --git a/vendor/web-sys/tests/wasm/dom_point.rs b/vendor/web-sys/tests/wasm/dom_point.rs new file mode 100644 index 000000000..4ed22c37f --- /dev/null +++ b/vendor/web-sys/tests/wasm/dom_point.rs @@ -0,0 +1,33 @@ +use wasm_bindgen::JsValue; +use wasm_bindgen_test::*; +use web_sys::{DomPoint, DomPointReadOnly}; + +#[wasm_bindgen_test] +fn dom_point() { + let x = DomPoint::new_with_x_and_y_and_z_and_w(1.0, 2.0, 3.0, 4.0).unwrap(); + assert_eq!(x.x(), 1.0); + x.set_x(1.5); + assert_eq!(x.x(), 1.5); + + assert_eq!(x.y(), 2.0); + x.set_y(2.5); + assert_eq!(x.y(), 2.5); + + assert_eq!(x.z(), 3.0); + x.set_z(3.5); + assert_eq!(x.z(), 3.5); + + assert_eq!(x.w(), 4.0); + x.set_w(4.5); + assert_eq!(x.w(), 4.5); +} + +#[wasm_bindgen_test] +fn dom_point_readonly() { + let x = DomPoint::new_with_x_and_y_and_z_and_w(1.0, 2.0, 3.0, 4.0).unwrap(); + let x = DomPointReadOnly::from(JsValue::from(x)); + assert_eq!(x.x(), 1.0); + assert_eq!(x.y(), 2.0); + assert_eq!(x.z(), 3.0); + assert_eq!(x.w(), 4.0); +} diff --git a/vendor/web-sys/tests/wasm/element.js b/vendor/web-sys/tests/wasm/element.js new file mode 100644 index 000000000..ed51fbdbe --- /dev/null +++ b/vendor/web-sys/tests/wasm/element.js @@ -0,0 +1,158 @@ +export function new_a() { + return document.createElement("a"); +} + +export function new_body() { + return document.createElement("body"); +} + +export function new_br() { + return document.createElement("br"); +} + +export function new_button() { + return document.createElement("button"); +} + +export function new_caption() { + return document.createElement("caption"); +} + +export function new_del() { + return document.createElement("del"); +} + +export function new_div() { + return document.createElement("div"); +} + +export function new_form() { + return document.createElement("form"); +} + +export function new_food_options_collection() { + return new_select_with_food_opts().options; +} + +export function new_head() { + return document.createElement("head"); +} + +export function new_heading() { + return document.createElement("h1"); +} + +export function new_hr() { + return document.createElement("hr"); +} + +export function new_html() { + return document.createElement("html"); +} + +export function new_input() { + return document.createElement("input"); +} + +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"); +} + +export function new_optgroup() { + return document.createElement("optgroup"); +} + +export function new_output() { + return document.createElement("output"); +} + +export function new_paragraph() { + return document.createElement("p"); +} + +export function new_param() { + return document.createElement("param"); +} + +export function new_pre() { + return document.createElement("pre"); +} + +export function new_progress() { + return document.createElement("progress"); +} + +export function new_quote() { + return document.createElement("q"); +} + +export function new_script() { + return document.createElement("script"); +} + +export function new_select_with_food_opts() { + let select = document.createElement("select"); + let opts = ["tomato", "potato", "orange", "apple"]; + + for(let i = 0; i < opts.length; i++) { + let opt = document.createElement("option"); + opt.value = opts[i]; + opt.text = opts[i]; + select.appendChild(opt); + } + return select; +} + +export function new_slot() { + return document.createElement("slot"); +} + +export function new_span() { + return document.createElement("span"); +} + +export function new_style() { + return document.createElement("style"); +} + +export function new_table() { + return document.createElement("table"); +} + +export function new_tfoot() { + return document.createElement("tfoot"); +} + +export function new_thead() { + return document.createElement("thead"); +} + +export function new_title() { + return document.createElement("title"); +} + +export function new_xpath_result() { + let xmlDoc = new DOMParser().parseFromString("<root><value>tomato</value></root>", "application/xml"); + let xpathResult = xmlDoc.evaluate("/root//value", xmlDoc, null, XPathResult.ANY_TYPE, null); + return xpathResult; +} diff --git a/vendor/web-sys/tests/wasm/element.rs b/vendor/web-sys/tests/wasm/element.rs new file mode 100644 index 000000000..a408a9c7c --- /dev/null +++ b/vendor/web-sys/tests/wasm/element.rs @@ -0,0 +1,226 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::Element; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_div() -> Element; +} + +#[wasm_bindgen_test] +fn element() { + /* Tests needed for: + namespace_uri + */ + let element = new_div(); + + assert_eq!(element, element); + + assert_eq!(element.prefix(), None, "Shouldn't have a prefix"); + assert_eq!(element.local_name(), "div", "Should have a div local name"); + assert_eq!(element.tag_name(), "DIV", "Should be a div tag"); + assert!(!element.has_attribute("id"), "Shouldn't have an id"); + element.set_id("beep"); + assert_eq!(element.id(), "beep", "Should have an id of 'beep'"); + + // must_use is set on this result? + assert_eq!( + element.set_attribute("id", "beep").unwrap(), + (), + "Should set id" + ); + assert!(element.has_attribute("id"), "Should now have an id"); + assert_eq!( + element.remove_attribute("id").unwrap(), + (), + "Should return nothing if removed" + ); + + assert_eq!(element.class_name(), "", "Shouldn't have a class name"); + element.set_class_name("test thing"); + assert_eq!( + element.class_name(), + "test thing", + "Should have a class name" + ); + assert_eq!( + element.get_attribute("class").unwrap(), + "test thing", + "Should have a class name" + ); + assert_eq!( + element.remove_attribute("class").unwrap(), + (), + "Should return nothing if removed" + ); + /* Tests needed for: + get_attribute_ns + */ + + /*TODO should we enable toggle_attribute tests? (Firefox Nightly + Chrome canary only) + // TODO toggle_attribute should permit a single argument when optional arguments are supported + assert!(!element.has_attribute("disabled"), "Should not be disabled"); + assert!(element.toggle_attribute("disabled", true).unwrap(), "Should return true when attribute is set"); + assert!(element.has_attribute("disabled"), "Should be disabled"); + assert!(!element.toggle_attribute("disabled", false).unwrap(), "Should return false when attribute is not set"); + assert!(!element.has_attribute("disabled"), "Should not be disabled"); + */ + + assert!(!element.has_attribute("title"), "Should not have a title"); + assert_eq!( + element.set_attribute("title", "boop").unwrap(), + (), + "Should return nothing if set correctly" + ); + assert!(element.has_attribute("title"), "Should have a title"); + // TODO check get_attribute here when supported + assert_eq!( + element.remove_attribute("title").unwrap(), + (), + "Should return nothing if removed" + ); + assert!(!element.has_attribute("title"), "Should not have a title"); + /* Tests needed for: + set_attribute_ns + */ + + assert!(!element.has_attributes(), "Should not have any attributes"); + assert_eq!( + element.set_attribute("title", "boop").unwrap(), + (), + "Should return nothing if set correctly" + ); + assert!(element.has_attributes(), "Should have attributes"); + assert_eq!( + element.remove_attribute("title").unwrap(), + (), + "Should return nothing if removed" + ); + /* Tests needed for: + remove_attribute_ns + has_attribure_ns + closest + */ + + assert_eq!( + element.matches(".this-is-a-thing").unwrap(), + false, + "Should not match selector" + ); + assert_eq!( + element.webkit_matches_selector(".this-is-a-thing").unwrap(), + false, + "Should not match selector" + ); + element.set_class_name("this-is-a-thing"); + assert_eq!( + element.matches(".this-is-a-thing").unwrap(), + true, + "Should match selector" + ); + assert_eq!( + element.webkit_matches_selector(".this-is-a-thing").unwrap(), + true, + "Should match selector" + ); + assert_eq!( + element.remove_attribute("class").unwrap(), + (), + "Should return nothing if removed" + ); + + // TODO non standard moz_matches_selector should we even support? + + /* Tests needed for: + insert_adjacent_element + insert_adjacent_text + set_pointer_capture + release_pointer_capture + has_pointer_capture + set_capture + release_capture + scroll_top + set_scroll_top + scroll_left + set_scroll_left + scroll_width + scroll_height + scroll, + scroll_to + scroll_by + client_top + client_left + client_width + client_height + scroll_top_max + scroll_left_max + */ + assert_eq!(element.inner_html(), "", "Should return no content"); + element.set_inner_html("<strong>Hey!</strong><em>Web!</em>"); + assert_eq!( + element.inner_html(), + "<strong>Hey!</strong><em>Web!</em>", + "Should return HTML conent" + ); + assert_eq!( + element.query_selector_all("strong").unwrap().length(), + 1, + "Should return one element" + ); + assert!( + element.query_selector("strong").unwrap().is_some(), + "Should return an element" + ); + element.set_inner_html(""); + assert_eq!(element.inner_html(), "", "Should return no content"); + + /* Tests needed for: + outer_html + set_outer_html + insert_adjacent_html + */ + + assert!( + element.query_selector(".none-existant").unwrap().is_none(), + "Should return no results" + ); + assert_eq!( + element + .query_selector_all(".none-existant") + .unwrap() + .length(), + 0, + "Should return no results" + ); + /* Tests needed for: + slot + set_slot + request_fullscreen + request_pointer_lock + */ + + let child = new_div(); + assert_eq!( + element.get_elements_by_tag_name("div").length(), + 0, + "Element should not contain any div child" + ); + element.append_child(&child).unwrap(); + assert_eq!( + element.get_elements_by_tag_name("div").length(), + 1, + "Element should contain one div child" + ); + assert_eq!( + element.get_elements_by_class_name("foo").length(), + 0, + "Element should not have childs with class foo" + ); + child.class_list().add_1("foo").unwrap(); + assert_eq!( + element.get_elements_by_class_name("foo").length(), + 1, + "Element should have one child with class foo" + ); + element.remove_child(&child).unwrap(); +} diff --git a/vendor/web-sys/tests/wasm/event.js b/vendor/web-sys/tests/wasm/event.js new file mode 100644 index 000000000..48203ecf8 --- /dev/null +++ b/vendor/web-sys/tests/wasm/event.js @@ -0,0 +1,10 @@ +export function new_event() { + return new Promise(resolve => { + window.addEventListener("test-event", resolve); + window.dispatchEvent(new Event("test-event", { + bubbles: true, + cancelable: true, + composed: true, + })); + }); +} diff --git a/vendor/web-sys/tests/wasm/event.rs b/vendor/web-sys/tests/wasm/event.rs new file mode 100644 index 000000000..4ffb48f16 --- /dev/null +++ b/vendor/web-sys/tests/wasm/event.rs @@ -0,0 +1,30 @@ +use js_sys::{Object, Promise}; +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::JsFuture; +use wasm_bindgen_test::*; +use web_sys::Event; + +#[wasm_bindgen(module = "/tests/wasm/event.js")] +extern "C" { + fn new_event() -> Promise; +} + +#[wasm_bindgen_test] +async fn event() { + let result = JsFuture::from(new_event()).await.unwrap(); + let event = Event::from(result); + // All DOM interfaces should inherit from `Object`. + assert!(event.is_instance_of::<Object>()); + let _: &Object = event.as_ref(); + + // These should match `new Event`. + assert!(event.bubbles()); + assert!(event.cancelable()); + assert!(event.composed()); + + // The default behavior not initially prevented, but after + // we call `prevent_default` it better be. + assert!(!event.default_prevented()); + event.prevent_default(); + assert!(event.default_prevented()); +} diff --git a/vendor/web-sys/tests/wasm/head_element.rs b/vendor/web-sys/tests/wasm/head_element.rs new file mode 100644 index 000000000..4b8273357 --- /dev/null +++ b/vendor/web-sys/tests/wasm/head_element.rs @@ -0,0 +1,14 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlHeadElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_head() -> HtmlHeadElement; +} + +#[wasm_bindgen_test] +fn test_head_element() { + let _element = new_head(); + assert!(true, "Head doesn't have an interface"); +} diff --git a/vendor/web-sys/tests/wasm/headers.js b/vendor/web-sys/tests/wasm/headers.js new file mode 100644 index 000000000..3b71cdc66 --- /dev/null +++ b/vendor/web-sys/tests/wasm/headers.js @@ -0,0 +1,3 @@ +export function new_headers() { + return new Headers({'Content-Type': 'text/plain'}); +} diff --git a/vendor/web-sys/tests/wasm/headers.rs b/vendor/web-sys/tests/wasm/headers.rs new file mode 100644 index 000000000..08751444b --- /dev/null +++ b/vendor/web-sys/tests/wasm/headers.rs @@ -0,0 +1,31 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::Headers; + +#[wasm_bindgen(module = "/tests/wasm/headers.js")] +extern "C" { + fn new_headers() -> Headers; +} + +#[wasm_bindgen_test] +fn headers() { + let headers = new_headers(); + assert_eq!(headers.get("foo").unwrap(), None); + assert_eq!( + headers.get("content-type").unwrap(), + Some("text/plain".to_string()), + ); + assert_eq!( + headers.get("Content-Type").unwrap(), + Some("text/plain".to_string()), + ); + assert!(headers.get("").is_err()); + assert!(headers.set("", "").is_err()); + assert!(headers.set("x", "").is_ok()); + assert_eq!(headers.get("x").unwrap(), Some(String::new())); + assert!(headers.delete("x").is_ok()); + assert_eq!(headers.get("x").unwrap(), None); + assert!(headers.append("a", "y").is_ok()); + assert!(headers.append("a", "z").is_ok()); + assert_eq!(headers.get("a").unwrap(), Some("y, z".to_string())); +} diff --git a/vendor/web-sys/tests/wasm/heading_element.rs b/vendor/web-sys/tests/wasm/heading_element.rs new file mode 100644 index 000000000..47a2fc0a3 --- /dev/null +++ b/vendor/web-sys/tests/wasm/heading_element.rs @@ -0,0 +1,16 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlHeadingElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_heading() -> HtmlHeadingElement; +} + +#[wasm_bindgen_test] +fn heading_element() { + let element = new_heading(); + assert_eq!(element.align(), "", "Shouldn't have an align"); + element.set_align("justify"); + assert_eq!(element.align(), "justify", "Should have an align"); +} diff --git a/vendor/web-sys/tests/wasm/history.rs b/vendor/web-sys/tests/wasm/history.rs new file mode 100644 index 000000000..f3ecdc42e --- /dev/null +++ b/vendor/web-sys/tests/wasm/history.rs @@ -0,0 +1,28 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::{History, ScrollRestoration}; + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_name = history, js_namespace = window)] + static HISTORY: History; +} + +#[wasm_bindgen_test] +fn history() { + HISTORY + .set_scroll_restoration(ScrollRestoration::Manual) + .expect("failure to set scroll restoration"); + assert_eq!( + HISTORY.scroll_restoration().unwrap(), + ScrollRestoration::Manual + ); + + HISTORY + .set_scroll_restoration(ScrollRestoration::Auto) + .expect("failure to set scroll restoration"); + assert_eq!( + HISTORY.scroll_restoration().unwrap(), + ScrollRestoration::Auto + ); +} diff --git a/vendor/web-sys/tests/wasm/hr_element.rs b/vendor/web-sys/tests/wasm/hr_element.rs new file mode 100644 index 000000000..fe63c1404 --- /dev/null +++ b/vendor/web-sys/tests/wasm/hr_element.rs @@ -0,0 +1,24 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlHrElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_hr() -> HtmlHrElement; +} + +#[wasm_bindgen_test] +fn test_hr_element() { + let hr = new_hr(); + hr.set_color("blue"); + assert_eq!(hr.color(), "blue"); + + hr.set_width("128"); + assert_eq!(hr.width(), "128"); + + hr.set_width("256"); + assert_eq!(hr.width(), "256"); + + hr.set_no_shade(true); + assert_eq!(hr.no_shade(), true); +} diff --git a/vendor/web-sys/tests/wasm/html_element.rs b/vendor/web-sys/tests/wasm/html_element.rs new file mode 100644 index 000000000..73157ceee --- /dev/null +++ b/vendor/web-sys/tests/wasm/html_element.rs @@ -0,0 +1,160 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_html() -> HtmlElement; +} + +#[wasm_bindgen_test] +fn test_html_element() { + let element = new_html(); + assert!(element.is_instance_of::<HtmlElement>()); + + assert_eq!(element.title(), "", "Shouldn't have a title"); + element.set_title("boop"); + assert_eq!(element.title(), "boop", "Should have a title"); + + assert_eq!(element.lang(), "", "Shouldn't have a lang"); + element.set_lang("en-us"); + assert_eq!(element.lang(), "en-us", "Should have a lang"); + + assert_eq!(element.dir(), "", "Shouldn't have a dir"); + element.set_dir("ltr"); + assert_eq!(element.dir(), "ltr", "Should have a dir"); + + assert_eq!(element.inner_text(), "", "Shouldn't have inner_text"); + element.set_inner_text("hey"); + assert_eq!(element.inner_text(), "hey", "Should have inner_text"); + + assert!(!element.hidden(), "Shouldn't be hidden"); + element.set_hidden(true); + assert!(element.hidden(), "Should be hidden"); + + assert_eq!( + element.class_list().get(0), + None, + "Shouldn't have class at index 0" + ); + element.class_list().add_2("a", "b").unwrap(); + assert_eq!( + element.class_list().get(0).unwrap(), + "a", + "Should have class at index 0" + ); + assert_eq!( + element.class_list().get(1).unwrap(), + "b", + "Should have class at index 1" + ); + assert_eq!( + element.class_list().get(2), + None, + "Shouldn't have class at index 2" + ); + + assert_eq!(element.dataset().get("id"), None, "Shouldn't have data-id"); + element.dataset().set("id", "123").unwrap(); + assert_eq!( + element.dataset().get("id").unwrap(), + "123", + "Should have data-id" + ); + + assert_eq!( + element.style().get(0), + None, + "Shouldn't have style property name at index 0" + ); + element + .style() + .set_property("background-color", "red") + .unwrap(); + assert_eq!( + element.style().get(0).unwrap(), + "background-color", + "Should have style property at index 0" + ); + assert_eq!( + element + .style() + .get_property_value("background-color") + .unwrap(), + "red", + "Should have style property" + ); + + // TODO add a click handler here + element.click(); + + assert_eq!(element.tab_index(), -1, "Shouldn't be tab_index"); + element.set_tab_index(1); + assert_eq!(element.tab_index(), 1, "Should be tab_index"); + + // TODO add a focus handler here + assert_eq!(element.focus().unwrap(), (), "No result"); + + // TODO add a blur handler here + assert_eq!(element.blur().unwrap(), (), "No result"); + + assert_eq!(element.access_key(), "", "Shouldn't have a access_key"); + element.set_access_key("a"); + assert_eq!(element.access_key(), "a", "Should have a access_key"); + + // TODO add test for access_key_label + + assert!(!element.draggable(), "Shouldn't be draggable"); + element.set_draggable(true); + assert!(element.draggable(), "Should be draggable"); + + assert_eq!( + element.content_editable(), + "inherit", + "Shouldn't have a content_editable" + ); + element.set_content_editable("true"); + assert_eq!( + element.content_editable(), + "true", + "Should be content_editable" + ); + assert!(element.is_content_editable(), "Should be content_editable"); + + /*TODO doesn't work in Chrome + // TODO verify case where menu is passed + match element.context_menu() { + None => assert!(true, "Shouldn't have a custom menu set"), + _ => assert!(false, "Shouldn't have a custom menu set") + }; + */ + + // TODO: This test is also broken in Chrome (but not Firefox). + // assert!(!element.spellcheck(), "Shouldn't be spellchecked"); + element.set_spellcheck(true); + assert!(element.spellcheck(), "Should be dragspellcheckedgable"); + + // TODO verify case where we have an offset_parent + match element.offset_parent() { + None => assert!(true, "Shouldn't have an offset_parent set"), + _ => assert!(false, "Shouldn't have a offset_parent set"), + }; + + // TODO verify when we have offsets + assert_eq!(element.offset_top(), 0, "Shouldn't have an offset_top yet"); + assert_eq!( + element.offset_left(), + 0, + "Shouldn't have an offset_left yet" + ); + assert_eq!( + element.offset_width(), + 0, + "Shouldn't have an offset_width yet" + ); + assert_eq!( + element.offset_height(), + 0, + "Shouldn't have an offset_height yet" + ); +} diff --git a/vendor/web-sys/tests/wasm/html_html_element.rs b/vendor/web-sys/tests/wasm/html_html_element.rs new file mode 100644 index 000000000..ddfae4c12 --- /dev/null +++ b/vendor/web-sys/tests/wasm/html_html_element.rs @@ -0,0 +1,16 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlHtmlElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_html() -> HtmlHtmlElement; +} + +#[wasm_bindgen_test] +fn test_html_html_element() { + let element = new_html(); + assert_eq!(element.version(), "", "Shouldn't have a version"); + element.set_version("4"); + assert_eq!(element.version(), "4", "Should have a version"); +} diff --git a/vendor/web-sys/tests/wasm/image_data.rs b/vendor/web-sys/tests/wasm/image_data.rs new file mode 100644 index 000000000..0689425fe --- /dev/null +++ b/vendor/web-sys/tests/wasm/image_data.rs @@ -0,0 +1,18 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen::Clamped; +use wasm_bindgen_test::*; +use web_sys::HtmlAnchorElement; +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_a() -> HtmlAnchorElement; +} + +#[wasm_bindgen_test] +fn test_anchor_element() { + // This test is to make sure there is no weird mutability going on. + let buf = vec![1, 2, 3, 255]; + let image_data = web_sys::ImageData::new_with_u8_clamped_array(Clamped(&buf), 1).unwrap(); + let mut data = image_data.data(); + data[1] = 4; + assert_eq!(buf[1], 2); +} diff --git a/vendor/web-sys/tests/wasm/indexeddb.rs b/vendor/web-sys/tests/wasm/indexeddb.rs new file mode 100644 index 000000000..cfaa2ea43 --- /dev/null +++ b/vendor/web-sys/tests/wasm/indexeddb.rs @@ -0,0 +1,7 @@ +use wasm_bindgen_test::*; + +#[wasm_bindgen_test] +fn accessor_works() { + let window = web_sys::window().unwrap(); + assert!(window.indexed_db().unwrap().is_some()); +} diff --git a/vendor/web-sys/tests/wasm/input_element.rs b/vendor/web-sys/tests/wasm/input_element.rs new file mode 100644 index 000000000..460576328 --- /dev/null +++ b/vendor/web-sys/tests/wasm/input_element.rs @@ -0,0 +1,217 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlInputElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_input() -> HtmlInputElement; +} + +#[wasm_bindgen_test] +fn test_input_element() { + let element = new_input(); + let location = web_sys::window().unwrap().location().href().unwrap(); + assert_eq!(element.accept(), "", "Shouldn't have an accept"); + element.set_accept("audio/*"); + assert_eq!(element.accept(), "audio/*", "Should have an accept"); + + assert_eq!(element.alt(), "", "Shouldn't have an alt"); + element.set_alt("alt text"); + assert_eq!(element.alt(), "alt text", "Should have an alt"); + + element.set_type("text"); + assert_eq!(element.autocomplete(), "", "Shouldn't have an autocomplete"); + element.set_autocomplete("on"); + assert_eq!( + element.autocomplete(), + "on", + "Shouldn't have an autocomplete" + ); + + assert!(!element.autofocus(), "Shouldn't have an autofocus"); + element.set_autofocus(true); + assert!(element.autofocus(), "Should have an autofocus"); + + element.set_type("checkbox"); + assert!( + !element.default_checked(), + "Shouldn't have an default_checked" + ); + element.set_default_checked(true); + assert!(element.default_checked(), "Should have an default_checked"); + + /*TODO fix + assert!(!element.checked(), "Shouldn't be checked"); + element.set_checked(true); + assert!(element.checked(), "Should be checked"); + */ + + assert!(!element.disabled(), "Shouldn't be disabled"); + element.set_disabled(true); + assert!(element.disabled(), "Should be disabled"); + + match element.form() { + None => assert!(true, "Shouldn't have a form"), + _ => assert!(false, "Shouldn't have a form"), + }; + + assert_eq!( + element.form_action(), + location, + "Should have the pages location" + ); + element.set_form_action("http://boop.com/"); + assert_eq!( + element.form_action(), + "http://boop.com/", + "Should have a form_action" + ); + + assert_eq!(element.form_enctype(), "", "Should have no enctype"); + element.set_form_enctype("text/plain"); + assert_eq!( + element.form_enctype(), + "text/plain", + "Should have a plain text enctype" + ); + + assert_eq!(element.form_method(), "", "Should have no method"); + element.set_form_method("POST"); + assert_eq!(element.form_method(), "post", "Should have a POST method"); + + assert!(!element.form_no_validate(), "Should validate"); + element.set_form_no_validate(true); + assert!(element.form_no_validate(), "Should not validate"); + + assert_eq!(element.form_target(), "", "Should have no target"); + element.set_form_target("_blank"); + assert_eq!( + element.form_target(), + "_blank", + "Should have a _blank target" + ); + + assert_eq!(element.height(), 0, "Should have no height"); + element.set_height(12); + assert_eq!(element.height(), 0, "Should have no height"); // Doesn't change, TODO check with get_attribute("height")=="12" + + /*TODO fails in chrome + element.set_type("checkbox"); + assert!(element.indeterminate(), "Should be indeterminate"); + element.set_checked(true); + assert!(!element.indeterminate(), "Shouldn't be indeterminate"); + */ + /*TODO add tests + pub fn indeterminate(&self) -> bool + pub fn set_indeterminate(&self, indeterminate: bool) + pub fn input_mode(&self) -> String + pub fn set_input_mode(&self, input_mode: &str) + pub fn list(&self) -> Option<HtmlElement> + pub fn max(&self) -> String + pub fn set_max(&self, max: &str) + pub fn max_length(&self) -> i32 + pub fn set_max_length(&self, max_length: i32) + pub fn min(&self) -> String + pub fn set_min(&self, min: &str) + pub fn min_length(&self) -> i32 + pub fn set_min_length(&self, min_length: i32) + pub fn multiple(&self) -> bool + pub fn set_multiple(&self, multiple: bool) + */ + assert_eq!(element.name(), "", "Should not have a name"); + element.set_name("namey"); + assert_eq!(element.name(), "namey", "Should have a name"); + /*TODO add tests + pub fn pattern(&self) -> String + pub fn set_pattern(&self, pattern: &str) + */ + assert_eq!(element.placeholder(), "", "Should not have a placeholder"); + element.set_placeholder("some text"); + assert_eq!( + element.placeholder(), + "some text", + "Should have a placeholder" + ); + + assert!(!element.read_only(), "Should have not be readonly"); + element.set_read_only(true); + assert!(element.read_only(), "Should be readonly"); + + assert!(!element.required(), "Should have not be required"); + element.set_required(true); + assert!(element.required(), "Should be required"); + /*TODO add tests + pub fn size(&self) -> u32 + pub fn set_size(&self, size: u32) + */ + /*TODO fails in chrome + element.set_type("image"); + assert_eq!(element.src(), "", "Should have no src"); + element.set_value("hey.png"); + assert_eq!(element.src(), "hey.png", "Should have a src"); + */ + /*TODO add tests + pub fn src(&self) -> String + pub fn set_src(&self, src: &str) + pub fn step(&self) -> String + pub fn set_step(&self, step: &str) + pub fn type_(&self) -> String + pub fn set_type(&self, type_: &str) + pub fn default_value(&self) -> String + pub fn set_default_value(&self, default_value: &str) + */ + /*TODO fails in chrome + assert_eq!(element.value(), "", "Should have no value"); + element.set_value("hey!"); + assert_eq!(element.value(), "hey!", "Should have a value"); + */ + element.set_type("number"); + element.set_value("1"); + assert_eq!(element.value_as_number(), 1.0, "Should have value 1"); + element.set_value_as_number(2.0); + assert_eq!(element.value(), "2", "Should have value 2"); + + assert_eq!(element.width(), 0, "Should have no width"); + element.set_width(12); + assert_eq!(element.width(), 0, "Should have no width"); // Doesn't change, TODO check with get_attribute("width")=="12" + + assert_eq!(element.will_validate(), false, "Shouldn't validate"); + assert_eq!( + element.validation_message().unwrap(), + "", + "Shouldn't have a value" + ); + assert_eq!(element.check_validity(), true, "Should be valid"); + assert_eq!(element.report_validity(), true, "Should be valid"); + element.set_custom_validity("Boop"); // Method exists but doesn't impact validity ?!??! TODO look into + assert_eq!(element.check_validity(), true, "Should be valid"); + assert_eq!(element.report_validity(), true, "Should be valid"); + /*TODO add tests + pub fn labels(&self) -> Option<NodeList> + pub fn select(&self) + pub fn selection_direction(&self) -> Result<Option<String>, JsValue> + pub fn set_selection_direction( + &self, + selection_direction: Option<&str> + ) -> Result<(), JsValue> + pub fn set_range_text(&self, replacement: &str) -> Result<(), JsValue> + pub fn set_selection_range( + &self, + start: u32, + end: u32, + direction: &str + ) -> Result<(), JsValue> + */ + + assert_eq!(element.align(), "", "Should have no align"); + element.set_align("left"); + assert_eq!(element.align(), "left", "Should have an align"); + /*TODO add tests + pub fn use_map(&self) -> String + pub fn set_use_map(&self, use_map: &str) + pub fn text_length(&self) -> i32 + pub fn webkitdirectory(&self) -> bool + pub fn set_webkitdirectory(&self, webkitdirectory: bool) + pub fn set_focus_state(&self, a_is_focused: bool) + */ +} diff --git a/vendor/web-sys/tests/wasm/location.rs b/vendor/web-sys/tests/wasm/location.rs new file mode 100644 index 000000000..aa41d0d5a --- /dev/null +++ b/vendor/web-sys/tests/wasm/location.rs @@ -0,0 +1,60 @@ +use wasm_bindgen_test::*; +use web_sys::{self, Location}; + +fn location() -> Location { + web_sys::window().unwrap().location() +} + +#[wasm_bindgen_test] +fn href() { + let loc = location(); + loc.href().unwrap(); +} + +#[wasm_bindgen_test] +fn origin() { + let loc = location(); + loc.origin().unwrap(); +} + +#[wasm_bindgen_test] +fn protocol() { + let loc = location(); + loc.protocol().unwrap(); +} + +#[wasm_bindgen_test] +fn host() { + let loc = location(); + loc.host().unwrap(); +} + +#[wasm_bindgen_test] +fn hostname() { + let loc = location(); + loc.hostname().unwrap(); +} + +#[wasm_bindgen_test] +fn port() { + let loc = location(); + loc.port().unwrap(); +} + +#[wasm_bindgen_test] +fn pathname() { + let loc = location(); + loc.pathname().unwrap(); +} + +#[wasm_bindgen_test] +fn search() { + let loc = location(); + loc.search().unwrap(); +} + +#[wasm_bindgen_test] +fn hash() { + let loc = location(); + loc.hash().unwrap(); +} diff --git a/vendor/web-sys/tests/wasm/main.rs b/vendor/web-sys/tests/wasm/main.rs new file mode 100644 index 000000000..f78f773a9 --- /dev/null +++ b/vendor/web-sys/tests/wasm/main.rs @@ -0,0 +1,65 @@ +#![cfg(target_arch = "wasm32")] + +use wasm_bindgen_test::*; + +wasm_bindgen_test_configure!(run_in_browser); + +pub mod anchor_element; +pub mod blob; +pub mod body_element; +pub mod br_element; +pub mod button_element; +pub mod console; +pub mod div_element; +pub mod element; +pub mod event; +pub mod head_element; +pub mod headers; +pub mod heading_element; +pub mod history; +pub mod hr_element; +pub mod html_element; +pub mod html_html_element; +pub mod image_data; +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 dom_point; +pub mod indexeddb; +pub mod location; +pub mod meta_element; +pub mod meter_element; +pub mod mod_elements; +pub mod olist_element; +pub mod optgroup_element; +pub mod option_element; +pub mod options_collection; +pub mod output_element; +pub mod paragraph_element; +pub mod param_element; +pub mod performance; +pub mod pre_element; +pub mod progress_element; +pub mod quote_element; +pub mod response; +pub mod rtc_rtp_transceiver_direction; +pub mod script_element; +pub mod select_element; +pub mod slot_element; +pub mod span_element; +pub mod style_element; +pub mod table_element; +pub mod title_element; +pub mod whitelisted_immutable_slices; +pub mod xpath_result; + +#[wasm_bindgen_test] +fn deref_works() { + fn _check(a: &web_sys::XmlHttpRequestUpload) { + let _x: &web_sys::XmlHttpRequestEventTarget = a; + let _x: &web_sys::EventTarget = a; + let _x: &js_sys::Object = a; + let _x: &wasm_bindgen::JsValue = a; + } +} diff --git a/vendor/web-sys/tests/wasm/menu_element.rs b/vendor/web-sys/tests/wasm/menu_element.rs new file mode 100644 index 000000000..92456133f --- /dev/null +++ b/vendor/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 "C" { + 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."); +} diff --git a/vendor/web-sys/tests/wasm/menu_item_element.rs b/vendor/web-sys/tests/wasm/menu_item_element.rs new file mode 100644 index 000000000..6b6eaaffb --- /dev/null +++ b/vendor/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 "C" { + 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."); +} diff --git a/vendor/web-sys/tests/wasm/meta_element.rs b/vendor/web-sys/tests/wasm/meta_element.rs new file mode 100644 index 000000000..697316cb8 --- /dev/null +++ b/vendor/web-sys/tests/wasm/meta_element.rs @@ -0,0 +1,41 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlMetaElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + 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." + ); +} diff --git a/vendor/web-sys/tests/wasm/meter_element.rs b/vendor/web-sys/tests/wasm/meter_element.rs new file mode 100644 index 000000000..7bff14d98 --- /dev/null +++ b/vendor/web-sys/tests/wasm/meter_element.rs @@ -0,0 +1,56 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlMeterElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + 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." + ); +} diff --git a/vendor/web-sys/tests/wasm/mod_elements.rs b/vendor/web-sys/tests/wasm/mod_elements.rs new file mode 100644 index 000000000..c8b0db881 --- /dev/null +++ b/vendor/web-sys/tests/wasm/mod_elements.rs @@ -0,0 +1,44 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlModElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_del() -> HtmlModElement; + fn new_ins() -> HtmlModElement; +} + +#[wasm_bindgen_test] +fn test_mod_elements() { + let del = new_del(); + + del.set_cite("https://www.rust-lang.org/en-US/"); + assert_eq!( + del.cite(), + "https://www.rust-lang.org/en-US/", + "Option should have the cite URI we gave it." + ); + + del.set_date_time("Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)"); + assert_eq!( + del.date_time(), + "Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)", + "Option should have the date_time we gave it." + ); + + let ins = new_ins(); + + ins.set_cite("https://www.rust-lang.org/en-US/"); + assert_eq!( + ins.cite(), + "https://www.rust-lang.org/en-US/", + "Option should have the cite URI we gave it." + ); + + ins.set_date_time("Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)"); + assert_eq!( + ins.date_time(), + "Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)", + "Option should have the date_time we gave it." + ); +} diff --git a/vendor/web-sys/tests/wasm/olist_element.rs b/vendor/web-sys/tests/wasm/olist_element.rs new file mode 100644 index 000000000..56785c0e7 --- /dev/null +++ b/vendor/web-sys/tests/wasm/olist_element.rs @@ -0,0 +1,62 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlOListElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_olist() -> HtmlOListElement; +} + +#[wasm_bindgen_test] +fn test_olist_element() { + let olist = new_olist(); + + olist.set_reversed(true); + assert_eq!( + olist.reversed(), + true, + "Olist should be reversed after we set it to be reversed." + ); + + olist.set_reversed(false); + assert_eq!( + olist.reversed(), + false, + "Olist should not be reversed after we set it to be not reversed." + ); + + olist.set_start(23); + assert_eq!( + olist.start(), + 23, + "Olist should have the start value we gave it." + ); + + olist.set_type("A"); + assert_eq!( + olist.type_(), + "A", + "Olist should be type 'A' after we set it to be type 'A'." + ); + + olist.set_type("I"); + assert_eq!( + olist.type_(), + "I", + "Olist should be type 'I' after we set it to be type 'I'." + ); + + olist.set_compact(true); + assert_eq!( + olist.compact(), + true, + "Olist should be compact after we set it to be compact." + ); + + olist.set_compact(false); + assert_eq!( + olist.compact(), + false, + "Olist should not be compact after we set it to be not compact." + ); +} diff --git a/vendor/web-sys/tests/wasm/optgroup_element.rs b/vendor/web-sys/tests/wasm/optgroup_element.rs new file mode 100644 index 000000000..99d72dada --- /dev/null +++ b/vendor/web-sys/tests/wasm/optgroup_element.rs @@ -0,0 +1,34 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlOptGroupElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_optgroup() -> HtmlOptGroupElement; +} + +#[wasm_bindgen_test] +fn test_optgroup_element() { + let optgroup = new_optgroup(); + + optgroup.set_disabled(true); + assert_eq!( + optgroup.disabled(), + true, + "Optgroup should be disabled after we set it to be disabled." + ); + + optgroup.set_disabled(false); + assert_eq!( + optgroup.disabled(), + false, + "Optgroup should not be disabled after we set it to be not-disabled." + ); + + optgroup.set_label("Group of options below"); + assert_eq!( + optgroup.label(), + "Group of options below", + "Optgroup should have the label we gave it." + ); +} diff --git a/vendor/web-sys/tests/wasm/option_element.rs b/vendor/web-sys/tests/wasm/option_element.rs new file mode 100644 index 000000000..10661b29b --- /dev/null +++ b/vendor/web-sys/tests/wasm/option_element.rs @@ -0,0 +1,87 @@ +use wasm_bindgen_test::*; +use web_sys::HtmlOptionElement; + +#[wasm_bindgen_test] +fn test_option_element() { + let option = HtmlOptionElement::new_with_text_and_value_and_default_selected_and_selected( + "option_text", + "option_value", + false, + true, + ) + .unwrap(); + + option.set_disabled(true); + assert_eq!( + option.disabled(), + true, + "Option should be disabled after we set it to be disabled." + ); + + option.set_disabled(false); + assert_eq!( + option.disabled(), + false, + "Option should not be disabled after we set it to be not-disabled." + ); + + assert!( + option.form().is_none(), + "Our option should not be associated with a form." + ); + + option.set_label("Well this truly is a neat option"); + assert_eq!( + option.label(), + "Well this truly is a neat option", + "Option should have the label we gave it." + ); + + option.set_default_selected(true); + assert_eq!( + option.default_selected(), + true, + "Option should be default_selected after we set it to be default_selected." + ); + + option.set_default_selected(false); + assert_eq!( + option.default_selected(), + false, + "Option should not be default_selected after we set it to be not default_selected." + ); + + option.set_selected(true); + assert_eq!( + option.selected(), + true, + "Option should be selected after we set it to be selected." + ); + + option.set_selected(false); + assert_eq!( + option.selected(), + false, + "Option should not be selected after we set it to be not selected." + ); + + option.set_value("tomato"); + assert_eq!( + option.value(), + "tomato", + "Option should have the value we gave it." + ); + + option.set_text("potato"); + assert_eq!( + option.text(), + "potato", + "Option should have the text we gave it." + ); + + assert_eq!( + option.index(), + 0, + "This should be the first option, since there are no other known options." + ); +} diff --git a/vendor/web-sys/tests/wasm/options_collection.rs b/vendor/web-sys/tests/wasm/options_collection.rs new file mode 100644 index 000000000..6b7e3b3ad --- /dev/null +++ b/vendor/web-sys/tests/wasm/options_collection.rs @@ -0,0 +1,43 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlOptionsCollection; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_food_options_collection() -> HtmlOptionsCollection; +} + +#[wasm_bindgen_test] +fn test_options_collection() { + let opt_collection = new_food_options_collection(); + + assert!( + opt_collection.length() == 4, + "Our option collection should have four options." + ); + assert!( + opt_collection.remove(0).is_ok(), + "We should be able to successfully remove an element from an option collection." + ); + assert!( + opt_collection.length() == 3, + "Our option collection should have three options after removing one." + ); + + assert!( + opt_collection.set_selected_index(1).is_ok(), + "Should be able to set the selected index of an option collection if it is valid." + ); + assert_eq!( + opt_collection.selected_index().unwrap(), + 1, + "The second option should be selected in our option collection." + ); + + opt_collection.set_length(1234); + assert_eq!( + opt_collection.length(), + 1234, + "Our option collections length should update after being set to 1234." + ); +} diff --git a/vendor/web-sys/tests/wasm/output_element.rs b/vendor/web-sys/tests/wasm/output_element.rs new file mode 100644 index 000000000..bb25f1824 --- /dev/null +++ b/vendor/web-sys/tests/wasm/output_element.rs @@ -0,0 +1,71 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlOutputElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_output() -> HtmlOutputElement; +} + +#[wasm_bindgen_test] +fn test_output_element() { + let output = new_output(); + assert!( + output.html_for().length() == 0, + "Our basic <output> should have no html associated with it." + ); + assert!( + output.form().is_none(), + "Our basic <output> should have no form associated with it." + ); + + output.set_name("Calculation result"); + assert_eq!( + output.name(), + "Calculation result", + "Output name should be 'Calculation result'." + ); + + assert_eq!( + output.type_(), + "output", + "Our basic <output> should have an type of 'output'." + ); + + output.set_default_value("27"); + assert_eq!( + output.default_value(), + "27", + "Default output value should be '27'." + ); + + output.set_value("49"); + assert_eq!(output.value(), "49", "Output value should be '49'."); + + // TODO: Fails in Chrome, but not in Firefox. + //assert!(output.will_validate(), "Output should validate by default (maybe browser dependent?)"); + + assert!( + output.validity().valid(), + "Our <output>s validity should be true." + ); + + assert!( + output.validation_message().is_ok(), + "We should be able to retrieve some validation message from our <output>." + ); + + assert!(output.check_validity(), "Our <output> should be valid."); + + assert!( + output.report_validity(), + "Our <output> should report valid." + ); + + output.set_custom_validity("Some scary error message."); + + assert!( + output.labels().length() == 0, + "Our basic <output> shouldn't have any labels associated with it." + ); +} diff --git a/vendor/web-sys/tests/wasm/paragraph_element.rs b/vendor/web-sys/tests/wasm/paragraph_element.rs new file mode 100644 index 000000000..2e1ddde3b --- /dev/null +++ b/vendor/web-sys/tests/wasm/paragraph_element.rs @@ -0,0 +1,19 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlParagraphElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_paragraph() -> HtmlParagraphElement; +} + +#[wasm_bindgen_test] +fn test_paragraph_element() { + let paragraph = new_paragraph(); + paragraph.set_align("right"); + assert_eq!( + paragraph.align(), + "right", + "Paragraph should be aligned 'right'." + ); +} diff --git a/vendor/web-sys/tests/wasm/param_element.rs b/vendor/web-sys/tests/wasm/param_element.rs new file mode 100644 index 000000000..def2d5317 --- /dev/null +++ b/vendor/web-sys/tests/wasm/param_element.rs @@ -0,0 +1,36 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlParamElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_param() -> HtmlParamElement; +} + +#[wasm_bindgen_test] +fn test_param_element() { + let param = new_param(); + param.set_name("color"); + assert_eq!(param.name(), "color", "Name of param should be 'color'."); + + param.set_value("purple"); + assert_eq!( + param.value(), + "purple", + "Value of param should be 'purple'." + ); + + param.set_value_type("ref"); + assert_eq!( + param.value_type(), + "ref", + "Value type of param should be 'ref'." + ); + + param.set_type("text/plain"); + assert_eq!( + param.type_(), + "text/plain", + "Value of param should be 'text/plain'." + ); +} diff --git a/vendor/web-sys/tests/wasm/performance.rs b/vendor/web-sys/tests/wasm/performance.rs new file mode 100644 index 000000000..84931a627 --- /dev/null +++ b/vendor/web-sys/tests/wasm/performance.rs @@ -0,0 +1,15 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::Performance; + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_name = performance)] + static PERFORMANCE: Performance; +} + +#[wasm_bindgen_test] +fn to_json() { + let perf = JsValue::from(PERFORMANCE.to_json()); + assert!(perf.is_object()); +} diff --git a/vendor/web-sys/tests/wasm/pre_element.rs b/vendor/web-sys/tests/wasm/pre_element.rs new file mode 100644 index 000000000..9ff7d1163 --- /dev/null +++ b/vendor/web-sys/tests/wasm/pre_element.rs @@ -0,0 +1,15 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlPreElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_pre() -> HtmlPreElement; +} + +#[wasm_bindgen_test] +fn test_pre_element() { + let pre = new_pre(); + pre.set_width(150); + assert_eq!(pre.width(), 150, "Pre width should be 150."); +} diff --git a/vendor/web-sys/tests/wasm/progress_element.rs b/vendor/web-sys/tests/wasm/progress_element.rs new file mode 100644 index 000000000..9b6db0b4a --- /dev/null +++ b/vendor/web-sys/tests/wasm/progress_element.rs @@ -0,0 +1,32 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlProgressElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_progress() -> HtmlProgressElement; +} + +#[wasm_bindgen_test] +fn test_progress_element() { + let progress = new_progress(); + progress.set_max(150.5); + assert_eq!( + progress.max(), + 150.5, + "Maximum progress value should be 150.5." + ); + + progress.set_value(22.); + assert_eq!(progress.value(), 22., "Progress value should be 22 units."); + assert_eq!( + progress.position(), + (22. / 150.5), + "Progress position should be 22 divided by the max possible value." + ); + + assert!( + progress.labels().length() == 0, + "Our simple progress bar shouldn't be associated with any labels." + ); +} diff --git a/vendor/web-sys/tests/wasm/quote_element.rs b/vendor/web-sys/tests/wasm/quote_element.rs new file mode 100644 index 000000000..202bf67c6 --- /dev/null +++ b/vendor/web-sys/tests/wasm/quote_element.rs @@ -0,0 +1,18 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlQuoteElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_quote() -> HtmlQuoteElement; +} + +#[wasm_bindgen_test] +fn test_quote_element() { + let quote = new_quote(); + quote.set_cite("https://en.wikipedia.org/wiki/Rust_(programming_language)"); + assert_eq!( + quote.cite(), + "https://en.wikipedia.org/wiki/Rust_(programming_language)" + ); +} diff --git a/vendor/web-sys/tests/wasm/response.js b/vendor/web-sys/tests/wasm/response.js new file mode 100644 index 000000000..0d2e68647 --- /dev/null +++ b/vendor/web-sys/tests/wasm/response.js @@ -0,0 +1,13 @@ +export function new_response() { + return new Response(null, {status: 501}); +} + +export function get_wasm_imports() { + return { + imports: { + imported_func: function () { + return 1; + } + } + }; +} diff --git a/vendor/web-sys/tests/wasm/response.rs b/vendor/web-sys/tests/wasm/response.rs new file mode 100644 index 000000000..bd1727971 --- /dev/null +++ b/vendor/web-sys/tests/wasm/response.rs @@ -0,0 +1,68 @@ +use js_sys::{ArrayBuffer, DataView, Object, Promise, Reflect, WebAssembly}; +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::JsFuture; +use wasm_bindgen_test::*; +use web_sys::{Headers, Response, ResponseInit}; + +#[wasm_bindgen(module = "/tests/wasm/response.js")] +extern "C" { + fn new_response() -> Response; + fn get_wasm_imports() -> Object; +} + +#[wasm_bindgen_test] +fn test_response_from_js() { + let response = new_response(); + assert!(!response.ok()); + assert!(!response.redirected()); + assert_eq!(response.status(), 501); +} + +#[wasm_bindgen_test] +async fn test_response_from_bytes() { + let mut bytes: [u8; 3] = [1, 3, 5]; + let response = Response::new_with_opt_u8_array(Some(&mut bytes)).unwrap(); + assert!(response.ok()); + assert_eq!(response.status(), 200); + + let buf_promise = response.array_buffer().unwrap(); + let buf_val = JsFuture::from(buf_promise).await.unwrap(); + assert!(buf_val.is_instance_of::<ArrayBuffer>()); + let array_buf: ArrayBuffer = buf_val.dyn_into().unwrap(); + let data_view = DataView::new(&array_buf, 0, bytes.len()); + for (i, byte) in bytes.iter().enumerate() { + assert_eq!(&data_view.get_uint8(i), byte); + } +} + +#[wasm_bindgen_test] +async fn test_response_from_other_body() { + let input = "Hello, world!"; + let response_a = Response::new_with_opt_str(Some(input)).unwrap(); + let body = response_a.body(); + let response_b = Response::new_with_opt_readable_stream(body.as_ref()).unwrap(); + let output = JsFuture::from(response_b.text().unwrap()).await.unwrap(); + assert_eq!(JsValue::from_str(input), output); +} + +// Because it relies on `Response`, this can't go in `js-sys`, so put it here instead. +#[wasm_bindgen_test] +async fn wasm_instantiate_streaming() { + // Taken from `crates/js-sys/tests/wasm/WebAssembly.js`. + let mut wasm = *b"\x00asm\x01\x00\x00\x00\x01\x08\x02`\x01\x7f\x00`\x00\x00\x02\x19\x01\x07imports\rimported_func\x00\x00\x03\x02\x01\x01\x07\x11\x01\rexported_func\x00\x01\n\x08\x01\x06\x00A*\x10\x00\x0b"; + + let headers = Headers::new().unwrap(); + headers.append("Content-Type", "application/wasm").unwrap(); + let response = Response::new_with_opt_u8_array_and_init( + Some(&mut wasm), + ResponseInit::new().headers(&headers), + ) + .unwrap(); + let response = Promise::resolve(&response); + let imports = get_wasm_imports(); + let p = WebAssembly::instantiate_streaming(&response, &imports); + let obj = JsFuture::from(p).await.unwrap(); + assert!(Reflect::get(obj.as_ref(), &"instance".into()) + .unwrap() + .is_instance_of::<WebAssembly::Instance>()); +} diff --git a/vendor/web-sys/tests/wasm/rtc_rtp_transceiver_direction.rs b/vendor/web-sys/tests/wasm/rtc_rtp_transceiver_direction.rs new file mode 100644 index 000000000..38b30dd0b --- /dev/null +++ b/vendor/web-sys/tests/wasm/rtc_rtp_transceiver_direction.rs @@ -0,0 +1,80 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::JsFuture; +use wasm_bindgen_test::*; + +use web_sys::{ + RtcPeerConnection, RtcRtpTransceiver, RtcRtpTransceiverDirection, RtcRtpTransceiverInit, + RtcSessionDescriptionInit, +}; + +#[wasm_bindgen( + inline_js = "export function is_unified_avail() { return Object.keys(RTCRtpTransceiver.prototype).indexOf('currentDirection')>-1; }" +)] +extern "C" { + /// Available in FF since forever, in Chrome since 72, in Safari since 12.1 + fn is_unified_avail() -> bool; +} + +#[wasm_bindgen_test] +async fn rtc_rtp_transceiver_direction() { + if !is_unified_avail() { + return; + } + + let mut tr_init: RtcRtpTransceiverInit = RtcRtpTransceiverInit::new(); + + let pc1: RtcPeerConnection = RtcPeerConnection::new().unwrap(); + + let tr1: RtcRtpTransceiver = pc1.add_transceiver_with_str_and_init( + "audio", + tr_init.direction(RtcRtpTransceiverDirection::Sendonly), + ); + assert_eq!(tr1.direction(), RtcRtpTransceiverDirection::Sendonly); + assert_eq!(tr1.current_direction(), None); + + let pc2: RtcPeerConnection = RtcPeerConnection::new().unwrap(); + + let (_, p2) = exchange_sdps(pc1, pc2).await; + assert_eq!(tr1.direction(), RtcRtpTransceiverDirection::Sendonly); + assert_eq!( + tr1.current_direction(), + Some(RtcRtpTransceiverDirection::Sendonly) + ); + + let tr2: RtcRtpTransceiver = js_sys::try_iter(&p2.get_transceivers()) + .unwrap() + .unwrap() + .next() + .unwrap() + .unwrap() + .unchecked_into(); + + assert_eq!(tr2.direction(), RtcRtpTransceiverDirection::Recvonly); + assert_eq!( + tr2.current_direction(), + Some(RtcRtpTransceiverDirection::Recvonly) + ); +} + +async fn exchange_sdps( + p1: RtcPeerConnection, + p2: RtcPeerConnection, +) -> (RtcPeerConnection, RtcPeerConnection) { + let offer = JsFuture::from(p1.create_offer()).await.unwrap(); + let offer = offer.unchecked_into::<RtcSessionDescriptionInit>(); + JsFuture::from(p1.set_local_description(&offer)) + .await + .unwrap(); + JsFuture::from(p2.set_remote_description(&offer)) + .await + .unwrap(); + let answer = JsFuture::from(p2.create_answer()).await.unwrap(); + let answer = answer.unchecked_into::<RtcSessionDescriptionInit>(); + JsFuture::from(p2.set_local_description(&answer)) + .await + .unwrap(); + JsFuture::from(p1.set_remote_description(&answer)) + .await + .unwrap(); + (p1, p2) +} diff --git a/vendor/web-sys/tests/wasm/script_element.rs b/vendor/web-sys/tests/wasm/script_element.rs new file mode 100644 index 000000000..f8816bd8f --- /dev/null +++ b/vendor/web-sys/tests/wasm/script_element.rs @@ -0,0 +1,80 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlScriptElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_script() -> HtmlScriptElement; +} + +#[wasm_bindgen_test] +fn test_script_element() { + let element = new_script(); + assert_eq!(element.src(), "", "Shouldn't have a src"); + element.set_src("https://example.com/script.js"); + assert_eq!( + element.src(), + "https://example.com/script.js", + "Should have a src" + ); + + assert_eq!(element.type_(), "", "Shouldn't have a type"); + element.set_type("application/javascript"); + assert_eq!( + element.type_(), + "application/javascript", + "Should have a type" + ); + + assert!(!element.no_module(), "Shouldn't be a nomodule"); + element.set_no_module(true); + assert!(element.no_module(), "Should be a nomodule"); + + assert_eq!(element.charset(), "", "Shouldn't have a charset"); + element.set_charset("UTF-8"); + assert_eq!(element.charset(), "UTF-8", "Should have a charset"); + + assert!(element.r#async(), "Should be async"); + element.set_async(false); + assert!(!element.r#async(), "Shouldn't be a async"); + + assert!(!element.defer(), "Shouldn't be a defer"); + element.set_defer(true); + assert!(element.defer(), "Should be a defer"); + + assert!( + element.cross_origin().is_none(), + "Shouldn't have a crossorigin" + ); + element.set_cross_origin(Some("anonymous")); + assert_eq!( + element.cross_origin().unwrap(), + "anonymous", + "Should have a crossorigin" + ); + element.set_cross_origin(None); + assert!( + element.cross_origin().is_none(), + "Shouldn't have a crossorigin" + ); + + assert_eq!(element.text().unwrap(), "", "Shouldn't have text"); + assert_eq!(element.set_text("text").unwrap(), ()); + assert_eq!(element.text().unwrap(), "text", "Should have text"); + + assert_eq!(element.event(), "", "Shouldn't have an event"); + element.set_event("ev"); + assert_eq!(element.event(), "ev", "Should have an event"); + + assert_eq!(element.html_for(), "", "Shouldn't have an html_for"); + element.set_html_for("hey"); + assert_eq!(element.html_for(), "hey", "Should have an html_for"); + + assert_eq!(element.integrity(), "", "Shouldn't have an integrity"); + element.set_integrity("integrity-val"); + assert_eq!( + element.integrity(), + "integrity-val", + "Should have an integrity" + ); +} diff --git a/vendor/web-sys/tests/wasm/select_element.rs b/vendor/web-sys/tests/wasm/select_element.rs new file mode 100644 index 000000000..2f2319f4f --- /dev/null +++ b/vendor/web-sys/tests/wasm/select_element.rs @@ -0,0 +1,181 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlSelectElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_select_with_food_opts() -> HtmlSelectElement; +} + +#[wasm_bindgen_test] +fn test_select_element() { + // Creates a select with four options. Options are ["tomato", "potato", "orange", "apple"], where + // the string is the .value and .text of each option. + let select = new_select_with_food_opts(); + select.set_autofocus(true); + assert_eq!( + select.autofocus(), + true, + "Select element should have a true autofocus property." + ); + + select.set_autofocus(false); + assert_eq!( + select.autofocus(), + false, + "Select element should have a false autofocus property." + ); + + // TODO: This test currently fails on Firefox, but not Chrome. In Firefox, even though we select.set_autocomplete(), select.autocomplete() yields an empty String. + // select.set_autocomplete("tomato"); + // assert_eq!(select.autocomplete(), "tomato", "Select element should have a 'tomato' autocomplete property."); + + select.set_disabled(true); + assert_eq!( + select.disabled(), + true, + "Select element should be disabled." + ); + + select.set_disabled(false); + assert_eq!( + select.disabled(), + false, + "Select element should not be disabled." + ); + + assert!( + select.form().is_none(), + "Select should not be associated with a form." + ); + + select.set_multiple(false); + assert_eq!( + select.multiple(), + false, + "Select element should have a false multiple property." + ); + + select.set_multiple(true); + assert_eq!( + select.multiple(), + true, + "Select element should have a true multiple property." + ); + + select.set_name("potato"); + assert_eq!( + select.name(), + "potato", + "Select element should have a name property of 'potato'." + ); + + select.set_required(true); + assert_eq!( + select.required(), + true, + "Select element should be required." + ); + + select.set_required(false); + assert_eq!( + select.required(), + false, + "Select element should not be required." + ); + + select.set_size(432); + assert_eq!( + select.size(), + 432, + "Select element should have a size property of 432." + ); + + // Default type seems to be "select-multiple" for the browsers I tested, but there's no guarantee + // on this, so let's just make sure we get back something here. + assert!( + select.type_().len() > 0, + "Select element should have some type." + ); + + assert!( + select.options().length() == 4, + "Select element should have four options." + ); + + select.set_length(12); + assert_eq!( + select.length(), + 12, + "Select element should have a length of 12." + ); + // Reset the length to four, as that's how many options we actually have. + select.set_length(4); + + assert!( + select + .named_item("this should definitely find nothing") + .is_none(), + "Shouldn't be able to find a named item with the given string." + ); + + assert!( + select.selected_options().length() == 1, + "One option should be selected by default, just by way of having items." + ); + + select.set_selected_index(2); + assert_eq!( + select.selected_index(), + 2, + "Select element should have a selected index of 2." + ); + + // Quote from docs: The value property sets or returns the value of the selected option in a drop-down list. + select.set_value("tomato"); // Select the "tomato" option + assert_eq!( + select.value(), + "tomato", + "Select element should have no selected value." + ); + + // This might be browser dependent, potentially rendering this test useless? Worked fine in Chrome and Firefox for now. + assert_eq!( + select.will_validate(), + true, + "Select element should not validate by default." + ); + + assert!( + select.validation_message().is_ok(), + "Select element should retrieve a validation message." + ); + + assert!( + select.validity().valid(), + "Our basic select should be valid." + ); + + assert!( + select.check_validity(), + "Our basic select should check out as valid." + ); + + assert!( + select.report_validity(), + "Our basic select should report valid." + ); + + select.set_custom_validity("Some custom validity error."); + + assert!( + select.labels().length() == 0, + "There should be no labels associated with our select element." + ); + + // TODO: This test won't work until this bug is fixed: https://www.w3.org/Bugs/Public/show_bug.cgi?id=20720. Sometime in the future, either remove this test or uncomment after bug is fixed. + // assert!(select.named_item("tomato").is_some(), "Should be able to find the 'tomato' option before removing it."); + // select.remove(0); + // assert!(select.named_item("tomato").is_none(), "Shouldn't be able to find the 'tomato' option after removing it.") + // TODO: As a result, we are missing a test for the remove() method. +} diff --git a/vendor/web-sys/tests/wasm/slot_element.rs b/vendor/web-sys/tests/wasm/slot_element.rs new file mode 100644 index 000000000..d01ccc9fc --- /dev/null +++ b/vendor/web-sys/tests/wasm/slot_element.rs @@ -0,0 +1,16 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlSlotElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_slot() -> HtmlSlotElement; +} + +#[wasm_bindgen_test] +fn test_slot_element() { + let _slot = new_slot(); + // TODO: Test fails in Firefox, but not in Chrome. Error in Firefox is 'ReferenceError: HTMLSlotElement is not defined'. https://w3c-test.org/shadow-dom/HTMLSlotElement-interface.html + // slot.set_name("root_separator"); + // assert_eq!(slot.name(), "root_separator", "Slot name should 'root_separator'."); +} diff --git a/vendor/web-sys/tests/wasm/span_element.rs b/vendor/web-sys/tests/wasm/span_element.rs new file mode 100644 index 000000000..490df42ad --- /dev/null +++ b/vendor/web-sys/tests/wasm/span_element.rs @@ -0,0 +1,14 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlSpanElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_span() -> HtmlSpanElement; +} + +#[wasm_bindgen_test] +fn test_span_element() { + let _element = new_span(); + assert!(true, "Span doesn't have an interface"); +} diff --git a/vendor/web-sys/tests/wasm/style_element.rs b/vendor/web-sys/tests/wasm/style_element.rs new file mode 100644 index 000000000..eaa43a9ed --- /dev/null +++ b/vendor/web-sys/tests/wasm/style_element.rs @@ -0,0 +1,24 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlStyleElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_style() -> HtmlStyleElement; +} + +#[wasm_bindgen_test] +fn test_style_element() { + let element = new_style(); + assert!(!element.disabled(), "Should be disabled"); + element.set_disabled(true); + assert!(!element.disabled(), "Should be disabled"); // Not sure why this is but Chrome in Firefox behabe the same + + assert_eq!(element.type_(), "", "Shouldn't have a type"); + element.set_type("text/css"); + assert_eq!(element.type_(), "text/css", "Should have a type"); + + assert_eq!(element.media(), "", "Shouldn't have a media"); + element.set_media("screen, print"); + assert_eq!(element.media(), "screen, print", "Should have a media"); +} diff --git a/vendor/web-sys/tests/wasm/table_element.rs b/vendor/web-sys/tests/wasm/table_element.rs new file mode 100644 index 000000000..3f974c59f --- /dev/null +++ b/vendor/web-sys/tests/wasm/table_element.rs @@ -0,0 +1,179 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::{HtmlTableCaptionElement, HtmlTableElement, HtmlTableSectionElement}; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_table() -> HtmlTableElement; + fn new_caption() -> HtmlTableCaptionElement; + fn new_thead() -> HtmlTableSectionElement; + fn new_tfoot() -> HtmlTableSectionElement; +} + +#[wasm_bindgen_test] +fn test_table_element() { + let table = new_table(); + assert!( + table.caption().is_none(), + "New table element should have no caption element." + ); + + table.create_caption(); + assert!( + table.caption().is_some(), + "Table element should have caption element after create caption." + ); + + table.delete_caption(); + assert!( + table.caption().is_none(), + "Table element should have no caption element after delete caption." + ); + + table.set_caption(Some(&new_caption())); + assert!( + table.caption().is_some(), + "Table element should have caption element after set." + ); + + assert!( + table.t_head().is_none(), + "New table element should have no thead element." + ); + + table.create_t_head(); + assert!( + table.t_head().is_some(), + "Table element should have thead element after create thead." + ); + + table.delete_t_head(); + assert!( + table.t_head().is_none(), + "Table element should have no thead element after delete thead." + ); + + table.set_t_head(Some(&new_thead())); + assert!( + table.t_head().is_some(), + "Table element should have thead element after set." + ); + + assert!( + table.t_foot().is_none(), + "New table element should have no tfoot element." + ); + + table.create_t_foot(); + assert!( + table.t_foot().is_some(), + "Table element should have tfoot element after create tfoot." + ); + + table.delete_t_foot(); + assert!( + table.t_foot().is_none(), + "Table element should have no tfoot element after delete tfoot." + ); + + table.set_t_foot(Some(&new_tfoot())); + assert!( + table.t_foot().is_some(), + "Table element should have tfoot element after set." + ); + + assert!( + table.t_bodies().length() == 0, + "New table element should have no tbody element." + ); + + table.create_t_body(); + assert!( + table.t_bodies().length() == 1, + "Table element should have tbody element after create tbody." + ); + + assert!( + table.rows().length() == 0, + "New table element should have no rows." + ); + + table + .insert_row_with_index(0) + .expect("Failed to insert row at index 0"); + assert!( + table.rows().length() == 1, + "Table element should have rows after insert row." + ); + + table + .delete_row(0) + .expect("Failed to delete row at index 0"); + assert!( + table.rows().length() == 0, + "Table element should have no rows after delete row." + ); + + table.set_align("left"); + assert_eq!( + table.align(), + "left", + "Table element should have an align property of 'left'" + ); + + table.set_border("10"); + assert_eq!( + table.border(), + "10", + "Table element should have a border property of '10'" + ); + + table.set_frame("above"); + assert_eq!( + table.frame(), + "above", + "Table element should have an frame property of 'above'" + ); + + table.set_rules("none"); + assert_eq!( + table.rules(), + "none", + "Table element should have an rules property of 'none'" + ); + + table.set_summary("summary"); + assert_eq!( + table.summary(), + "summary", + "Table element should have an summary property of 'summary'" + ); + + table.set_width("1000"); + assert_eq!( + table.width(), + "1000", + "Table element should have a width property of '1000'" + ); + + table.set_bg_color("#ffffff"); + assert_eq!( + table.bg_color(), + "#ffffff", + "Table element should have an bgColor property of '#ffffff'" + ); + + table.set_cell_padding("1"); + assert_eq!( + table.cell_padding(), + "1", + "Table element should have an cellPadding property of '1'" + ); + + table.set_cell_spacing("1"); + assert_eq!( + table.cell_spacing(), + "1", + "Table element should have an cellSpacing property of '1'" + ); +} diff --git a/vendor/web-sys/tests/wasm/title_element.rs b/vendor/web-sys/tests/wasm/title_element.rs new file mode 100644 index 000000000..ebc7aa74e --- /dev/null +++ b/vendor/web-sys/tests/wasm/title_element.rs @@ -0,0 +1,16 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::HtmlTitleElement; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_title() -> HtmlTitleElement; +} + +#[wasm_bindgen_test] +fn title_element() { + let element = new_title(); + assert_eq!(element.text().unwrap(), "", "Shouldn't have an text"); + assert_eq!(element.set_text("page text").unwrap(), ()); + assert_eq!(element.text().unwrap(), "page text", "Should have an text"); +} diff --git a/vendor/web-sys/tests/wasm/whitelisted_immutable_slices.rs b/vendor/web-sys/tests/wasm/whitelisted_immutable_slices.rs new file mode 100644 index 000000000..14bda73c0 --- /dev/null +++ b/vendor/web-sys/tests/wasm/whitelisted_immutable_slices.rs @@ -0,0 +1,77 @@ +//! When generating our web_sys APIs we default to setting slice references that +//! get passed to JS as mutable in case they get mutated in JS. +//! +//! In certain cases we know for sure that the slice will not get mutated - for +//! example when working with the WebGlRenderingContext APIs. +//! +//! These tests ensure that whitelisted methods do indeed accept immutable slices. +//! Especially important since this whitelist is stringly typed and currently +//! maintained by hand. +//! +//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005 + +use wasm_bindgen::{JsCast, JsValue}; +use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket}; + +// Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices. +fn test_webgl_rendering_context_immutable_slices() { + let gl = JsValue::null().unchecked_into::<WebGlRenderingContext>(); + + gl.vertex_attrib1fv_with_f32_array(0, &[1.]); + gl.vertex_attrib2fv_with_f32_array(0, &[1.]); + gl.vertex_attrib3fv_with_f32_array(0, &[1.]); + gl.vertex_attrib4fv_with_f32_array(0, &[1.]); + + gl.uniform1fv_with_f32_array(None, &[1.]); + gl.uniform2fv_with_f32_array(None, &[1.]); + gl.uniform3fv_with_f32_array(None, &[1.]); + gl.uniform4fv_with_f32_array(None, &[1.]); + + gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]); + gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]); + gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]); + + gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Some(&[1]), + ); + gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array( + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Some(&[1]), + ); + gl.compressed_tex_image_2d_with_u8_array(0, 0, 0, 0, 0, 0, &[1]); +} + +// Ensure that our whitelisted WebGl2RenderingContext methods compile with immutable slices. +fn test_webgl2_rendering_context_immutable_slices() { + let gl = JsValue::null().unchecked_into::<WebGl2RenderingContext>(); + + gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); + gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); + gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]); +} + +// Ensure that our whitelisted WebSocket methods compile with immutable slices. +fn test_websocket_immutable_slices() { + let ws = JsValue::null().unchecked_into::<WebSocket>(); + ws.send_with_u8_array(&[0]); +} + +// TODO: +//#[wasm_bindgen_test] +//fn test_another_types_immutable_slices_here() { +//} diff --git a/vendor/web-sys/tests/wasm/xpath_result.rs b/vendor/web-sys/tests/wasm/xpath_result.rs new file mode 100644 index 000000000..933ac97ba --- /dev/null +++ b/vendor/web-sys/tests/wasm/xpath_result.rs @@ -0,0 +1,27 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::XPathResult; + +#[wasm_bindgen(module = "/tests/wasm/element.js")] +extern "C" { + fn new_xpath_result() -> XPathResult; +} + +#[wasm_bindgen_test] +fn test_xpath_result() { + let xpath_result = new_xpath_result(); + assert_eq!( + xpath_result.result_type(), + XPathResult::UNORDERED_NODE_ITERATOR_TYPE + ); + assert_eq!(xpath_result.invalid_iterator_state(), false); + assert_eq!( + xpath_result + .iterate_next() + .unwrap() + .unwrap() + .text_content() + .unwrap(), + "tomato" + ); +} |