Files
openlayers/tests/Layer/test_GeoRSS.html
crschmidt 0fa07edb04 Firefox 2.0.0.13 changed behavior iwth regard to loading files relative to an
iframe included in a page from matching every other browser to matching IE.
Rather than try and guess what's going to happen with this in the future, at
the moment, just duplicate the data, in hopes of a more sane solution coming 
along in the future for all our data loading needs.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@6712 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2008-03-31 02:41:26 +00:00

208 lines
9.6 KiB
HTML

<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var isMSIE = (navigator.userAgent.indexOf("MSIE") > -1);
var layer;
var georss_txt = "./georss.txt";
var atom_xml = "./atom-1.0.xml";
// The actual path these files are read from differs:
// some browsers treat relative paths from within an iframe
// as relative to the parent, some treat them as relative to the child
// At this time:
// * IE6 + IE7
// * Firefox 2.0.0.13+
// read them from relative to the iframe contents, rather than parent,
// so these files are in *two* places: one in the "Layer/" subdirectory,
// and one in the root. This majorly sucks, but it's a way to keep it
// working without hardcoding a version number into the tests.
function test_01_Layer_GeoRSS_constructor (t) {
t.plan( 5 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt );
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" );
t.eq( layer.location, georss_txt, "layer.location is correct" );
var markers;
layer.loadRSS();
t.delay_call( 1, function() {
t.eq( layer.markers.length, 40, "marker length is correct" );
var ll = new OpenLayers.LonLat(-71.142197, 42.405696);
t.ok( layer.markers[0].lonlat.equals(ll), "lonlat on first marker is correct" );
t.eq( layer.name, "Crschmidt's Places At Platial", "Layer name is correct." );
} );
}
function test_Layer_GeoRSS_dontUseFeedTitle (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt, {'useFeedTitle': false} );
t.delay_call( 1, function() {
t.eq( layer.name, "Test Layer", "Layer name is correct when not used from feed." );
} );
}
function test_01_Layer_GeoRSS_AtomParsing (t) {
t.plan( 6 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', atom_xml );
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" );
t.eq( layer.location, atom_xml, "layer.location is correct" );
var markers;
layer.loadRSS();
t.delay_call( 1, function() {
t.eq( layer.markers.length, 2, "marker length is correct" );
var ll = new OpenLayers.LonLat(29.9805, 36.7702);
t.ok( layer.markers[0].lonlat.equals(ll), "lonlat on first marker is correct" );
t.like( layer.features[0].data['popupContentHTML'], '<a class="link" href="http://pleiades.stoa.org/places/638896" target="_blank">Unnamed Tumulus</a>', "Link is correct.");
t.eq( layer.name, "tumulus", "Layer name is correct." );
} );
}
function test_02_Layer_GeoRSS_draw (t) {
// t.plan(5);
t.plan( 2 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt);
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" );
var map = new OpenLayers.Map('map');
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(baseLayer);
map.addLayer(layer);
t.delay_call( 1, function() {
map.setCenter(new OpenLayers.LonLat(0,0),0);
t.eq( map.layers[1].name, layer.name, "Layer name is correct" );
});;
}
function test_03_Layer_GeoRSS_events (t) {
t.plan( 4 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt);
var map = new OpenLayers.Map('map');
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(baseLayer);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),0);
var event = {};
t.delay_call( 2, function() {
t.ok(layer.markers[0].events, "First marker has an events object");
t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object");
layer.markers[0].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "Popup opened correctly");
layer.markers[1].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
});
}
function test_Layer_GeoRSS_popups (t) {
t.plan( 8 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt);
var map = new OpenLayers.Map('map');
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(baseLayer);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),0);
var event = {};
t.delay_call( 1, function() {
t.ok(layer.markers[0].events, "First marker has an events object");
t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object");
layer.markers[0].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "Popup opened correctly");
t.eq(map.popups[0].size.w, 250, "Popup sized correctly x");
t.eq(map.popups[0].size.h, 120, "Popup sized correctly y");
layer.markers[1].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
t.eq(map.popups[0].size.w, 250, "Popup sized correctly x");
t.eq(map.popups[0].size.h, 120, "Popup sized correctly y");
});
}
function test_Layer_GeoRSS_resizedPopups(t) {
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt, {'popupSize': new OpenLayers.Size(200,100)});
t.plan( 8 );
var map = new OpenLayers.Map('map');
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(baseLayer);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),0);
var event = {};
t.delay_call( 1, function() {
t.ok(layer.markers[0].events, "First marker has an events object");
t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object");
layer.markers[0].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "Popup opened correctly");
t.eq(map.popups[0].size.w, 200, "Popup sized correctly x");
t.eq(map.popups[0].size.h, 100, "Popup sized correctly y");
map.popups[0].size.w=300;
layer.markers[1].events.triggerEvent('click', event);
t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
t.eq(map.popups[0].size.w, 200, "Popup sized correctly x");
t.eq(map.popups[0].size.h, 100, "Popup sized correctly y");
});
}
function test_04_Layer_GeoRSS_icon(t) {
t.plan( 3 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt);
var the_icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png');
var otherLayer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt,{icon:the_icon});
var map = new OpenLayers.Map('map');
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(baseLayer);
map.addLayers([layer,otherLayer]);
map.setCenter(new OpenLayers.LonLat(0,0),0);
var defaultIcon = OpenLayers.Marker.defaultIcon();
layer.loadRSS();
otherLayer.loadRSS();
t.delay_call( 2, function() {
t.ok(layer.markers[0].icon, "The layer has a icon");
t.eq(layer.markers[0].icon.url, defaultIcon.url, "The layer without icon has the default icon.");
t.eq(otherLayer.markers[0].icon.url, the_icon.url,"The layer with an icon has that icon.");
});
}
function test_Layer_GeoRSS_loadend_Event(t) {
var browserCode = OpenLayers.Util.getBrowserName();
if (browserCode == "msie") {
t.plan(1);
t.ok(true, "IE fails the GeoRSS test. This could probably be fixed by someone with enough energy to fix it.");
} else {
t.plan(2);
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt);
t.delay_call(2, function() {
layer.events.register('loadend', layer, function() {
t.ok(true, "Loadend event fired");
});
layer.parseData({
'responseText': '<xml xmlns="http://example.com"><title> </title></xml>'
});
t.ok(true, "Parsing data didn't fail");
});
}
}
function test_99_Layer_GeoRSS_destroy (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt);
var map = new OpenLayers.Map('map');
map.addLayer(layer);
t.delay_call( 1, function() {
layer.destroy();
t.eq( layer.map, null, "layer.map is null after destroy" );
});
}
</script>
</head>
<body>
<div id="map" style="width:500px; height:500px"></div>
</body>
</html>