Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRalf Sternberg2011-01-27 17:35:54 +0000
committerRalf Sternberg2011-01-27 17:35:54 +0000
commite0a5784a90f93ebd6370976948cdef5e079a729b (patch)
tree5c67141256c7d4228b6adf78cd6d525c065ade1d /tests
parent4eb80bbe3926e94c21592d4891ef2e8b95119c68 (diff)
downloadorg.eclipse.rap-e0a5784a90f93ebd6370976948cdef5e079a729b.tar.gz
org.eclipse.rap-e0a5784a90f93ebd6370976948cdef5e079a729b.tar.xz
org.eclipse.rap-e0a5784a90f93ebd6370976948cdef5e079a729b.zip
Fixed bug 282449: Keybindings in RAP
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282449
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/index.html3
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/TestRunner.js1
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js12
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js30
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/AsyncKeyEventUtilTest.js (renamed from tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js)18
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js188
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js58
-rw-r--r--tests/org.eclipse.rap.rwt.q07.jstest/index.html3
-rw-r--r--tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/TestRunner.js1
-rw-r--r--tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js12
-rw-r--r--tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js30
-rw-r--r--tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/AsyncKeyEventUtilTest.js (renamed from tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js)18
-rw-r--r--tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js188
-rw-r--r--tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js58
-rw-r--r--tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java3
-rw-r--r--tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/displaykit/KeyBindingUtil_Test.java126
16 files changed, 700 insertions, 49 deletions
diff --git a/tests/org.eclipse.rap.rwt.jstest/index.html b/tests/org.eclipse.rap.rwt.jstest/index.html
index 35569e4a76..2fceaff7ef 100644
--- a/tests/org.eclipse.rap.rwt.jstest/index.html
+++ b/tests/org.eclipse.rap.rwt.jstest/index.html
@@ -22,10 +22,11 @@
<script src="./js/org/eclipse/rwt/test/tests/CalendarTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/ScrollBarTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/ScrolledCompositeTest.js" type="text/javascript"></script>
+ <script src="./js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/ListTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/ComboTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/EventHandlerTest.js" type="text/javascript"></script>
- <script src="./js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js" type="text/javascript"></script>
+ <script src="./js/org/eclipse/rwt/test/tests/AsyncKeyEventUtilTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/DNDTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/MobileWebkitSupportTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/IFrameTest.js" type="text/javascript"></script>
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/TestRunner.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/TestRunner.js
index 239b2c3c8f..7d72c54871 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/TestRunner.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/TestRunner.js
@@ -206,6 +206,7 @@ qx.Class.define("org.eclipse.rwt.test.TestRunner", {
org.eclipse.rwt.test.fixture.TestUtil.restoreAppearance();
org.eclipse.rwt.test.fixture.TestUtil.emptyDragCache();
org.eclipse.rwt.test.fixture.TestUtil.resetEventHandler();
+ org.eclipse.rwt.test.fixture.TestUtil.cleanUpKeyUtil();
org.eclipse.rwt.test.fixture.TestUtil.clearErrorPage();
qx.ui.core.Widget.flushGlobalQueues();
},
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js
index d80375b590..5f957250ce 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 EclipseSource and others. All rights reserved.
+ * Copyright (c) 2009, 2011 EclipseSource and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -69,7 +69,7 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.RAPServer", {
this.respond( request );
},
- respond : function(request) {
+ respond : function( request ) {
var response = this.handleMessage( request.getData() );
request.setResponse( response );
if( request.getAsynchronous() ){
@@ -79,14 +79,16 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.RAPServer", {
}
},
- handleMessage : function(message) {
+ handleMessage : function( message ) {
this._requestCounter++;
var response = "";
if( this.getRequestHandler() ) {
response += this.getRequestHandler()( message );
}
- response += "org.eclipse.swt.Request.getInstance()." +
- "setRequestCounter("+this._requestCounter+");";
+ response += "org.eclipse.swt.Request.getInstance()."
+ + "setRequestCounter("
+ + this._requestCounter
+ + ");";
return response;
}
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js
index 235d489283..7fbc89b854 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js
@@ -335,23 +335,23 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.TestUtil", {
},
keyDown : function( target, key, mod ) {
- this.fakeKeyEventDOM( target, "keydown", key, mod );
+ this.fireFakeKeyDomEvent( target, "keydown", key, mod );
if( this._sendKeyPress( key ) ) {
- this.fakeKeyEventDOM( target, "keypress", key, mod );
+ this.fireFakeKeyDomEvent( target, "keypress", key, mod );
}
},
keyHold : function( target, key, mod ) {
if( this._sendKeyDownOnHold( key ) ) {
- this.fakeKeyEventDOM( target, "keydown", key, mod );
+ this.fireFakeKeyDomEvent( target, "keydown", key, mod );
}
if( this._sendKeyPress( key ) ) {
- this.fakeKeyEventDOM( target, "keypress", key, mod );
+ this.fireFakeKeyDomEvent( target, "keypress", key, mod );
}
},
keyUp : function( target, key, mod ) {
- this.fakeKeyEventDOM( target, "keyup", key, mod );
+ this.fireFakeKeyDomEvent( target, "keyup", key, mod );
},
_sendKeyDownOnHold : qx.core.Variant.select("qx.client", {
@@ -371,12 +371,20 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.TestUtil", {
return this._isPrintable( key );
}
} ),
-
- fakeKeyEventDOM : function( target, type, stringOrKeyCode, mod ) {
+
+ createFakeDomKeyEvent : function( target, type, stringOrKeyCode, mod ) {
var domEvent = this._createFakeDomEvent( target, type, mod );
domEvent.keyCode = this._getKeyCode( type, stringOrKeyCode );
domEvent.charCode = this._getCharCode( type, stringOrKeyCode );
domEvent.isChar = stringOrKeyCode === "string"; // not always correct
+ return domEvent;
+ },
+
+ fireFakeKeyDomEvent : function( target, type, stringOrKeyCode, mod ) {
+ var domEvent = this.createFakeDomKeyEvent( target,
+ type,
+ stringOrKeyCode,
+ mod );
this.fireFakeDomEvent( domEvent );
},
@@ -808,6 +816,14 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.TestUtil", {
qx.event.handler.DragAndDropHandler.__dragCache = null;
},
+ cleanUpKeyUtil : function() {
+ org.eclipse.rwt.KeyEventUtil.getInstance().setKeyBindings( {} );
+ var instance = org.eclipse.rwt.KeyEventUtil.getInstance()._getDelegate();
+ if( instance instanceof org.eclipse.rwt.AsyncKeyEventUtil ) {
+ instance.cancelEvent();
+ }
+ },
+
/**
* Delays exection of next test function so events may be fired.
* To be used with multi-part tests, i.e. a test that is composed
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/AsyncKeyEventUtilTest.js
index 86aabf8b14..1384bbe762 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/AsyncKeyEventUtilTest.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 EclipseSource and others. All rights reserved.
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -8,7 +8,7 @@
* EclipseSource - initial API and implementation
******************************************************************************/
-qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
+qx.Class.define( "org.eclipse.rwt.test.tests.AsyncKeyEventUtilTest", {
extend : qx.core.Object,
@@ -22,7 +22,7 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
TARGETENGINE : [ "gecko" ],
testGetInstance : function() {
- var instance = org.eclipse.rwt.KeyEventUtil.getInstance()._getInstance();
+ var instance = org.eclipse.rwt.KeyEventUtil.getInstance()._getDelegate();
assertTrue( instance instanceof org.eclipse.rwt.AsyncKeyEventUtil );
},
@@ -36,7 +36,7 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
assertNull( keyUtil._pendingEventInfo );
assertEquals( 0, testUtil.getRequestsSend() );
// cancel event
- testUtil.fakeKeyEventDOM( node, "keypress", "x" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "x" );
var expected = "org.eclipse.swt.events.keyDown.charCode="
+ "x".charCodeAt( 0 );
assertTrue( testUtil.getMessage().indexOf( expected ) != -1 );
@@ -57,7 +57,7 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
assertNull( keyUtil._pendingEventInfo );
assertEquals( 0, testUtil.getRequestsSend() );
// cancel event
- testUtil.fakeKeyEventDOM( node, "keypress", "x" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "x" );
var expected = "org.eclipse.swt.events.keyDown.charCode="
+ "x".charCodeAt( 0 );
assertTrue( testUtil.getMessage().indexOf( expected ) != -1 );
@@ -80,14 +80,14 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
var node = text._inputElement;
assertEquals( "", text.getComputedValue() );
assertNull( keyUtil._pendingEventInfo );
- testUtil.fakeKeyEventDOM( node, "keypress", "x" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "x" );
assertEquals( 0, keyUtil._bufferedEvents.length );
assertNotNull( keyUtil._pendingEventInfo );
var pending = keyUtil._pendingEventInfo;
- testUtil.fakeKeyEventDOM( node, "keypress", "y" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "y" );
assertEquals( 1, keyUtil._bufferedEvents.length );
assertIdentical( pending, keyUtil._pendingEventInfo );
- testUtil.fakeKeyEventDOM( node, "keypress", "z" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "z" );
assertIdentical( pending, keyUtil._pendingEventInfo );
assertEquals( "", text.getComputedValue() );
assertEquals( 2, keyUtil._bufferedEvents.length );
@@ -112,7 +112,7 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
// cancel event
assertNull( keyUtil._pendingEventInfo );
assertEquals( 0, testUtil.getRequestsSend() );
- testUtil.fakeKeyEventDOM( node, "keydown", 37 );
+ testUtil.fireFakeKeyDomEvent( node, "keydown", 37 );
assertNull( keyUtil._pendingEventInfo );
this._disposeTextWidget( text );
},
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js
new file mode 100644
index 0000000000..4d3cca573b
--- /dev/null
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
+
+qx.Class.define( "org.eclipse.rwt.test.tests.KeyEventUtilTest", {
+
+ extend : qx.core.Object,
+
+ construct : function() {
+ this.base( arguments );
+ org.eclipse.rwt.test.fixture.TestUtil.prepareTimerUse();
+ },
+
+ members : {
+
+ testKeyBindingSingleCharacter : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( {
+ "66" : true
+ } );
+ testUtil.press( widget, "a", false, 0 );
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.press( widget, "c", false, 0 );
+ assertEquals( 1, testUtil.getRequestsSend() );
+ var expected1 = "org.eclipse.swt.events.keyDown=w1";
+ var expected2 = "org.eclipse.swt.events.keyDown.keyCode=66";
+ var msg = testUtil.getMessage();
+ console.log( msg );
+ assertTrue( msg.indexOf( expected1 ) != -1 );
+ assertTrue( msg.indexOf( expected2 ) != -1 );
+ widget.destroy();
+ },
+
+ testKeyBindingPreventDefaultNotCalled : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var prevented = false;
+ var preventDefault = function() {
+ prevented = true;
+ };
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( { "66" : true } );
+ var node = widget._getTargetNode();
+ var event = testUtil.createFakeDomKeyEvent( node, "keydown", "a", 0 );
+ event.preventDefault = preventDefault;
+ testUtil.fireFakeDomEvent( event );
+ var event = testUtil.createFakeDomKeyEvent( node, "keypress", "b", 0 );
+ event.preventDefault = preventDefault;
+ testUtil.fireFakeDomEvent( event );
+ var event = testUtil.createFakeDomKeyEvent( node, "keyup", "b", 0 );
+ event.preventDefault = preventDefault;
+ testUtil.fireFakeDomEvent( event );
+ assertFalse( prevented );
+ widget.destroy();
+ },
+
+ testKeyBindingPreventDefaultCalled : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var prevented = false;
+ var preventDefault = function() {
+ prevented = true;
+ };
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( { "66" : true } );
+ var node = widget._getTargetNode();
+ var event = testUtil.createFakeDomKeyEvent( node, "keydown", "b", 0 );
+ event.preventDefault = preventDefault;
+ testUtil.fireFakeDomEvent( event );
+ assertTrue( prevented );
+ widget.destroy();
+ },
+
+ testKeyBindingWithServerKeyListener : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ widget.setUserData( "isControl", true );
+ widget.setUserData( "keyListener", true );
+ widget.focus();
+ keyUtil.setKeyBindings( { "66" : true } );
+ var instance = keyUtil._getDelegate();
+ assertEquals( 0, testUtil.getRequestsSend() );
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.forceTimerOnce();
+ assertEquals( 1, testUtil.getRequestsSend() );
+ assertTrue( instance._keyEventRequestRunning !== true );
+ widget.destroy();
+ },
+
+ testKeyBindingWithClientKeyListener : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ var log = [];
+ var logger = function( event ) {
+ log.push( event );
+ };
+ widget.addEventListener( "keydown", logger );
+ widget.addEventListener( "keypress", logger );
+ widget.addEventListener( "keyup", logger );
+ widget.focus();
+ keyUtil.setKeyBindings( { "66" : true } );
+ var instance = keyUtil._getDelegate();
+ assertEquals( 0, testUtil.getRequestsSend() );
+ testUtil.press( widget, "a", false, 0 );
+ assertEquals( 0, testUtil.getRequestsSend() );
+ assertEquals( 3, log.length );
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.forceTimerOnce();
+ assertEquals( 1, testUtil.getRequestsSend() );
+ assertEquals( 3, log.length );
+ widget.destroy();
+ },
+
+ testKeyBindingsNoModifiersAllowed : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( {
+ "66" : true
+ } );
+ var dom = qx.event.type.DomEvent;
+ testUtil.press( widget, "b", false, dom.CTRL_MASK );
+ testUtil.press( widget, "b", false, dom.ALT_MASK );
+ testUtil.press( widget, "b", false, dom.SHIFT_MASK );
+ var all = dom.CTRL_MASK | dom.SHIFT_MASK | dom.ALT_MASK;
+ testUtil.press( widget, "b", false, all );
+ assertEquals( 0, testUtil.getRequestsSend() );
+ widget.destroy();
+ },
+
+ testKeyBindingsModifiersNeeded : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( {
+ "SHIFT+66" : true
+ } );
+ var dom = qx.event.type.DomEvent;
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.press( widget, "b", false, dom.ALT_MASK );
+ assertEquals( 0, testUtil.getRequestsSend() );
+ testUtil.press( widget, "b", false, dom.SHIFT_MASK );
+ assertEquals( 1, testUtil.getRequestsSend() );
+ widget.destroy();
+ },
+
+ testKeyBindingsModifiersOrder : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( {
+ "ALT+CTRL+SHIFT+66" : true
+ } );
+ var dom = qx.event.type.DomEvent;
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.press( widget, "b", false, dom.CTRL_MASK );
+ testUtil.press( widget, "b", false, dom.ALT_MASK );
+ testUtil.press( widget, "b", false, dom.SHIFT_MASK );
+ assertEquals( 0, testUtil.getRequestsSend() );
+ var all = dom.CTRL_MASK | dom.SHIFT_MASK | dom.ALT_MASK;
+ testUtil.press( widget, "b", false, all );
+ assertEquals( 1, testUtil.getRequestsSend() );
+ widget.destroy();
+ },
+
+
+ _createWidget : function() {
+ var result = new org.eclipse.rwt.widgets.MultiCellWidget( [] );
+ result.addToDocument();
+ result.setLocation( 0, 0 );
+ result.setDimension( 100, 100 );
+ qx.ui.core.Widget.flushGlobalQueues();
+ return result;
+ }
+
+ }
+
+} ); \ No newline at end of file
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js
index f051e2e80d..8bdcb42e01 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 EclipseSource and others. All rights reserved.
+ * Copyright (c) 2010, 2011 EclipseSource and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -13,7 +13,22 @@ qx.Class.define( "org.eclipse.rwt.test.tests.TestUtilTest", {
extend : qx.core.Object,
members : {
-
+
+ testSendSynchronousRequestsBug : function() {
+ var req = org.eclipse.swt.Request.getInstance();
+ req.send();
+ var counter = req.getRequestCounter();
+ req.sendSyncronous();
+ counter++;
+ assertEquals( counter, req.getRequestCounter() );
+ req.send();
+ counter++;
+ assertEquals( counter, req.getRequestCounter() );
+ req.send();
+ counter++;
+ assertEquals( counter, req.getRequestCounter() );
+ },
+
testGetElementBounds : function() {
var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
var parent = document.createElement( "div" );
@@ -610,9 +625,48 @@ qx.Class.define( "org.eclipse.rwt.test.tests.TestUtilTest", {
assertNull( testUtil.getErrorPage() );
},
+ testCleanUpKeyUtil : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var prevented = false;
+ var preventDefault = function() {
+ prevented = true;
+ };
+ var widget = this._createWidget();
+ widget.setUserData( "isControl", true );
+ widget.setUserData( "keyListener", true );
+ widget.focus();
+ var bindings = { "66" : true };
+ keyUtil.setKeyBindings( bindings );
+ var instance = keyUtil._getDelegate();
+ testUtil.press( widget, "a", false, 0 );
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.press( widget, "c", false, 0 );
+ testUtil.forceTimerOnce();
+ if( instance instanceof org.eclipse.rwt.AsyncKeyEventUtil ) {
+ assertNotNull( instance._pendingEventInfo );
+ }
+ assertIdentical( bindings, keyUtil._keyBindings );
+ testUtil.cleanUpKeyUtil();
+ if( instance instanceof org.eclipse.rwt.AsyncKeyEventUtil ) {
+ assertNull( instance._pendingEventInfo );
+ }
+ assertEquals( {}, keyUtil._keyBindings );
+ widget.destroy();
+ },
+
/////////
// helper
+ _createWidget : function() {
+ var result = new org.eclipse.rwt.widgets.MultiCellWidget( [] );
+ result.addToDocument();
+ result.setLocation( 0, 0 );
+ result.setDimension( 100, 100 );
+ qx.ui.core.Widget.flushGlobalQueues();
+ return result;
+ },
+
_addKeyLogger : function( widget, type, identifier, modifier ) {
var log = [];
var logger = function( event ) {
diff --git a/tests/org.eclipse.rap.rwt.q07.jstest/index.html b/tests/org.eclipse.rap.rwt.q07.jstest/index.html
index 35569e4a76..2fceaff7ef 100644
--- a/tests/org.eclipse.rap.rwt.q07.jstest/index.html
+++ b/tests/org.eclipse.rap.rwt.q07.jstest/index.html
@@ -22,10 +22,11 @@
<script src="./js/org/eclipse/rwt/test/tests/CalendarTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/ScrollBarTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/ScrolledCompositeTest.js" type="text/javascript"></script>
+ <script src="./js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/ListTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/ComboTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/EventHandlerTest.js" type="text/javascript"></script>
- <script src="./js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js" type="text/javascript"></script>
+ <script src="./js/org/eclipse/rwt/test/tests/AsyncKeyEventUtilTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/DNDTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/MobileWebkitSupportTest.js" type="text/javascript"></script>
<script src="./js/org/eclipse/rwt/test/tests/IFrameTest.js" type="text/javascript"></script>
diff --git a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/TestRunner.js b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/TestRunner.js
index 239b2c3c8f..7d72c54871 100644
--- a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/TestRunner.js
+++ b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/TestRunner.js
@@ -206,6 +206,7 @@ qx.Class.define("org.eclipse.rwt.test.TestRunner", {
org.eclipse.rwt.test.fixture.TestUtil.restoreAppearance();
org.eclipse.rwt.test.fixture.TestUtil.emptyDragCache();
org.eclipse.rwt.test.fixture.TestUtil.resetEventHandler();
+ org.eclipse.rwt.test.fixture.TestUtil.cleanUpKeyUtil();
org.eclipse.rwt.test.fixture.TestUtil.clearErrorPage();
qx.ui.core.Widget.flushGlobalQueues();
},
diff --git a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js
index d80375b590..5f957250ce 100644
--- a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js
+++ b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/RAPServer.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 EclipseSource and others. All rights reserved.
+ * Copyright (c) 2009, 2011 EclipseSource and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -69,7 +69,7 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.RAPServer", {
this.respond( request );
},
- respond : function(request) {
+ respond : function( request ) {
var response = this.handleMessage( request.getData() );
request.setResponse( response );
if( request.getAsynchronous() ){
@@ -79,14 +79,16 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.RAPServer", {
}
},
- handleMessage : function(message) {
+ handleMessage : function( message ) {
this._requestCounter++;
var response = "";
if( this.getRequestHandler() ) {
response += this.getRequestHandler()( message );
}
- response += "org.eclipse.swt.Request.getInstance()." +
- "setRequestCounter("+this._requestCounter+");";
+ response += "org.eclipse.swt.Request.getInstance()."
+ + "setRequestCounter("
+ + this._requestCounter
+ + ");";
return response;
}
diff --git a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js
index 235d489283..7fbc89b854 100644
--- a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js
+++ b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/fixture/TestUtil.js
@@ -335,23 +335,23 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.TestUtil", {
},
keyDown : function( target, key, mod ) {
- this.fakeKeyEventDOM( target, "keydown", key, mod );
+ this.fireFakeKeyDomEvent( target, "keydown", key, mod );
if( this._sendKeyPress( key ) ) {
- this.fakeKeyEventDOM( target, "keypress", key, mod );
+ this.fireFakeKeyDomEvent( target, "keypress", key, mod );
}
},
keyHold : function( target, key, mod ) {
if( this._sendKeyDownOnHold( key ) ) {
- this.fakeKeyEventDOM( target, "keydown", key, mod );
+ this.fireFakeKeyDomEvent( target, "keydown", key, mod );
}
if( this._sendKeyPress( key ) ) {
- this.fakeKeyEventDOM( target, "keypress", key, mod );
+ this.fireFakeKeyDomEvent( target, "keypress", key, mod );
}
},
keyUp : function( target, key, mod ) {
- this.fakeKeyEventDOM( target, "keyup", key, mod );
+ this.fireFakeKeyDomEvent( target, "keyup", key, mod );
},
_sendKeyDownOnHold : qx.core.Variant.select("qx.client", {
@@ -371,12 +371,20 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.TestUtil", {
return this._isPrintable( key );
}
} ),
-
- fakeKeyEventDOM : function( target, type, stringOrKeyCode, mod ) {
+
+ createFakeDomKeyEvent : function( target, type, stringOrKeyCode, mod ) {
var domEvent = this._createFakeDomEvent( target, type, mod );
domEvent.keyCode = this._getKeyCode( type, stringOrKeyCode );
domEvent.charCode = this._getCharCode( type, stringOrKeyCode );
domEvent.isChar = stringOrKeyCode === "string"; // not always correct
+ return domEvent;
+ },
+
+ fireFakeKeyDomEvent : function( target, type, stringOrKeyCode, mod ) {
+ var domEvent = this.createFakeDomKeyEvent( target,
+ type,
+ stringOrKeyCode,
+ mod );
this.fireFakeDomEvent( domEvent );
},
@@ -808,6 +816,14 @@ qx.Class.define( "org.eclipse.rwt.test.fixture.TestUtil", {
qx.event.handler.DragAndDropHandler.__dragCache = null;
},
+ cleanUpKeyUtil : function() {
+ org.eclipse.rwt.KeyEventUtil.getInstance().setKeyBindings( {} );
+ var instance = org.eclipse.rwt.KeyEventUtil.getInstance()._getDelegate();
+ if( instance instanceof org.eclipse.rwt.AsyncKeyEventUtil ) {
+ instance.cancelEvent();
+ }
+ },
+
/**
* Delays exection of next test function so events may be fired.
* To be used with multi-part tests, i.e. a test that is composed
diff --git a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/AsyncKeyEventUtilTest.js
index 86aabf8b14..1384bbe762 100644
--- a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js
+++ b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/AsyncKeyEventUtilTest.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 EclipseSource and others. All rights reserved.
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -8,7 +8,7 @@
* EclipseSource - initial API and implementation
******************************************************************************/
-qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
+qx.Class.define( "org.eclipse.rwt.test.tests.AsyncKeyEventUtilTest", {
extend : qx.core.Object,
@@ -22,7 +22,7 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
TARGETENGINE : [ "gecko" ],
testGetInstance : function() {
- var instance = org.eclipse.rwt.KeyEventUtil.getInstance()._getInstance();
+ var instance = org.eclipse.rwt.KeyEventUtil.getInstance()._getDelegate();
assertTrue( instance instanceof org.eclipse.rwt.AsyncKeyEventUtil );
},
@@ -36,7 +36,7 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
assertNull( keyUtil._pendingEventInfo );
assertEquals( 0, testUtil.getRequestsSend() );
// cancel event
- testUtil.fakeKeyEventDOM( node, "keypress", "x" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "x" );
var expected = "org.eclipse.swt.events.keyDown.charCode="
+ "x".charCodeAt( 0 );
assertTrue( testUtil.getMessage().indexOf( expected ) != -1 );
@@ -57,7 +57,7 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
assertNull( keyUtil._pendingEventInfo );
assertEquals( 0, testUtil.getRequestsSend() );
// cancel event
- testUtil.fakeKeyEventDOM( node, "keypress", "x" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "x" );
var expected = "org.eclipse.swt.events.keyDown.charCode="
+ "x".charCodeAt( 0 );
assertTrue( testUtil.getMessage().indexOf( expected ) != -1 );
@@ -80,14 +80,14 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
var node = text._inputElement;
assertEquals( "", text.getComputedValue() );
assertNull( keyUtil._pendingEventInfo );
- testUtil.fakeKeyEventDOM( node, "keypress", "x" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "x" );
assertEquals( 0, keyUtil._bufferedEvents.length );
assertNotNull( keyUtil._pendingEventInfo );
var pending = keyUtil._pendingEventInfo;
- testUtil.fakeKeyEventDOM( node, "keypress", "y" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "y" );
assertEquals( 1, keyUtil._bufferedEvents.length );
assertIdentical( pending, keyUtil._pendingEventInfo );
- testUtil.fakeKeyEventDOM( node, "keypress", "z" );
+ testUtil.fireFakeKeyDomEvent( node, "keypress", "z" );
assertIdentical( pending, keyUtil._pendingEventInfo );
assertEquals( "", text.getComputedValue() );
assertEquals( 2, keyUtil._bufferedEvents.length );
@@ -112,7 +112,7 @@ qx.Class.define( "org.eclipse.rwt.test.tests.ASyncKeyEventUtilTest", {
// cancel event
assertNull( keyUtil._pendingEventInfo );
assertEquals( 0, testUtil.getRequestsSend() );
- testUtil.fakeKeyEventDOM( node, "keydown", 37 );
+ testUtil.fireFakeKeyDomEvent( node, "keydown", 37 );
assertNull( keyUtil._pendingEventInfo );
this._disposeTextWidget( text );
},
diff --git a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js
new file mode 100644
index 0000000000..4d3cca573b
--- /dev/null
+++ b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/KeyEventUtilTest.js
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
+
+qx.Class.define( "org.eclipse.rwt.test.tests.KeyEventUtilTest", {
+
+ extend : qx.core.Object,
+
+ construct : function() {
+ this.base( arguments );
+ org.eclipse.rwt.test.fixture.TestUtil.prepareTimerUse();
+ },
+
+ members : {
+
+ testKeyBindingSingleCharacter : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( {
+ "66" : true
+ } );
+ testUtil.press( widget, "a", false, 0 );
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.press( widget, "c", false, 0 );
+ assertEquals( 1, testUtil.getRequestsSend() );
+ var expected1 = "org.eclipse.swt.events.keyDown=w1";
+ var expected2 = "org.eclipse.swt.events.keyDown.keyCode=66";
+ var msg = testUtil.getMessage();
+ console.log( msg );
+ assertTrue( msg.indexOf( expected1 ) != -1 );
+ assertTrue( msg.indexOf( expected2 ) != -1 );
+ widget.destroy();
+ },
+
+ testKeyBindingPreventDefaultNotCalled : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var prevented = false;
+ var preventDefault = function() {
+ prevented = true;
+ };
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( { "66" : true } );
+ var node = widget._getTargetNode();
+ var event = testUtil.createFakeDomKeyEvent( node, "keydown", "a", 0 );
+ event.preventDefault = preventDefault;
+ testUtil.fireFakeDomEvent( event );
+ var event = testUtil.createFakeDomKeyEvent( node, "keypress", "b", 0 );
+ event.preventDefault = preventDefault;
+ testUtil.fireFakeDomEvent( event );
+ var event = testUtil.createFakeDomKeyEvent( node, "keyup", "b", 0 );
+ event.preventDefault = preventDefault;
+ testUtil.fireFakeDomEvent( event );
+ assertFalse( prevented );
+ widget.destroy();
+ },
+
+ testKeyBindingPreventDefaultCalled : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var prevented = false;
+ var preventDefault = function() {
+ prevented = true;
+ };
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( { "66" : true } );
+ var node = widget._getTargetNode();
+ var event = testUtil.createFakeDomKeyEvent( node, "keydown", "b", 0 );
+ event.preventDefault = preventDefault;
+ testUtil.fireFakeDomEvent( event );
+ assertTrue( prevented );
+ widget.destroy();
+ },
+
+ testKeyBindingWithServerKeyListener : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ widget.setUserData( "isControl", true );
+ widget.setUserData( "keyListener", true );
+ widget.focus();
+ keyUtil.setKeyBindings( { "66" : true } );
+ var instance = keyUtil._getDelegate();
+ assertEquals( 0, testUtil.getRequestsSend() );
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.forceTimerOnce();
+ assertEquals( 1, testUtil.getRequestsSend() );
+ assertTrue( instance._keyEventRequestRunning !== true );
+ widget.destroy();
+ },
+
+ testKeyBindingWithClientKeyListener : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ var log = [];
+ var logger = function( event ) {
+ log.push( event );
+ };
+ widget.addEventListener( "keydown", logger );
+ widget.addEventListener( "keypress", logger );
+ widget.addEventListener( "keyup", logger );
+ widget.focus();
+ keyUtil.setKeyBindings( { "66" : true } );
+ var instance = keyUtil._getDelegate();
+ assertEquals( 0, testUtil.getRequestsSend() );
+ testUtil.press( widget, "a", false, 0 );
+ assertEquals( 0, testUtil.getRequestsSend() );
+ assertEquals( 3, log.length );
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.forceTimerOnce();
+ assertEquals( 1, testUtil.getRequestsSend() );
+ assertEquals( 3, log.length );
+ widget.destroy();
+ },
+
+ testKeyBindingsNoModifiersAllowed : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( {
+ "66" : true
+ } );
+ var dom = qx.event.type.DomEvent;
+ testUtil.press( widget, "b", false, dom.CTRL_MASK );
+ testUtil.press( widget, "b", false, dom.ALT_MASK );
+ testUtil.press( widget, "b", false, dom.SHIFT_MASK );
+ var all = dom.CTRL_MASK | dom.SHIFT_MASK | dom.ALT_MASK;
+ testUtil.press( widget, "b", false, all );
+ assertEquals( 0, testUtil.getRequestsSend() );
+ widget.destroy();
+ },
+
+ testKeyBindingsModifiersNeeded : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( {
+ "SHIFT+66" : true
+ } );
+ var dom = qx.event.type.DomEvent;
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.press( widget, "b", false, dom.ALT_MASK );
+ assertEquals( 0, testUtil.getRequestsSend() );
+ testUtil.press( widget, "b", false, dom.SHIFT_MASK );
+ assertEquals( 1, testUtil.getRequestsSend() );
+ widget.destroy();
+ },
+
+ testKeyBindingsModifiersOrder : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var widget = this._createWidget();
+ keyUtil.setKeyBindings( {
+ "ALT+CTRL+SHIFT+66" : true
+ } );
+ var dom = qx.event.type.DomEvent;
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.press( widget, "b", false, dom.CTRL_MASK );
+ testUtil.press( widget, "b", false, dom.ALT_MASK );
+ testUtil.press( widget, "b", false, dom.SHIFT_MASK );
+ assertEquals( 0, testUtil.getRequestsSend() );
+ var all = dom.CTRL_MASK | dom.SHIFT_MASK | dom.ALT_MASK;
+ testUtil.press( widget, "b", false, all );
+ assertEquals( 1, testUtil.getRequestsSend() );
+ widget.destroy();
+ },
+
+
+ _createWidget : function() {
+ var result = new org.eclipse.rwt.widgets.MultiCellWidget( [] );
+ result.addToDocument();
+ result.setLocation( 0, 0 );
+ result.setDimension( 100, 100 );
+ qx.ui.core.Widget.flushGlobalQueues();
+ return result;
+ }
+
+ }
+
+} ); \ No newline at end of file
diff --git a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js
index f051e2e80d..8bdcb42e01 100644
--- a/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js
+++ b/tests/org.eclipse.rap.rwt.q07.jstest/js/org/eclipse/rwt/test/tests/TestUtilTest.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 EclipseSource and others. All rights reserved.
+ * Copyright (c) 2010, 2011 EclipseSource and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -13,7 +13,22 @@ qx.Class.define( "org.eclipse.rwt.test.tests.TestUtilTest", {
extend : qx.core.Object,
members : {
-
+
+ testSendSynchronousRequestsBug : function() {
+ var req = org.eclipse.swt.Request.getInstance();
+ req.send();
+ var counter = req.getRequestCounter();
+ req.sendSyncronous();
+ counter++;
+ assertEquals( counter, req.getRequestCounter() );
+ req.send();
+ counter++;
+ assertEquals( counter, req.getRequestCounter() );
+ req.send();
+ counter++;
+ assertEquals( counter, req.getRequestCounter() );
+ },
+
testGetElementBounds : function() {
var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
var parent = document.createElement( "div" );
@@ -610,9 +625,48 @@ qx.Class.define( "org.eclipse.rwt.test.tests.TestUtilTest", {
assertNull( testUtil.getErrorPage() );
},
+ testCleanUpKeyUtil : function() {
+ var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
+ var keyUtil = org.eclipse.rwt.KeyEventUtil.getInstance();
+ var prevented = false;
+ var preventDefault = function() {
+ prevented = true;
+ };
+ var widget = this._createWidget();
+ widget.setUserData( "isControl", true );
+ widget.setUserData( "keyListener", true );
+ widget.focus();
+ var bindings = { "66" : true };
+ keyUtil.setKeyBindings( bindings );
+ var instance = keyUtil._getDelegate();
+ testUtil.press( widget, "a", false, 0 );
+ testUtil.press( widget, "b", false, 0 );
+ testUtil.press( widget, "c", false, 0 );
+ testUtil.forceTimerOnce();
+ if( instance instanceof org.eclipse.rwt.AsyncKeyEventUtil ) {
+ assertNotNull( instance._pendingEventInfo );
+ }
+ assertIdentical( bindings, keyUtil._keyBindings );
+ testUtil.cleanUpKeyUtil();
+ if( instance instanceof org.eclipse.rwt.AsyncKeyEventUtil ) {
+ assertNull( instance._pendingEventInfo );
+ }
+ assertEquals( {}, keyUtil._keyBindings );
+ widget.destroy();
+ },
+
/////////
// helper
+ _createWidget : function() {
+ var result = new org.eclipse.rwt.widgets.MultiCellWidget( [] );
+ result.addToDocument();
+ result.setLocation( 0, 0 );
+ result.setDimension( 100, 100 );
+ qx.ui.core.Widget.flushGlobalQueues();
+ return result;
+ },
+
_addKeyLogger : function( widget, type, identifier, modifier ) {
var log = [];
var logger = function( event ) {
diff --git a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java
index 0cad43f6b0..74158eab42 100644
--- a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java
+++ b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2010 Innoopract Informationssysteme GmbH.
+ * Copyright (c) 2002, 2011 Innoopract Informationssysteme GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -145,6 +145,7 @@ public class RWTQ07TestSuite {
suite.addTestSuite( CanvasLCA_Test.class );
suite.addTestSuite( GCOperationWriter_Test.class );
suite.addTestSuite( ToolTipLCA_Test.class );
+ suite.addTestSuite( KeyBindingUtil_Test.class );
return suite;
}
} \ No newline at end of file
diff --git a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/displaykit/KeyBindingUtil_Test.java b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/displaykit/KeyBindingUtil_Test.java
new file mode 100644
index 0000000000..094b7e6333
--- /dev/null
+++ b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/displaykit/KeyBindingUtil_Test.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.internal.widgets.displaykit;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+import org.eclipse.rwt.Fixture;
+import org.eclipse.rwt.internal.lifecycle.JSConst;
+import org.eclipse.rwt.internal.service.ContextProvider;
+import org.eclipse.rwt.internal.service.IServiceStateInfo;
+import org.eclipse.rwt.lifecycle.PhaseId;
+import org.eclipse.rwt.lifecycle.WidgetUtil;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.*;
+
+
+public class KeyBindingUtil_Test extends TestCase {
+
+ protected void setUp() throws Exception {
+ Fixture.setUp();
+ Fixture.fakePhase( PhaseId.PROCESS_ACTION );
+ }
+
+ protected void tearDown() throws Exception {
+ Fixture.tearDown();
+ }
+
+ public void testNoKeyEventsForIllegalWidgetId() {
+ final ArrayList log = new ArrayList();
+ Display display = new Display();
+ display.addFilter( SWT.KeyDown, new Listener() {
+ public void handleEvent( final Event event ) {
+ log.add( event );
+ }
+ } );
+ Fixture.fakeNewRequest();
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN, "" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_KEY_CODE, "32" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_CHAR_CODE, "0" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_MODIFIER, "ctrl,alt" );
+ Fixture.readDataAndProcessAction( display );
+ assertEquals( 0, log.size() );
+ }
+
+ public void testReadKeyBindingEvents() {
+ final ArrayList log = new ArrayList();
+ Display display = new Display();
+ display.addFilter( SWT.KeyDown, new Listener() {
+ public void handleEvent( final Event event ) {
+ log.add( event );
+ }
+ } );
+ Fixture.fakeNewRequest();
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN, "w1" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_KEY_CODE, "32" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_CHAR_CODE, "0" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_MODIFIER, "ctrl,alt" );
+ Fixture.readDataAndProcessAction( display );
+ assertEquals( 1, log.size() );
+ Event event1 = ( Event )log.get( 0 );
+ assertEquals( SWT.KeyDown, event1.type );
+ assertEquals( null, event1.widget );
+ assertEquals( 32, event1.keyCode );
+ assertEquals( 32, event1.character );
+ assertEquals( SWT.CTRL | SWT.ALT, event1.stateMask );
+ Fixture.fakeNewRequest();
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN, "w1" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_KEY_CODE, "116" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_CHAR_CODE, "0" );
+ Fixture.fakeRequestParam( JSConst.EVENT_KEY_DOWN_MODIFIER, "alt,shift" );
+ Fixture.readDataAndProcessAction( display );
+ assertEquals( 2, log.size() );
+ Event event2 = ( Event )log.get( 1 );
+ assertEquals( SWT.KeyDown, event2.type );
+ assertEquals( null, event1.widget );
+ assertEquals( SWT.F5, event2.keyCode );
+ assertEquals( 0, event2.character );
+ assertEquals( SWT.SHIFT | SWT.ALT, event2.stateMask );
+ }
+
+ public void testWriteKeyBindings() throws IOException {
+ Display display = new Display();
+ String[] keyBindings = new String[] {
+ "65536,39",
+ "262144,16777225",
+ "262144,69",
+ "458752,49"
+ };
+ Fixture.fakeNewRequest();
+ IServiceStateInfo stateInfo = ContextProvider.getStateInfo();
+ stateInfo.setAttribute( KeyBindingUtil.KEYBINDING_LIST, keyBindings );
+ KeyBindingUtil.writeKeyBindings( display );
+ String expected
+ = "org.eclipse.rwt.KeyEventUtil.getInstance().setKeyBindings({"
+ + "\"ALT+222\":true,"
+ + "\"CTRL+45\":true,"
+ + "\"CTRL+69\":true,"
+ + "\"ALT+CTRL+SHIFT+49\":true"
+ + "});";
+ assertEquals( expected, Fixture.getAllMarkup() );
+ Fixture.fakeNewRequest();
+ keyBindings = new String[ 0 ];
+ stateInfo = ContextProvider.getStateInfo();
+ stateInfo.setAttribute( KeyBindingUtil.KEYBINDING_LIST, keyBindings );
+ KeyBindingUtil.writeKeyBindings( display );
+ expected = "org.eclipse.rwt.KeyEventUtil.getInstance().setKeyBindings({});";
+ assertEquals( expected, Fixture.getAllMarkup() );
+ Fixture.fakeNewRequest();
+ KeyBindingUtil.writeKeyBindings( display );
+ expected = "";
+ assertEquals( expected, Fixture.getAllMarkup() );
+ }
+
+}

Back to the top