diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dd1d71ec..d9f714026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ zombie.js-changelog(7) -- Changelog =================================== +Added element offset properties. Google Maps demand these. + + ## Version 0.12.11 2012-01-06 Maintenance update, mostly more test coverage, and updates to dependencies. diff --git a/lib/zombie/jsdom_patches.coffee b/lib/zombie/jsdom_patches.coffee index 0a3e9308b..b39337c88 100644 --- a/lib/zombie/jsdom_patches.coffee +++ b/lib/zombie/jsdom_patches.coffee @@ -3,6 +3,13 @@ HTML = require("jsdom").dom.level3.html URL = require("url") { raise } = require("./helpers") + +HTML.HTMLElement.prototype.__defineGetter__ "offsetLeft", -> 0 +HTML.HTMLElement.prototype.__defineGetter__ "offsetTop", -> 0 +HTML.HTMLElement.prototype.__defineGetter__ "offsetWidth", -> 100 +HTML.HTMLElement.prototype.__defineGetter__ "offsetHeight", -> 100 + + # Default behavior for clicking on links: navigate to new URL is specified. HTML.HTMLAnchorElement.prototype._eventDefaults = click: (event)-> diff --git a/package.json b/package.json index d40a42b72..be1a332a0 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "docco": "~0.3.0", "express": "~2.5.4", "highlight": "~0.2.0", + "replay": "~1.2.2", "ronn": "~0.3.8", "vows": "~0.6.1" }, diff --git a/spec/google_map_spec.coffee b/spec/google_map_spec.coffee new file mode 100644 index 000000000..79304ff34 --- /dev/null +++ b/spec/google_map_spec.coffee @@ -0,0 +1,41 @@ +{ Vows, assert, brains, Browser } = require("./helpers") + + +Vows.describe("Google map").addBatch + + "display": + topic: -> + brains.get "/browser/map", (req, res)-> + res.send """ + +
+ + + + + + + + """ + + brains.ready => + browser = new Browser + browser.visit "http://localhost:3003/browser/map" + browser.wait @callback + "should load map": (browser)-> + assert.ok browser.window.map + "should set bounds": (browser)-> + bounds = browser.window.map.getBounds() + assert.ok bounds, "No map bounds yet" + assert.equal bounds.toString(), "((-34.62332513513795, 150.369341796875), (-34.17006113241608, 150.918658203125))" + + +.export(module) diff --git a/spec/helpers.coffee b/spec/helpers.coffee index 142c2190f..776148297 100644 --- a/spec/helpers.coffee +++ b/spec/helpers.coffee @@ -3,6 +3,7 @@ Express = require("express") WebSocket = require("ws") File = require("fs") Path = require("path") +Replay = require("replay") Browser = require("../lib/zombie.js") @@ -12,8 +13,9 @@ Browser.silent = !Browser.debug # Redirect all HTTP requests to localhost -DNS.lookup = (domain, callback)-> - callback null, "127.0.0.1", 4 +Replay.fixtures = "#{__dirname}/replay" +Replay.networkAccess = true +Replay.ignore "mt0.googleapis.com", "mt1.googleapis.com" # An express server we use to test the browser. diff --git a/spec/replay/maps.googleapis.com/1326781231603 b/spec/replay/maps.googleapis.com/1326781231603 new file mode 100644 index 000000000..009376762 --- /dev/null +++ b/spec/replay/maps.googleapis.com/1326781231603 @@ -0,0 +1,40 @@ +GET /maps/api/js?v=3&sensor=false&callback=initialize +user-agent: Mozilla/5.0 Chrome/10.0.613.0 Safari/534.15 Zombie.js/0.12.11 +host: maps.googleapis.com + +200 HTTP/1.1 +content-type: text/javascript; charset=UTF-8 +date: Tue, 17 Jan 2012 06:20:31 GMT +expires: Tue, 17 Jan 2012 06:50:31 GMT +cache-control: public, max-age=1800 +vary: Accept-Language +server: mafe +x-xss-protection: 1; mode=block +x-frame-options: SAMEORIGIN +transfer-encoding: chunked + + + +window.google = window.google || {}; +google.maps = google.maps || {}; +(function() { + + function getScript(src) { + var s = document.createElement('script'); + + s.src = src; + document.body.appendChild(s); + } + + var modules = google.maps.modules = {}; + google.maps.__gjsload__ = function(name, text) { + modules[name] = text; + }; + + google.maps.Load = function(apiLoad) { + delete google.maps.Load; + apiLoad([null,[[["http://mt0.googleapis.com/vt?lyrs=m@169000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=m@169000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"m@169000000"],[["http://khm0.googleapis.com/kh?v=102\u0026hl=en-US\u0026","http://khm1.googleapis.com/kh?v=102\u0026hl=en-US\u0026"],null,null,null,1,"102"],[["http://mt0.googleapis.com/vt?lyrs=h@169000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=h@169000000\u0026src=api\u0026hl=en-US\u0026"],null,null,"imgtp=png32\u0026",null,"h@169000000"],[["http://mt0.googleapis.com/vt?lyrs=t@128,r@169000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=t@128,r@169000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"t@128,r@169000000"],null,[[null,0,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.15\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.15\u0026hl=en-US\u0026"]],[null,0,8,8,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[354690000,1286700000],[386200000,1320035000]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.15\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.15\u0026hl=en-US\u0026"]],[null,0,9,9,[[[330000000,1246050000],[386200000,1279600000]],[[340000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1302000000]],[[368300000,1302000000],[386200000,1320035000]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.15\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.15\u0026hl=en-US\u0026"]],[null,0,10,19,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.15\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.15\u0026hl=en-US\u0026"]],[null,3,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]],[null,3,8,8,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[354690000,1286700000],[386200000,1320035000]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]],[null,3,9,9,[[[330000000,1246050000],[386200000,1279600000]],[[340000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1302000000]],[[368300000,1302000000],[386200000,1320035000]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]],[null,3,10,null,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]]],[["http://cbk0.googleapis.com/cbk?","http://cbk1.googleapis.com/cbk?"]],[["http://khmdb0.googleapis.com/kh?v=49\u0026hl=en-US\u0026","http://khmdb1.googleapis.com/kh?v=49\u0026hl=en-US\u0026"],null,null,null,null,"49"],[["http://mt0.googleapis.com/mapslt?hl=en-US\u0026","http://mt1.googleapis.com/mapslt?hl=en-US\u0026"]],[["http://mt0.googleapis.com/mapslt/ft?hl=en-US\u0026","http://mt1.googleapis.com/mapslt/ft?hl=en-US\u0026"]],[["http://mt0.googleapis.com/vt?hl=en-US\u0026","http://mt1.googleapis.com/vt?hl=en-US\u0026"]]],["en-US","US",null,0,null,null,"http://maps.gstatic.com/mapfiles/","http://csi.gstatic.com","https://maps.googleapis.com","http://maps.googleapis.com"],["http://maps.gstatic.com/intl/en_us/mapfiles/api-3/7/7","3.7.7"],[2795959736],1.0,null,null,null,null,0,"initialize",null,null,0,"http://khm.googleapis.com/mz?v=102\u0026"], loadScriptTime); + }; + var loadScriptTime = (new Date).getTime(); + getScript("http://maps.gstatic.com/intl/en_us/mapfiles/api-3/7/7/main.js"); +})(); diff --git a/spec/replay/maps.gstatic.com/1326781231887 b/spec/replay/maps.gstatic.com/1326781231887 new file mode 100644 index 000000000..bc1ef088a --- /dev/null +++ b/spec/replay/maps.gstatic.com/1326781231887 @@ -0,0 +1,60 @@ +GET /intl/en_us/mapfiles/api-3/7/7/main.js +user-agent: Mozilla/5.0 Chrome/10.0.613.0 Safari/534.15 Zombie.js/0.12.11 +host: maps.gstatic.com + +200 HTTP/1.1 +vary: Accept-Encoding +content-type: text/javascript +last-modified: Tue, 10 Jan 2012 01:24:16 GMT +date: Thu, 12 Jan 2012 01:22:13 GMT +expires: Fri, 11 Jan 2013 01:22:13 GMT +x-content-type-options: nosniff +server: sffe +x-xss-protection: 1; mode=block +cache-control: public, max-age=31536000 +age: 449898 +transfer-encoding: chunked + +(function(){function aa(a){throw a;}var ba=void 0,i=!0,j=null,k=!1,ca=encodeURIComponent,l=window,da=Object,ea=Infinity,m=document,o=Math,fa=Array,ga=screen,ha=navigator,ia=Error,ja=parseInt,ka=RegExp;function ma(a,b){return a.onload=b}function oa(a,b){return a.center_changed=b}function pa(a,b){return a.isEmpty=b}function qa(a,b){return a.width=b}function ra(a,b){return a.extend=b}function sa(a,b){return a.onerror=b}function ta(a,b){return a.map_changed=b}function ua(a,b){return a.visible_changed=b} +function va(a,b){return a.minZoom=b}function wa(a,b){return a.remove=b}function xa(a,b){return a.equals=b}function ya(a,b){return a.setZoom=b}function za(a,b){return a.tileSize=b}function Ba(a,b){return a.getBounds=b}function Ca(a,b){return a.changed=b}function Da(a,b){return a.clear=b}function Ea(a,b){return a.name=b}function Fa(a,b){return a.overflow=b}function Ga(a,b){return a.getTile=b}function Ha(a,b){return a.toString=b}function Ia(a,b){return a.length=b} +function Ja(a,b){return a.getZoom=b}function Ka(a,b){return a.size=b}function La(a,b){return a.search=b}function Ma(a,b){return a.releaseTile=b}function Na(a,b){return a.controls=b}function Oa(a,b){return a.maxZoom=b}function Pa(a,b){return a.getUrl=b}function Qa(a,b){return a.contains=b}function Ra(a,b){return a.height=b}function Sa(a,b){return a.zoom=b} +var Ta="appendChild",p="push",Ua="isEmpty",Va="fillColor",Xa="deviceXDPI",q="trigger",s="bindTo",Ya="shift",Za="clearTimeout",$a="exec",bb="fromLatLngToPoint",t="width",v="round",cb="slice",db="replace",eb="nodeType",fb="ceil",gb="floor",hb="getVisible",ib="offsetWidth",jb="concat",kb="removeListener",lb="extend",mb="charAt",nb="unbind",ob="preventDefault",pb="getNorthEast",qb="minZoom",rb="indexOf",ub="strokeColor",vb="remove",wb="equals",xb="createElement",zb="atan2",Ab="firstChild",Bb="forEach", +Cb="setZoom",Db="sqrt",w="setAttribute",Eb="setValues",Fb="tileSize",Gb="toUrlValue",Hb="addListenerOnce",Ib="removeAt",Jb="changed",y="type",Kb="getTileUrl",Lb="clearInstanceListeners",z="bind",Mb="name",Nb="getElementsByTagName",Ob="substr",Pb="getTile",Qb="notify",Rb="strokeOpacity",Sb="toString",Tb="setVisible",B="length",Ub="fillOpacity",Vb="onRemove",C="prototype",Wb="setTimeout",Xb="intersects",Yb="document",Zb="split",D="forward",$b="from",bc="getLength",cc="getSouthWest",dc="getAt",ec="message", +fc="hasOwnProperty",E="style",gc="strokeWeight",F="addListener",hc="removeChild",ic="insertAt",jc="target",kc="releaseTile",lc="call",mc="getMap",nc="atan",oc="random",pc="returnValue",qc="charCodeAt",rc="getArray",sc="href",tc="maxZoom",uc="addDomListener",vc="setMap",wc="where",xc="contains",yc="apply",zc="setAt",Ac="tagName",Bc="parentNode",Cc="asin",Dc="label",H="height",Ec="splice",Fc="offsetHeight",Gc="join",Hc="toLowerCase",Ic="ERROR",Jc="INVALID_REQUEST",Kc="MAX_DIMENSIONS_EXCEEDED",Lc="MAX_ELEMENTS_EXCEEDED", +Mc="MAX_WAYPOINTS_EXCEEDED",Nc="OK",Oc="OVER_QUERY_LIMIT",Pc="REQUEST_DENIED",Qc="UNKNOWN_ERROR",Rc="ZERO_RESULTS";function Sc(){return function(a){return a}}function Tc(){return function(){}}function Uc(a){return function(){return this[a]}}var J,Vc=[];function Wc(a){return function(){return Vc[a][yc](this,arguments)}}var Xc={ROADMAP:"roadmap",SATELLITE:"satellite",HYBRID:"hybrid",TERRAIN:"terrain"};var Yc=this;o[gb](2147483648*o[oc]())[Sb](36);var Zc=ka("'","g");function $c(a,b){var c=[];ad(a,b,c,ba);return c[Gc]("&")[db](Zc,"%27")}function ad(a,b,c,d){for(var e=d?1:0;e=o.abs(a-b)}function Dd(a){return a*(o.PI/180)}function Ed(a){return a/(o.PI/180)}function Fd(a,b){for(var c=Gd(ba,K(b)),d=Gd(ba,0);d