Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7295)

Unified Diff: chrome/test/functional/gtalk/jsutils.js

Issue 8528012: Introduce Pyauto tests for Quasar (Google Talk Extension). (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/functional/gtalk/gtalk_base_test.py ('k') | chrome/test/functional/gtalk/pyauto_gtalk.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/functional/gtalk/jsutils.js
===================================================================
--- chrome/test/functional/gtalk/jsutils.js (revision 0)
+++ chrome/test/functional/gtalk/jsutils.js (revision 0)
@@ -0,0 +1,109 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview JS utilities automatically injected by GTalk PyAuto tests.
+ */
+
+/**
+ * Key codes to use with KeyboardEvent.
+ */
+$KEYS = {
+ ENTER: 13,
+ ESC: 27
+};
+
+/**
+ * The first Chrome extension view with a URL containing the query.
+ */
+$VIEW = function(query) {
+ var views = chrome.extension.getViews();
+ for (var i = 0; i < views.length; i++) {
+ var url = views[i].location.href;
+ if (url && url.indexOf(query) >= 0) {
+ return views[i];
+ }
+ }
+ return null;
+};
+
+/**
+ * The body element of the given window.
+ */
+$BODY = function(opt_window) {
+ return (opt_window || window).document.body;
+};
+
+/**
+ * Find the ancestor of the given element with a particular tag name.
+ */
+$FindByTagName = function(element, tag, index) {
+ var tagElements = element.getElementsByTagName(tag);
+ if (index < tagElements.length) {
+ return tagElements[index];
+ }
+ return null;
+};
+
+/**
+ * Find the first ancestor of the given element containing the given text.
+ */
+$FindByText = function(baseElement, text) {
+ var allElements = baseElement.getElementsByTagName('*');
+ for (var i = 0; i < allElements.length; i++) {
+ var element = allElements[i];
+ if (element.innerText && element.innerText.indexOf(text) >= 0) {
+ var child = $FindByText(element, text);
+ return child != null ? child : element;
+ }
+ }
+ return null;
+};
+
+/**
+ * Simulate a click on a given element.
+ */
+$Click = function(element) {
+ var mouseEvent = element.ownerDocument.createEvent('MouseEvent');
+ mouseEvent.initMouseEvent('click', true, true, window,
+ 1, 0, 0, 0, 0, false, false, false, false, 0, null);
+ element.dispatchEvent(mouseEvent);
+ return true;
+};
+
+/**
+ * Simulate typing text on a given element.
+ */
+$Type = function(element, text) {
+ var keyEvent = element.ownerDocument.createEvent('TextEvent');
+ keyEvent.initTextEvent('textInput', true, true, window, text);
+ element.dispatchEvent(keyEvent);
+ return true;
+};
+
+/**
+ * Simulate pressing a certain key on a given element.
+ */
+$Press = function(baseElement, keycode, opt_ctrlKey, opt_shiftKey,
+ opt_altKey, opt_metaKey) {
+ var sendKeyEvent = function(element, eventType) {
+ // Unfortuantely, using the typical KeyboardEvent and initKeyboardEvent
+ // fails in Chrome due to a webkit bug:
+ // https://bugs.webkit.org/show_bug.cgi?id=16735
+ // We employ a workaround of synthesizing a raw 'Event' suggested here:
+ // http://code.google.com/p/selenium/issues/detail?id=567
+ var keyEvent = element.ownerDocument.createEvent('Events');
+ keyEvent.ctrlKey = Boolean(opt_ctrlKey);
+ keyEvent.shiftKey = Boolean(opt_shiftKey);
+ keyEvent.altKey = Boolean(opt_altKey);
+ keyEvent.metaKey = Boolean(opt_metaKey);
+ keyEvent.initEvent(eventType, true, true);
+ keyEvent.keyCode = keycode;
+ element.dispatchEvent(keyEvent);
+ }
+ sendKeyEvent(baseElement, 'keydown');
+ sendKeyEvent(baseElement, 'keypress');
+ sendKeyEvent(baseElement, 'keyup');
+ return true;
+};
« no previous file with comments | « chrome/test/functional/gtalk/gtalk_base_test.py ('k') | chrome/test/functional/gtalk/pyauto_gtalk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698