summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Control.html
blob: 06f057cd091d077e92e47139198f98cf5ebbf657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<html>
<head>
  <script src="OLLoader.js"></script>
  <script type="text/javascript">
    function test_Control_constructor(t) {
        t.plan(4);
    
        var control = new OpenLayers.Control();

        t.ok(control instanceof OpenLayers.Control, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControl", "displayClass set correctly");
        t.ok(control.id != null, "default id assigned to control");
        
        var testID = {};
        control = new OpenLayers.Control({ 'id': testID });
        t.ok(control.id == testID, "if id specified in options, no default assigned.");
    }

    function test_Control_addControl(t) {
        t.plan(2);
    
        var map = new OpenLayers.Map('map');
        var control = new OpenLayers.Control();
        map.addControl(control);

        t.ok(control.map === map, "Control.map is set to the map object" );
        t.ok(map.controls[map.controls.length - 1] === control, "map.controls contains control");
    }
    
    function test_Control_title(t) { 
        t.plan( 1 ); 
        var titleText = 'Title test'; 
        control = new OpenLayers.Control({title:titleText}); 
        t.eq( control.title, titleText, "control.title set correctly" ); 
    }
    
    function test_eventListeners(t) {
        t.plan(1);
        
        var method = OpenLayers.Events.prototype.on;
        // test that events.on is called at control construction
        var options = {
            eventListeners: {foo: "bar"}
        };
        OpenLayers.Events.prototype.on = function(obj) {
            t.eq(obj, options.eventListeners, "events.on called with eventListeners");
        }
        var control = new OpenLayers.Control(options);
        OpenLayers.Events.prototype.on = method;
        control.destroy();

        // if events.on is called again, this will fail due to an extra test
        // test control without eventListeners
        OpenLayers.Events.prototype.on = function(obj) {
            t.fail("events.on called without eventListeners");
        }
        var control2 = new OpenLayers.Control();
        OpenLayers.Events.prototype.on = method;
        control2.destroy();
    }

    function test_Control_destroy(t) {
        t.plan(4);
    
        var map = new OpenLayers.Map('map');
        var control = new OpenLayers.Control();
        map.addControl(control);

        control.destroy();
        t.ok(map.controls[map.controls.length - 1] != control, "map.controls doesn't contains control");

        t.ok(control.map == null, "Control.map is null");
        t.ok(control.div == null, "Control.div is null");
        t.ok(control.handler == null, "Control.handler is null");
    }
    
    function test_autoActivate(t) {
        
        t.plan(3);
        
        var control, map = new OpenLayers.Map("map");

        // confirm that a control is not activated by default
        control = new OpenLayers.Control();
        map.addControl(control);
        t.ok(!control.active, "control is not activated by default");
        
        // confirm that control is activated with autoActivate true
        control = new OpenLayers.Control({autoActivate: true});
        map.addControl(control);
        t.ok(control.active, "control is activated with autoActivate true");
       
        // confirm that control is not activated with autoActivate false
        control = new OpenLayers.Control({autoActivate: false});
        map.addControl(control);
        t.ok(!control.active, "control is not activated with autoActivate false");
        
        map.destroy();
        
    }

  </script>
</head>
<body>
    <div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>