Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: third_party/WebKit/LayoutTests/fast/dom/dataset-svg.html

Issue 2231053003: Add dataset property to SVGElement interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/virtual/stable/webexposed/global-interface-listing-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/fast/dom/dataset-svg.html
diff --git a/third_party/WebKit/LayoutTests/fast/dom/dataset-svg.html b/third_party/WebKit/LayoutTests/fast/dom/dataset-svg.html
new file mode 100644
index 0000000000000000000000000000000000000000..4be98aa2519b24215a4db6d9bc10d898eded0a53
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/dom/dataset-svg.html
@@ -0,0 +1,272 @@
+<!DOCTYPE html>
+<script src="../../resources/testharness.js"></script>
pdr. 2016/08/24 18:42:15 This test copies fast/dom/script-tests/dataset.js.
ramya.v 2016/08/25 10:51:33 If we wrap this way, getting the below error at li
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<script>
+var svgNS = "http://www.w3.org/2000/svg";
+
+function getSVGCircle(c) {
+ c = document.createElementNS(svgNS,"circle");
+ c.setAttributeNS(null, "cx", 25);
+ c.setAttributeNS(null, "cy", 25);
+ c.setAttributeNS(null, "r", 20);
+ return c;
+}
+
+function testGet(attr, expected)
+{
+ var c = getSVGCircle(c);
+ c.setAttribute(attr, "value");
+ return c.dataset[expected] == "value";
+}
+
+test (function() {
+ assert_true(testGet('data-foo', 'foo'));
+ assert_true(testGet('data-foo-bar', 'fooBar'));
+ assert_true(testGet('data--', '-'));
+ assert_true(testGet('data--foo', 'Foo'));
+ assert_true(testGet('data---foo', '-Foo'));
+ assert_true(testGet('data---foo--bar', '-Foo-Bar'));
+ assert_true(testGet('data---foo---bar', '-Foo--Bar'));
+ assert_true(testGet('data-foo-', 'foo-'));
+ assert_true(testGet('data-foo--', 'foo--'));
+ assert_true(testGet('data-Foo', 'Foo'));
+ assert_true(testGet('data-', ''));
+ assert_true(testGet('data-\xE0', '\xE0'));
+ assert_true(testGet('data-1', '1'));
+ assert_true(testGet('data-01', '01'));
+ assert_true(testGet('data-zx81', 'zx81'));
+ assert_true(testGet('data-i4770k', 'i4770k'));
+ assert_true(testGet('data-r-7', 'r-7'));
+ assert_true(testGet('data-r-7-k', 'r-7K'));
+ assert_equals(document.body.dataset.nonExisting, undefined);
+},'This tests Get function');
+
+
+function testIsUndefined(attr, prop)
+{
+ var c = getSVGCircle(c);
+ c.setAttribute(attr, "value");
+ return c.dataset[prop] === undefined;
+}
+
+test (function() {
+ assert_true(testIsUndefined('data-022', '22'));
+ assert_true(testIsUndefined('data-22', '022'));
+},'Tests Undefined');
+
+
+function matchesNothingInDataset(attr)
+{
+ var c = getSVGCircle(c);
+ c.setAttribute(attr, "value");
+
+ var count = 0;
+ for (var item in c.dataset)
+ count++;
+ return count == 0;
+}
+
+test (function() {
+ assert_true(matchesNothingInDataset('dataFoo'));
+},'Tests matchesNothingInDataset');
+
+
+function testSet(prop, expected)
+{
+ var c = getSVGCircle(c);
+ c.dataset[prop] = "value";
+ return c.getAttribute(expected) == "value";
+}
+
+test (function() {
+ assert_true(testSet('foo', 'data-foo'));
+ assert_true(testSet('fooBar', 'data-foo-bar'));
+ assert_true(testSet('-', 'data--'));
+ assert_true(testSet('Foo', 'data--foo'));
+ assert_true(testSet('-Foo', 'data---foo'));
+ assert_true(testSet('', 'data-'));
+ assert_true(testSet('\xE0', 'data-\xE0'));
+ assert_true(testSet('32', 'data-32'));
+ assert_true(testSet('0032', 'data-0032'));
+ assert_true(testSet('i18n', 'data-i18n'));
+ assert_true(testSet('d2', 'data-d2'));
+ assert_true(testSet('2d', 'data-2d'));
+ assert_true(testSet('d-2', 'data-d-2'));
+ assert_true(testSet('A--S', 'data--a---s'));
+ assert_throws(null, function() { testSet('-foo', 'dummy'); }, '"SyntaxError: Failed to set the \'-foo\' property on \'DOMStringMap\': \'-foo\' is not a valid property name."');
+ assert_throws(null, function() { testSet('foo\x20', 'dummy'); }, '"InvalidCharacterError: Failed to set the \'foo\x20\' property on \'DOMStringMap\': \'data-foo\x20\' is not a valid attribute name."');
+ assert_throws(null, function() { testSet('foo\uF900', 'dummy'); }, '"InvalidCharacterError: Failed to set the \'foo\uF900\' property on \'DOMStringMap\': \'data-foo\uF900\' is not a valid attribute name."');
+},'Tests Set');
+
+
+function testIsNull(prop, attr)
+{
+ var c = getSVGCircle(c);
+ c.dataset[prop] = "value";
+ return c.getAttribute(attr) === null;
+}
+
+test (function() {
+ assert_true(testIsNull('0123', 'data-123'));
+ assert_true(testIsNull('123', 'data-0123'));
+},'Tests Is Null');
+
+
+function testDelete(attr, prop)
+{
+ var c = getSVGCircle(c);
+ c.setAttribute(attr, "value");
+ delete c.dataset[prop];
+ return c.getAttribute(attr) != "value";
+}
+
+test (function() {
+ assert_true(testDelete('data-foo', 'foo'));
+ assert_true(testDelete('data-foo-bar', 'fooBar'));
+ assert_true(testDelete('data--', '-'));
+ assert_true(testDelete('data--foo', 'Foo'));
+ assert_true(testDelete('data---foo', '-Foo'));
+ assert_true(testDelete('data-', ''));
+ assert_true(testDelete('data-\xE0', '\xE0'));
+ assert_true(testDelete('data-33', '33'));
+ assert_true(testDelete('data-00033', '00033'));
+ assert_true(testDelete('data-r2', 'r2'));
+ assert_true(testDelete('data-2r', '2r'));
+ assert_true(testDelete('data-r-2', 'r-2'));
+ assert_true(testDelete('data--r-2-', 'R-2-'));
+ assert_true(testDelete('data--r-2r', 'R-2r'));
+ assert_true(testDelete('data--r-2-----r', 'R-2----R'));
+ assert_false(testDelete('dummy', '-foo'));
+},'Tests Delete');
+
+
+
+// The SVGElement.dataset deleter is only applied to properties
+// that are present; check that any underlying native property
+// is deleted instead.
+function testNativeDelete(prop, isConfigurable)
+{
+ var c = getSVGCircle(c);
+ Object.defineProperty(c.dataset, prop, {configurable: isConfigurable, value: "native_value"});
+ delete c.dataset[prop];
+ return isConfigurable ? !(prop in c.dataset) : (c.dataset[prop] === "native_value");
+}
+
+test (function() {
+ // TODO(jochen): Reenable this once it behaves correctly
+ //assert_true(testNativeDelete('-r-2-', false));
+ assert_true(testNativeDelete('foo', true));
+},'Tests Native Delete');
+
+
+function testForIn(array)
+{
+ var c = getSVGCircle(c);
+ for (var i = 0; i < array.length; ++i) {
+ c.setAttribute(array[i], "value");
+ }
+
+ var count = 0;
+ for (var item in c.dataset)
+ count++;
+
+ return count;
+}
+
+test (function() {
+ assert_equals(testForIn(['data-foo', 'data-bar', 'data-baz']), 3);
+ assert_equals(testForIn(['data-foo', 'data-bar', 'dataFoo']), 2);
+ assert_equals(testForIn(['data-foo', 'data-bar', 'style']), 2);
+ assert_equals(testForIn(['data-foo', 'data-bar', 'data-']), 3);
+ assert_equals(testForIn(['data-foo', 'data-bar', 'data-43']), 3);
+ assert_equals(testForIn(['data-foo', 'data-oric1', 'data-bar']), 3);
+ assert_equals(testForIn(['data-foo', 'data-oric-1', 'data-bar']), 3);
+ assert_equals(testForIn(['data-foo', 'data-oric-1x', 'data-bar']), 3);
+},'Tests For In');
+
+test (function() {
+ var c = getSVGCircle(c);
+
+ // If the Object prototype already has "foo", dataset doesnot create the corresponding attribute for foo
+ Object.prototype.foo = 'on Object';
+ assert_equals(c.dataset.foo, 'on Object');
+ c.dataset['foo'] = 'on dataset';
+ assert_equals(c.dataset.foo, 'on dataset');
+ assert_true(c.hasAttribute('data-foo'));
+ c.setAttribute('data-foo', 'attr');
+ assert_equals(c.dataset.foo, 'attr');
+
+ // Update the JavaScript property
+ c.dataset.foo = 'updated';
+ assert_equals(c.dataset.foo, 'updated');
+ assert_equals(c.getAttribute('data-foo'), 'updated');
+
+ // "Bar" can't be represented as a data- attribute.
+ c.dataset.Bar = 'on dataset';
+ assert_equals(c.dataset.Bar, 'on dataset');
+ assert_false(c.hasAttribute('data-Bar'));
+
+ // Make the JavaScript property empty
+ c.dataset.foo = '';
+ assert_equals(c.dataset.foo, '');
+ assert_equals(c.getAttribute('data-foo'), '');
+
+ // Remove the attribute
+ c.removeAttribute('data-foo');
+ assert_equals(c.dataset.foo, 'on Object');
+
+ // Remove the JavaScript property
+ c.setAttribute('data-foo', 'attr');
+ delete c.dataset.foo;
+ assert_equals(c.dataset.foo, 'on Object');
+ assert_false(c.hasAttribute('foo'));
+ delete c.dataset.Bar;
+ assert_equals(c.dataset.Bar, undefined);
+ Object.prototype[11] = 'on Object';
+ assert_equals(c.dataset[11], 'on Object');
+ c.dataset['11'] = 'on dataset';
+ assert_equals(c.dataset[11], 'on dataset');
+ assert_true(c.hasAttribute('data-11'));
+ c.setAttribute('data-11', 'attr');
+ assert_equals(c.dataset[11], 'attr');
+
+ // Update the JavaScript property
+ c.dataset[11] = 'updated';
+ assert_equals(c.dataset[11], 'updated');
+ assert_equals(c.getAttribute('data-11'), 'updated');
+
+ Object.prototype['a500'] = 'on Object';
+ assert_equals(c.dataset['a500'], 'on Object');
+ c.dataset['a500'] = 'on dataset';
+ assert_equals(c.dataset['a500'], 'on dataset');
+ assert_true(c.hasAttribute('data-a500'));
+ c.setAttribute('data-a500', 'attr');
+ assert_equals(c.dataset['a500'], 'attr');
+
+ // Update the JavaScript property
+ c.dataset['a500'] = 'updated';
+ assert_equals(c.dataset['a500'], 'updated');
+ assert_equals(c.getAttribute('data-a500'), 'updated');
+ Object.prototype['a-500k'] = 'on Object';
+ assert_equals(c.dataset['a-500k'], 'on Object');
+ c.dataset['a-500k'] = 'on dataset';
+ assert_equals(c.dataset['a-500k'], 'on dataset');
+ assert_true(c.hasAttribute('data-a-500k'));
+ c.setAttribute('data-a-500k', 'attr');
+ assert_equals(c.dataset['a-500k'], 'attr');
+
+ // Update the JavaScript property
+ c.dataset['a-500k'] = 'updated';
+ assert_equals(c.dataset['a-500k'], 'updated');
+ assert_equals(c.getAttribute('data-a-500k'), 'updated');
+
+},'');
+
+test (function() {
+ var c = getSVGCircle(c);
+ c.dataset.foo = null;
+ assert_equals(c.dataset.foo, 'null');
+},'Set null');
+</script>
+</body>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/virtual/stable/webexposed/global-interface-listing-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698