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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
var layer;
function test_Layer_EventPane_constructor (t) {
t.plan( 5 );
var layer = new OpenLayers.Layer.EventPane('Test Layer');
t.ok( layer instanceof OpenLayers.Layer.EventPane, "new OpenLayers.Layer.EventPane returns object" );
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.EventPane", "CLASS_NAME variable set correctly");
t.eq( layer.name, "Test Layer", "layer.name is correct" );
t.eq( layer.isBaseLayer, true, "EventPane layer is always base layer" );
if (!isMozilla) {
t.ok( true, "skipping element test outside of Mozilla");
} else {
t.ok( layer.pane instanceof HTMLDivElement, "layer.pane is an HTMLDivElement" );
}
}
function test_Layer_EventPane_clone (t) {
t.plan( 1 );
t.ok( true, "need to actually write some tests here" );
return;
/// FIX ME FIX ME: fix this later
var map = new OpenLayers.Map('map');
var options = { chicken: 151, foo: "bar" };
var layer = new OpenLayers.Layer('Test Layer', options);
map.addLayer(layer);
// randomly assigned property
layer.chocolate = 5;
var clone = layer.clone();
t.ok( clone instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
t.eq( clone.name, "Test Layer", "default clone.name is correct" );
t.ok( ((clone.options["chicken"] == 151) && (clone.options["foo"] == "bar")), "clone.options correctly set" );
t.eq(clone.chocolate, 5, "correctly copied randomly assigned property");
layer.addOptions({chicken:152});
t.eq(clone.options["chicken"], 151, "made a clean copy of options");
t.ok( clone.map == null, "cloned layer has map property set to null")
}
function test_Layer_EventPane_setMap (t) {
// MOUSEMOVE test does not seem to work...
// t.plan( 2 );
if (OpenLayers.BROWSER_NAME != "firefox" && OpenLayers.BROWSER_NAME != "mozilla") {
t.plan(4);
} else {
t.plan(0);
t.debug_print("Firefox gives different results for different browsers on setMap on EventPane, so just don't run it for now.")
return;
}
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.EventPane('Test Layer');
//give dummy function so test wont bomb on layer.setMap()
layer.loadMapObject = function() { };
layer.getWarningHTML = function() { this.warning = true; return ""; };
map.addLayer(layer);
t.eq( parseInt(layer.pane.style.zIndex) - parseInt(layer.div.style.zIndex),
1, "layer pane is 1 z-level above its div" );
t.ok( layer.warning, "warning correctly registered on no mapObject load" );
layer2 = new OpenLayers.Layer.EventPane('Test Layer');
//give dummy function so test wont bomb on layer.setMap()
layer2.loadMapObject = function() { this.mapObject = {}; };
layer2.getWarningHTML = function() { this.warning = true; return ""; }
map.addLayer(layer2);
t.ok(!layer2.warning, "warning not registered on mapObject load");
var log = [];
map.events.register("mousemove", map, function(event) {
log.push(event);
});
if (document.createEvent) { // Mozilla
var evObj = document.createEvent('MouseEvents');
evObj.initEvent('mousemove', true, false);
map.viewPortDiv.dispatchEvent(evObj);
} else if(document.createEventObject) { // IE
map.viewPortDiv.fireEvent('onmousemove');
}
t.eq(log.length, 1, "got one event");
}
function test_Layer_EventPane_setVisibility (t) {
t.plan( 2 );
layer = new OpenLayers.Layer.EventPane('Test Layer');
layer.setVisibility(false);
t.eq(layer.visibility, false, "layer pane is now invisible");
layer.setVisibility(true);
t.eq(layer.visibility, true, "layer pane is now visible");
}
function test_Layer_EventPane_removeLayer(t) {
t.plan(1);
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.EventPane('Test Layer');
layer.loadMapObject = function() { };
layer.getWarningHTML = function() { this.warning = true; return ""; };
map.addLayer(layer);
map.removeLayer(layer);
var parent = layer.pane.parentNode;
// IE creates a DOCUMENT_FRAGMENT_NODE for the parent
t.ok(!parent || parent.nodeType == 11, "Layer.pane removed from dom.");
}
function test_repeat_add(t) {
t.plan(1);
var map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer.EventPane();
layer.loadMapObject = function() {};
layer.getWarningHTML = function() {this.warning = true; return "";};
map.addLayer(layer);
map.removeLayer(layer);
// try adding the layer a second time
var msg = "layer successfully added after being removed";
var pass = true;
try {
map.addLayer(layer);
} catch (err) {
msg = "couldn't add layer after removing: " + err;
pass = false;
}
t.ok(pass, msg);
}
function test_destroy(t) {
t.plan(2);
layer = new OpenLayers.Layer.EventPane();
t.ok(layer.pane, "pane created on initialize");
layer.destroy();
t.ok(!layer.pane, "pane deleted on destroy");
}
</script>
</head>
<body>
<div id="map" style="height:500px;width:500px"></div>
</body>
</html>
|