Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // eslint-disable-next-line rulesdir/es_modules_import |
| 6 | import idl from '@webref/idl'; |
| 7 | import * as assert from 'assert'; |
| 8 | |
| 9 | import {SPECS} from './config.js'; |
| 10 | import {addMetadata, getIDLProps, minimize} from './get-props.js'; |
| 11 | import {getMissingTypes} from './util.js'; |
| 12 | |
| 13 | describe('DOM pinned properties dataset generation', function() { |
| 14 | let output; |
| 15 | |
| 16 | this.beforeEach(async () => { |
| 17 | const files = await idl.listAll(); |
| 18 | const names = Object.keys(SPECS); |
| 19 | const specs = await Promise.all(names.map(name => files[name].parse().then(idls => ({name, idls})))); |
| 20 | output = addMetadata(getIDLProps(specs)); |
| 21 | }); |
| 22 | |
| 23 | it('doesn\'t have missing types', () => { |
| 24 | const missing = getMissingTypes(output); |
| 25 | assert.strictEqual(missing.length, 0); |
| 26 | }); |
| 27 | |
| 28 | it('generates valid data for HTMLElement', () => { |
| 29 | const type = output.HTMLElement; |
| 30 | assert.strictEqual(type.inheritance, 'Element'); |
| 31 | assert.deepEqual(type.includes, [ |
| 32 | 'GlobalEventHandlers', |
| 33 | 'DocumentAndElementEventHandlers', |
| 34 | 'ElementContentEditable', |
| 35 | 'HTMLOrSVGElement', |
| 36 | 'ElementCSSInlineStyle', |
| 37 | ]); |
| 38 | assert.deepEqual(type.props.title, { |
| 39 | global: true, |
| 40 | specs: ['html'], |
| 41 | }); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 42 | assert.strictEqual(type.rules, undefined); |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 43 | }); |
| 44 | |
| 45 | it('generates valid data for HTMLInputElement', () => { |
| 46 | const type = output.HTMLInputElement; |
| 47 | assert.strictEqual(type.inheritance, 'HTMLElement'); |
| 48 | assert.deepEqual(type.includes, []); |
| 49 | assert.deepEqual(type.props.checked, { |
| 50 | global: false, |
| 51 | specs: ['html'], |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 52 | rules: [{when: 'type', is: 'checkbox'}, {when: 'type', is: 'radio'}], |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 53 | }); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 54 | assert.deepEqual(type.props.required, { |
| 55 | global: false, |
| 56 | specs: ['html'], |
| 57 | rules: [ |
| 58 | {when: 'type', is: 'text'}, {when: 'type', is: 'search'}, {when: 'type', is: 'url'}, {when: 'type', is: 'tel'}, |
| 59 | {when: 'type', is: 'email'}, {when: 'type', is: 'password'}, {when: 'type', is: 'date'}, |
| 60 | {when: 'type', is: 'month'}, {when: 'type', is: 'week'}, {when: 'type', is: 'time'}, |
| 61 | {when: 'type', is: 'datetime-local'}, {when: 'type', is: 'number'}, {when: 'type', is: 'checkbox'}, |
| 62 | {when: 'type', is: 'radio'}, {when: 'type', is: 'file'} |
| 63 | ] |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 64 | }); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 65 | assert.deepEqual(type.props.value, { |
| 66 | global: false, |
| 67 | specs: ['html'], |
| 68 | rules: type.rules, |
| 69 | }); |
| 70 | assert.deepEqual(type.rules, [ |
| 71 | {when: 'type', is: 'hidden'}, {when: 'type', is: 'text'}, {when: 'type', is: 'search'}, |
| 72 | {when: 'type', is: 'url'}, {when: 'type', is: 'tel'}, {when: 'type', is: 'email'}, |
| 73 | {when: 'type', is: 'password'}, {when: 'type', is: 'date'}, {when: 'type', is: 'month'}, |
| 74 | {when: 'type', is: 'week'}, {when: 'type', is: 'time'}, {when: 'type', is: 'datetime-local'}, |
| 75 | {when: 'type', is: 'number'}, {when: 'type', is: 'range'}, {when: 'type', is: 'color'}, |
| 76 | {when: 'type', is: 'checkbox'}, {when: 'type', is: 'radio'}, {when: 'type', is: 'file'}, |
| 77 | {when: 'type', is: 'submit'}, {when: 'type', is: 'image'}, {when: 'type', is: 'reset'}, |
| 78 | {when: 'type', is: 'button'}, |
| 79 | ]); |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 80 | }); |
| 81 | |
| 82 | it('generates valid data for MouseEvent', () => { |
| 83 | const type = output.MouseEvent; |
| 84 | assert.strictEqual(type.inheritance, 'UIEvent'); |
| 85 | assert.deepEqual(type.includes, []); |
| 86 | assert.deepEqual(type.props.screenX, { |
| 87 | global: false, |
| 88 | specs: ['uievents'], |
| 89 | }); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 90 | assert.strictEqual(type.rules, undefined); |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 91 | }); |
| 92 | |
| 93 | it('generates valid data for PointerEvent', () => { |
| 94 | const type = output.PointerEvent; |
| 95 | assert.strictEqual(type.inheritance, 'MouseEvent'); |
| 96 | assert.deepEqual(type.includes, []); |
| 97 | assert.deepEqual(type.props.pressure, { |
| 98 | global: false, |
| 99 | specs: ['pointerevents'], |
| 100 | }); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 101 | assert.strictEqual(type.rules, undefined); |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 102 | }); |
| 103 | |
| 104 | it('generates an entry for DOMParser', () => { |
| 105 | const type = output.DOMParser; |
| 106 | assert.strictEqual(type.inheritance, null); |
| 107 | assert.deepEqual(type.includes, []); |
| 108 | assert.deepEqual(type.props, {}); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 109 | assert.strictEqual(type.rules, undefined); |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 110 | }); |
| 111 | |
| 112 | it('minimizes the data for HTMLInputElement', () => { |
| 113 | const minimized = minimize(output); |
| 114 | const type = minimized.HTMLInputElement; |
| 115 | assert.strictEqual(type.inheritance, 'HTMLElement'); |
| 116 | assert.strictEqual(type.includes, undefined); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 117 | assert.deepEqual(type.props.checked, { |
| 118 | rules: [ |
| 119 | {when: 'type', is: 'checkbox'}, |
| 120 | {when: 'type', is: 'radio'}, |
| 121 | ], |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 122 | }); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 123 | assert.deepEqual(type.props.required, { |
| 124 | rules: [ |
| 125 | {when: 'type', is: 'text'}, {when: 'type', is: 'search'}, {when: 'type', is: 'url'}, {when: 'type', is: 'tel'}, |
| 126 | {when: 'type', is: 'email'}, {when: 'type', is: 'password'}, {when: 'type', is: 'date'}, |
| 127 | {when: 'type', is: 'month'}, {when: 'type', is: 'week'}, {when: 'type', is: 'time'}, |
| 128 | {when: 'type', is: 'datetime-local'}, {when: 'type', is: 'number'}, {when: 'type', is: 'checkbox'}, |
| 129 | {when: 'type', is: 'radio'}, {when: 'type', is: 'file'} |
| 130 | ], |
| 131 | }); |
| 132 | assert.deepEqual(type.props.value, { |
| 133 | rules: type.rules, |
| 134 | }); |
| 135 | assert.deepEqual(type.rules, [ |
| 136 | {when: 'type', is: 'hidden'}, {when: 'type', is: 'text'}, {when: 'type', is: 'search'}, |
| 137 | {when: 'type', is: 'url'}, {when: 'type', is: 'tel'}, {when: 'type', is: 'email'}, |
| 138 | {when: 'type', is: 'password'}, {when: 'type', is: 'date'}, {when: 'type', is: 'month'}, |
| 139 | {when: 'type', is: 'week'}, {when: 'type', is: 'time'}, {when: 'type', is: 'datetime-local'}, |
| 140 | {when: 'type', is: 'number'}, {when: 'type', is: 'range'}, {when: 'type', is: 'color'}, |
| 141 | {when: 'type', is: 'checkbox'}, {when: 'type', is: 'radio'}, {when: 'type', is: 'file'}, |
| 142 | {when: 'type', is: 'submit'}, {when: 'type', is: 'image'}, {when: 'type', is: 'reset'}, |
| 143 | {when: 'type', is: 'button'}, |
| 144 | ]); |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 145 | }); |
| 146 | |
| 147 | it('minimizes the data for PointerEvent', () => { |
| 148 | const minimized = minimize(output); |
| 149 | const type = minimized.PointerEvent; |
| 150 | assert.strictEqual(type.inheritance, 'MouseEvent'); |
| 151 | assert.strictEqual(type.includes, undefined); |
| 152 | assert.deepEqual(type.props.pressure, { |
| 153 | specs: 8, |
| 154 | }); |
Victor Porof | 7e0446e | 2022-06-15 12:03:33 +0000 | [diff] [blame] | 155 | assert.strictEqual(type.rules, undefined); |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 156 | }); |
| 157 | |
| 158 | it('removes the entry for DOMParser in the minimized output', () => { |
| 159 | const minimized = minimize(output); |
| 160 | assert.strictEqual(minimized.DOMParser, undefined); |
| 161 | }); |
| 162 | }); |