Include applicable state information alongside all the other other property information

This makes it easier to consume the data in the frontend.

Bug: 1325812
Change-Id: I37979a7266af728399a9c4938bf97f77e5781b5b
Signed-off-by: Victor Porof <victorporof@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3702682
Reviewed-by: Mathias Bynens <mathias@chromium.org>
diff --git a/scripts/webidl-properties/tests.js b/scripts/webidl-properties/tests.js
index 7301840..1d686f6 100644
--- a/scripts/webidl-properties/tests.js
+++ b/scripts/webidl-properties/tests.js
@@ -39,7 +39,7 @@
       global: true,
       specs: ['html'],
     });
-    assert.strictEqual(type.states, undefined);
+    assert.strictEqual(type.rules, undefined);
   });
 
   it('generates valid data for HTMLInputElement', () => {
@@ -49,12 +49,34 @@
     assert.deepEqual(type.props.checked, {
       global: false,
       specs: ['html'],
+      rules: [{when: 'type', is: 'checkbox'}, {when: 'type', is: 'radio'}],
     });
-    assert.deepEqual(type.states['[type=checkbox]'], {
-      checked: {global: false, specs: ['html']},
-      required: {global: false, specs: ['html']},
-      value: {global: false, specs: ['html']},
+    assert.deepEqual(type.props.required, {
+      global: false,
+      specs: ['html'],
+      rules: [
+        {when: 'type', is: 'text'}, {when: 'type', is: 'search'}, {when: 'type', is: 'url'}, {when: 'type', is: 'tel'},
+        {when: 'type', is: 'email'}, {when: 'type', is: 'password'}, {when: 'type', is: 'date'},
+        {when: 'type', is: 'month'}, {when: 'type', is: 'week'}, {when: 'type', is: 'time'},
+        {when: 'type', is: 'datetime-local'}, {when: 'type', is: 'number'}, {when: 'type', is: 'checkbox'},
+        {when: 'type', is: 'radio'}, {when: 'type', is: 'file'}
+      ]
     });
+    assert.deepEqual(type.props.value, {
+      global: false,
+      specs: ['html'],
+      rules: type.rules,
+    });
+    assert.deepEqual(type.rules, [
+      {when: 'type', is: 'hidden'},   {when: 'type', is: 'text'},  {when: 'type', is: 'search'},
+      {when: 'type', is: 'url'},      {when: 'type', is: 'tel'},   {when: 'type', is: 'email'},
+      {when: 'type', is: 'password'}, {when: 'type', is: 'date'},  {when: 'type', is: 'month'},
+      {when: 'type', is: 'week'},     {when: 'type', is: 'time'},  {when: 'type', is: 'datetime-local'},
+      {when: 'type', is: 'number'},   {when: 'type', is: 'range'}, {when: 'type', is: 'color'},
+      {when: 'type', is: 'checkbox'}, {when: 'type', is: 'radio'}, {when: 'type', is: 'file'},
+      {when: 'type', is: 'submit'},   {when: 'type', is: 'image'}, {when: 'type', is: 'reset'},
+      {when: 'type', is: 'button'},
+    ]);
   });
 
   it('generates valid data for MouseEvent', () => {
@@ -65,7 +87,7 @@
       global: false,
       specs: ['uievents'],
     });
-    assert.strictEqual(type.states, undefined);
+    assert.strictEqual(type.rules, undefined);
   });
 
   it('generates valid data for PointerEvent', () => {
@@ -76,7 +98,7 @@
       global: false,
       specs: ['pointerevents'],
     });
-    assert.strictEqual(type.states, undefined);
+    assert.strictEqual(type.rules, undefined);
   });
 
   it('generates an entry for DOMParser', () => {
@@ -84,7 +106,7 @@
     assert.strictEqual(type.inheritance, null);
     assert.deepEqual(type.includes, []);
     assert.deepEqual(type.props, {});
-    assert.strictEqual(type.states, undefined);
+    assert.strictEqual(type.rules, undefined);
   });
 
   it('minimizes the data for HTMLInputElement', () => {
@@ -92,12 +114,34 @@
     const type = minimized.HTMLInputElement;
     assert.strictEqual(type.inheritance, 'HTMLElement');
     assert.strictEqual(type.includes, undefined);
-    assert.deepEqual(type.props.checked, {});
-    assert.deepEqual(type.states['[type=checkbox]'], {
-      checked: {},
-      required: {},
-      value: {},
+    assert.deepEqual(type.props.checked, {
+      rules: [
+        {when: 'type', is: 'checkbox'},
+        {when: 'type', is: 'radio'},
+      ],
     });
+    assert.deepEqual(type.props.required, {
+      rules: [
+        {when: 'type', is: 'text'}, {when: 'type', is: 'search'}, {when: 'type', is: 'url'}, {when: 'type', is: 'tel'},
+        {when: 'type', is: 'email'}, {when: 'type', is: 'password'}, {when: 'type', is: 'date'},
+        {when: 'type', is: 'month'}, {when: 'type', is: 'week'}, {when: 'type', is: 'time'},
+        {when: 'type', is: 'datetime-local'}, {when: 'type', is: 'number'}, {when: 'type', is: 'checkbox'},
+        {when: 'type', is: 'radio'}, {when: 'type', is: 'file'}
+      ],
+    });
+    assert.deepEqual(type.props.value, {
+      rules: type.rules,
+    });
+    assert.deepEqual(type.rules, [
+      {when: 'type', is: 'hidden'},   {when: 'type', is: 'text'},  {when: 'type', is: 'search'},
+      {when: 'type', is: 'url'},      {when: 'type', is: 'tel'},   {when: 'type', is: 'email'},
+      {when: 'type', is: 'password'}, {when: 'type', is: 'date'},  {when: 'type', is: 'month'},
+      {when: 'type', is: 'week'},     {when: 'type', is: 'time'},  {when: 'type', is: 'datetime-local'},
+      {when: 'type', is: 'number'},   {when: 'type', is: 'range'}, {when: 'type', is: 'color'},
+      {when: 'type', is: 'checkbox'}, {when: 'type', is: 'radio'}, {when: 'type', is: 'file'},
+      {when: 'type', is: 'submit'},   {when: 'type', is: 'image'}, {when: 'type', is: 'reset'},
+      {when: 'type', is: 'button'},
+    ]);
   });
 
   it('minimizes the data for PointerEvent', () => {
@@ -108,7 +152,7 @@
     assert.deepEqual(type.props.pressure, {
       specs: 8,
     });
-    assert.strictEqual(type.states, undefined);
+    assert.strictEqual(type.rules, undefined);
   });
 
   it('removes the entry for DOMParser in the minimized output', () => {