Index: LayoutTests/fast/forms/select/popup-menu-position.html |
diff --git a/LayoutTests/fast/forms/select/popup-menu-position.html b/LayoutTests/fast/forms/select/popup-menu-position.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..47b4d259ed5d25a37e50b5a62bc483aee217c057 |
--- /dev/null |
+++ b/LayoutTests/fast/forms/select/popup-menu-position.html |
@@ -0,0 +1,123 @@ |
+<!DOCTYPE html> |
+<html> |
+<head> |
+<script> |
+window.enablePixelTesting = true; |
+</script> |
+<script src="../../../resources/js-test.js"></script> |
+<script src="../resources/picker-common.js"></script> |
+</head> |
+<body> |
+<style> |
+select { |
+ position: absolute; |
+ -webkit-appearance: none; |
+} |
+</style> |
+<select id="menu" style="width: 200px; height: 10px;"> |
+</select> |
+<p id="description" style="opacity: 0"></p> |
+<div id="console" style="opacity: 0"></div> |
+<script> |
+var menu = document.getElementById('menu'); |
+var windowWidth = 500; |
+var windowHeight = 500; |
+var menuWidth = 200; |
+var menuHeight = 10; |
+test1(); |
+ |
+function test1() { |
+ // Position menu at top left. |
+ menu.style.top = 0; |
+ menu.style.left = 0; |
+ setItemCount(1); |
+ openPicker(menu, function () { |
+ injectFakeScreenSize() |
+ injectFakeItemSize(20, 100, test2); |
+ }); |
+} |
+function test2() { |
+ popupWindowRect = getPopupWindowRect(); |
+ shouldBe('popupWindowRect.x', '0'); |
+ shouldBe('popupWindowRect.y', 'menuHeight'); |
+ |
+ popupWindow.pagePopupController.closePopup(); |
+ // Position menu at bottom right. |
+ menu.style.top = (500 - menuHeight) + 'px'; |
+ menu.style.left = (500 - menuWidth) + 'px'; |
+ setItemCount(1); |
+ openPicker(menu, function () { |
+ injectFakeScreenSize(); |
+ injectFakeItemSize(20, 100, test3); |
+ }); |
+} |
+function test3() { |
+ popupWindowRect = getPopupWindowRect(); |
+ shouldBe('popupWindowRect.x', 'windowWidth - popupWindowRect.width'); |
+ shouldBe('popupWindowRect.y', 'windowHeight - popupWindowRect.height - menuHeight'); |
+ |
+ popupWindow.pagePopupController.closePopup(); |
+ // Position menu at right edge, clipped. |
+ menu.style.top = '0'; |
+ menu.style.left = (500 - 100) + 'px'; |
+ setItemCount(1); |
+ openPicker(menu, function () { |
+ injectFakeScreenSize(); |
+ injectFakeItemSize(200, 100, test4); |
+ }); |
+} |
+function test4() { |
+ popupWindowRect = getPopupWindowRect(); |
+ shouldBe('popupWindowRect.x', 'windowWidth - menuWidth'); |
+ shouldBe('popupWindowRect.y', 'menuHeight'); |
+ |
+ popupWindow.pagePopupController.closePopup(); |
+ // Position menu at right edge, clipped. |
+ menu.style.top = '0'; |
+ menu.style.left = '-100px'; |
+ setItemCount(1); |
+ openPicker(menu, function () { |
+ injectFakeScreenSize(); |
+ injectFakeItemSize(200, 100, test5); |
+ }); |
+} |
+function test5() { |
+ popupWindowRect = getPopupWindowRect(); |
+ shouldBe('popupWindowRect.x', '0'); |
+ shouldBe('popupWindowRect.y', 'menuHeight'); |
+ |
+ finishJSTest(); |
+} |
+ |
+function getPopupWindowRect() { |
+ return new popupWindow.Rectangle(popupWindow.screenX - window.screen.availLeft, popupWindow.screenY - window.screen.availTop, popupWindow.innerWidth, popupWindow.innerHeight); |
+} |
+function setItemCount(count) { |
+ menu.innerHTML = ''; |
+ for (var i = 0; i < count; i++) { |
+ var option = document.createElement('option'); |
+ menu.appendChild(option); |
+ } |
+} |
+function injectFakeScreenSize() { |
+ Object.defineProperty(popupWindow, 'screen', { |
+ value: { |
+ width: windowWidth, |
+ height: windowHeight, |
+ availLeft: window.screen.availLeft, |
+ availTop: window.screen.availTop, |
+ availWidth: windowWidth, |
+ availHeight: windowHeight |
+ } |
+ }); |
+} |
+function injectFakeItemSize(width, height, callback) { |
+ var style = popupWindow.document.createElement('style'); |
+ style.innerHTML = 'option { width: ' + width + 'px; height: ' + height + 'px; }'; |
+ popupWindow.document.body.appendChild(style); |
+ popupWindow.global.picker._fixWindowSize(); |
+ popupWindow.addEventListener('resize', callback, false); |
+} |
+</script> |
+</body> |
+</html> |