Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

simulate key event

  • Loading branch information...
commit ed173846060d63120ea9c933436e877a23a63f7a 1 parent 34f16eb
@redmunds redmunds authored
View
24 test/spec/InlineEditorProviders-test.js
@@ -325,6 +325,30 @@ define(function (require, exports, module) {
});
});
+ it("should close inline widget on Esc Key", function () {
+ initInlineTest("test1.html", 0);
+
+ var hostEditor, inlineWidget, inlinePos, savedPos;
+
+ runs(function () {
+ hostEditor = EditorManager.getCurrentFullEditor();
+ inlineWidget = hostEditor.getInlineWidgets()[0];
+ inlinePos = inlineWidget.editors[0].getCursorPos();
+
+ // verify cursor position in inline editor
+ expect(inlinePos).toEqual(this.infos["test1.css"].offsets[0]);
+
+ // close the editor by simulating Esc key
+ var key = 27, // Esc key
+ doc = testWindow.document,
+ element = doc.getElementsByClassName("inline-widget")[0];
+ SpecRunnerUtils.simulateKeyEvent(key, doc, element);
+
+ // verify no inline widgets
+ expect(hostEditor.getInlineWidgets().length).toBe(0);
+ });
+ });
+
it("should not open an inline editor when positioned on textContent", function () {
initInlineTest("test1.html", 3, false);
View
31 test/spec/Menu-test.js
@@ -22,7 +22,7 @@
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
-/*global define, describe, it, expect, beforeEach, afterEach, waitsFor, runs, $ */
+/*global define, describe, it, xit, expect, beforeEach, afterEach, waitsFor, runs, $ */
define(function (require, exports, module) {
'use strict';
@@ -619,7 +619,36 @@ define(function (require, exports, module) {
// verify all dropdowns are closed
var $menus = testWindow.$(".dropdown.open");
expect($menus.length).toBe(0);
+ });
+
+ it("close context menu using Esc key", function () {
+ CommandManager.register("Brackets Test Command Custom", "custom.command", function () {});
+ var cmenu = Menus.registerContextMenu("test-cmenu");
+ var menuItem = cmenu.addMenuItem("custom.command");
+
+ var closeEvent = false;
+ testWindow.$(cmenu).on("contextMenuClose", function () {
+ closeEvent = true;
+ });
+ cmenu.open({pageX: 0, pageY: 0});
+
+ // verify dropdown is open
+ var $menus = testWindow.$(".dropdown.open");
+ expect($menus.length).toBe(1);
+
+ // close the context menu by simulating Esc key
+ var key = 27, // Esc key
+ doc = testWindow.document,
+ element = doc.getElementsByClassName("dropdown open")[0];
+ SpecRunnerUtils.simulateKeyEvent(key, doc, element);
+ // verify close event
+ // TODO: issue #1270
+ //expect(closeEvent).toBeTruthy();
+
+ // verify all dropdowns are closed
+ $menus = testWindow.$(".dropdown.open");
+ expect($menus.length).toBe(0);
});
});
});
View
39 test/spec/SpecRunnerUtils.js
@@ -475,6 +475,44 @@ define(function (require, exports, module) {
return result.promise();
}
+ /**
+ * Simulate key event
+ *
+ * TODO: need parameter(s) for modifier keys
+ *
+ * @param {number} key - key code
+ * @param {HTMLDocument} doc - containing document
+ * @param {HTMLElement} element - element to receive event
+ */
+ function simulateKeyEvent(key, doc, element) {
+ var oEvent = doc.createEvent('KeyboardEvent');
+
+ // Chromium Hack
+ Object.defineProperty(oEvent, 'keyCode', {
+ get : function() {
+ return this.keyCodeVal;
+ }
+ });
+ Object.defineProperty(oEvent, 'which', {
+ get : function() {
+ return this.keyCodeVal;
+ }
+ });
+
+ if (oEvent.initKeyboardEvent) {
+ oEvent.initKeyboardEvent("keydown", true, true, doc.defaultView, false, false, false, false, key, key);
+ } else {
+ oEvent.initKeyEvent("keydown", true, true, doc.defaultView, false, false, false, false, key, 0);
+ }
+
+ oEvent.keyCodeVal = key;
+ if (oEvent.keyCode !== key) {
+ console.log("keyCode mismatch " + oEvent.keyCode + "(" + oEvent.which + ")");
+ }
+
+ element.dispatchEvent(oEvent);
+ }
+
function getTestWindow() {
return testWindow;
}
@@ -497,4 +535,5 @@ define(function (require, exports, module) {
exports.saveFileWithoutOffsets = saveFileWithoutOffsets;
exports.deleteFile = deleteFile;
exports.getTestWindow = getTestWindow;
+ exports.simulateKeyEvent = simulateKeyEvent;
});
Please sign in to comment.
Something went wrong with that request. Please try again.