blob: 4d8b53aa2f34ca85c5ba4b294dd5937c3ed9ec77 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.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=week id=week value="2012-12-24" list=suggestions>
<datalist id=suggestions>
<option label="This Week">2012-W01</option>
<option>2012-W02</option>
<option>2012-W03</option>
<option>2012-W04</option>
<option>2012-W05</option>
<option>2012-W06</option>
<option>2012-W07</option>
<option>2012-W08</option>
<option>2012-W09</option>
<option>2012-W10</option>
<option>2012-W11</option>
<option>2012-W12</option>
<option>2012-W13</option>
<option>2012-W14</option>
<option>2012-W15</option>
<option>2012-W16</option>
<option>2012-W17</option>
<option>2012-W18</option>
<option>2012-W19</option>
<option>2012-W20</option>
<option>2012-W21</option>
<option>2012-W22</option>
<option>2012-W23</option>
<option>2012-W24</option>
<option>2012-W25</option>
<option>2012-W26</option>
<option>2012-W27</option>
<option>2012-W28</option>
<option>2012-W29</option>
<option>2012-W30</option>
<option>2012-W31</option>
<option>2012-W32</option>
<option>2012-W33</option>
<option>2012-W34</option>
<option>2012-W35</option>
<option>2012-W36</option>
<option>2012-W37</option>
<option>2012-W38</option>
<option>2012-W39</option>
<option>2012-W40</option>
<option>2012-W41</option>
<option>2012-W42</option>
<option>2012-W43</option>
<option>2012-W44</option>
<option>2012-W45</option>
<option>2012-W46</option>
<option>2012-W47</option>
<option>2012-W48</option>
<option>2012-W49</option>
<option>2012-W50</option>
<option>2012-W51</option>
<option>2012-W52</option>
<option>2013-W01</option>
<option>2013-W02</option>
<option>2013-W03</option>
<option>2013-W04</option>
<option>2013-W05</option>
<option>2013-W06</option>
<option>2013-W07</option>
<option>2013-W08</option>
<option>2013-W09</option>
<option>2013-W10</option>
<option>2013-W11</option>
<option>2013-W12</option>
<option>2013-W13</option>
<option>2013-W14</option>
<option>2013-W15</option>
<option>2012-W00</option> <!--invalid-->
<option>2012-01-01</option> <!--invalid-->
<option>foo</option> <!--invalid-->
</datalist>
<script>
debug('Check that page popup doesn\'t exist at first.');
shouldBeNull('$("mock-page-popup")');
openPicker($('week'), 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()', '2012-W02');
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('$("mock-page-popup")');
shouldBeEqualToString('document.getElementById("week").value', '2012-W03');
openPicker($('week'), 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);
}
function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
}
function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}
scrollDown();
}
function test2AfterClosing() {
shouldBeNull('$("mock-page-popup")');
openPicker($('week'), 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();
scrollTopAfterWheelEvent = suggestionList.scrollTop;
shouldBeTrue('scrollTopBeforeWheelEvent < scrollTopAfterWheelEvent');
finishJSTest();
}
</script>
</body>
</html>