Testing web-sys for input, heading and title elements. (#596)

This commit is contained in:
Jonathan Kingston
2018-07-31 16:57:16 +01:00
committed by Alex Crichton
parent 05f3eec76d
commit 26a3e57536
12 changed files with 273 additions and 75 deletions

View File

@ -178,13 +178,13 @@ bindings are fully working and have full test coverage.
- [ ] HiddenPluginEvent.webidl
- [ ] History.webidl
- [ ] HTMLAllCollection.webidl
- [ ] HTMLAnchorElement.webidl
- [x] HTMLAnchorElement.webidl
- [ ] HTMLAreaElement.webidl
- [ ] HTMLAudioElement.webidl
- [ ] HTMLBaseElement.webidl
- [ ] HTMLBodyElement.webidl
- [ ] HTMLBRElement.webidl
- [ ] HTMLButtonElement.webidl
- [x] HTMLBodyElement.webidl
- [x] HTMLBRElement.webidl
- [x] HTMLButtonElement.webidl
- [ ] HTMLCanvasElement.webidl
- [ ] HTMLCollection.webidl
- [ ] HTMLDataElement.webidl
@ -192,10 +192,10 @@ bindings are fully working and have full test coverage.
- [ ] HTMLDetailsElement.webidl
- [ ] HTMLDialogElement.webidl
- [ ] HTMLDirectoryElement.webidl
- [ ] HTMLDivElement.webidl
- [x] HTMLDivElement.webidl
- [ ] HTMLDListElement.webidl
- [ ] HTMLDocument.webidl
- [ ] HTMLElement.webidl
- [x] HTMLElement.webidl
- [ ] HTMLEmbedElement.webidl
- [ ] HTMLFieldSetElement.webidl
- [ ] HTMLFontElement.webidl
@ -204,13 +204,13 @@ bindings are fully working and have full test coverage.
- [ ] HTMLFrameElement.webidl
- [ ] HTMLFrameSetElement.webidl
- [ ] HTMLHeadElement.webidl
- [ ] HTMLHeadingElement.webidl
- [x] HTMLHeadingElement.webidl
- [x] HTMLHRElement.webidl
- [ ] HTMLHtmlElement.webidl
- [x] HTMLHtmlElement.webidl
- [ ] HTMLHyperlinkElementUtils.webidl
- [ ] HTMLIFrameElement.webidl
- [ ] HTMLImageElement.webidl
- [ ] HTMLInputElement.webidl
- [x] HTMLInputElement.webidl
- [ ] HTMLLabelElement.webidl
- [ ] HTMLLegendElement.webidl
- [ ] HTMLLIElement.webidl
@ -234,12 +234,12 @@ bindings are fully working and have full test coverage.
- [ ] HTMLPreElement.webidl
- [ ] HTMLProgressElement.webidl
- [ ] HTMLQuoteElement.webidl
- [ ] HTMLScriptElement.webidl
- [x] HTMLScriptElement.webidl
- [ ] HTMLSelectElement.webidl
- [ ] HTMLSlotElement.webidl
- [ ] HTMLSourceElement.webidl
- [ ] HTMLSpanElement.webidl
- [ ] HTMLStyleElement.webidl
- [x] HTMLStyleElement.webidl
- [ ] HTMLTableCaptionElement.webidl
- [ ] HTMLTableCellElement.webidl
- [ ] HTMLTableColElement.webidl
@ -249,7 +249,7 @@ bindings are fully working and have full test coverage.
- [ ] HTMLTemplateElement.webidl
- [ ] HTMLTextAreaElement.webidl
- [ ] HTMLTimeElement.webidl
- [ ] HTMLTitleElement.webidl
- [x] HTMLTitleElement.webidl
- [ ] HTMLTrackElement.webidl
- [ ] HTMLUListElement.webidl
- [ ] HTMLVideoElement.webidl

View File

@ -46,6 +46,18 @@ export function new_style() {
return document.createElement("style");
}
export function new_input() {
return document.createElement("input");
}
export function new_title() {
return document.createElement("title");
}
export function new_heading() {
return document.createElement("h1");
}
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);

View File

@ -0,0 +1,16 @@
use wasm_bindgen_test::*;
use wasm_bindgen::prelude::*;
use web_sys::HtmlHeadingElement;
#[wasm_bindgen(module = "./tests/wasm/element.js")]
extern {
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");
}

View File

@ -58,11 +58,13 @@ fn test_html_element() {
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")
};
*/
assert!(!element.spellcheck(), "Shouldn't be spellchecked");
element.set_spellcheck(true);

View File

@ -0,0 +1,198 @@
use wasm_bindgen_test::*;
use wasm_bindgen::prelude::*;
use web_sys::HtmlInputElement;
#[wasm_bindgen(module = "./tests/wasm/element.js")]
extern {
fn new_input() -> HtmlInputElement;
}
#[wasm_bindgen]
extern {
#[wasm_bindgen(js_name = location, js_namespace = document)]
static LOCATION: Location;
type Location;
// FIXME: `href` should be structural in `web_sys`
#[wasm_bindgen(getter, method, structural)]
fn href(this: &Location) -> String;
}
#[wasm_bindgen_test]
fn test_input_element() {
let element = new_input();
let location = LOCATION.href();
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)
*/
}

View File

@ -15,74 +15,16 @@ pub mod button_element;
pub mod div_element;
pub mod element;
pub mod head_element;
pub mod heading_element;
pub mod headers;
pub mod history;
pub mod hr_element;
pub mod html_element;
pub mod html_html_element;
pub mod input_element;
pub mod response;
pub mod script_element;
pub mod span_element;
pub mod style_element;
/*TODO tests for:
web_sys::HtmlFontElement,
web_sys::HtmlMenuItemElement,
web_sys::HtmlSourceElement,
web_sys::HtmlAreaElement,
web_sys::HtmlFormElement,
web_sys::HtmlMetaElement,
web_sys::HtmlAudioElement,
web_sys::HtmlFrameElement,
web_sys::HtmlMeterElement,
web_sys::HtmlBaseElement,
web_sys::HtmlFrameSetElement,
web_sys::HtmlModElement,
web_sys::HtmlTableCaptionElement,
web_sys::HtmlObjectElement,
web_sys::HtmlTableCellElement,
web_sys::HtmlHeadingElement,
web_sys::HtmlOListElement,
web_sys::HtmlTableColElement,
web_sys::HtmlHRElement,
web_sys::HtmlOptGroupElement,
web_sys::HtmlTableElement,
web_sys::HtmlCanvasElement,
web_sys::HtmlOptionElement,
web_sys::HtmlTableRowElement,
web_sys::HtmlDataElement,
web_sys::HtmlIFrameElement,
web_sys::HtmlOutputElement,
web_sys::HtmlTableSectionElement,
web_sys::HtmlDataListElement,
web_sys::HtmlImageElement,
web_sys::HtmlParagraphElement,
web_sys::HtmlTemplateElement,
web_sys::HtmlDetailsElement,
web_sys::HtmlInputElement,
web_sys::HtmlParamElement,
web_sys::HtmlTextAreaElement,
web_sys::HtmlDialogElement,
web_sys::HtmlLabelElement,
web_sys::HtmlPictureElement,
web_sys::HtmlTimeElement,
web_sys::HtmlDirectoryElement,
web_sys::HtmlLegendElement,
web_sys::HtmlPreElement,
web_sys::HtmlTitleElement,
web_sys::HtmlLIElement,
web_sys::HtmlProgressElement,
web_sys::HtmlTrackElement,
web_sys::HtmlDListElement,
web_sys::HtmlLinkElement,
web_sys::HtmlQuoteElement,
web_sys::HtmlUListElement,
web_sys::HtmlMapElement,
web_sys::HtmlVideoElement,
web_sys::HtmlEmbedElement,
web_sys::HtmlMediaElement,
web_sys::HtmlSelectElement,
web_sys::HtmlFieldSetElement,
web_sys::HtmlMenuElement,
web_sys::HtmlSlotElement,
*/
pub mod title_element;
pub mod xpath_result;

View File

@ -0,0 +1,16 @@
use wasm_bindgen_test::*;
use wasm_bindgen::prelude::*;
use web_sys::HtmlTitleElement;
#[wasm_bindgen(module = "./tests/wasm/element.js")]
extern {
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");
}

View File

@ -14,8 +14,10 @@
dictionary EventListenerOptions {
boolean capture = false;
/* Setting to true make the listener be added to the system group. */
/*Non standard
[Func="ThreadSafeIsChromeOrXBL"]
boolean mozSystemGroup = false;
*/
};
dictionary AddEventListenerOptions : EventListenerOptions {

View File

@ -50,8 +50,8 @@ interface HTMLElement : Element {
attribute DOMString contentEditable;
[Pure]
readonly attribute boolean isContentEditable;
[Pure]
readonly attribute HTMLMenuElement? contextMenu;
//[Pure]
//readonly attribute HTMLMenuElement? contextMenu;
//[SetterThrows]
// attribute HTMLMenuElement? contextMenu;
[CEReactions, SetterThrows, Pure]

View File

@ -198,15 +198,18 @@ interface MozEditableElement {
[Pure, ChromeOnly]
readonly attribute nsIEditor? editor;
/*Non standard
// This is similar to set .value on nsIDOMInput/TextAreaElements, but handling
// of the value change is closer to the normal user input, so 'change' event
// for example will be dispatched when focusing out the element.
[Func="IsChromeOrXBL", NeedsSubjectPrincipal]
void setUserInput(DOMString input);
*/
};
HTMLInputElement implements MozEditableElement;
/*Non standard
partial interface HTMLInputElement {
[Pref="dom.input.dirpicker", SetterThrows]
attribute boolean allowdirs;
@ -223,6 +226,7 @@ partial interface HTMLInputElement {
[Throws, Pref="dom.input.dirpicker"]
void chooseDirectory();
};
*/
HTMLInputElement implements MozImageLoadingContent;
@ -261,6 +265,7 @@ partial interface HTMLInputElement {
BinaryName="getMaximumAsDouble"]
double getMaximum();
/*Non standard
[Pref="dom.forms.datetime", Func="IsChromeOrXBL"]
void openDateTimePicker(optional DateTimeValue initialValue);
@ -283,6 +288,7 @@ partial interface HTMLInputElement {
[Pref="dom.forms.datetime", Func="IsChromeOrXBL",
BinaryName="getStepBaseAsDouble"]
double getStepBase();
*/
};
partial interface HTMLInputElement {

View File

@ -119,9 +119,11 @@ partial interface HTMLMediaElement {
attribute boolean mozPreservesPitch;
/*Non standard
// NB: for internal use with the video controls:
[Func="IsChromeOrXBL"] attribute boolean mozAllowCasting;
[Func="IsChromeOrXBL"] attribute boolean mozIsCasting;
*/
// Mozilla extension: stream capture
[Throws]

View File

@ -46,6 +46,7 @@ partial interface HTMLVideoElement {
// True if the video has an audio track available.
readonly attribute boolean mozHasAudio;
/*Non standard
// Attributes for builtin video controls to lock screen orientation.
// True if video controls should lock orientation when fullscreen.
[Pref="media.videocontrols.lock-video-orientation", Func="IsChromeOrXBL"]
@ -53,6 +54,7 @@ partial interface HTMLVideoElement {
// True if screen orientation is locked by video controls.
[Pref="media.videocontrols.lock-video-orientation", Func="IsChromeOrXBL"]
attribute boolean mozIsOrientationLocked;
*/
};
// https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#idl-def-HTMLVideoElement