Bug 1497821 [wpt PR 13450] - [css-properties-values-api] Proper types from StylePropertyMap iterator., a=testonly
authorAnders Hartvoll Ruud <andruud@chromium.org>
Thu, 11 Oct 2018 10:03:55 +0000
changeset 499515 40e4e38aceb9741999de7b9728339fa47eef82f2
parent 499514 696aabb8f7015b1441e0fc03ed3ab8a7aff66216
child 499516 620367d865abe05f5fee4c1c8f96b5d563fe51c0
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1497821, 13450, 641877, 1264540, 598247
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1497821 [wpt PR 13450] - [css-properties-values-api] Proper types from StylePropertyMap iterator., a=testonly Automatic update from web-platform-tests[css-properties-values-api] Proper types from StylePropertyMap iterator. When iterating a StylePropertyMap, any registered custom properties in that map must have the appropriate type according to the registration. Currently all custom properties are always CSSUnparsedValue, which is only correct for unregistered properties and properties registered as "*". Fixed by parsing the value on its way out, similar to how get/getAll implements the same behavior. R=chrishtr@chromium.org Bug: 641877 Change-Id: I5e0b2d064cd0ce4827eabf464a5cf0a0e138c5db Reviewed-on: https://chromium-review.googlesource.com/c/1264540 Commit-Queue: Anders Ruud <andruud@chromium.org> Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Cr-Commit-Position: refs/heads/master@{#598247} -- wpt-commits: 280f7802e54b7c439bf0fe0cf8c2fe8838f6ed4f wpt-pr: 13450
testing/web-platform/tests/css/css-paint-api/registered-property-type.https.html
testing/web-platform/tests/css/css-properties-values-api/typedom.tentative.html
--- a/testing/web-platform/tests/css/css-paint-api/registered-property-type.https.html
+++ b/testing/web-platform/tests/css/css-paint-api/registered-property-type.https.html
@@ -22,26 +22,52 @@
   // - props: Test data.
 
   registerPaint('geometry', class {
     static get inputProperties() { return props.map(p => p.name); }
 
     paint(ctx, geom, styleMap) {
       ctx.strokeStyle = 'green';
       for (let prop of props) {
-        let first = styleMap.get(prop.name);
-        let all = styleMap.getAll(prop.name);
+        // Read values using get, getAll and iterator:
+        let valueFromGet = styleMap.get(prop.name);
+        let valueFromGetAll = styleMap.getAll(prop.name);
+        let valueFromIterator = Array.from(styleMap).filter(e => e[0] == prop.name)[0][1];
+
+        // Serialize 'actual'-values for all three cases:
         let serialize = v => v.constructor.name + '=' + v.toString()
-        let actual = all.map(serialize).join(',');
-        let expected = prop.expected.join(',');
-        let pass = actual === expected
-            && serialize(first) === prop.expected[0];
+        let actualFromGet = serialize(valueFromGet);
+        let actualFromGetAll = valueFromGetAll.map(serialize).join(',');
+        let actualFromIterator = valueFromIterator.map(serialize).join(',');
+
+        // Create 'expected'-values for all three cases:
+        let expectedForGet = prop.expected[0];
+        let expectedForGetAll = prop.expected.join(',');
+        let expectedForIterator = expectedForGetAll;
+
+        let pass = true;
+
+        // Assertions:
+        if (actualFromGet !== expectedForGet) {
+          debugLog(`FAIL: StylePropertyMap.get: actual: ${actualFromGet}  expected: ${expectedForGet}`);
+          pass = false;
+        }
+        if (actualFromGetAll !== expectedForGetAll) {
+          debugLog(`FAIL: StylePropertyMap.getAll: actual: ${actualFromGetAll}  expected: ${expectedForGetAll}`);
+          pass = false;
+        }
+        if (actualFromIterator !== expectedForIterator) {
+          debugLog(`FAIL: StylePropertyMap iterator: actual: ${actualFromIterator}  expected: ${expectedForIterator}`);
+          pass = false;
+        }
+
         if (!pass)
           ctx.strokeStyle = 'red';
-        debugLog(pass ? 'PASS' : 'FAIL', prop.syntax, actual, expected);
+        else
+          debugLog('PASS', prop.syntax, actualFromGetAll, expectedForGetAll);
       }
       ctx.lineWidth = 4;
       ctx.strokeRect(0, 0, geom.width, geom.height);
     }
   });
 </script>
 <script>
     // A copy of this array (automatically enriched with 'name' and 'expected')
--- a/testing/web-platform/tests/css/css-properties-values-api/typedom.tentative.html
+++ b/testing/web-platform/tests/css/css-properties-values-api/typedom.tentative.html
@@ -28,16 +28,23 @@ function gen_prop(syntax, initialValue) 
         name: name,
         syntax: syntax,
         initialValue: initialValue,
         inherits: false
     });
     return name;
 }
 
+// Cleans style rules used for testing between every test.
+add_result_callback(function(){
+    target.attributeStyleMap.clear();
+    // Clears 'div' rule in #style:
+    style.sheet.rules[0].styleMap.clear();
+});
+
 // On the target element, verify that computed value of 'name' is an instance
 // of 'expected' and not an instance of CSSUnparsedValue.
 //
 // If 'value' is non-null, that value is first set on the attributeStyleMap
 // of the target.
 function assert_computed_type(name, value, expected) {
     if (expected == CSSUnparsedValue) {
         throw 'CSSUnparsedValue may not be used as expected type';
@@ -597,9 +604,121 @@ test(function(){
 // StylePropertyMapReadOnly iteration
 
 test(function(){
     let name = gen_prop('<length>', '10px');
     let result = Array.from(target.computedStyleMap()).filter(e => e[0] == name)[0];
     assert_true(typeof(result) !== 'undefined');
 }, 'Registered property with initial value show up on iteration of computedStyleMap');
 
+// Verifies that iterating a StylePropertyMap[ReadOnly] yields correctly
+// typed objects for a given syntax/value.
+function test_iteration_type_for_property_map(propertyMapName, propertyMap, options) {
+    test(function(){
+        let name = gen_prop(options.syntax, options.initialValue);
+        if (propertyMap instanceof StylePropertyMap) {
+            // Only set the value if the propertyMap is mutable.
+            propertyMap.set(name, options.value);
+        }
+        let result = Array.from(propertyMap).filter(e => e[0] == name)[0];
+        let value = result[1];
+        assert_true(options.expect(value));
+    }, `Iteration on ${propertyMapName} produces correct type for ${options.syntax}`);
+}
+
+function test_iteration_type(options) {
+    test_iteration_type_for_property_map('computedStyleMap', target.computedStyleMap(), options);
+    test_iteration_type_for_property_map('attributeStyleMap', target.attributeStyleMap, options);
+    test_iteration_type_for_property_map('styleMap', style.sheet.rules[0].styleMap, options);
+}
+
+test_iteration_type({
+    syntax: '*',
+    initialValue: 'none',
+    value: 'thing',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnparsedValue,
+});
+
+test_iteration_type({
+    syntax: '<angle>',
+    initialValue: '0deg',
+    value: '42deg',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnitValue,
+});
+
+test_iteration_type({
+    syntax: '<custom-ident>',
+    initialValue: 'none',
+    value: 'thing',
+    expect: v => v.length == 1 && v[0] instanceof CSSKeywordValue,
+});
+
+test_iteration_type({
+    syntax: '<image>',
+    initialValue: 'url(a)',
+    value: 'url(b)',
+    expect: v => v.length == 1 && v[0] instanceof CSSImageValue,
+});
+
+test_iteration_type({
+    syntax: '<integer>',
+    initialValue: '0',
+    value: '100',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnitValue,
+});
+
+test_iteration_type({
+    syntax: '<length>',
+    initialValue: '0px',
+    value: '10px',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnitValue,
+});
+
+test_iteration_type({
+    syntax: '<number>',
+    initialValue: '0',
+    value: '42',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnitValue,
+});
+
+test_iteration_type({
+    syntax: '<percentage>',
+    initialValue: '0%',
+    value: '10%',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnitValue,
+});
+
+test_iteration_type({
+    syntax: '<resolution>',
+    initialValue: '0dpi',
+    value: '300dpi',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnitValue,
+});
+
+test_iteration_type({
+    syntax: '<time>',
+    initialValue: '0s',
+    value: '10s',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnitValue,
+});
+
+test_iteration_type({
+    syntax: '<url>',
+    initialValue: 'url(a)',
+    value: 'url(b)',
+    expect: v => v.length == 1 && v[0].constructor === CSSStyleValue,
+});
+
+test_iteration_type({
+    syntax: 'none | thing | THING',
+    initialValue: 'none',
+    value: 'THING',
+    expect: v => v.length == 1 && v[0] instanceof CSSKeywordValue,
+});
+
+test_iteration_type({
+    syntax: '<angle> | <length>',
+    initialValue: '0deg',
+    value: '10px',
+    expect: v => v.length == 1 && v[0] instanceof CSSUnitValue,
+});
+
 </script>