code
stringlengths
28
313k
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
74
language
stringclasses
1 value
repo
stringlengths
5
60
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function apply_key_behavior(key) { function __update_key(e) { var guac = GuacUI.Client.attachedClient; if (!guac) return; e.preventDefault(); e.stopPropagation(); // Pull properties of key var keysym = parseInt(key.getAttribute("data-keysym")); var sticky = (key.getAttribute("data-sticky") === "true"); var pressed = (key.className.indexOf("pressed") !== -1); // If sticky, toggle pressed state if (sticky) { if (pressed) { GuacUI.removeClass(key, "pressed"); guac.sendKeyEvent(0, keysym); delete active_sticky_keys[keysym]; } else { GuacUI.addClass(key, "pressed"); guac.sendKeyEvent(1, keysym); active_sticky_keys[keysym] = key; } } // For all non-sticky keys, press and release key immediately else send_keysym(keysym); } var ignore_mouse = false; // Press/release key when clicked key.addEventListener("mousedown", function __mouse_key(e) { // Ignore clicks which follow touches if (ignore_mouse) return; __update_key(e); }, false); // Press/release key when tapped key.addEventListener("touchstart", function __touch_key(e) { // Ignore following clicks ignore_mouse = true; __update_key(e); }, false); // Restore handling of mouse events when mouse is used key.addEventListener("mousemove", function __reset_mouse() { ignore_mouse = false; }, false); }
Presses/releases the keysym defined by the "data-keysym" attribute on the given element whenever the element is pressed. The "data-sticky" attribute, if present and set to "true", causes the key to remain pressed until text is sent. @param {Element} key The element which will control its associated key.
apply_key_behavior
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function release_sticky_keys() { var guac = GuacUI.Client.attachedClient; if (!guac) return; // Release all active sticky keys for (var keysym in active_sticky_keys) { var key = active_sticky_keys[keysym]; GuacUI.removeClass(key, "pressed"); guac.sendKeyEvent(0, keysym); } // Reset set of active keys active_sticky_keys = {}; }
Releases all currently-held sticky keys within the text input UI.
release_sticky_keys
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function reset_text_input_target(padding) { var padding_char = String.fromCharCode(GuacUI.Client.TEXT_INPUT_PADDING_CODEPOINT); // Pad text area with an arbitrary, non-typable character (so there is something // to delete with backspace or del), and position cursor in middle. GuacUI.Client.text_input.target.value = new Array(padding*2 + 1).join(padding_char); GuacUI.Client.text_input.target.setSelectionRange(padding-1, padding); }
Removes all content from the text input target, replacing it with the given number of padding characters. Padding of the requested size is added on both sides of the cursor, thus the overall number of characters added will be twice the number specified. @param {Number} padding The number of characters to pad the text area with.
reset_text_input_target
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function addGroupContents(group, appendChild) { var i; // Add all contained connections if (show_connections) { for (i=0; i<group.connections.length; i++) addConnection(group.connections[i], appendChild); } // Add all contained groups for (i=0; i<group.groups.length; i++) addGroup(group.groups[i], appendChild); }
Adds the contents of the given group via the given appendChild() function, but not the given group itself. @param {GuacamoleService.ConnectionGroup} group The group whose contents should be added. @param {Function} appendChild A function which, given an element, will add that element the the display as desired.
addGroupContents
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
MIT
function addConnection(connection, appendChild) { // Do not add connection if filter says "no" if (connection_filter && !connection_filter(connection)) return; group_view.connections[connection.id] = connection; // Add connection to connection list or parent group var guacui_connection = new GuacUI.ListConnection(connection); GuacUI.addClass(guacui_connection.getElement(), "list-item"); // If multiselect, add checkbox for each connection if (multiselect) { var connection_choice = GuacUI.createElement("div", "choice"); var connection_checkbox = GuacUI.createChildElement(connection_choice, "input"); connection_checkbox.setAttribute("type", "checkbox"); connection_choice.appendChild(guacui_connection.getElement()); appendChild(connection_choice); function fire_connection_change(e) { // Prevent click from affecting parent e.stopPropagation(); // Fire event if handler defined if (group_view.onconnectionchange) group_view.onconnectionchange(connection, this.checked); } // Fire change events when checkbox modified connection_checkbox.addEventListener("click", fire_connection_change, false); connection_checkbox.addEventListener("change", fire_connection_change, false); // Add checbox to set of connection checkboxes connection_checkboxes[connection.id] = connection_checkbox; } else appendChild(guacui_connection.getElement()); // Fire click events when connection clicked guacui_connection.onclick = function() { if (group_view.onconnectionclick) group_view.onconnectionclick(connection); }; }
Adds the given connection via the given appendChild() function. @param {GuacamoleService.Connection} connection The connection to add. @param {Function} appendChild A function which, given an element, will add that element the the display as desired.
addConnection
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
MIT
function addGroup(group, appendChild) { // Do not add group if filter says "no" if (group_filter && !group_filter(group)) return; // Add group to groups collection group_view.groups[group.id] = group; // Create element for group var list_group = new GuacUI.ListGroup(group.name); list_groups[group.id] = list_group; GuacUI.addClass(list_group.getElement(), "list-item"); // Mark group as balancer if appropriate if (group.type === GuacamoleService.ConnectionGroup.Type.BALANCING) GuacUI.addClass(list_group.getElement(), "balancer"); // Recursively add all children to the new element addGroupContents(group, list_group.addElement); // If multiselect, add checkbox for each group if (multiselect) { var group_choice = GuacUI.createElement("div", "choice"); var group_checkbox = GuacUI.createChildElement(group_choice, "input"); group_checkbox.setAttribute("type", "checkbox"); group_choice.appendChild(list_group.getElement()); appendChild(group_choice); function fire_group_change(e) { // Prevent click from affecting parent e.stopPropagation(); // Fire event if handler defined if (group_view.ongroupchange) group_view.ongroupchange(group, this.checked); } // Fire change events when checkbox modified group_checkbox.addEventListener("click", fire_group_change, false); group_checkbox.addEventListener("change", fire_group_change, false); // Add checbox to set of group checkboxes group_checkboxes[group.id] = group_checkbox; } else appendChild(list_group.getElement()); // Fire click events when group clicked list_group.onclick = function() { if (group_view.ongroupclick) group_view.ongroupclick(group); }; }
Adds the given group via the given appendChild() function. @param {GuacamoleService.ConnectionGroup} group The group to add. @param {Function} appendChild A function which, given an element, will add that element the the display as desired.
addGroup
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
MIT
function truncate() { // Build list of entries var entries = []; for (var old_id in history) entries.push(history[old_id]); // Avoid history growth beyond defined number of entries if (entries.length > IDEAL_LENGTH) { // Sort list entries.sort(GuacamoleHistory.Entry.compare); // Remove entries until length is ideal or all are recent var now = new Date().getTime(); while (entries.length > IDEAL_LENGTH && now - entries[0].accessed > CUTOFF_AGE) { // Remove entry var removed = entries.shift(); delete history[removed.id]; } } }
The maximum age of a history entry before it is removed, in milliseconds.
truncate
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/history.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/history.js
MIT
function hasEntry(object) { for (var name in object) return true; return false; }
Resets the interface such that the login UI is displayed if the user is not authenticated (or authentication fails) and the connection list UI (or the client for the only available connection, if there is only one) is displayed if the user is authenticated.
hasEntry
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/root-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/root-ui.js
MIT
function parseConnection(parent, element) { var i; var connection = new GuacamoleService.Connection( element.getAttribute("protocol"), element.getAttribute("id"), element.getAttribute("name") ); // Set parent connection.parent = parent; // Add parameter values for each parmeter received var paramElements = element.getElementsByTagName("param"); for (i=0; i<paramElements.length; i++) { var paramElement = paramElements[i]; var name = paramElement.getAttribute("name"); connection.parameters[name] = paramElement.textContent; } // Parse history, if available var historyElements = element.getElementsByTagName("history"); if (historyElements.length === 1) { // For each record in history var history = historyElements[0]; var recordElements = history.getElementsByTagName("record"); for (i=0; i<recordElements.length; i++) { // Get record var recordElement = recordElements[i]; var record = new GuacamoleService.Connection.Record( recordElement.textContent, parseInt(recordElement.getAttribute("start")), parseInt(recordElement.getAttribute("end")), recordElement.getAttribute("active") === "yes" ); // Append to connection history connection.history.push(record); } } // Return parsed connection return connection; }
Parse the contents of the given connection element within XML, returning a corresponding GuacamoleService.Connection. @param {GuacamoleService.ConnectionGroup} The connection group containing this connection. @param {Element} element The element being parsed. @return {GuacamoleService.Connection} The connection represented by the element just parsed.
parseConnection
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/service.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/service.js
MIT
function parseGroup(parent, element) { var id = element.getAttribute("id"); var name = element.getAttribute("name"); var type_string = element.getAttribute("type"); // Translate type name var type; if (type_string === "organizational") type = GuacamoleService.ConnectionGroup.Type.ORGANIZATIONAL; else if (type_string === "balancing") type = GuacamoleService.ConnectionGroup.Type.BALANCING; // Create corresponding group var group = new GuacamoleService.ConnectionGroup(type, id, name); // Set parent group.parent = parent; // For each child element var current = element.firstChild; while (current !== null) { var i, child; var children = current.childNodes; if (current.localName === "connections") { // Parse all child connections for (i=0; i<children.length; i++) { var child = children[i]; if (child.localName === "connection") group.connections.push(parseConnection(group, child)); } } else if (current.localName === "groups") { // Parse all child groups for (i=0; i<children.length; i++) { var child = children[i]; if (child.localName === "group") group.groups.push(parseGroup(group, child)); } } // Next element current = current.nextSibling; } // Sort groups and connections group.groups.sort(GuacamoleService.Connections.comparator); group.connections.sort(GuacamoleService.Connections.comparator); // Return created group return group; }
Recursively parse the contents of the given group element within XML, returning a corresponding GuacamoleService.ConnectionGroup. @param {GuacamoleService.ConnectionGroup} The connection group containing this group. @param {Element} element The element being parsed. @return {GuacamoleService.ConnectionGroup} The connection group represented by the element just parsed.
parseGroup
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/service.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/service.js
MIT
function __notify_changed(name, value) { for (var i=0; i<listeners.length; i++) listeners[i](name, value); }
Notifies all listeners that an item has changed. @param {String} name The name of the item that changed. @param value The new item value.
__notify_changed
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/session.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/session.js
MIT
function __send_blob(bytes) { var binary = ""; // Produce binary string from bytes in buffer for (var i=0; i<bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]); // Send as base64 stream.sendBlob(window.btoa(binary)); }
Encodes the given data as base64, sending it as a blob. The data must be small enough to fit into a single blob instruction. @private @param {Uint8Array} bytes The data to send.
__send_blob
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/ArrayBufferWriter.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/ArrayBufferWriter.js
MIT
handleReady = function(buffer) { readyBuffer = buffer; }
Schedules this packet for playback at the given time. @function @param {Number} when The time this packet should be played, in milliseconds.
handleReady
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/AudioChannel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/AudioChannel.js
MIT
function getLayer(index) { // Get layer, create if necessary var layer = layers[index]; if (!layer) { // Create layer based on index if (index === 0) layer = display.getDefaultLayer(); else if (index > 0) layer = display.createLayer(); else layer = display.createBuffer(); // Add new layer layers[index] = layer; } return layer; }
Returns the layer with the given index, creating it if necessary. Positive indices refer to visible layers, an index of zero refers to the default layer, and negative indices refer to buffers. @param {Number} index The index of the layer to retrieve. @return {Guacamole.Display.VisibleLayer|Guacamole.Layer} The layer having the given index.
getLayer
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Client.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Client.js
MIT
function Frame(callback, tasks) { /** * Returns whether this frame is ready to be rendered. This function * returns true if and only if ALL underlying tasks are unblocked. * * @returns {Boolean} true if all underlying tasks are unblocked, * false otherwise. */ this.isReady = function() { // Search for blocked tasks for (var i=0; i < tasks.length; i++) { if (tasks[i].blocked) return false; } // If no blocked tasks, the frame is ready return true; }; /** * Renders this frame, calling the associated callback, if any, after * the frame is complete. This function MUST only be called when no * blocked tasks exist. Calling this function with blocked tasks * will result in undefined behavior. */ this.flush = function() { // Draw all pending tasks. for (var i=0; i < tasks.length; i++) tasks[i].execute(); // Call callback if (callback) callback(); }; }
An ordered list of tasks which must be executed atomically. Once executed, an associated (and optional) callback will be called. @private @constructor @param {function} callback The function to call when this frame is rendered. @param {Task[]} tasks The set of tasks which must be executed to render this frame.
Frame
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function Task(taskHandler, blocked) { var task = this; /** * Whether this Task is blocked. * * @type boolean */ this.blocked = blocked; /** * Unblocks this Task, allowing it to run. */ this.unblock = function() { if (task.blocked) { task.blocked = false; __flush_frames(); } }; /** * Calls the handler associated with this task IMMEDIATELY. This * function does not track whether this task is marked as blocked. * Enforcing the blocked status of tasks is up to the caller. */ this.execute = function() { if (taskHandler) taskHandler(); }; }
A container for an task handler. Each operation which must be ordered is associated with a Task that goes into a task queue. Tasks in this queue are executed in order once their handlers are set, while Tasks without handlers block themselves and any following Tasks from running. @constructor @private @param {function} taskHandler The function to call when this task runs, if any. @param {boolean} blocked Whether this task should start blocked.
Task
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function scheduleTask(handler, blocked) { var task = new Task(handler, blocked); tasks.push(task); return task; }
Schedules a task for future execution. The given handler will execute immediately after all previous tasks upon frame flush, unless this task is blocked. If any tasks is blocked, the entire frame will not render (and no tasks within will execute) until all tasks are unblocked. @private @param {function} handler The function to call when possible, if any. @param {boolean} blocked Whether the task should start blocked. @returns {Task} The Task created and added to the queue for future running.
scheduleTask
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function render_callback() { layer.drawImage(0, 0, video); if (!video.ended) window.setTimeout(render_callback, 20); }
Plays the video at the specified URL within this layer. The video will be loaded automatically, and this and any future operations will wait for the video to finish loading. Future operations will not be executed until the video finishes playing. @param {Guacamole.Layer} layer The layer to draw upon. @param {String} mimetype The mimetype of the video to play. @param {Number} duration The duration of the video in milliseconds. @param {String} url The URL of the video to play.
render_callback
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function get_children(layer) { // Build array of children var children = []; for (var index in layer.children) children.push(layer.children[index]); // Sort children.sort(function children_comparator(a, b) { // Compare based on Z order var diff = a.z - b.z; if (diff !== 0) return diff; // If Z order identical, use document order var a_element = a.getElement(); var b_element = b.getElement(); var position = b_element.compareDocumentPosition(a_element); if (position & Node.DOCUMENT_POSITION_PRECEDING) return -1; if (position & Node.DOCUMENT_POSITION_FOLLOWING) return 1; // Otherwise, assume same return 0; }); // Done return children; }
Returns a canvas element containing the entire display, with all child layers composited within. @return {HTMLCanvasElement} A new canvas element containing a copy of the display.
get_children
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
KeyEvent = function() { /** * Reference to this key event. */ var key_event = this; /** * An arbitrary timestamp in milliseconds, indicating this event's * position in time relative to other events. * * @type Number */ this.timestamp = new Date().getTime(); /** * Whether the default action of this key event should be prevented. * * @type Boolean */ this.defaultPrevented = false; /** * The keysym of the key associated with this key event, as determined * by a best-effort guess using available event properties and keyboard * state. * * @type Number */ this.keysym = null; /** * Whether the keysym value of this key event is known to be reliable. * If false, the keysym may still be valid, but it's only a best guess, * and future key events may be a better source of information. * * @type Boolean */ this.reliable = false; /** * Returns the number of milliseconds elapsed since this event was * received. * * @return {Number} The number of milliseconds elapsed since this * event was received. */ this.getAge = function() { return new Date().getTime() - key_event.timestamp; }; }
A key event having a corresponding timestamp. This event is non-specific. Its subclasses should be used instead when recording specific key events. @private @constructor
KeyEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
KeydownEvent = function(keyCode, keyIdentifier, key, location) { // We extend KeyEvent KeyEvent.apply(this); /** * The JavaScript key code of the key pressed. * * @type Number */ this.keyCode = keyCode; /** * The legacy DOM3 "keyIdentifier" of the key pressed, as defined at: * http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/#events-Events-KeyboardEvent * * @type String */ this.keyIdentifier = keyIdentifier; /** * The standard name of the key pressed, as defined at: * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent * * @type String */ this.key = key; /** * The location on the keyboard corresponding to the key pressed, as * defined at: * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent * * @type Number */ this.location = location; // If key is known from keyCode or DOM3 alone, use that this.keysym = keysym_from_key_identifier(key, location) || keysym_from_keycode(keyCode, location); // DOM3 and keyCode are reliable sources if (this.keysym) this.reliable = true; // Use legacy keyIdentifier as a last resort, if it looks sane if (!this.keysym && key_identifier_sane(keyCode, keyIdentifier)) this.keysym = keysym_from_key_identifier(keyIdentifier, location, guac_keyboard.modifiers.shift); // Determine whether default action for Alt+combinations must be prevented var prevent_alt = !guac_keyboard.modifiers.ctrl && !(navigator && navigator.platform && navigator.platform.match(/^mac/i)); // Determine whether default action for Ctrl+combinations must be prevented var prevent_ctrl = !guac_keyboard.modifiers.alt; // We must rely on the (potentially buggy) keyIdentifier if preventing // the default action is important if ((prevent_ctrl && guac_keyboard.modifiers.ctrl) || (prevent_alt && guac_keyboard.modifiers.alt) || guac_keyboard.modifiers.meta || guac_keyboard.modifiers.hyper) this.reliable = true; // Record most recently known keysym by associated key code recentKeysym[keyCode] = this.keysym; }
Information related to the pressing of a key, which need not be a key associated with a printable character. The presence or absence of any information within this object is browser-dependent. @private @constructor @augments Guacamole.Keyboard.KeyEvent @param {Number} keyCode The JavaScript key code of the key pressed. @param {String} keyIdentifier The legacy DOM3 "keyIdentifier" of the key pressed, as defined at: http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/#events-Events-KeyboardEvent @param {String} key The standard name of the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent @param {Number} location The location on the keyboard corresponding to the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
KeydownEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
KeypressEvent = function(charCode) { // We extend KeyEvent KeyEvent.apply(this); /** * The Unicode codepoint of the character that would be typed by the * key pressed. * * @type Number */ this.charCode = charCode; // Pull keysym from char code this.keysym = keysym_from_charcode(charCode); // Keypress is always reliable this.reliable = true; }
Information related to the pressing of a key, which MUST be associated with a printable character. The presence or absence of any information within this object is browser-dependent. @private @constructor @augments Guacamole.Keyboard.KeyEvent @param {Number} charCode The Unicode codepoint of the character that would be typed by the key pressed.
KeypressEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
KeyupEvent = function(keyCode, keyIdentifier, key, location) { // We extend KeyEvent KeyEvent.apply(this); /** * The JavaScript key code of the key released. * * @type Number */ this.keyCode = keyCode; /** * The legacy DOM3 "keyIdentifier" of the key released, as defined at: * http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/#events-Events-KeyboardEvent * * @type String */ this.keyIdentifier = keyIdentifier; /** * The standard name of the key released, as defined at: * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent * * @type String */ this.key = key; /** * The location on the keyboard corresponding to the key released, as * defined at: * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent * * @type Number */ this.location = location; // If key is known from keyCode or DOM3 alone, use that this.keysym = keysym_from_keycode(keyCode, location) || recentKeysym[keyCode] || keysym_from_key_identifier(key, location); // keyCode is still more reliable for keyup when dead keys are in use // Keyup is as reliable as it will ever be this.reliable = true; }
Information related to the pressing of a key, which need not be a key associated with a printable character. The presence or absence of any information within this object is browser-dependent. @private @constructor @augments Guacamole.Keyboard.KeyEvent @param {Number} keyCode The JavaScript key code of the key released. @param {String} keyIdentifier The legacy DOM3 "keyIdentifier" of the key released, as defined at: http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/#events-Events-KeyboardEvent @param {String} key The standard name of the key released, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent @param {Number} location The location on the keyboard corresponding to the key released, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
KeyupEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function get_keysym(keysyms, location) { if (!keysyms) return null; return keysyms[location] || keysyms[0]; }
Given an array of keysyms indexed by location, returns the keysym for the given location, or the keysym for the standard location if undefined. @param {Array} keysyms An array of keysyms, where the index of the keysym in the array is the location value. @param {Number} location The location on the keyboard corresponding to the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
get_keysym
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function key_identifier_sane(keyCode, keyIdentifier) { // Assume non-Unicode keyIdentifier values are sane var unicodePrefixLocation = keyIdentifier.indexOf("U+"); if (unicodePrefixLocation === -1) return true; // If the Unicode codepoint isn't identical to the keyCode, // then the identifier is likely correct var codepoint = parseInt(keyIdentifier.substring(unicodePrefixLocation+2), 16); if (keyCode !== codepoint) return true; // The keyCodes for A-Z and 0-9 are actually identical to their // Unicode codepoints if ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 48 && keyCode <= 57)) return true; // The keyIdentifier does NOT appear sane return false; }
Heuristically detects if the legacy keyIdentifier property of a keydown/keyup event looks incorrectly derived. Chrome, and presumably others, will produce the keyIdentifier by assuming the keyCode is the Unicode codepoint for that key. This is not correct in all cases. @param {Number} keyCode The keyCode from a browser keydown/keyup event. @param {String} keyIdentifier The legacy keyIdentifier from a browser keydown/keyup event. @returns {Boolean} true if the keyIdentifier looks sane, false if the keyIdentifier appears incorrectly derived.
key_identifier_sane
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function press_key(keysym) { // Don't bother with pressing the key if the key is unknown if (keysym === null) return; // Only press if released if (!guac_keyboard.pressed[keysym]) { // Mark key as pressed guac_keyboard.pressed[keysym] = true; // Send key event if (guac_keyboard.onkeydown) { var result = guac_keyboard.onkeydown(keysym); last_keydown_result[keysym] = result; // Stop any current repeat window.clearTimeout(key_repeat_timeout); window.clearInterval(key_repeat_interval); // Repeat after a delay as long as pressed if (!no_repeat[keysym]) key_repeat_timeout = window.setTimeout(function() { key_repeat_interval = window.setInterval(function() { guac_keyboard.onkeyup(keysym); guac_keyboard.onkeydown(keysym); }, 50); }, 500); return result; } } // Return the last keydown result by default, resort to false if unknown return last_keydown_result[keysym] || false; }
Marks a key as pressed, firing the keydown event if registered. Key repeat for the pressed key will start after a delay if that key is not a modifier. @private @param keysym The keysym of the key to press. @return {Boolean} true if event should NOT be canceled, false otherwise.
press_key
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function release_key(keysym) { // Only release if pressed if (guac_keyboard.pressed[keysym]) { // Mark key as released delete guac_keyboard.pressed[keysym]; // Stop repeat window.clearTimeout(key_repeat_timeout); window.clearInterval(key_repeat_interval); // Send key event if (keysym !== null && guac_keyboard.onkeyup) guac_keyboard.onkeyup(keysym); } }
Marks a key as released, firing the keyup event if registered. @private @param keysym The keysym of the key to release.
release_key
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function update_modifier_state(e) { // Get state var state = Guacamole.Keyboard.ModifierState.fromKeyboardEvent(e); // Release alt if implicitly released if (guac_keyboard.modifiers.alt && state.alt === false) { release_key(0xFFE9); // Left alt release_key(0xFFEA); // Right alt release_key(0xFE03); // AltGr } // Release shift if implicitly released if (guac_keyboard.modifiers.shift && state.shift === false) { release_key(0xFFE1); // Left shift release_key(0xFFE2); // Right shift } // Release ctrl if implicitly released if (guac_keyboard.modifiers.ctrl && state.ctrl === false) { release_key(0xFFE3); // Left ctrl release_key(0xFFE4); // Right ctrl } // Release meta if implicitly released if (guac_keyboard.modifiers.meta && state.meta === false) { release_key(0xFFE7); // Left meta release_key(0xFFE8); // Right meta } // Release hyper if implicitly released if (guac_keyboard.modifiers.hyper && state.hyper === false) { release_key(0xFFEB); // Left hyper release_key(0xFFEC); // Right hyper } // Update state guac_keyboard.modifiers = state; }
Given a keyboard event, updates the local modifier state and remote key state based on the modifier flags within the event. This function pays no attention to keycodes. @param {KeyboardEvent} e The keyboard event containing the flags to update.
update_modifier_state
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function interpret_events() { // Do not prevent default if no event could be interpreted var handled_event = interpret_event(); if (!handled_event) return false; // Interpret as much as possible var last_event; do { last_event = handled_event; handled_event = interpret_event(); } while (handled_event !== null); return last_event.defaultPrevented; }
Reads through the event log, removing events from the head of the log when the corresponding true key presses are known (or as known as they can be). @return {Boolean} Whether the default action of the latest event should be prevented.
interpret_events
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function indexof_keyup(keydown) { var i; // Search event log for keyup events having the given keysym for (i=0; i<eventLog.length; i++) { // Return index of key event if found var event = eventLog[i]; if (event instanceof KeyupEvent && event.keyCode === keydown.keyCode) return i; } // No such keyup found return -1; }
Searches the event log for a keyup event corresponding to the given keydown event, returning its index within the log. @param {KeydownEvent} keydown The keydown event whose corresponding keyup event we are to search for. @returns {Number} The index of the first keyup event in the event log matching the given keydown event, or -1 if no such event exists.
indexof_keyup
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function release_simulated_altgr(keysym) { // Both Ctrl+Alt must be pressed if simulated AltGr is in use if (!guac_keyboard.modifiers.ctrl || !guac_keyboard.modifiers.alt) return; // Assume [A-Z] never require AltGr if (keysym >= 0x0041 && keysym <= 0x005A) return; // Assume [a-z] never require AltGr if (keysym >= 0x0061 && keysym <= 0x007A) return; // Release Ctrl+Alt if the keysym is printable if (keysym <= 0xFF || (keysym & 0xFF000000) === 0x01000000) { release_key(0xFFE3); // Left ctrl release_key(0xFFE4); // Right ctrl release_key(0xFFE9); // Left alt release_key(0xFFEA); // Right alt } }
Releases Ctrl+Alt, if both are currently pressed and the given keysym looks like a key that may require AltGr. @param {Number} keysym The key that was just pressed.
release_simulated_altgr
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function interpret_event() { // Peek at first event in log var first = eventLog[0]; if (!first) return null; // Keydown event if (first instanceof KeydownEvent) { var keysym = null; var accepted_events = []; // If event itself is reliable, no need to wait for other events if (first.reliable) { keysym = first.keysym; accepted_events = eventLog.splice(0, 1); } // If keydown is immediately followed by a keypress, use the indicated character else if (eventLog[1] instanceof KeypressEvent) { keysym = eventLog[1].keysym; accepted_events = eventLog.splice(0, 2); } // If there is a keyup already, the event must be handled now else if (indexof_keyup(first) !== -1) { keysym = first.keysym; accepted_events = eventLog.splice(0, 1); } // Fire a key press if valid events were found if (accepted_events.length > 0) { if (keysym) { // Fire event release_simulated_altgr(keysym); var defaultPrevented = !press_key(keysym); recentKeysym[first.keyCode] = keysym; // If a key is pressed while meta is held down, the keyup will // never be sent in Chrome, so send it now. (bug #108404) if (guac_keyboard.modifiers.meta && keysym !== 0xFFE7 && keysym !== 0xFFE8) release_key(keysym); // Record whether default was prevented for (var i=0; i<accepted_events.length; i++) accepted_events[i].defaultPrevented = defaultPrevented; } return first; } } // end if keydown // Keyup event else if (first instanceof KeyupEvent) { var keysym = first.keysym; if (keysym) { release_key(keysym); first.defaultPrevented = true; } return eventLog.shift(); } // end if keyup // Ignore any other type of event (keypress by itself is invalid) else return eventLog.shift(); // No event interpreted return null; }
Reads through the event log, interpreting the first event, if possible, and returning that event. If no events can be interpreted, due to a total lack of events or the need for more events, null is returned. Any interpreted events are automatically removed from the log. @return {KeyEvent} The first key event in the log, if it can be interpreted, or null otherwise.
interpret_event
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function resize(newWidth, newHeight) { // Only preserve old data if width/height are both non-zero var oldData = null; if (layer.width !== 0 && layer.height !== 0) { // Create canvas and context for holding old data oldData = document.createElement("canvas"); oldData.width = layer.width; oldData.height = layer.height; var oldDataContext = oldData.getContext("2d"); // Copy image data from current oldDataContext.drawImage(canvas, 0, 0, layer.width, layer.height, 0, 0, layer.width, layer.height); } // Preserve composite operation var oldCompositeOperation = context.globalCompositeOperation; // Resize canvas canvas.width = newWidth; canvas.height = newHeight; // Redraw old data, if any if (oldData) context.drawImage(oldData, 0, 0, layer.width, layer.height, 0, 0, layer.width, layer.height); // Restore composite operation context.globalCompositeOperation = oldCompositeOperation; layer.width = newWidth; layer.height = newHeight; // Acknowledge reset of stack (happens on resize of canvas) stackSize = 0; context.save(); }
Resizes the canvas element backing this Layer without testing the new size. This function should only be used internally. @private @param {Number} newWidth The new width to assign to this Layer. @param {Number} newHeight The new height to assign to this Layer.
resize
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Layer.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Layer.js
MIT
function fitRect(x, y, w, h) { // Calculate bounds var opBoundX = w + x; var opBoundY = h + y; // Determine max width var resizeWidth; if (opBoundX > layer.width) resizeWidth = opBoundX; else resizeWidth = layer.width; // Determine max height var resizeHeight; if (opBoundY > layer.height) resizeHeight = opBoundY; else resizeHeight = layer.height; // Resize if necessary layer.resize(resizeWidth, resizeHeight); }
Given the X and Y coordinates of the upper-left corner of a rectangle and the rectangle's width and height, resize the backing canvas element as necessary to ensure that the rectangle fits within the canvas element's coordinate space. This function will only make the canvas larger. If the rectangle already fits within the canvas element's coordinate space, the canvas is left unchanged. @private @param {Number} x The X coordinate of the upper-left corner of the rectangle to fit. @param {Number} y The Y coordinate of the upper-left corner of the rectangle to fit. @param {Number} w The width of the the rectangle to fit. @param {Number} h The height of the the rectangle to fit.
fitRect
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Layer.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Layer.js
MIT
function cancelEvent(e) { e.stopPropagation(); if (e.preventDefault) e.preventDefault(); e.returnValue = false; }
Cumulative scroll delta amount. This value is accumulated through scroll events and results in scroll button clicks if it exceeds a certain threshold.
cancelEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function press_button(button) { if (!guac_touchscreen.currentState[button]) { guac_touchscreen.currentState[button] = true; if (guac_touchscreen.onmousedown) guac_touchscreen.onmousedown(guac_touchscreen.currentState); } }
Presses the given mouse button, if it isn't already pressed. Valid button values are "left", "middle", "right", "up", and "down". @private @param {String} button The mouse button to press.
press_button
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function release_button(button) { if (guac_touchscreen.currentState[button]) { guac_touchscreen.currentState[button] = false; if (guac_touchscreen.onmouseup) guac_touchscreen.onmouseup(guac_touchscreen.currentState); } }
Releases the given mouse button, if it isn't already released. Valid button values are "left", "middle", "right", "up", and "down". @private @param {String} button The mouse button to release.
release_button
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function click_button(button) { press_button(button); release_button(button); }
Clicks (presses and releases) the given mouse button. Valid button values are "left", "middle", "right", "up", and "down". @private @param {String} button The mouse button to click.
click_button
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function move_mouse(x, y) { guac_touchscreen.currentState.fromClientPosition(element, x, y); if (guac_touchscreen.onmousemove) guac_touchscreen.onmousemove(guac_touchscreen.currentState); }
Moves the mouse to the given coordinates. These coordinates must be relative to the browser window, as they will be translated based on the touch event target's location within the browser window. @private @param {Number} x The X coordinate of the mouse pointer. @param {Number} y The Y coordinate of the mouse pointer.
move_mouse
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function finger_moved(e) { var touch = e.touches[0] || e.changedTouches[0]; var delta_x = touch.clientX - gesture_start_x; var delta_y = touch.clientY - gesture_start_y; return Math.sqrt(delta_x*delta_x + delta_y*delta_y) >= guac_touchscreen.clickMoveThreshold; }
Returns whether the given touch event exceeds the movement threshold for clicking, based on where the touch gesture began. @private @param {TouchEvent} e The touch event to check. @return {Boolean} true if the movement threshold is exceeded, false otherwise.
finger_moved
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function begin_gesture(e) { var touch = e.touches[0]; gesture_in_progress = true; gesture_start_x = touch.clientX; gesture_start_y = touch.clientY; }
Begins a new gesture at the location of the first touch in the given touch event. @private @param {TouchEvent} e The touch event beginning this new gesture.
begin_gesture
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function end_gesture() { window.clearTimeout(click_release_timeout); window.clearTimeout(long_press_timeout); gesture_in_progress = false; }
End the current gesture entirely. Wait for all touches to be done before resuming gesture detection. @private
end_gesture
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function __decode_utf8(buffer) { var text = ""; var bytes = new Uint8Array(buffer); for (var i=0; i<bytes.length; i++) { // Get current byte var value = bytes[i]; // Start new codepoint if nothing yet read if (bytes_remaining === 0) { // 1 byte (0xxxxxxx) if ((value | 0x7F) === 0x7F) text += String.fromCharCode(value); // 2 byte (110xxxxx) else if ((value | 0x1F) === 0xDF) { codepoint = value & 0x1F; bytes_remaining = 1; } // 3 byte (1110xxxx) else if ((value | 0x0F )=== 0xEF) { codepoint = value & 0x0F; bytes_remaining = 2; } // 4 byte (11110xxx) else if ((value | 0x07) === 0xF7) { codepoint = value & 0x07; bytes_remaining = 3; } // Invalid byte else text += "\uFFFD"; } // Continue existing codepoint (10xxxxxx) else if ((value | 0x3F) === 0xBF) { codepoint = (codepoint << 6) | (value & 0x3F); bytes_remaining--; // Write codepoint if finished if (bytes_remaining === 0) text += String.fromCharCode(codepoint); } // Invalid byte else { bytes_remaining = 0; text += "\uFFFD"; } } return text; }
Decodes the given UTF-8 data into a Unicode string. The data may end in the middle of a multibyte character. @private @param {ArrayBuffer} buffer Arbitrary UTF-8 data. @return {String} A decoded Unicode string.
__decode_utf8
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringReader.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringReader.js
MIT
function __expand(bytes) { // Resize buffer if more space needed if (length+bytes >= buffer.length) { var new_buffer = new Uint8Array((length+bytes)*2); new_buffer.set(buffer); buffer = new_buffer; } length += bytes; }
Expands the size of the underlying buffer by the given number of bytes, updating the length appropriately. @private @param {Number} bytes The number of bytes to add to the underlying buffer.
__expand
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
MIT
function __append_utf8(codepoint) { var mask; var bytes; // 1 byte if (codepoint <= 0x7F) { mask = 0x00; bytes = 1; } // 2 byte else if (codepoint <= 0x7FF) { mask = 0xC0; bytes = 2; } // 3 byte else if (codepoint <= 0xFFFF) { mask = 0xE0; bytes = 3; } // 4 byte else if (codepoint <= 0x1FFFFF) { mask = 0xF0; bytes = 4; } // If invalid codepoint, append replacement character else { __append_utf8(0xFFFD); return; } // Offset buffer by size __expand(bytes); var offset = length - 1; // Add trailing bytes, if any for (var i=1; i<bytes; i++) { buffer[offset--] = 0x80 | (codepoint & 0x3F); codepoint >>= 6; } // Set initial byte buffer[offset] = mask | codepoint; }
Appends a single Unicode character to the current buffer, resizing the buffer if necessary. The character will be encoded as UTF-8. @private @param {Number} codepoint The codepoint of the Unicode character to append.
__append_utf8
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
MIT
function __encode_utf8(text) { // Fill buffer with UTF-8 for (var i=0; i<text.length; i++) { var codepoint = text.charCodeAt(i); __append_utf8(codepoint); } // Flush buffer if (length > 0) { var out_buffer = buffer.subarray(0, length); length = 0; return out_buffer; } }
Encodes the given string as UTF-8, returning an ArrayBuffer containing the resulting bytes. @private @param {String} text The string to encode as UTF-8. @return {Uint8Array} The encoded UTF-8 data.
__encode_utf8
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
MIT
function reset_timeout() { // Get rid of old timeout (if any) window.clearTimeout(receive_timeout); // Set new timeout receive_timeout = window.setTimeout(function () { close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout.")); }, tunnel.receiveTimeout); }
Initiates a timeout which, if data is not received, causes the tunnel to close with an error. @private
reset_timeout
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function close_tunnel(status) { // Ignore if already closed if (tunnel.state === Guacamole.Tunnel.State.CLOSED) return; // If connection closed abnormally, signal error. if (status.code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror) { // Ignore RESOURCE_NOT_FOUND if we've already connected, as that // only signals end-of-stream for the HTTP tunnel. if (tunnel.state === Guacamole.Tunnel.State.CONNECTING || status.code !== Guacamole.Status.Code.RESOURCE_NOT_FOUND) tunnel.onerror(status); } // Mark as closed tunnel.state = Guacamole.Tunnel.State.CLOSED; if (tunnel.onstatechange) tunnel.onstatechange(tunnel.state); }
Closes this tunnel, signaling the given status and corresponding message, which will be sent to the onerror handler if the status is an error status. @private @param {Guacamole.Status} status The status causing the connection to close;
close_tunnel
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function getElement(value) { var string = new String(value); return string.length + "." + string; }
Converts the given value to a length/string pair for use as an element in a Guacamole instruction. @private @param value The value to convert. @return {String} The converted value.
getElement
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function makeRequest() { // Make request, increment request ID var xmlhttprequest = new XMLHttpRequest(); xmlhttprequest.open("GET", TUNNEL_READ + tunnel_uuid + ":" + (request_id++)); xmlhttprequest.send(null); return xmlhttprequest; }
Arbitrary integer, unique for each tunnel read request. @private
makeRequest
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function attach(tunnel) { // Set own functions to tunnel's functions chained_tunnel.disconnect = tunnel.disconnect; chained_tunnel.sendMessage = tunnel.sendMessage; /** * Fails the currently-attached tunnel, attaching a new tunnel if * possible. * * @private * @return {Guacamole.Tunnel} The next tunnel, or null if there are no * more tunnels to try. */ function fail_tunnel() { // Get next tunnel var next_tunnel = tunnels.shift(); // If there IS a next tunnel, try using it. if (next_tunnel) { tunnel.onerror = null; tunnel.oninstruction = null; tunnel.onstatechange = null; attach(next_tunnel); } return next_tunnel; } /** * Use the current tunnel from this point forward. Do not try any more * tunnels, even if the current tunnel fails. * * @private */ function commit_tunnel() { tunnel.onstatechange = chained_tunnel.onstatechange; tunnel.oninstruction = chained_tunnel.oninstruction; tunnel.onerror = chained_tunnel.onerror; } // Wrap own onstatechange within current tunnel tunnel.onstatechange = function(state) { switch (state) { // If open, use this tunnel from this point forward. case Guacamole.Tunnel.State.OPEN: commit_tunnel(); if (chained_tunnel.onstatechange) chained_tunnel.onstatechange(state); break; // If closed, mark failure, attempt next tunnel case Guacamole.Tunnel.State.CLOSED: if (!fail_tunnel() && chained_tunnel.onstatechange) chained_tunnel.onstatechange(state); break; } }; // Wrap own oninstruction within current tunnel tunnel.oninstruction = function(opcode, elements) { // Accept current tunnel commit_tunnel(); // Invoke handler if (chained_tunnel.oninstruction) chained_tunnel.oninstruction(opcode, elements); }; // Attach next tunnel on error tunnel.onerror = function(status) { // Mark failure, attempt next tunnel if (!fail_tunnel() && chained_tunnel.onerror) chained_tunnel.onerror(status); }; // Attempt connection tunnel.connect(connect_data); }
Sets the current tunnel. @private @param {Guacamole.Tunnel} tunnel The tunnel to set as the current tunnel.
attach
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function fail_tunnel() { // Get next tunnel var next_tunnel = tunnels.shift(); // If there IS a next tunnel, try using it. if (next_tunnel) { tunnel.onerror = null; tunnel.oninstruction = null; tunnel.onstatechange = null; attach(next_tunnel); } return next_tunnel; }
Fails the currently-attached tunnel, attaching a new tunnel if possible. @private @return {Guacamole.Tunnel} The next tunnel, or null if there are no more tunnels to try.
fail_tunnel
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function commit_tunnel() { tunnel.onstatechange = chained_tunnel.onstatechange; tunnel.oninstruction = chained_tunnel.oninstruction; tunnel.onerror = chained_tunnel.onerror; }
Use the current tunnel from this point forward. Do not try any more tunnels, even if the current tunnel fails. @private
commit_tunnel
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function every (arr, fn, thisObj) { var scope = thisObj || global; for (var i = 0, j = arr.length; i < j; ++i) { if (!fn.call(scope, arr[i], i, arr)) { return false; } } return true; }
Array every compatibility @see bit.ly/5Fq1N2 @api public
every
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/expect.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/expect.js
MIT
function indexOf (arr, o, i) { if (Array.prototype.indexOf) { return Array.prototype.indexOf.call(arr, o, i); } if (arr.length === undefined) { return -1; } for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0 ; i < j && arr[i] !== o; i++); return j <= i ? -1 : i; }
Array indexOf compatibility. @see bit.ly/a5Dxa2 @api public
indexOf
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/expect.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/expect.js
MIT
function isArray(obj) { return '[object Array]' == {}.toString.call(obj); }
Check if `obj` is an array.
isArray
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Hook(title, fn) { Runnable.call(this, title, fn); this.type = 'hook'; }
Initialize a new `Hook` with the given `title` and callback `fn`. @param {String} title @param {Function} fn @api private
Hook
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function visit(obj) { var suite; for (var key in obj) { if ('function' == typeof obj[key]) { var fn = obj[key]; switch (key) { case 'before': suites[0].beforeAll(fn); break; case 'after': suites[0].afterAll(fn); break; case 'beforeEach': suites[0].beforeEach(fn); break; case 'afterEach': suites[0].afterEach(fn); break; default: suites[0].addTest(new Test(key, fn)); } } else { var suite = Suite.create(suites[0], key); suites.unshift(suite); visit(obj[key]); suites.shift(); } } }
TDD-style interface: exports.Array = { '#indexOf()': { 'should return -1 when the value is not present': function(){ }, 'should return the correct index when the value is present': function(){ } } };
visit
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function image(name) { return __dirname + '/../images/' + name + '.png'; }
Return image `name` path. @param {String} name @return {String} @api private
image
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Mocha(options) { options = options || {}; this.files = []; this.options = options; this.grep(options.grep); this.suite = new exports.Suite('', new exports.Context); this.ui(options.ui); this.bail(options.bail); this.reporter(options.reporter); if (null != options.timeout) this.timeout(options.timeout); if (options.slow) this.slow(options.slow); }
Setup mocha with `options`. Options: - `ui` name "bdd", "tdd", "exports" etc - `reporter` reporter instance, defaults to `mocha.reporters.Dot` - `globals` array of accepted globals - `timeout` timeout in milliseconds - `bail` bail on the first test failure - `slow` milliseconds to wait before considering a test slow - `ignoreLeaks` ignore global leaks - `grep` string or regexp to filter tests with @param {Object} options @api public
Mocha
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function parse(str) { var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str); if (!match) return; var n = parseFloat(match[1]); var type = (match[2] || 'ms').toLowerCase(); switch (type) { case 'years': case 'year': case 'y': return n * y; case 'days': case 'day': case 'd': return n * d; case 'hours': case 'hour': case 'h': return n * h; case 'minutes': case 'minute': case 'm': return n * m; case 'seconds': case 'second': case 's': return n * s; case 'ms': return n; } }
Parse the given `str` and return milliseconds. @param {String} str @return {Number} @api private
parse
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function short(ms) { if (ms >= d) return Math.round(ms / d) + 'd'; if (ms >= h) return Math.round(ms / h) + 'h'; if (ms >= m) return Math.round(ms / m) + 'm'; if (ms >= s) return Math.round(ms / s) + 's'; return ms + 'ms'; }
Short format for `ms`. @param {Number} ms @return {String} @api private
short
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function long(ms) { return plural(ms, d, 'day') || plural(ms, h, 'hour') || plural(ms, m, 'minute') || plural(ms, s, 'second') || ms + ' ms'; }
Long format for `ms`. @param {Number} ms @return {String} @api private
long
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Base(runner) { var self = this , stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 } , failures = this.failures = []; if (!runner) return; this.runner = runner; runner.stats = stats; runner.on('start', function(){ stats.start = new Date; }); runner.on('suite', function(suite){ stats.suites = stats.suites || 0; suite.root || stats.suites++; }); runner.on('test end', function(test){ stats.tests = stats.tests || 0; stats.tests++; }); runner.on('pass', function(test){ stats.passes = stats.passes || 0; var medium = test.slow() / 2; test.speed = test.duration > test.slow() ? 'slow' : test.duration > medium ? 'medium' : 'fast'; stats.passes++; }); runner.on('fail', function(test, err){ stats.failures = stats.failures || 0; stats.failures++; test.err = err; failures.push(test); }); runner.on('end', function(){ stats.end = new Date; stats.duration = new Date - stats.start; }); runner.on('pending', function(){ stats.pending++; }); }
Initialize a new `Base` reporter. All other reporters generally inherit from this reporter, providing stats such as test duration, number of tests passed / failed etc. @param {Runner} runner @api public
Base
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function pad(str, len) { str = String(str); return Array(len - str.length + 1).join(' ') + str; }
Pad the given `str` to `len`. @param {String} str @param {String} len @return {String} @api private
pad
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function inlineDiff(err, escape) { var msg = errorDiff(err, 'WordsWithSpace', escape); // linenos var lines = msg.split('\n'); if (lines.length > 4) { var width = String(lines.length).length; msg = lines.map(function(str, i){ return pad(++i, width) + ' |' + ' ' + str; }).join('\n'); } // legend msg = '\n' + color('diff removed', 'actual') + ' ' + color('diff added', 'expected') + '\n\n' + msg + '\n'; // indent msg = msg.replace(/^/gm, ' '); return msg; }
Returns an inline diff between 2 strings with coloured ANSI output @param {Error} Error with actual/expected @return {String} Diff @api private
inlineDiff
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function unifiedDiff(err, escape) { var indent = ' '; function cleanUp(line) { if (escape) { line = escapeInvisibles(line); } if (line[0] === '+') return indent + colorLines('diff added', line); if (line[0] === '-') return indent + colorLines('diff removed', line); if (line.match(/\@\@/)) return null; if (line.match(/\\ No newline/)) return null; else return indent + line; } function notBlank(line) { return line != null; } msg = diff.createPatch('string', err.actual, err.expected); var lines = msg.split('\n').splice(4); return '\n ' + colorLines('diff added', '+ expected') + ' ' + colorLines('diff removed', '- actual') + '\n\n' + lines.map(cleanUp).filter(notBlank).join('\n'); }
Returns a unified diff between 2 strings @param {Error} Error with actual/expected @return {String} Diff @api private
unifiedDiff
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function errorDiff(err, type, escape) { var actual = escape ? escapeInvisibles(err.actual) : err.actual; var expected = escape ? escapeInvisibles(err.expected) : err.expected; return diff['diff' + type](actual, expected).map(function(str){ if (str.added) return colorLines('diff added', str.value); if (str.removed) return colorLines('diff removed', str.value); return str.value; }).join(''); }
Return a character diff for `err`. @param {Error} err @return {String} @api private
errorDiff
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function escapeInvisibles(line) { return line.replace(/\t/g, '<tab>') .replace(/\r/g, '<CR>') .replace(/\n/g, '<LF>\n'); }
Returns a string with all invisible characters in plain text @param {String} line @return {String} @api private
escapeInvisibles
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function colorLines(name, str) { return str.split('\n').map(function(str){ return color(name, str); }).join('\n'); }
Color lines for `str`, using the color `name`. @param {String} name @param {String} str @return {String} @api private
colorLines
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function stringify(obj) { if (obj instanceof RegExp) return obj.toString(); return JSON.stringify(obj, null, 2); }
Stringify `obj`. @param {Mixed} obj @return {String} @api private
stringify
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function sameType(a, b) { a = Object.prototype.toString.call(a); b = Object.prototype.toString.call(b); return a == b; }
Check that a / b have the same type. @param {Object} a @param {Object} b @return {Boolean} @api private
sameType
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Doc(runner) { Base.call(this, runner); var self = this , stats = this.stats , total = runner.total , indents = 2; function indent() { return Array(indents).join(' '); } runner.on('suite', function(suite){ if (suite.root) return; ++indents; console.log('%s<section class="suite">', indent()); ++indents; console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title)); console.log('%s<dl>', indent()); }); runner.on('suite end', function(suite){ if (suite.root) return; console.log('%s</dl>', indent()); --indents; console.log('%s</section>', indent()); --indents; }); runner.on('pass', function(test){ console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title)); var code = utils.escape(utils.clean(test.fn.toString())); console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code); }); }
Initialize a new `Doc` reporter. @param {Runner} runner @api public
Doc
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Dot(runner) { Base.call(this, runner); var self = this , stats = this.stats , width = Base.window.width * .75 | 0 , n = 0; runner.on('start', function(){ process.stdout.write('\n '); }); runner.on('pending', function(test){ process.stdout.write(color('pending', Base.symbols.dot)); }); runner.on('pass', function(test){ if (++n % width == 0) process.stdout.write('\n '); if ('slow' == test.speed) { process.stdout.write(color('bright yellow', Base.symbols.dot)); } else { process.stdout.write(color(test.speed, Base.symbols.dot)); } }); runner.on('fail', function(test, err){ if (++n % width == 0) process.stdout.write('\n '); process.stdout.write(color('fail', Base.symbols.dot)); }); runner.on('end', function(){ console.log(); self.epilogue(); }); }
Initialize a new `Dot` matrix test reporter. @param {Runner} runner @api public
Dot
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function HTMLCov(runner) { var jade = require('jade') , file = __dirname + '/templates/coverage.jade' , str = fs.readFileSync(file, 'utf8') , fn = jade.compile(str, { filename: file }) , self = this; JSONCov.call(this, runner, false); runner.on('end', function(){ process.stdout.write(fn({ cov: self.cov , coverageClass: coverageClass })); }); }
Initialize a new `JsCoverage` reporter. @param {Runner} runner @api public
HTMLCov
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function coverageClass(n) { if (n >= 75) return 'high'; if (n >= 50) return 'medium'; if (n >= 25) return 'low'; return 'terrible'; }
Return coverage class for `n`. @return {String} @api private
coverageClass
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function hideSuitesWithout(classname) { var suites = document.getElementsByClassName('suite'); for (var i = 0; i < suites.length; i++) { var els = suites[i].getElementsByClassName(classname); if (0 == els.length) suites[i].className += ' hidden'; } }
Check for suites that do not have elements with `classname`, and hide them.
hideSuitesWithout
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function on(el, event, fn) { if (el.addEventListener) { el.addEventListener(event, fn, false); } else { el.attachEvent('on' + event, fn); } }
Listen on `event` with callback `fn`.
on
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function JSONCov(runner, output) { var self = this , output = 1 == arguments.length ? true : output; Base.call(this, runner); var tests = [] , failures = [] , passes = []; runner.on('test end', function(test){ tests.push(test); }); runner.on('pass', function(test){ passes.push(test); }); runner.on('fail', function(test){ failures.push(test); }); runner.on('end', function(){ var cov = global._$jscoverage || {}; var result = self.cov = map(cov); result.stats = self.stats; result.tests = tests.map(clean); result.failures = failures.map(clean); result.passes = passes.map(clean); if (!output) return; process.stdout.write(JSON.stringify(result, null, 2 )); }); }
Initialize a new `JsCoverage` reporter. @param {Runner} runner @param {Boolean} output @api public
JSONCov
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function map(cov) { var ret = { instrumentation: 'node-jscoverage' , sloc: 0 , hits: 0 , misses: 0 , coverage: 0 , files: [] }; for (var filename in cov) { var data = coverage(filename, cov[filename]); ret.files.push(data); ret.hits += data.hits; ret.misses += data.misses; ret.sloc += data.sloc; } ret.files.sort(function(a, b) { return a.filename.localeCompare(b.filename); }); if (ret.sloc > 0) { ret.coverage = (ret.hits / ret.sloc) * 100; } return ret; }
Map jscoverage data to a JSON structure suitable for reporting. @param {Object} cov @return {Object} @api private
map
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function coverage(filename, data) { var ret = { filename: filename, coverage: 0, hits: 0, misses: 0, sloc: 0, source: {} }; data.source.forEach(function(line, num){ num++; if (data[num] === 0) { ret.misses++; ret.sloc++; } else if (data[num] !== undefined) { ret.hits++; ret.sloc++; } ret.source[num] = { source: line , coverage: data[num] === undefined ? '' : data[num] }; }); ret.coverage = ret.hits / ret.sloc * 100; return ret; }
Map jscoverage data for a single source file to a JSON structure suitable for reporting. @param {String} filename name of the source file @param {Object} data jscoverage coverage data @return {Object} @api private
coverage
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function clean(test) { return { title: test.title , fullTitle: test.fullTitle() , duration: test.duration } }
Return a plain-object representation of `test` free of cyclic properties etc. @param {Object} test @return {Object} @api private
clean
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function List(runner) { Base.call(this, runner); var self = this , stats = this.stats , total = runner.total; runner.on('start', function(){ console.log(JSON.stringify(['start', { total: total }])); }); runner.on('pass', function(test){ console.log(JSON.stringify(['pass', clean(test)])); }); runner.on('fail', function(test, err){ console.log(JSON.stringify(['fail', clean(test)])); }); runner.on('end', function(){ process.stdout.write(JSON.stringify(['end', self.stats])); }); }
Initialize a new `List` test reporter. @param {Runner} runner @api public
List
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function JSONReporter(runner) { var self = this; Base.call(this, runner); var tests = [] , failures = [] , passes = []; runner.on('test end', function(test){ tests.push(test); }); runner.on('pass', function(test){ passes.push(test); }); runner.on('fail', function(test){ failures.push(test); }); runner.on('end', function(){ var obj = { stats: self.stats , tests: tests.map(clean) , failures: failures.map(clean) , passes: passes.map(clean) }; process.stdout.write(JSON.stringify(obj, null, 2)); }); }
Initialize a new `JSON` reporter. @param {Runner} runner @api public
JSONReporter
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function runway() { var buf = Array(width).join('-'); return ' ' + color('runway', buf); }
Initialize a new `Landing` reporter. @param {Runner} runner @api public
runway
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Markdown(runner) { Base.call(this, runner); var self = this , stats = this.stats , level = 0 , buf = ''; function title(str) { return Array(level).join('#') + ' ' + str; } function indent() { return Array(level).join(' '); } function mapTOC(suite, obj) { var ret = obj; obj = obj[suite.title] = obj[suite.title] || { suite: suite }; suite.suites.forEach(function(suite){ mapTOC(suite, obj); }); return ret; } function stringifyTOC(obj, level) { ++level; var buf = ''; var link; for (var key in obj) { if ('suite' == key) continue; if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n'; if (key) buf += Array(level).join(' ') + link; buf += stringifyTOC(obj[key], level); } --level; return buf; } function generateTOC(suite) { var obj = mapTOC(suite, {}); return stringifyTOC(obj, 0); } generateTOC(runner.suite); runner.on('suite', function(suite){ ++level; var slug = utils.slug(suite.fullTitle()); buf += '<a name="' + slug + '"></a>' + '\n'; buf += title(suite.title) + '\n'; }); runner.on('suite end', function(suite){ --level; }); runner.on('pass', function(test){ var code = utils.clean(test.fn.toString()); buf += test.title + '.\n'; buf += '\n```js\n'; buf += code + '\n'; buf += '```\n\n'; }); runner.on('end', function(){ process.stdout.write('# TOC\n'); process.stdout.write(generateTOC(runner.suite)); process.stdout.write(buf); }); }
Initialize a new `Markdown` reporter. @param {Runner} runner @api public
Markdown
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Min(runner) { Base.call(this, runner); runner.on('start', function(){ // clear screen process.stdout.write('\u001b[2J'); // set cursor position process.stdout.write('\u001b[1;3H'); }); runner.on('end', this.epilogue.bind(this)); }
Initialize a new `Min` minimal test reporter (best used with --watch). @param {Runner} runner @api public
Min
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function draw(color, n) { write(' '); write('\u001b[' + color + 'm' + n + '\u001b[0m'); write('\n'); }
Draw the "scoreboard" showing the number of passes, failures and pending tests. @api private
draw
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function indent() { return Array(indents).join(' ') }
Initialize a new `Spec` test reporter. @param {Runner} runner @api public
indent
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function TAP(runner) { Base.call(this, runner); var self = this , stats = this.stats , n = 1 , passes = 0 , failures = 0; runner.on('start', function(){ var total = runner.grepTotal(runner.suite); console.log('%d..%d', 1, total); }); runner.on('test end', function(){ ++n; }); runner.on('pending', function(test){ console.log('ok %d %s # SKIP -', n, title(test)); }); runner.on('pass', function(test){ passes++; console.log('ok %d %s', n, title(test)); }); runner.on('fail', function(test, err){ failures++; console.log('not ok %d %s', n, title(test)); if (err.stack) console.log(err.stack.replace(/^/gm, ' ')); }); runner.on('end', function(){ console.log('# tests ' + (passes + failures)); console.log('# pass ' + passes); console.log('# fail ' + failures); }); }
Initialize a new `TAP` reporter. @param {Runner} runner @api public
TAP
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function title(test) { return test.fullTitle().replace(/#/g, ''); }
Return a TAP-safe title of `test` @param {Object} test @return {String} @api private
title
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function XUnit(runner) { Base.call(this, runner); var stats = this.stats , tests = [] , self = this; runner.on('pass', function(test){ tests.push(test); }); runner.on('fail', function(test){ tests.push(test); }); runner.on('end', function(){ console.log(tag('testsuite', { name: 'Mocha Tests' , tests: stats.tests , failures: stats.failures , errors: stats.failures , skipped: stats.tests - stats.failures - stats.passes , timestamp: (new Date).toUTCString() , time: (stats.duration / 1000) || 0 }, false)); tests.forEach(test); console.log('</testsuite>'); }); }
Initialize a new `XUnit` reporter. @param {Runner} runner @api public
XUnit
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function test(test) { var attrs = { classname: test.parent.fullTitle() , name: test.title , time: test.duration / 1000 }; if ('failed' == test.state) { var err = test.err; attrs.message = escape(err.message); console.log(tag('testcase', attrs, false, tag('failure', attrs, false, cdata(err.stack)))); } else if (test.pending) { console.log(tag('testcase', attrs, false, tag('skipped', {}, true))); } else { console.log(tag('testcase', attrs, true) ); } }
Output tag for the given `test.`
test
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Runnable(title, fn) { this.title = title; this.fn = fn; this.async = fn && fn.length; this.sync = ! this.async; this._timeout = 2000; this._slow = 75; this.timedOut = false; }
Initialize a new `Runnable` with the given `title` and callback `fn`. @param {String} title @param {Function} fn @api private
Runnable
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function multiple(err) { if (emitted) return; emitted = true; self.emit('error', err || new Error('done() called multiple times')); }
Run the test and invoke `fn(err)`. @param {Function} fn @api private
multiple
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Runner(suite) { var self = this; this._globals = []; this.suite = suite; this.total = suite.total(); this.failures = 0; this.on('test end', function(test){ self.checkGlobals(test); }); this.on('hook end', function(hook){ self.checkGlobals(hook); }); this.grep(/.*/); this.globals(this.globalProps().concat(['errno'])); }
Initialize a `Runner` for the given `suite`. Events: - `start` execution started - `end` execution complete - `suite` (suite) test suite execution started - `suite end` (suite) all tests (and sub-suites) have finished - `test` (test) test execution started - `test end` (test) test completed - `hook` (hook) hook execution started - `hook end` (hook) hook complete - `pass` (test) test passed - `fail` (test, err) test failed - `pending` (test) test pending @api public
Runner
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function next(i) { var hook = hooks[i]; if (!hook) return fn(); if (self.failures && suite.bail()) return fn(); self.currentRunnable = hook; hook.ctx.currentTest = self.test; self.emit('hook', hook); hook.on('error', function(err){ self.failHook(hook, err); }); hook.run(function(err){ hook.removeAllListeners('error'); var testError = hook.error(); if (testError) self.fail(self.test, testError); if (err) return self.failHook(hook, err); self.emit('hook end', hook); delete hook.ctx.currentTest; next(++i); }); }
Run hook `name` callbacks and then invoke `fn()`. @param {String} name @param {Function} function @api private
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function next(suite) { self.suite = suite; if (!suite) { self.suite = orig; return fn(); } self.hook(name, function(err){ if (err) { self.suite = orig; return fn(err); } next(suites.pop()); }); }
Run hook `name` for the given array of `suites` in order, and callback `fn(err)`. @param {String} name @param {Array} suites @param {Function} fn @api private
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function next(err) { // if we bail after first err if (self.failures && suite._bail) return fn(); // next test test = tests.shift(); // all done if (!test) return fn(); // grep var match = self._grep.test(test.fullTitle()); if (self._invert) match = !match; if (!match) return next(); // pending if (test.pending) { self.emit('pending', test); self.emit('test end', test); return next(); } // execute test and hook(s) self.emit('test', self.test = test); self.hookDown('beforeEach', function(){ self.currentRunnable = self.test; self.runTest(function(err){ test = self.test; if (err) { self.fail(test, err); self.emit('test end', test); return self.hookUp('afterEach', next); } test.state = 'passed'; self.emit('pass', test); self.emit('test end', test); self.hookUp('afterEach', next); }); }); }
Run tests in the given `suite` and invoke the callback `fn()` when complete. @param {Suite} suite @param {Function} fn @api private
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function next() { var curr = suite.suites[i++]; if (!curr) return done(); self.runSuite(curr, next); }
Run the given `suite` and invoke the callback `fn()` when complete. @param {Suite} suite @param {Function} fn @api private
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT