From 4a43dba8d7ee1ed8247a97cd00120cbde106b28a Mon Sep 17 00:00:00 2001 From: Vijay Hebbar Date: Sat, 21 Oct 2017 23:46:55 +0000 Subject: [PATCH] Add implementation for itemprop and itemtype Created test file Added the stub methods for itemprop and itemscope Resolved html5ever dependency, added ItemScope and ItemProp attr Resolving dependency Added pref override on metadata attributes Resetting to original state due to change in requirement Reverted adding attributes 1. add a customized implementation of parse_plain_attribute 2. add the following methods to HTMLElement.webidl added itemprop and itemtype, enabled pref in test Added initial implementation for getting itemprop property values Adding the wireframe for testing Implemented function to handle itemType Corrected typo Fixed typo bug in code Handling duplicates for itemtype attribute values Added the test suite structure Added test for extra space Added test for regular test values Added test cases for Single property values Test cases to check absence of itemtype and itemprop attributes Added code to handle absence of itemtype or itemprop attributes Added shell script to run all test cases cleared up Cargo file Tidying up Removed the local test file Removed new line for test-tidy Ordered key in prefs.json Fixes for test-tidy Enabled test preferences Created test using wpt Creating WPT Tests for Regular and Single Prop Types Fixed the Regular type test Fixed tests Removed old test case metadata Incorporate review changes from PR Updated MANIFEST to sync test cases Making changed suggested in review Removed editor folding Removed unnecessary code Resolving cargo conflicts Updated PropertyNames and itemtypes implementation Trying different data in test case Updated manifest Updated code based on reviews --- .gitignore | 1 + components/script/dom/htmlelement.rs | 46 +++++++++++++++++ .../script/dom/webidls/HTMLElement.webidl | 5 ++ resources/prefs.json | 1 + tests/wpt/mozilla/meta/MANIFEST.json | 50 +++++++++++++++++++ .../meta/mozilla/microdata/__dir__.ini | 1 + .../mozilla/microdata/dup_prop_type_test.html | 48 ++++++++++++++++++ .../mozilla/microdata/extra_space_test.html | 49 ++++++++++++++++++ .../tests/mozilla/microdata/none_check.html | 48 ++++++++++++++++++ .../microdata/regular_prop_type_test.html | 48 ++++++++++++++++++ .../microdata/single_prop_type_test.html | 48 ++++++++++++++++++ 11 files changed, 345 insertions(+) create mode 100644 tests/wpt/mozilla/meta/mozilla/microdata/__dir__.ini create mode 100644 tests/wpt/mozilla/tests/mozilla/microdata/dup_prop_type_test.html create mode 100644 tests/wpt/mozilla/tests/mozilla/microdata/extra_space_test.html create mode 100644 tests/wpt/mozilla/tests/mozilla/microdata/none_check.html create mode 100644 tests/wpt/mozilla/tests/mozilla/microdata/regular_prop_type_test.html create mode 100644 tests/wpt/mozilla/tests/mozilla/microdata/single_prop_type_test.html diff --git a/.gitignore b/.gitignore index f6cf0b30e19..1a75979e55a 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ Servo.app .vscode /unminified-js + diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 616b69ebb95..d29251cb597 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -31,6 +31,7 @@ use dom::virtualmethods::VirtualMethods; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; use std::ascii::AsciiExt; +use std::collections::HashSet; use std::default::Default; use std::rc::Rc; use style::attr::AttrValue; @@ -277,6 +278,38 @@ impl HTMLElementMethods for HTMLElement { } } + // https://html.spec.whatwg.org/multipage/#attr-itemtype + fn Itemtypes(&self) -> Option> { + let atoms = self.element.get_tokenlist_attribute(&local_name!("itemtype"), ); + + if atoms.is_empty() { + return None; + } + + let mut item_attr_values = HashSet::new(); + for attr_value in &atoms { + item_attr_values.insert(DOMString::from(String::from(attr_value.trim()))); + } + + Some(item_attr_values.into_iter().collect()) + } + + // https://html.spec.whatwg.org/multipage/#names:-the-itemprop-attribute + fn PropertyNames(&self) -> Option> { + let atoms = self.element.get_tokenlist_attribute(&local_name!("itemprop"), ); + + if atoms.is_empty() { + return None; + } + + let mut item_attr_values = HashSet::new(); + for attr_value in &atoms { + item_attr_values.insert(DOMString::from(String::from(attr_value.trim()))); + } + + Some(item_attr_values.into_iter().collect()) + } + // https://html.spec.whatwg.org/multipage/#dom-click fn Click(&self) { if !self.upcast::().disabled_state() { @@ -577,4 +610,17 @@ impl VirtualMethods for HTMLElement { } self.update_sequentially_focusable_status(); } + + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { + match name { + &local_name!("itemprop") => AttrValue::from_serialized_tokenlist(value.into()), + &local_name!("itemtype") => AttrValue::from_serialized_tokenlist(value.into()), + _ => { + self.super_type().unwrap().parse_plain_attribute( + name, + value, + ) + }, + } + } } diff --git a/components/script/dom/webidls/HTMLElement.webidl b/components/script/dom/webidls/HTMLElement.webidl index 845b4445f9c..7c1b0d62c21 100644 --- a/components/script/dom/webidls/HTMLElement.webidl +++ b/components/script/dom/webidls/HTMLElement.webidl @@ -18,9 +18,14 @@ interface HTMLElement : Element { // microdata // attribute boolean itemScope; + // attribute DOMString itemId; //readonly attribute HTMLPropertiesCollection properties; // attribute any itemValue; // acts as DOMString on setting + [Pref="dom.microdata.testing.enabled"] + sequence? propertyNames(); + [Pref="dom.microdata.testing.enabled"] + sequence? itemtypes(); // user interaction [CEReactions] diff --git a/resources/prefs.json b/resources/prefs.json index d430b9f4e4b..1c5a5c92943 100644 --- a/resources/prefs.json +++ b/resources/prefs.json @@ -6,6 +6,7 @@ "dom.customelements.enabled": true, "dom.forcetouch.enabled": false, "dom.gamepad.enabled": false, + "dom.microdata.testing.enabled": true, "dom.mouseevent.which.enabled": false, "dom.mozbrowser.enabled": false, "dom.mutation_observer.enabled": false, diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index b292757f89e..4b4030f0d53 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -33350,6 +33350,36 @@ {} ] ], + "mozilla/microdata/dup_prop_type_test.html": [ + [ + "/_mozilla/mozilla/microdata/dup_prop_type_test.html", + {} + ] + ], + "mozilla/microdata/extra_space_test.html": [ + [ + "/_mozilla/mozilla/microdata/extra_space_test.html", + {} + ] + ], + "mozilla/microdata/none_check.html": [ + [ + "/_mozilla/mozilla/microdata/none_check.html", + {} + ] + ], + "mozilla/microdata/regular_prop_type_test.html": [ + [ + "/_mozilla/mozilla/microdata/regular_prop_type_test.html", + {} + ] + ], + "mozilla/microdata/single_prop_type_test.html": [ + [ + "/_mozilla/mozilla/microdata/single_prop_type_test.html", + {} + ] + ], "mozilla/mime_sniffing_font_context.html": [ [ "/_mozilla/mozilla/mime_sniffing_font_context.html", @@ -66385,6 +66415,26 @@ "4e0b6d4c416e2e3f26de64e9364f0a8c7a6dc5cb", "testharness" ], + "mozilla/microdata/dup_prop_type_test.html": [ + "4837cf896419aba6d1df6e89c5849a786d4e4be0", + "testharness" + ], + "mozilla/microdata/extra_space_test.html": [ + "0a941e2eb10013ab55049d4d6007d8301149f651", + "testharness" + ], + "mozilla/microdata/none_check.html": [ + "5addb47e08bdb4ad8293f22dffe95e4760336e08", + "testharness" + ], + "mozilla/microdata/regular_prop_type_test.html": [ + "8e67711c47afe50edaa9b6baaa1349862e639e2e", + "testharness" + ], + "mozilla/microdata/single_prop_type_test.html": [ + "0d81eecf7e52feb0964e879ffe9450881141caa5", + "testharness" + ], "mozilla/mime_sniffing_font_context.html": [ "1311e72e0a0dafa6fae594ca1ce2deca164acd36", "testharness" diff --git a/tests/wpt/mozilla/meta/mozilla/microdata/__dir__.ini b/tests/wpt/mozilla/meta/mozilla/microdata/__dir__.ini new file mode 100644 index 00000000000..f199618497d --- /dev/null +++ b/tests/wpt/mozilla/meta/mozilla/microdata/__dir__.ini @@ -0,0 +1 @@ +prefs: ["dom.microdata.testing.enabled:true"] diff --git a/tests/wpt/mozilla/tests/mozilla/microdata/dup_prop_type_test.html b/tests/wpt/mozilla/tests/mozilla/microdata/dup_prop_type_test.html new file mode 100644 index 00000000000..23afa74863c --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/microdata/dup_prop_type_test.html @@ -0,0 +1,48 @@ + + + + + + + + Duplicate ItemProperty and ItemType test + + + + +

Header H1

+

Header H2

+ +

Paragraph

+ +
+ Input Field in form +
+ +
    +
  • Unordered List Item
  • +
+ + Meta Tag + + Table
+ +
Hi
+ + + + + + + + diff --git a/tests/wpt/mozilla/tests/mozilla/microdata/extra_space_test.html b/tests/wpt/mozilla/tests/mozilla/microdata/extra_space_test.html new file mode 100644 index 00000000000..8ca5ff58729 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/microdata/extra_space_test.html @@ -0,0 +1,49 @@ + + + + + + + Extra Space ItemProperty and ItemType test + + + + +

Header H1

+

Header H2

+ +

Paragraph

+ +
+ Input Field in form +
+ +
    +
  • Unordered List Item
  • +
+ + Meta Tag + + Table
+ +
Hi
+ + + + + + + + diff --git a/tests/wpt/mozilla/tests/mozilla/microdata/none_check.html b/tests/wpt/mozilla/tests/mozilla/microdata/none_check.html new file mode 100644 index 00000000000..9cd9444a992 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/microdata/none_check.html @@ -0,0 +1,48 @@ + + + + + + + + None check test + + + + +

Header H1

+

Header H2

+ +

Paragraph

+ +
+ Input Field in form +
+ +
    +
  • Unordered List Item
  • +
+ + Meta Tag + + Table
+ +
Hi
+ + + + + + + + diff --git a/tests/wpt/mozilla/tests/mozilla/microdata/regular_prop_type_test.html b/tests/wpt/mozilla/tests/mozilla/microdata/regular_prop_type_test.html new file mode 100644 index 00000000000..e7b55d96d99 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/microdata/regular_prop_type_test.html @@ -0,0 +1,48 @@ + + + + + + + + Regular ItemProperty and ItemType test + + + + +

Header H1

+

Header H2

+ +

Paragraph

+ +
+ Input Field in form +
+ +
    +
  • Unordered List Item
  • +
+ + Meta Tag + + Table
+ +
Hi
+ + + + + + + + diff --git a/tests/wpt/mozilla/tests/mozilla/microdata/single_prop_type_test.html b/tests/wpt/mozilla/tests/mozilla/microdata/single_prop_type_test.html new file mode 100644 index 00000000000..15d6a413297 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/microdata/single_prop_type_test.html @@ -0,0 +1,48 @@ + + + + + + + + Single ItemProperty and ItemType test + + + + +

Header H1

+

Header H2

+ +

Paragraph

+ +
+ Input Field in form +
+ +
    +
  • Unordered List Item
  • +
+ + Meta Tag + + Table
+ +
Hi
+ + + + + + + +