Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f906014
commit 310071d
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
r: 2 | ||
spec: "http://www.w3.org/TR/html5/elements.html#embedding-custom-non-visible-data-with-the-data-attributes" | ||
sources: ["http://www.w3c-test.org/html/tests/approved/dataset/dataset-get.html"] | ||
title: "Custom Data Attributes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
test("Dataset", function() { | ||
assert( !!document.createElement("div").dataset, "Dataset supported" ); | ||
}); | ||
|
||
test("Dataset Implementation", function() { | ||
var DOMStringMap = window.DOMStringMap, | ||
fixture = document.createElement("div"), | ||
instance, length; | ||
|
||
// Avoid exceptions in Android #278 | ||
if ( !fixture.dataset ) { | ||
instance = false; | ||
length = 0; | ||
} else { | ||
fixture.dataset.beta = "b"; | ||
instance = (fixture.dataset instanceof DOMStringMap); | ||
length = Object.keys(fixture.dataset).length; | ||
} | ||
|
||
assert( instance, "fixture.dataset property is DOMStringMap" ); | ||
assert( length === 1, "fixture.dataset.length expects 1" ); | ||
}); | ||
|
||
test("Dataset Interop with Attributes", function() { | ||
var fixture = document.createElement("div"), | ||
attr, value; | ||
|
||
// Avoid exceptions in Android #278 | ||
if ( !fixture.dataset ) { | ||
attr = ""; | ||
value = ""; | ||
} else { | ||
fixture.setAttribute( "data-alpha", "a" ); | ||
fixture.dataset.beta = "b"; | ||
|
||
attr = fixture.getAttribute("data-beta"); | ||
value = fixture.dataset.alpha; | ||
} | ||
|
||
assert( attr === "b", "fixture.getAttribute('data-beta') === 'b' (set with dataset)" ); | ||
assert( value === "a", "fixture.dataset.alpha === 'a' (set with setAttribute)" ); | ||
}); | ||
|
||
test("Dataset Get*", function() { | ||
var fixture = document.createElement("div"); | ||
|
||
// Avoid exceptions in Android #278 | ||
if ( !fixture.dataset ) { | ||
assert( false, "Dataset not supported, not running get* tests" ); | ||
} else { | ||
fixture.setAttribute( "data-alpha", "a" ); | ||
fixture.dataset.beta = "b"; | ||
|
||
assert( fixture.getAttribute("data-beta") === "b", "compatible get with getAttribute" ); | ||
assert( fixture.dataset.alpha === "a", "compatible set with setAttribute" ); | ||
|
||
[ | ||
[ "data-foo", "foo" ], | ||
[ "data-foo-bar", "fooBar" ], | ||
[ "data--", "-" ], | ||
[ "data--foo", "Foo" ], | ||
[ "data---foo", "-Foo" ], | ||
[ "data-Foo", "foo" ], | ||
[ "data-", "" ], | ||
[ "data-\xE0", "\xE0" ] | ||
].forEach(function( array, index ) { | ||
|
||
var fixture = document.createElement("div"), | ||
value = index + ""; | ||
|
||
fixture.setAttribute( array[0], index + "" ); | ||
|
||
assert( fixture.dataset[ array[1] ] === value, "Expected: " + array.join(" = ") ); | ||
}); | ||
} | ||
}); | ||
|
||
test("Dataset Enumerable", function() { | ||
var fixture = document.createElement("div"), | ||
actuals = [ "hello", "helloWorld", "ohHai" ], | ||
length = actuals.length, | ||
prop; | ||
|
||
// Avoid exceptions in Android #278 | ||
if ( !fixture.dataset ) { | ||
assert( false, "Dataset not supported, not running Enumerable tests" ); | ||
} else { | ||
fixture.setAttribute( "data-hello", 1 ); | ||
fixture.setAttribute( "data-hello-world", 2 ); | ||
fixture.setAttribute( "data-oh-hai", 2 ); | ||
|
||
// This fails b/c Object.propertyIsEnumerable returns false... | ||
// turns out these properties don't have property descriptors | ||
// assert( Object.propertyIsEnumerable(fixture.dataset.ohHai) ); | ||
for ( prop in fixture.dataset ) { | ||
actuals.splice( actuals.indexOf( prop ), 1 ); | ||
length--; | ||
assert( actuals.length === length, prop ); | ||
} | ||
|
||
assert( !actuals.length, "Expecting length === 0" ); | ||
} | ||
}); |