OLD | NEW |
1 window.jsTestIsAsync = true; | 1 window.jsTestIsAsync = true; |
2 if (window.internals) | |
3 internals.setEnableMockPagePopup(true); | |
4 | 2 |
5 var popupWindow = null; | 3 var popupWindow = null; |
6 | 4 |
7 var popupOpenCallback = null; | 5 var popupOpenCallback = null; |
8 function openPicker(input, callback) { | 6 function openPicker(input, callback) { |
| 7 if (window.internals) |
| 8 internals.setEnableMockPagePopup(true); |
9 input.offsetTop; // Force to lay out | 9 input.offsetTop; // Force to lay out |
10 if (input.type === "color") { | 10 if (input.type === "color") { |
11 input.focus(); | 11 input.focus(); |
12 eventSender.keyDown(" "); | 12 eventSender.keyDown(" "); |
13 } else { | 13 } else { |
14 sendKey(input, "Down", false, true); | 14 sendKey(input, "Down", false, true); |
15 } | 15 } |
16 popupWindow = document.getElementById('mock-page-popup').contentWindow; | 16 popupWindow = document.getElementById('mock-page-popup').contentWindow; |
17 if (typeof callback === "function") { | 17 if (typeof callback === "function") { |
18 popupOpenCallback = callback; | 18 popupOpenCallback = callback; |
19 popupWindow.addEventListener("didOpenPicker", popupOpenCallbackWrapper,
false); | 19 popupWindow.addEventListener("didOpenPicker", popupOpenCallbackWrapper,
false); |
20 } | 20 } |
21 } | 21 } |
22 | 22 |
23 function popupOpenCallbackWrapper() { | 23 function popupOpenCallbackWrapper() { |
24 popupWindow.removeEventListener("didOpenPicker", popupOpenCallbackWrapper); | 24 popupWindow.removeEventListener("didOpenPicker", popupOpenCallbackWrapper); |
25 setTimeout(popupOpenCallback, 0); | 25 setTimeout(popupOpenCallback, 0); |
26 } | 26 } |
27 | 27 |
28 function waitUntilClosing(callback) { | 28 function waitUntilClosing(callback) { |
29 setTimeout(callback, 1); | 29 setTimeout(callback, 1); |
30 } | 30 } |
31 | 31 |
32 function sendKey(input, keyName, ctrlKey, altKey) { | 32 function sendKey(input, keyName, ctrlKey, altKey) { |
33 var event = document.createEvent('KeyboardEvent'); | 33 var event = document.createEvent('KeyboardEvent'); |
34 event.initKeyboardEvent('keydown', true, true, document.defaultView, keyName
, 0, ctrlKey, altKey); | 34 event.initKeyboardEvent('keydown', true, true, document.defaultView, keyName
, 0, ctrlKey, altKey); |
35 input.dispatchEvent(event); | 35 input.dispatchEvent(event); |
36 } | 36 } |
37 | 37 |
38 | 38 function openPickerWithoutMock(input, callback) { |
| 39 window.moveTo(); |
| 40 input.offsetTop; // Force to lay out |
| 41 if (input.type === "color") { |
| 42 input.focus(); |
| 43 eventSender.keyDown(" "); |
| 44 } else { |
| 45 sendKey(input, "Down", false, true); |
| 46 } |
| 47 popupWindow = window.internals.pagePopupWindow; |
| 48 if (typeof callback === "function") { |
| 49 popupOpenCallback = (function(callback) { |
| 50 // We need to move the window to the top left of available space |
| 51 // because the window will move back to (0, 0) when the |
| 52 // ShellViewMsg_SetTestConfiguration IPC arrives. |
| 53 window.moveTo(); |
| 54 callback(); |
| 55 }).bind(this, callback); |
| 56 popupWindow.addEventListener("didOpenPicker", popupOpenCallbackWrapper,
false); |
| 57 } |
| 58 } |
OLD | NEW |