mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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
This commit is contained in:
parent
88505dc2ff
commit
4a43dba8d7
11 changed files with 345 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -36,3 +36,4 @@ Servo.app
|
|||
.vscode
|
||||
|
||||
/unminified-js
|
||||
|
||||
|
|
|
@ -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<Vec<DOMString>> {
|
||||
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<Vec<DOMString>> {
|
||||
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::<Element>().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,
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DOMString>? propertyNames();
|
||||
[Pref="dom.microdata.testing.enabled"]
|
||||
sequence<DOMString>? itemtypes();
|
||||
|
||||
// user interaction
|
||||
[CEReactions]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
|
|
1
tests/wpt/mozilla/meta/mozilla/microdata/__dir__.ini
Normal file
1
tests/wpt/mozilla/meta/mozilla/microdata/__dir__.ini
Normal file
|
@ -0,0 +1 @@
|
|||
prefs: ["dom.microdata.testing.enabled:true"]
|
|
@ -0,0 +1,48 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>Duplicate ItemProperty and ItemType test</title>
|
||||
</head>
|
||||
|
||||
<body id="body" itemprop="hello world world" itemtype="hello world world">
|
||||
|
||||
<h1 id="h1" itemprop="hello world world" itemtype="hello world world">Header H1</h1>
|
||||
<h2 id="h2" itemprop="hello world world" itemtype="hello world world">Header H2</h2>
|
||||
|
||||
<p id="p" itemprop="hello world world" itemtype="hello world world">Paragraph</p>
|
||||
|
||||
<form id="form" itemprop="hello world world" itemtype="hello world world">
|
||||
<input id="input" itemprop="hello world world" itemtype="hello world world">Input Field in form</input>
|
||||
</form>
|
||||
|
||||
<ul id="ul" itemprop="hello world world" itemtype="hello world world">
|
||||
<li id="li" itemprop="hello world world" itemtype="hello world world">Unordered List Item</li>
|
||||
</ul>
|
||||
|
||||
<meta id="meta" itemprop="hello world world" itemtype="hello world world">Meta Tag</meta>
|
||||
|
||||
<table id="table" itemprop="hello world world" itemtype="hello world world">Table</table>
|
||||
|
||||
<div id="div" itemprop="hello world world" itemtype="hello world world">Hi</div>
|
||||
|
||||
<a id="anchor" itemprop="hello world world" itemtype="hello world world"></a>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
test(function() {
|
||||
// Test all elements
|
||||
var ids = ["body", "h1", "h2", "p", "input", "form", "li", "ul", "meta", "table", "div", "anchor"];
|
||||
for (let id of ids) {
|
||||
var elem = document.getElementById(id);
|
||||
assert_array_equals(elem.propertyNames().sort(), ["hello", "world"].sort(), "The method should return 'hello world' ");
|
||||
assert_array_equals(elem.itemtypes().sort(), ["hello", "world"].sort(), "The method should return 'hello world' ");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,49 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<html>
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>Extra Space ItemProperty and ItemType test</title>
|
||||
</head>
|
||||
|
||||
<body id="body" itemprop=" hello world " itemtype=" hello world ">
|
||||
|
||||
<h1 id="h1" itemprop=" hello world " itemtype=" hello world ">Header H1</h1>
|
||||
<h2 id="h2" itemprop=" hello world " itemtype=" hello world ">Header H2</h2>
|
||||
|
||||
<p id="p" itemprop=" hello world " itemtype=" hello world ">Paragraph</p>
|
||||
|
||||
<form id="form" itemprop=" hello world " itemtype=" hello world ">
|
||||
<input id="input" itemprop=" hello world " itemtype=" hello world ">Input Field in form</input>
|
||||
</form>
|
||||
|
||||
<ul id="ul" itemprop=" hello world " itemtype=" hello world ">
|
||||
<li id="li" itemprop=" hello world " itemtype=" hello world ">Unordered List Item</li>
|
||||
</ul>
|
||||
|
||||
<meta id="meta" itemprop=" hello world " itemtype=" hello world ">Meta Tag</meta>
|
||||
|
||||
<table id="table" itemprop=" hello world " itemtype=" hello world ">Table</table>
|
||||
|
||||
<div id="div" itemprop=" hello world " itemtype=" hello world ">Hi</div>
|
||||
|
||||
<a id="anchor" itemprop=" hello world " itemtype=" hello world "></a>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
test(function() {
|
||||
// Test all elements
|
||||
var ids = ["body", "h1", "h2", "p", "input", "form", "li", "ul", "meta", "table", "div", "anchor"];
|
||||
for (let id of ids) {
|
||||
var elem = document.getElementById(id);
|
||||
assert_array_equals(elem.propertyNames().sort(), ["hello", "world"].sort(), "The method should return 'hello world' ");
|
||||
assert_array_equals(elem.itemtypes().sort(), ["hello", "world"].sort(), "The method should return 'hello world' ");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
48
tests/wpt/mozilla/tests/mozilla/microdata/none_check.html
Normal file
48
tests/wpt/mozilla/tests/mozilla/microdata/none_check.html
Normal file
|
@ -0,0 +1,48 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>None check test</title>
|
||||
</head>
|
||||
|
||||
<body id="body">
|
||||
|
||||
<h1 id="h1">Header H1</h1>
|
||||
<h2 id="h2">Header H2</h2>
|
||||
|
||||
<p id="p">Paragraph</p>
|
||||
|
||||
<form id="form">
|
||||
<input id="input">Input Field in form</input>
|
||||
</form>
|
||||
|
||||
<ul id="ul">
|
||||
<li id="li">Unordered List Item</li>
|
||||
</ul>
|
||||
|
||||
<meta id="meta">Meta Tag</meta>
|
||||
|
||||
<table id="table">Table</table>
|
||||
|
||||
<div id="div">Hi</div>
|
||||
|
||||
<a id="anchor"></a>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
test(function() {
|
||||
// Test all elements
|
||||
var ids = ["body", "h1", "h2", "p", "input", "form", "li", "ul", "meta", "table", "div", "anchor"];
|
||||
for (let id of ids) {
|
||||
var elem = document.getElementById(id);
|
||||
assert_equals(elem.propertyNames(), null, "The method should return null ");
|
||||
assert_equals(elem.itemtypes(), null, "The method should return null ");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,48 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>Regular ItemProperty and ItemType test</title>
|
||||
</head>
|
||||
|
||||
<body id="body" itemprop="hello world" itemtype="hello world">
|
||||
|
||||
<h1 id="h1" itemprop="hello world" itemtype="hello world">Header H1</h1>
|
||||
<h2 id="h2" itemprop="hello world" itemtype="hello world">Header H2</h2>
|
||||
|
||||
<p id="p" itemprop="hello world" itemtype="hello world">Paragraph</p>
|
||||
|
||||
<form id="form" itemprop="hello world" itemtype="hello world">
|
||||
<input id="input" itemprop="hello world" itemtype="hello world">Input Field in form</input>
|
||||
</form>
|
||||
|
||||
<ul id="ul" itemprop="hello world" itemtype="hello world">
|
||||
<li id="li" itemprop="hello world" itemtype="hello world">Unordered List Item</li>
|
||||
</ul>
|
||||
|
||||
<meta id="meta" itemprop="hello world" itemtype="hello world">Meta Tag</meta>
|
||||
|
||||
<table id="table" itemprop="hello world" itemtype="hello world">Table</table>
|
||||
|
||||
<div id="div" itemprop="hello world" itemtype="hello world">Hi</div>
|
||||
|
||||
<a id="anchor" itemprop="hello world" itemtype="hello world"></a>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
test(function() {
|
||||
// Test all elements
|
||||
var ids = ["body", "h1", "h2", "p", "input", "form", "li", "ul", "meta", "table", "div", "anchor"];
|
||||
for (let id of ids) {
|
||||
var elem = document.getElementById(id);
|
||||
assert_array_equals(elem.propertyNames().sort(), ["hello", "world"].sort(), "The method should return 'hello world' ");
|
||||
assert_array_equals(elem.itemtypes().sort(), ["hello", "world"].sort(), "The method should return 'hello world' ");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,48 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>Single ItemProperty and ItemType test</title>
|
||||
</head>
|
||||
|
||||
<body id="body" itemprop="Hello" itemtype="Hello">
|
||||
|
||||
<h1 id="h1" itemprop="Hello" itemtype="Hello">Header H1</h1>
|
||||
<h2 id="h2" itemprop="Hello" itemtype="Hello">Header H2</h2>
|
||||
|
||||
<p id="p" itemprop="Hello" itemtype="Hello">Paragraph</p>
|
||||
|
||||
<form id="form" itemprop="Hello" itemtype="Hello">
|
||||
<input id="input" itemprop="Hello" itemtype="Hello">Input Field in form</input>
|
||||
</form>
|
||||
|
||||
<ul id="ul" itemprop="Hello" itemtype="Hello">
|
||||
<li id="li" itemprop="Hello" itemtype="Hello">Unordered List Item</li>
|
||||
</ul>
|
||||
|
||||
<meta id="meta" itemprop="Hello" itemtype="Hello">Meta Tag</meta>
|
||||
|
||||
<table id="table" itemprop="Hello" itemtype="Hello">Table</table>
|
||||
|
||||
<div id="div" itemprop="Hello" itemtype="Hello">Hi</div>
|
||||
|
||||
<a id="anchor" itemprop="Hello" itemtype="Hello"></a>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
test(function() {
|
||||
// Test all elements
|
||||
var ids = ["body", "h1", "h2", "p", "input", "form", "li", "ul", "meta", "table", "div", "anchor"];
|
||||
for (let id of ids) {
|
||||
var elem = document.getElementById(id);
|
||||
assert_array_equals(elem.propertyNames(), ["Hello"], "The method should return 'Hello' ");
|
||||
assert_array_equals(elem.itemtypes(), ["Hello"], "The method should return 'Hello' ");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue