[Commits] r2724 - in sandbox/gxm/geoext/gxm: lib tests/lib

commits at geoext.org commits at geoext.org
Thu May 26 17:01:44 CEST 2011


Author: marcjansen
Date: 2011-05-26 17:01:44 +0200 (Thu, 26 May 2011)
New Revision: 2724

Modified:
   sandbox/gxm/geoext/gxm/lib/Button.js
   sandbox/gxm/geoext/gxm/tests/lib/Button.test.html
Log:
  - tests and refinement for GXM.Button

Modified: sandbox/gxm/geoext/gxm/lib/Button.js
===================================================================
--- sandbox/gxm/geoext/gxm/lib/Button.js	2011-05-26 15:00:42 UTC (rev 2723)
+++ sandbox/gxm/geoext/gxm/lib/Button.js	2011-05-26 15:01:44 UTC (rev 2724)
@@ -47,6 +47,7 @@
                 });
             }
         }
+        
     },
 
     pHandler: function(cmp) {
@@ -55,7 +56,7 @@
            ctrl.type === OpenLayers.Control.TYPE_BUTTON) {
             ctrl.trigger();
         } else {
-            if ( this.pressed ) {
+            if ( !ctrl.active ) {
                 ctrl.activate();
             } else {
                 ctrl.deactivate();
@@ -84,7 +85,8 @@
     
     onCtrlActivate: function(){
         var exclusiveGroupMembers = this.getExclusiveGroupMembers();
-        var myId = this.id; 
+        var myId = this.id;
+        this._isDeactivating = true;
         Ext.each(exclusiveGroupMembers, function(member) {
             if (myId !== member.id) {
                 member.control.deactivate();
@@ -97,13 +99,19 @@
                 }
             }
         });
+        this._isDeactivating = false;
+
+        if (!this.getEl().hasCls(this.pressedCls)) {
+            this.addCls(this.pressedCls);
+        }
     },
     onCtrlDeactivate: function(){
+        if(!this._isDeactivating) {
+            this.removeCls(this.pressedCls);
+        }
     }
-//    ,onPress: function(e){
-//        GXM.Button.superclass.onPress.call(this, e);
-//    }
 });
+
 Ext.reg('gxm_button', GXM.Button);
 
 // usually a Ext.ComponentQuery.query('gxm_button[exclusiveGroup="humpty"]') 

Modified: sandbox/gxm/geoext/gxm/tests/lib/Button.test.html
===================================================================
--- sandbox/gxm/geoext/gxm/tests/lib/Button.test.html	2011-05-26 15:00:42 UTC (rev 2723)
+++ sandbox/gxm/geoext/gxm/tests/lib/Button.test.html	2011-05-26 15:01:44 UTC (rev 2724)
@@ -14,6 +14,32 @@
         
         <!-- load test helper functions -->
         <script type="text/javascript" src="../helperfunctions.js"></script>        
+
+        <script type="text/javascript">
+var recordedEventData = {
+    test_activateControlCalled: { checkpoints: [
+], events: [
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mousedown", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"1600"},
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mouseup", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"1400"},
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"click", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"1200"},
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mousedown", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"1000"},
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mouseup", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"800"},
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"click", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"600"},
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mousedown", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"400"},
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mouseup", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"200"},
+{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"click", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"0"}
+] },
+    test_triggerControlCalled: { checkpoints: [
+        ], events: [
+        {layerX:"9", y:"11", returnValue:"true", clientX:"55", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"55", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1008 DIV", layerY:"6", charCode:"0", type:"mousedown", pageX:"55", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"1000"},
+        {layerX:"9", y:"11", returnValue:"true", clientX:"55", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"55", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1008 DIV", layerY:"6", charCode:"0", type:"mouseup", pageX:"55", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"800"},
+        {layerX:"9", y:"11", returnValue:"true", clientX:"55", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"55", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1008 DIV", layerY:"6", charCode:"0", type:"click", pageX:"55", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"600"},
+        {layerX:"9", y:"11", returnValue:"true", clientX:"15", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"15", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1004 DIV", layerY:"6", charCode:"0", type:"mousedown", pageX:"15", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"400"},
+        {layerX:"9", y:"11", returnValue:"true", clientX:"15", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"15", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1004 DIV", layerY:"6", charCode:"0", type:"mouseup", pageX:"15", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"200"},
+        {layerX:"9", y:"11", returnValue:"true", clientX:"15", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"15", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1004 DIV", layerY:"6", charCode:"0", type:"click", pageX:"15", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"0"}
+        ] }
+};         
+        </script>
         
         <script type="text/javascript">
 
@@ -44,48 +70,25 @@
         t.ok(false, "Since the xtype is not registered, we cannot check whether it points to the right class");
     }
 }
-
-function test_triggerControlCalled(t) {
-    if(Ext.is.Phone){
+/*
+function test_triggerControlCalled(t){
+    if (Ext.is.Phone) {
         t.plan(1);
-        t.ok(true, 'skipped because of missing event emulation for mobile device. TODO revisit.');
+        t.ok(true, 'skipped because of missing event emulation for mobile device. Revisited in test "test_triggerAndHandler".');
         return;
     }
     
-    var expectedBtnClicks = [
-        'zoomIn',
-        'zoomOut'
-    ];
-    t.plan(expectedBtnClicks.length * 2);       
-  
-    t.open_window('./winopen/button-test-window.html', function(wnd) {
+    var expectedBtnClicks = ['zoomIn', 'zoomOut'];
+    t.plan(expectedBtnClicks.length * 2);
     
-    var recordedEvents = {};
-    if(!Ext.is.Phone) {
-        recordedEvents = { checkpoints: [
-        ], events: [
-        {layerX:"9", y:"11", returnValue:"true", clientX:"55", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"55", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1008 DIV", layerY:"6", charCode:"0", type:"mousedown", pageX:"55", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"1000"},
-        {layerX:"9", y:"11", returnValue:"true", clientX:"55", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"55", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1008 DIV", layerY:"6", charCode:"0", type:"mouseup", pageX:"55", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"800"},
-        {layerX:"9", y:"11", returnValue:"true", clientX:"55", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"55", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1008 DIV", layerY:"6", charCode:"0", type:"click", pageX:"55", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"600"},
-        {layerX:"9", y:"11", returnValue:"true", clientX:"15", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"15", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1004 DIV", layerY:"6", charCode:"0", type:"mousedown", pageX:"15", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"400"},
-        {layerX:"9", y:"11", returnValue:"true", clientX:"15", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"15", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1004 DIV", layerY:"6", charCode:"0", type:"mouseup", pageX:"15", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"200"},
-        {layerX:"9", y:"11", returnValue:"true", clientX:"15", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"15", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1004 DIV", layerY:"6", charCode:"0", type:"click", pageX:"15", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"0"}
-        ] };
-    } 
-//    else {
-//        recordedEvents = { checkpoints: [
-//        ], events: [
-//        {layerX:"9", y:"11", returnValue:"true", clientX:"55", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"55", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1008 DIV", layerY:"6", charCode:"0", type:"touchstart", pageX:"55", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"1000"},
-//        {layerX:"9", y:"11", returnValue:"true", clientX:"55", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"55", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1008 DIV", layerY:"6", charCode:"0", type:"touchend", pageX:"55", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"800"},
-//        {layerX:"9", y:"11", returnValue:"true", clientX:"15", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"15", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1004 DIV", layerY:"6", charCode:"0", type:"touchstart", pageX:"15", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"400"},
-//        {layerX:"9", y:"11", returnValue:"true", clientX:"15", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"1695", x:"15", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"6", clientY:"11", ctrlKey:"false", target:"#ext-comp-1004 DIV", layerY:"6", charCode:"0", type:"touchend", pageX:"15", cancelBubble:"false", pageY:"11", clipboardData:null, metaKey:"false", detail:"1", offsetX:"9", relatedTarget:null, screenY:"73", time:"200"}
-//        ] };
-//    }
-            
+    t.open_window('./winopen/button-test-window.html', function(wnd){
+        // grab recorded events
+        var recordedEvents = recordedEventData.test_triggerControlCalled;
+        
         t.replay_events(wnd, recordedEvents);
         
-        t.delay_call(5, function(){
-            Ext.each(expectedBtnClicks, function(expectedBtn) {
+        t.delay_call(1, function(){
+            Ext.each(expectedBtnClicks, function(expectedBtn){
                 t.ok(wnd.btnLogger[expectedBtn].handlerCalled, "Button '" + expectedBtn + "' was clicked and its handler-method invoked.");
                 t.ok(wnd.btnLogger[expectedBtn].triggerCalled, "Button '" + expectedBtn + "' was clicked and its trigger-method invoked.");
             });
@@ -94,40 +97,29 @@
 }
 
 function test_activateControlCalled(t){
-    if(Ext.is.Phone){
+    if (Ext.is.Phone) {
         t.plan(1);
-        t.ok(true, 'skipped because of missing event emulation for mobile device. TODO revisit.');
-        
+        t.ok(true, 'skipped because of missing event emulation for mobile device. Revisited in test "test_activateAndHandler".');
         return;
     }
     
     
     t.plan(3);
     
-    t.open_window('./winopen/button-test-window.html', function(wnd) {
+    t.open_window('./winopen/button-test-window.html', function(wnd){
     
-    var recordedEvents = { checkpoints: [
-], events: [
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mousedown", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"1600"},
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mouseup", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"1400"},
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"click", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"1200"},
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mousedown", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"1000"},
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mouseup", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"800"},
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"click", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"600"},
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mousedown", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"400"},
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"mouseup", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"200"},
-{layerX:"6", y:"10", returnValue:"true", clientX:"924", which:"1", shiftKey:"false", cancelable:"true", bubbles:"true", screenX:"3040", x:"924", button:"0", defaultPrevented:"false", altKey:"false", keyCode:"0", offsetY:"3", clientY:"10", ctrlKey:"false", target:"#ext-comp-1011 DIV", layerY:"3", charCode:"0", type:"click", pageX:"924", cancelBubble:"false", pageY:"10", clipboardData:null, metaKey:"false", detail:"1", offsetX:"6", relatedTarget:null, screenY:"297", time:"0"}
-] };
-            
+        // grab recorded events
+        var recordedEvents = recordedEventData.test_activateControlCalled;
+        
         t.replay_events(wnd, recordedEvents);
         
-        t.delay_call(5, function(){
-            
+        t.delay_call(1, function(){
+        
             t.eq(wnd.btnNavStates.length, 3, "Navigation button was clicked three times.");
             
             var stateAfterFirstClick = wnd.btnNavStates[0];
             var exp_stateAfterSecondClick = (stateAfterFirstClick === 'active') ? 'inactive' : 'active';
-            var exp_stateAfterThirdClick = stateAfterFirstClick
+            var exp_stateAfterThirdClick = stateAfterFirstClick;
             
             t.eq(wnd.btnNavStates[1], exp_stateAfterSecondClick, "State was correct toggled.");
             t.eq(wnd.btnNavStates[2], exp_stateAfterThirdClick, "State was correct toggled.");
@@ -135,8 +127,221 @@
         });
     }, 5);
 }
+*/
 
+function test_triggerAndHandler(t){
+    t.plan(2);
+    
+    t.delay_call(1, function(){
+        var triggerCnt = 0,
+            handlerCnt = 0;
+            
+        var ctrl = new OpenLayers.Control({
+            type: OpenLayers.Control.TYPE_BUTTON,
+            trigger: function() {
+                triggerCnt++;
+            }
+        });
         
+        var btn = new GXM.Button({
+            control: ctrl,
+            mapPanel: getMapPanel(),
+            handler: function() {
+                handlerCnt++;
+            }
+        });
+    
+        var tb = new Ext.Toolbar({
+            renderTo: "btn",
+            items: [btn]
+        });
+    
+        var myToolbar = new Ext.Toolbar({
+            dock: 'top',
+            title: 'My Toolbar',
+            items: [btn] 
+        });
+        
+        var myPanel = new Ext.Panel({
+            dockedItems: [myToolbar],
+            fullscreen: true,
+            html: 'Test Panel'
+        });
+        
+        // press the button, call internal method
+        btn.onPress();
+        
+        t.delay_call(1, function(){
+            t.eq(triggerCnt, 1, 'The controls trigger method has been called once (triggerCnt incremented)');
+            t.eq(handlerCnt, 1, 'The buttons handler method has been called once (handlerCnt incremented)');
+        });
+    });
+}
+
+
+function test_activateAndHandler(t){
+    t.plan(6);
+    
+    var activateCnt = 0,
+        deactivateCnt = 0,
+        handlerCnt = 0;
+        
+    var ctrl = new OpenLayers.Control({
+        activate: function(){
+            activateCnt++;
+            return OpenLayers.Control.prototype.activate.call(this, arguments);
+        },
+        deactivate: function(){
+            deactivateCnt++;
+            return OpenLayers.Control.prototype.deactivate.call(this, arguments);
+        }
+    });
+    ctrl.activate();
+    
+    var btn = new GXM.Button({
+        control: ctrl,
+        mapPanel: getMapPanel(),
+        handler: function() {
+            handlerCnt++;
+        }
+    });
+
+    var myToolbar = new Ext.Toolbar({
+        dock: 'top',
+        title: 'My Toolbar',
+        items: [btn] 
+    });
+    
+    var myPanel = new Ext.Panel({
+        dockedItems: [myToolbar],
+        fullscreen: true,
+        html: 'Test Panel'
+    });
+    
+    // reset
+    activateCnt = 0;
+    deactivateCnt = 0;
+    handlerCnt = 0;
+    
+    // press the button, call internal method
+    btn.onPress();
+    
+    t.delay_call(1, function(){
+        t.eq(activateCnt, 0, 'ctrl.activate() was not called.');
+        t.eq(deactivateCnt, 1, 'ctrl.deactivateCnt() was called.');
+        t.eq(handlerCnt, 1, 'btn.handler-meth0d was called.');
+        
+        // reset
+        activateCnt = 0;
+        deactivateCnt = 0;
+        handlerCnt = 0;
+        
+        // press the button, call internal method
+        btn.onPress();
+        t.delay_call(1, function(){
+            t.eq(activateCnt, 1, 'ctrl.activate() was called.');
+            t.eq(deactivateCnt, 0, 'ctrl.deactivateCnt() was not called.');
+            t.eq(handlerCnt, 1, 'btn.handler-meth0d was called.');
+        });
+    });
+}
+
+function test_handlerGetsControlStatePassed(t){
+    t.plan(4);
+        
+    var passedArguments = {
+        stdBtn: null,
+        gxmBtn: null
+    };
+        
+    var ctrl = new OpenLayers.Control({});
+    ctrl.activate();
+    
+    var stdBtn = new Ext.Button({
+        handler: function(){
+            passedArguments.stdBtn = arguments;
+        }
+    });
+    
+    var gxmBtn = new GXM.Button({
+        control: ctrl,
+        mapPanel: getMapPanel(),
+        handler: function() {
+            passedArguments.gxmBtn = arguments;
+        }
+    });
+
+    var myToolbar = new Ext.Toolbar({
+        dock: 'top',
+        title: 'My Toolbar',
+        items: [gxmBtn, stdBtn] 
+    });
+    
+    var myPanel = new Ext.Panel({
+        dockedItems: [myToolbar],
+        fullscreen: true,
+        html: 'Test Panel'
+    });
+    
+    // press the button, call internal method
+    gxmBtn.onPress();
+    stdBtn.onPress();
+    
+    t.delay_call(1, function(){
+        t.eq(passedArguments.gxmBtn.length, passedArguments.stdBtn.length + 1, 'GXM.Button instances pass one additional argument to the handler-method (compaired to Ext.Button).');
+        t.eq(passedArguments.gxmBtn.length, 3,  'GXM.Button instances pass exactly three arguments');
+        t.ok(Ext.isBoolean(passedArguments.gxmBtn[2]), 'Third argument is a boolean...');
+        t.eq(passedArguments.gxmBtn[2], ctrl.active,  '... that represents the controls active-state.');
+    });
+}
+
+function test_pressedCls(t){
+    t.plan(4);
+    
+    var ctrl = new OpenLayers.Control({});
+    
+    var gxmBtn = new GXM.Button({
+        control: ctrl,
+        mapPanel: getMapPanel()
+    });
+
+    var myToolbar = new Ext.Toolbar({
+        dock: 'top',
+        title: 'My Toolbar',
+        items: [gxmBtn] 
+    });
+    
+    var myPanel = new Ext.Panel({
+        dockedItems: [myToolbar],
+        fullscreen: true,
+        html: 'Test Panel'
+    });
+    
+    // press the button, call internal method
+    gxmBtn.onPress();
+    
+    t.delay_call(1, function(){
+        t.eq(gxmBtn.getEl().hasCls(gxmBtn.pressedCls), gxmBtn.control.active, 'states and pressedCls are in sync (triggered via btn), class present? ' + gxmBtn.getEl().hasCls(gxmBtn.pressedCls) + ', control active? ' + gxmBtn.control.active);
+        // press the button, call internal method
+        gxmBtn.onPress();
+        t.delay_call(1, function(){
+            t.eq(gxmBtn.getEl().hasCls(gxmBtn.pressedCls), gxmBtn.control.active, 'states and pressedCls are in sync (triggered via btn), class present? ' + gxmBtn.getEl().hasCls(gxmBtn.pressedCls) + ', control active? ' + gxmBtn.control.active);
+            
+            // now activate the ctrl, not through the button
+            ctrl.activate(); 
+            t.delay_call(1, function(){
+                t.eq(gxmBtn.getEl().hasCls(gxmBtn.pressedCls), gxmBtn.control.active, 'states and pressedCls are in sync (triggered via ctrl), class present? ' + gxmBtn.getEl().hasCls(gxmBtn.pressedCls) + ', control active? ' + gxmBtn.control.active);
+                
+                // now deactivate the ctrl, not through the button
+                ctrl.deactivate(); 
+                t.delay_call(1, function(){
+                    t.eq(gxmBtn.getEl().hasCls(gxmBtn.pressedCls), gxmBtn.control.active, 'states and pressedCls are in sync (triggered via ctrl), class present? ' + gxmBtn.getEl().hasCls(gxmBtn.pressedCls) + ', control active? ' + gxmBtn.control.active);
+                });
+            });
+        });
+    });
+}
+        
         </script>
     </head>
     <body>



More information about the Commits mailing list