Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview JS utilities automatically injected by Quasar PyAuto tests. | |
|
Nirnimesh
2011/11/11 01:01:21
s/Quasar/GTalk/
wud
2011/11/17 21:17:53
Thanks, done.
| |
| 7 */ | |
| 8 | |
| 9 $KEYS = { | |
| 10 ENTER: 13, | |
| 11 ESC: 27 | |
| 12 }; | |
| 13 | |
|
frankf
2011/11/11 01:35:03
Please add comments describing what these function
wud
2011/11/17 21:17:53
Done.
| |
| 14 $VIEW = function(query) { | |
| 15 var views = chrome.extension.getViews(); | |
| 16 for (var i = 0; i < views.length; i++) { | |
| 17 var url = views[i].location.href; | |
| 18 if (url && url.indexOf(query) >= 0) { | |
| 19 return views[i]; | |
| 20 } | |
| 21 } | |
| 22 return null; | |
| 23 }; | |
| 24 | |
| 25 $BODY = function(opt_window) { | |
| 26 return (opt_window || window).document.body; | |
| 27 }; | |
| 28 | |
| 29 $FindByTagName = function(element, tag, index) { | |
| 30 var tagElements = element.getElementsByTagName(tag); | |
| 31 if (index < tagElements.length) { | |
| 32 return tagElements[index]; | |
| 33 } | |
| 34 return null; | |
| 35 }; | |
| 36 | |
| 37 $FindByText = function(baseElement, text) { | |
| 38 var allElements = baseElement.getElementsByTagName('*'); | |
| 39 for (var i = 0; i < allElements.length; i++) { | |
| 40 var element = allElements[i]; | |
| 41 if (element.innerText && element.innerText.indexOf(text) >= 0) { | |
| 42 var child = $FindByText(element, text); | |
| 43 return child != null ? child : element; | |
| 44 } | |
| 45 } | |
| 46 return null; | |
| 47 }; | |
| 48 | |
| 49 $Click = function(element) { | |
| 50 var mouseEvent = element.ownerDocument.createEvent('MouseEvent'); | |
| 51 mouseEvent.initMouseEvent('click', true, true, window, | |
| 52 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
| 53 element.dispatchEvent(mouseEvent); | |
| 54 return true; | |
| 55 }; | |
| 56 | |
| 57 $Type = function(element, text) { | |
| 58 var keyEvent = element.ownerDocument.createEvent('TextEvent'); | |
| 59 keyEvent.initTextEvent('textInput', true, true, window, text); | |
| 60 element.dispatchEvent(keyEvent); | |
| 61 return true; | |
| 62 }; | |
| 63 | |
| 64 $Press = function(baseElement, keycode, opt_ctrlKey, opt_shiftKey, | |
| 65 opt_altKey, opt_metaKey) { | |
| 66 var sendKeyEvent = function(element, eventType) { | |
| 67 // Unfortuantely, using the typical KeyboardEvent and initKeyboardEvent | |
| 68 // fails in Chrome due to a webkit bug: | |
| 69 // https://bugs.webkit.org/show_bug.cgi?id=16735 | |
| 70 // We employ a workaround of synthesizing a raw 'Event' suggested here: | |
| 71 // http://code.google.com/p/selenium/issues/detail?id=567 | |
| 72 var keyEvent = element.ownerDocument.createEvent('Events'); | |
| 73 keyEvent.ctrlKey = Boolean(opt_ctrlKey); | |
| 74 keyEvent.shiftKey = Boolean(opt_shiftKey); | |
| 75 keyEvent.altKey = Boolean(opt_altKey); | |
| 76 keyEvent.metaKey = Boolean(opt_metaKey); | |
| 77 keyEvent.initEvent(eventType, true, true); | |
| 78 keyEvent.keyCode = keycode; | |
| 79 element.dispatchEvent(keyEvent); | |
| 80 } | |
| 81 sendKeyEvent(baseElement, 'keydown'); | |
| 82 sendKeyEvent(baseElement, 'keypress'); | |
| 83 sendKeyEvent(baseElement, 'keyup'); | |
| 84 return true; | |
| 85 }; | |
| OLD | NEW |