blob: fafdbe11addae6be2bbbcb9b829fcc71a3c0b33d [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../../forms/resources/common.js"></script>
<script src="../../forms/resources/common-wheel-event.js"></script>
<script src="../../forms/resources/picker-common.js"></script>
<script src="resources/suggestion-picker-common.js"></script>
</head>
<body style="background-color: #bbbbbb;">
<p id="description"></p>
<div id="console"></div>
<input type=time id=time value="01:00" list=suggestions>
<datalist id=suggestions>
<option label="Now">01:01</option>
<option>01:02</option>
<option>01:03</option>
<option>01:04</option>
<option>01:05</option>
<option>01:06</option>
<option>01:07</option>
<option>01:08</option>
<option>01:09</option>
<option>01:10</option>
<option>01:11</option>
<option>01:12</option>
<option>01:13</option>
<option>01:14</option>
<option>01:15</option>
<option>01:16</option>
<option>01:17</option>
<option>01:18</option>
<option>01:19</option>
<option>01:20</option>
<option>01:21</option>
</datalist>
<script>
debug('Check that page popup doesn\'t exist at first.');
shouldBeNull('$("mock-page-popup")');
window.onload = function() {
if (window.internals)
internals.settings.setScrollAnimatorEnabled(false);
openPicker($('time'), test1);
};
function test1() {
debug('Check that page popup exists.');
shouldBeEqualToString('popupWindow.pagePopupController.toString()', '[object PagePopupController]');
debug('Check that hovering over an entry highlights it.');
hoverOverElement(popupWindow.document.querySelector(".suggestion-list-entry:nth-child(2)"));
shouldBeEqualToString('highlightedEntry()', '01:02');
debug('Check that moving the mouse outside the popup de-highlights entries.');
hoverOverElement(document.getElementById('description'));
shouldBeNull('highlightedEntry()');
debug('Check that mouse click closes the popup and sets the value.');
clickElement(popupWindow.document.querySelector(".suggestion-list-entry:nth-child(3)"));
waitUntilClosing(test1AfterClosing);
}
function test1AfterClosing() {
shouldBeNull('document.getElementById("mock-page-popup")');
shouldBeEqualToString('document.getElementById("time").value', '01:03');
openPicker($('time'), test2);
}
var scrollTopBeforeWheelEvent = 0;
var scrollTopAfterWheelEvent = 0;
var suggestionList;
function test2() {
suggestionList = popupWindow.document.getElementsByClassName("suggestion-list")[0];
debug('Check that you can scroll using the mouse wheel.');
function finishTest() {
popupWindow.focus();
eventSender.keyDown('Escape');
waitUntilClosing(test2AfterClosing);
}
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
await dispatchWheelEvent(suggestionList, 0, -3);
await waitFor(() => {
return scrollTopBeforeWheelEvent > suggestionList.scrollTop});
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
}
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
await dispatchWheelEvent(suggestionList, 0, 3);
await waitFor(() => {
return scrollTopBeforeWheelEvent < suggestionList.scrollTop});
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}
scrollDown();
}
function test2AfterClosing() {
shouldBeNull('$("mock-page-popup")');
openPicker($('time'), test3);
}
function test3() {
debug('Check that you can scroll using the scroll bar.');
var suggestionList = popupWindow.document.getElementsByClassName("suggestion-list")[0];
var suggestionListOffset = cumulativeOffset(suggestionList);
var scrollbarCenterX = suggestionListOffset[0] + suggestionList.offsetWidth - popupWindow.getScrollbarWidth() / 2;
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
eventSender.mouseMoveTo(scrollbarCenterX, suggestionListOffset[1] + 20); // 20 is the height of the up arrow button plus a few pixels
eventSender.mouseDown();
eventSender.mouseMoveTo(scrollbarCenterX, suggestionListOffset[1] + suggestionList.offsetHeight);
eventSender.mouseUp();
requestAnimationFrame(function() {
scrollTopAfterWheelEvent = suggestionList.scrollTop;
shouldBeTrue('scrollTopBeforeWheelEvent < scrollTopAfterWheelEvent');
finishJSTest();
});
}
</script>
</body>
</html>