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
|
<html>
<head>
<script src="OLLoader.js"></script>
<script type="text/javascript">
var tile;
var map, layer;
function setUp() {
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer(null, {
isBaseLayer: true
});
map.addLayer(layer)
map.setCenter(new OpenLayers.LonLat(0, 0));
}
function tearDown() {
map.destroy();
map = null;
layer = null;
}
function test_Tile_constructor (t) {
t.plan( 13 );
setUp();
var dummy = {};
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "bobob";
var size = new OpenLayers.Size(5,6);
tile = new OpenLayers.Tile(layer, position, bounds, url, size, {
eventListeners: {
loadstart: OpenLayers.Function.False
}
});
t.ok(tile instanceof OpenLayers.Tile, "new OpenLayers.Tile returns Tile object");
t.ok(tile.layer === layer, "tile.layer set correctly");
t.ok(tile.position.equals(position), "tile.position set correctly");
t.ok(tile.position != position, "tile.position set not by reference");
t.ok(tile.bounds.equals(bounds), "tile.bounds set correctly");
t.ok(tile.bounds != bounds, "tile.bounds set not by reference");
t.eq(tile.url, url, "tile.url set correctly");
t.ok(tile.size.equals(size), "tile.size is set correctly");
t.ok(tile.size != size, "tile.size set not by reference");
t.ok(tile.id != null, "tile is given an id");
t.ok(OpenLayers.String.startsWith(tile.id, "Tile_"),
"tile's id starts correctly");
t.ok(tile.events != null, "tile's events initialized");
t.ok(tile.events.listeners.loadstart.length == 1,
"tile's events initialized from eventListeners option");
tearDown();
}
function test_Tile_draw(t) {
t.plan(6);
setUp();
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "bobob";
var size = new OpenLayers.Size(5,6);
tile = new OpenLayers.Tile(layer, position, bounds, url, size);
var log = [];
tile.clear = function() {
log.push("clear");
}
tile.draw();
t.eq(log.length, 1, "Tile cleared before drawing");
log = [];
tile.events.register("beforedraw", this, function() {
log.push("beforedraw");
return false;
});
var drawn = tile.draw();
t.eq(log[0], "clear", "tile cleared");
t.eq(log[1], "beforedraw", "beforedraw event fired");
t.eq(drawn, null, "tile not drawn when beforedraw listener returns false");
drawn = tile.draw(true);
t.eq(log.length, 2, "no beforedraw event fired and tile not cleared when draw called with 'deferred' argument set to true");
t.eq(drawn, true, "tile drawn when draw called with 'deferred' argument set to true");
tearDown();
}
function test_Tile_destroy(t) {
t.plan( 6 );
setUp();
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "bobob";
var size = new OpenLayers.Size(5,6);
tile = new OpenLayers.Tile(layer, position, bounds, url, size);
tile.events.destroy = function() {
t.ok(true, "tile events destroy() called");
};
tile.destroy();
t.ok(tile.layer == null, "tile.layer set to null");
t.ok(tile.bounds == null, "tile.bounds set to null");
t.ok(tile.size == null, "tile.size set to null");
t.ok(tile.position == null, "tile.position set to null");
t.ok(tile.events == null, "tile.events set to null");
tearDown();
}
</script>
</head>
<body>
</body>
</html>
|