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 | }); |
| 42 | assert.strictEqual(type.states, undefined); |
| 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'], |
| 52 | }); |
| 53 | assert.deepEqual(type.states['[type=checkbox]'], { |
| 54 | checked: {global: false, specs: ['html']}, |
| 55 | required: {global: false, specs: ['html']}, |
| 56 | value: {global: false, specs: ['html']}, |
| 57 | }); |
| 58 | }); |
| 59 | |
| 60 | it('generates valid data for MouseEvent', () => { |
| 61 | const type = output.MouseEvent; |
| 62 | assert.strictEqual(type.inheritance, 'UIEvent'); |
| 63 | assert.deepEqual(type.includes, []); |
| 64 | assert.deepEqual(type.props.screenX, { |
| 65 | global: false, |
| 66 | specs: ['uievents'], |
| 67 | }); |
| 68 | assert.strictEqual(type.states, undefined); |
| 69 | }); |
| 70 | |
| 71 | it('generates valid data for PointerEvent', () => { |
| 72 | const type = output.PointerEvent; |
| 73 | assert.strictEqual(type.inheritance, 'MouseEvent'); |
| 74 | assert.deepEqual(type.includes, []); |
| 75 | assert.deepEqual(type.props.pressure, { |
| 76 | global: false, |
| 77 | specs: ['pointerevents'], |
| 78 | }); |
| 79 | assert.strictEqual(type.states, undefined); |
| 80 | }); |
| 81 | |
| 82 | it('generates an entry for DOMParser', () => { |
| 83 | const type = output.DOMParser; |
| 84 | assert.strictEqual(type.inheritance, null); |
| 85 | assert.deepEqual(type.includes, []); |
| 86 | assert.deepEqual(type.props, {}); |
| 87 | assert.strictEqual(type.states, undefined); |
| 88 | }); |
| 89 | |
| 90 | it('minimizes the data for HTMLInputElement', () => { |
| 91 | const minimized = minimize(output); |
| 92 | const type = minimized.HTMLInputElement; |
| 93 | assert.strictEqual(type.inheritance, 'HTMLElement'); |
| 94 | assert.strictEqual(type.includes, undefined); |
| 95 | assert.deepEqual(type.props.checked, {}); |
| 96 | assert.deepEqual(type.states['[type=checkbox]'], { |
| 97 | checked: {}, |
| 98 | required: {}, |
| 99 | value: {}, |
| 100 | }); |
| 101 | }); |
| 102 | |
| 103 | it('minimizes the data for PointerEvent', () => { |
| 104 | const minimized = minimize(output); |
| 105 | const type = minimized.PointerEvent; |
| 106 | assert.strictEqual(type.inheritance, 'MouseEvent'); |
| 107 | assert.strictEqual(type.includes, undefined); |
| 108 | assert.deepEqual(type.props.pressure, { |
| 109 | specs: 8, |
| 110 | }); |
| 111 | assert.strictEqual(type.states, undefined); |
| 112 | }); |
| 113 | |
| 114 | it('removes the entry for DOMParser in the minimized output', () => { |
| 115 | const minimized = minimize(output); |
| 116 | assert.strictEqual(minimized.DOMParser, undefined); |
| 117 | }); |
| 118 | }); |