OpenLayers OpenLayers

Changeset 3705

Show
Ignore:
Timestamp:
07/11/07 14:44:39 (1 year ago)
Author:
tschaub
Message:

more tests (17) for the handler base class - these for checkModifiers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/tests/test_Handler.html

    r3697 r3705  
    120120             "handler.map is null after destroy"); 
    121121    } 
     122     
     123    function test_Handler_checkModifiers(t) { 
     124        t.plan(17); 
     125        var handler = new OpenLayers.Handler({}); 
     126        handler.keyMask = null; 
     127        var proceed = handler.checkModifiers({}); 
     128        t.ok(proceed, 
     129             "checkModifiers returns true if no keyMask on the handler"); 
     130         
     131        var constants = { 
     132            MOD_NONE: null, 
     133            MOD_SHIFT: "shiftKey", 
     134            MOD_CTRL: "ctrlKey", 
     135            MOD_ALT: "altKey" 
     136        } 
     137         
     138        /** 
     139         * Test checkModifiers for single keyMask values.  The method should 
     140         *     return false if the corresponding key is associated with the 
     141         *     event.  For example, if evt.shiftKey is true and handler.keyMask 
     142         *     is OpenLayers.Handler.MOD_SHIFT, checkModifiers should return 
     143         *     true. 
     144         */ 
     145        var proceed, evt, value, c, k; 
     146        for(c in constants) { 
     147            handler.keyMask = OpenLayers.Handler[c]; 
     148            // for this key mask, we want to test all single key possibilities 
     149            for(k in constants) { 
     150                value = constants[k]; 
     151                evt = {}; 
     152                if(value) { 
     153                    // mimic a key down on an event 
     154                    evt[value] = true; 
     155                } 
     156                proceed = handler.checkModifiers(evt); 
     157                // if k == c, proceed should be true - false otherwise 
     158                t.eq(k == c, proceed, 
     159                     "returns " + proceed + " if keyMask is " + c + 
     160                     " and " + ((value) ? value : "no key") + " is down"); 
     161            } 
     162        } 
     163             
     164    } 
    122165 
    123166  // -->