fix(Page.select): synthesized events should bubble

This patch fixes `Page.select` to synthesize bubbling events.
This commit is contained in:
Christian Davis 2017-10-07 12:27:38 -05:00 committed by Andrey Lushnikov
parent 44cdf85b77
commit 3ecd98d634
3 changed files with 23 additions and 3 deletions

View File

@ -732,9 +732,8 @@ class Page extends EventEmitter {
} else { } else {
element.value = values.shift(); element.value = values.shift();
} }
element.dispatchEvent(new Event('input', { 'bubbles': true }));
element.dispatchEvent(new Event('change')); element.dispatchEvent(new Event('change', { 'bubbles': true }));
element.dispatchEvent(new Event('input'));
}, values); }, values);
} }

View File

@ -25,6 +25,8 @@
window.result = { window.result = {
onInput: null, onInput: null,
onChange: null, onChange: null,
onBubblingChange: null,
onBubblingInput: null,
}; };
let select = document.querySelector('select'); let select = document.querySelector('select');
@ -50,6 +52,18 @@
return option.value; return option.value;
}); });
}, false); }, false);
document.body.addEventListener('input', () => {
result.onBubblingInput = Array.from(select.querySelectorAll('option:checked')).map((option) => {
return option.value;
});
}, false);
document.body.addEventListener('change', () => {
result.onBubblingChange = Array.from(select.querySelectorAll('option:checked')).map((option) => {
return option.value;
});
}, false);
</script> </script>
</body> </body>
</html> </html>

View File

@ -2244,6 +2244,13 @@ describe('Page', function() {
expect(await page.evaluate(() => result.onChange)).toEqual(['blue', 'green', 'red']); expect(await page.evaluate(() => result.onChange)).toEqual(['blue', 'green', 'red']);
})); }));
it('should respect event bubbling', SX(async function() {
await page.goto(PREFIX + '/input/select.html');
await page.select('select', 'blue');
expect(await page.evaluate(() => result.onBubblingInput)).toEqual(['blue']);
expect(await page.evaluate(() => result.onBubblingChange)).toEqual(['blue']);
}));
it('should work with no options', SX(async function() { it('should work with no options', SX(async function() {
await page.goto(PREFIX + '/input/select.html'); await page.goto(PREFIX + '/input/select.html');
await page.evaluate(() => makeEmpty()); await page.evaluate(() => makeEmpty());