1 window.jsTestIsAsync = true;
3 var popupWindow = null;
5 var popupOpenCallback = null;
7 function popupOpenCallbackWrapper() {
8 popupWindow.removeEventListener("didOpenPicker", popupOpenCallbackWrapper);
9 setTimeout(popupOpenCallback, 0);
12 function waitUntilClosing(callback) {
13 setTimeout(callback, 1);
16 function sendKey(input, keyName, ctrlKey, altKey) {
17 var event = document.createEvent('KeyboardEvent');
18 event.initKeyboardEvent('keydown', true, true, document.defaultView, keyName, 0, ctrlKey, altKey);
19 input.dispatchEvent(event);
22 function rootWindow() {
23 var currentWindow = window;
24 while (currentWindow !== currentWindow.parent) {
25 currentWindow = currentWindow.parent;
30 // openPicker opens a picker UI for the following types:
33 // - INPUT date/datetime-local/month/week
35 // |callback| is called if we successfully open the picker UI. However it is
36 // called only for the following types:
37 // - menulist SELECT on Windows, Linux, and CrOS
38 // - INPUT color with DATALIST
39 // - INPUT date/datetime-local/month/week
40 function openPicker(element, callback, errorCallback) {
41 rootWindow().moveTo(window.screenX, window.screenY);
42 element.offsetTop; // Force to lay out
44 if (element.tagName === "SELECT") {
45 sendKey(element, "Down", false, true);
46 } else if (element.tagName === "INPUT") {
47 if (element.type === "color") {
49 eventSender.keyDown(" ");
51 sendKey(element, "Down", false, true);
54 popupWindow = window.internals.pagePopupWindow;
55 if (typeof callback === "function" && popupWindow)
56 setPopupOpenCallback(callback);
57 else if (typeof errorCallback === "function" && !popupWindow)
61 function clickToOpenPicker(x, y, callback, errorCallback) {
62 rootWindow().moveTo(window.screenX, window.screenY);
63 eventSender.mouseMoveTo(x, y);
64 eventSender.mouseDown();
65 eventSender.mouseUp();
66 popupWindow = window.internals.pagePopupWindow;
67 if (typeof callback === "function" && popupWindow)
68 setPopupOpenCallback(callback);
69 else if (typeof errorCallback === "function" && !popupWindow)
73 function setPopupOpenCallback(callback) {
74 console.assert(popupWindow);
75 popupOpenCallback = (function(callback) {
76 // We need to move the window to the top left of available space
77 // because the window will move back to (0, 0) when the
78 // ShellViewMsg_SetTestConfiguration IPC arrives.
79 rootWindow().moveTo(window.screenX, window.screenY);
81 }).bind(this, callback);
83 popupWindow.addEventListener("didOpenPicker", popupOpenCallbackWrapper, false);