Permalink
Browse files

Got FB Connect to show login form ... almost, bug in Request/Replay.

  • Loading branch information...
1 parent 711fe02 commit 06a7fd6bc8f5f517cab5b1f0901acb79ed7e431d @assaf committed May 4, 2012
View
@@ -2,7 +2,7 @@ zombie.js-changelog(7) -- Changelog
===================================
-## Version 0.14.0 2012-05-03
+## Version 0.13.7 2012-05-03
Added support for `postMessage`.
@@ -15,6 +15,8 @@ IFrame window name based on element's `name` attribute.
Fixed IFrame document and window to include Zombie enhancements.
+Zombie can now show FB Connect form.
+
## Version 0.13.6 2012-05-02
@@ -113,7 +113,7 @@ class History
unless @_stack[@_index]
@_stack[@_index].update ABOUT_BLANK
try
- @_window._evaluate script, "javascript:"
+ @_window._evaluate url.pathname, "javascript:"
@_browser.emit "loaded", @_browser
catch error
@_browser.emit "error", error
@@ -55,28 +55,23 @@ HTML.resourceLoader.load = (element, href, callback)->
HTML.Document.prototype._elementBuilders["iframe"] = (doc, tag)->
parent = doc.window
iframe = new HTML.HTMLIFrameElement(doc, tag)
-
- # Need to bypass JSDOM's window/document creation and use ours
- contentWindow = parent.browser.open(parent: parent)
+ window = null
Object.defineProperty iframe, "contentWindow", get: ->
- return contentWindow
+ return window
Object.defineProperty iframe, "contentDocument", get: ->
- return contentWindow.document
+ return window.document
# This is also necessary to prevent JSDOM from messing with window/document
iframe.setAttribute = (name, value)->
HTML.HTMLElement.prototype.setAttribute.call(this, name, value)
- if name == "name"
- # Set window name from iframe name attribute.
- contentWindow.name = iframe.name
- #parent.__defineGetter__ value, -> return contentWindow
- else if name == "src" && value
+ if name == "src" && value
+ unless window
+ # Need to bypass JSDOM's window/document creation and use ours
+ window = parent.browser.open(name: iframe.name, parent: parent)
+
# Point IFrame at new location and wait for it to load
- contentWindow.location = URL.resolve(parent.location, value)
- contentWindow.document.addEventListener "DOMContentLoaded", (event)->
- # IFrame could have a new window now, need to update reference and
- # fire onload event on the iframe element itself.
- contentWindow = event.target.window
+ window.location = URL.resolve(parent.location, value)
+ window.document.addEventListener "DOMContentLoaded", (event)->
onload = parent.document.createEvent("HTMLEvents")
onload.initEvent "load", false, false
parent.browser._eventloop.dispatch iframe, onload
@@ -45,11 +45,7 @@ describe "Facebook Connect", ->
before (done)->
browser.visit "http://localhost:3003/browser/facebook", ->
- browser.clickLink "Connect", ->
- setTimeout ->
- done()
- , 500
+ browser.clickLink "Connect", done
- it "should show FB Connect option", ->
- console.dir browser.errors
- console.log browser.evaluate("window.FB.getAuthResponse()")
+ it "should show FB Connect login form", ->
+ assert browser.query(".login_form_container #loginform")
@@ -0,0 +1,25 @@
+GET /connect/xd_arbiter.php?version=5
+
+200 HTTP/1.1
+content-type: text/html; charset=utf-8
+x-fb-debug: Zg3M5/D9AF9/D/5VSgkZaW7p1tYqiXngTg0f8wu0OLA=
+x-cnection: close
+cache-control: public, max-age=30227538
+expires: Fri, 19 Apr 2013 00:13:22 GMT
+date: Fri, 04 May 2012 03:41:04 GMT
+content-length: 12805
+connection: keep-alive
+
+<html><head></head><body><script>function bagofholding() {};(function(a){if(a.require)return;var b={},c={},d={},e=0,f=1,g=2,h='special',i='refcount',j='exports',k='dependencies',l='module',m='waiting',n='factory',o=undefined,p='define',q='global',r='require',s='requireLazy',t='requireDynamic',u='context',v=Object.prototype.hasOwnProperty;function w(ha){if(!b[ha]){var ia='Requiring unknown module "'+ha+'"';throw new Error(ia);}var ja=b[ha],ka,la,ma;if(ja[m]&&ja[h]&g)z();if(ja[m]){ma='Requiring module "'+ha+'" with unresolved dependencies';throw new Error(ma);}if(!ja[j]){var na=ja[j]={},oa=ja[n];if(Object.prototype.toString.call(oa)==='[object Function]'){var pa=[],qa=ja[k],ra=qa.length;if(ja[h]&g)ra=Math.min(ra,oa.length);for(la=0;la<ra;la++){ka=qa[la];pa.push(ka===l?ja:(ka===j?na:w(ka)));}var sa=oa.apply(ja[u]||a,pa);if(sa)ja[j]=sa;}else ja[j]=oa;}if(ja[i]--===1)delete b[ha];return ja[j];}function x(ha,ia,ja,ka,la,ma){if(ia===o){ia=[];ja=ha;ha=ba();}else if(ja===o){ja=ia;ia=ha;ha=ba();}var na=b[ha];if(na){if(ma)na[i]+=ma;return;}else if(!ia&&!ja&&ma){d[ha]=(d[ha]||0)+ma;return;}else{na={id:ha};na[i]=(d[ha]||0)+(ma||0);delete d[ha];}na[n]=ja;na[k]=ia;na[u]=la;na[h]=ka;b[ha]=na;ca(ha);}function y(ha,ia,ja){x(ha,ia,o,f,ja,1);}function z(){var ha={},ia;for(ia in c)if(v.call(c,ia))if(b[ia]&&!ha[ia]&&b[ia][h]&g)aa({},ia,ha);}function aa(ha,ia,ja){ja[ia]=1;var ka=c[ia],la;if(!ka)return;ha[ia]=1;for(la in ka)if(v.call(ka,la)){if(!b[la][h]&g)continue;if(ha[la]){delete ka[la];b[la][m]--;if(!b[la][m])da(la);}else aa(ha,la,ja);}ha[ia]=0;}function ba(){return '__mod__'+e++;}function ca(ha){var ia=b[ha],ja=0;for(var ka=0;ka<ia[k].length;ka++){var la=ia[k][ka];if(!b[la]||b[la][m]){c[la]||(c[la]={});if(!c[la][ha])ja++;c[la][ha]=1;}}ia[m]=ja;if(!ja)da(ha);}function da(ha){var ia=b[ha];if(ia[h]&f)w(ha);var ja=c[ha];if(ja){delete c[ha];for(var ka in ja)if(v.call(ja,ka))if(!--b[ka][m])da(ka);}}function ea(ha,ia){b[ha]={id:ha};b[ha][j]=ia;}ea(l,0);ea(j,0);ea(p,x);ea(q,a);ea(r,w);ea(t,w);ea(s,y);x.amd={};a[p]=x;a[r]=w;a[t]=w;a[s]=y;var fa=false,ga=function(ha,ia,ja,ka){x(ha,ia,ja,ka||g);if(b[ha][m]&&!fa)fa=setTimeout(function(){z();fa=false;},9);};a.__d=function(ha,ia,ja,ka){ia=[q,r,t,s,l,j].concat(ia);ga(ha,ia,ja,ka);};a.__e=a.__d;})(this);
+__d("XDMConfig",[],{"Flash":{"path":"https:\/\/s-static.ak.fbcdn.net\/rsrc.php\/v1\/ys\/r\/WON-TVLCpDP.swf"}});__d("initXdArbiter",["QueryString","resolveWindow","Log","XDM","XDMConfig"],function(a,b,c,d,e,f){var g=b('QueryString'),h=b('resolveWindow'),i=b('Log'),j=b('XDM'),k=c('XDMConfig'),l=location.protocol.replace(':',''),m=/#(.*)|$/.exec(location.href)[1];if(!m){i.error('xd_arbiter.php loaded without a valid hash, referrer: %s',document.referrer);return;}var n=g.decode(m);function o(y){return y.replace(/["'<>\(\)\\]/g,'');}function p(){if(window!=parent&&window.parent!=window.parent.parent)try{return parent.parent.XdArbiter.register(window);}catch(y){i.error('Could not register with XdArbiter in parent.parent');}return '';}function q(y,z){if(!y||y.length===0)return true;var aa='.'+(/https?:\/\/(.*)$/).exec(z)[1],ba=y.length;while(ba--){var ca='.'+y[ba];if(ca==aa.substring(aa.length-ca.length))return true;}i.error('Failed proxying to %s, expected %s',aa,y.toString());return false;}function r(y,z){var aa=y?h(y):parent.parent;try{aa.XdArbiter.handleMessage(z);}catch(ba){i.error('Could not reach www.facebook.com using %s',y);return;}}function s(){try{h(n.relation).frames['fb_xdm_frame_'+l].proxyMessage(m);}catch(y){setTimeout(s,50);}}function t(){var y=/^(.*)\/(.*)$/.exec(n.origin)[1];if(window.__fbNative&&window.__fbNative.postMessage){__fbNative.postMessage(m,y);}else{var z=function(aa){window.removeEventListener('fbNativeReady',z);__fbNative.postMessage(m,y);};window.addEventListener('fbNativeReady',z);}}document.domain='facebook.com';if(n.xd_rel){r(n.xd_rel,n);return;}else if(n.relation){if(window===top&&/FBAN\/\w+;/i.test(navigator.userAgent)){i.info('Native proxy');t();}else{i.info('Legacy proxy to %s',n.relation);s();}return;}if(l!=/https?/.exec(window.name)[0]){i.info('Redirection to %s detected, aborting',l);return;}var u=o(n.transport),v=o(n.channel),w=o(n.channel_path),x=o(n.origin);if(!/^https?/.test(x)){i.error('Invalid origin presented, aborting.');return;}j.create({root:document.body,transport:u,channel:v+'_'+l,channelPath:w,flashUrl:k.Flash.path,onMessage:function(y,z){y=g.decode(y);r(y.relation,y);},whenReady:function(y){window.proxyMessage=function(ca,da){if(q(da,x))y.send(ca,x,parent,v);};var z=null,aa={xd_action:'proxy_ready',data:z},ba=p();if(ba)aa.registered=ba;y.send(g.encode(aa),x,parent,v);}});});
+__d("QueryString",[],function(a,b,c,d,e,f){var g={encode:function(h){var i=[];for(var j in h)if(h.hasOwnProperty(j))i.push(encodeURIComponent(j)+'='+encodeURIComponent(h[j]));return i.join('&');},decode:function(h){var i=h.split('&'),j=i.length,k={};while(j--){var l=i[j].split('=',2);k[decodeURIComponent(l[0])]=decodeURIComponent(l[1]);}return k;}};e.exports=g;});
+__d("resolveWindow",[],function(a,b,c,d,e,f){function g(h){var i=window,j=h.split('.');try{for(var l=0;l<j.length;l++){var m=j[l],n=/^frames\[['"]?([a-zA-Z0-9\-_]+)['"]?\]$/.exec(m);if(n){i=i.frames[n[1]];}else if(m==='opener'||m==='parent'||m==='top'){i=i[m];}else return null;}}catch(k){return null;}return i;}e.exports=g;});
+__d("Log",["sprintf"],function(a,b,c,d,e,f){var g=b("sprintf"),h=Array.prototype.slice,i={DEBUG:3,INFO:2,WARNING:1,ERROR:0};function j(l,m,n){var o=g.apply(null,n);if(k.level>=l&&window.console)console[m in console?m:'log'](o);}var k={level:-1,Level:i,debug:function(){j(i.DEBUG,'debug',h.call(arguments));},info:function(){j(i.INFO,'info',h.call(arguments));},warn:function(){j(i.WARNING,'warn',h.call(arguments));},error:function(){j(i.ERROR,'error',h.call(arguments));}};e.exports=k;});
+__d("sprintf",[],function(a,b,c,d,e,f){function g(h,i){i=Array.prototype.slice.call(arguments,1);var j=0;return h.replace(/%s/g,function(k){return i[j++];});}e.exports=g;});
+__d("XDM",["Flash","DOMEventListener","Log","guid","copyProperties"],function(a,b,c,d,e,f){var g=b('Flash'),h=b('DOMEventListener'),i=b('Log'),j=b('guid'),k=b('copyProperties'),l={},m={transports:[]};function n(p){var q={},r=p.length,s=m.transports;while(r--)q[p[r]]=1;r=s.length;while(r--){var t=s[r],u=l[t];if(!q[t]&&u.isAvailable())return t;}}var o={register:function(p,q){i.debug('Registering %s as XDM provider',p);m.transports.push(p);l[p]=q;},create:function(p){if(!p.whenReady&&!p.onMessage){i.error('An instance without whenReady or onMessage makes no sense');throw new Error('An instance without whenReady or '+'onMessage makes no sense');}if(!p.channel){i.warn('Missing channel name, selecting at random');p.channel=j();}if(!p.whenReady)p.whenReady=bagofholding;if(!p.onMessage)p.onMessage=bagofholding;var q=p.transport||n(p.blacklist||[]),r=l[q];if(r&&r.isAvailable()){i.debug('%s is available',q);r.init(p);return q;}}};o.register('fragment',(function(){var p=false,q,r=location.protocol+'//'+location.host;function s(t){var u=document.createElement('iframe');u.src='javascript:false';var v=h.add(u,'load',function(){v.remove();setTimeout(function(){u.parentNode.removeChild(u);},5000);});q.appendChild(u);u.src=t;}return {isAvailable:function(){return true;},init:function(t){i.debug('init fragment');var u={send:function(v,w,x,y){i.debug('sending to: %s (%s)',w+t.channelPath,y);s(w+t.channelPath+v+'&xd_rel=parent.parent&relation=parent.parent&xd_origin='+encodeURIComponent(r));}};if(p){t.whenReady(u);return;}q=t.root;p=true;t.whenReady(u);}};})());o.register('flash',(function(){var p=false,q,r={},s=false;return {isAvailable:function(){return g.isAvailable();},init:function(t){i.debug('init flash: '+t.channel);var u={send:function(x,y,z,aa){i.debug('sending to: %s (%s)',y,aa);q.postMessage(x,y,aa);}};if(p){t.whenReady(u);return;}var v=t.root.appendChild(document.createElement('div')),w=j();r[w]=function(){i.info('xdm.swf called the callback');delete r[w];w=j();r[w]=function(x,y){x=decodeURIComponent(x);i.debug('received message %s from %s',x,y);t.onMessage(x,y);};q.init(t.channel,'FB_XDM_CALLBACKS.'+w);t.whenReady(u);};window.FB_XDM_CALLBACKS=r;q=g.embed(t.flashUrl,v,null,{protocol:location.protocol.replace(':',''),host:location.host,callback:'FB_XDM_CALLBACKS.'+w,log:s});p=true;}};})());o.register('postmessage',(function(){var p=false;return {isAvailable:function(){return !!window.postMessage;},init:function(q){i.debug('init postMessage: '+q.channel);var r='_FB_'+q.channel,s={send:function(t,u,v,w){if(window===v){i.error('Invalid windowref, equal to window (self)');throw new Error();}i.debug('sending to: %s (%s)',u,w);v.postMessage('_FB_'+w+t,u);}};if(p){q.whenReady(s);return;}h.add(window,'message',function(event){var t=event.data,u=event.origin||'native';if(typeof t!='string'){i.warn('Received message of type %s from %s, expected a string',typeof t,u);return;}i.debug('received message %s from %s',t,u);if(u!='native')if(t.substring(0,r.length)==r){t=t.substring(r.length);}else return;q.onMessage(t,u);});q.whenReady(s);p=true;}};})());e.exports=o;});
+__d("Flash",["ua","copyProperties","QueryString","guid"],function(a,b,c,d,e,f){var g=b("ua"),h=b("copyProperties"),i=b("QueryString"),j=b("guid"),k={},l;function m(r){var s=document.getElementById(r);if(s)s.parentNode.removeChild(s);delete k[r];}function n(){for(var r in k)if(k.hasOwnProperty(r))m(r);}function o(r){return r.replace(/\d+/g,function(s){return '000'.substring(s.length)+s;});}function p(r){if(!l){if(g.ie()>=9)window.attachEvent('onunload',n);l=true;}k[r]=r;}var q={embed:function(r,s,t,u){var v=j();r=encodeURI(r);t=h({allowscriptaccess:'always',flashvars:u,movie:r},t||{});if(typeof t.flashvars=='object')t.flashvars=i.encode(t.flashvars);var w=[];for(var x in t)if(t.hasOwnProperty(x)&&t[x])w.push('<param name="'+encodeURI(x)+'" value="'+encodeURI(t[x])+'">');var y=document.createElement('div'),z='<object '+(g.ie()?'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ':'type="application/x-shockwave-flash"')+'data="'+r+'" '+'id="'+v+'">'+w.join('')+'</object>';y.innerHTML=z;s.appendChild(y.firstChild);p(v);return s.firstChild;},remove:m,getVersion:function(){var r='Shockwave Flash',s='application/x-shockwave-flash',t='ShockwaveFlash.ShockwaveFlash',u;if(navigator.plugins&&typeof navigator.plugins[r]=='object'){var v=navigator.plugins[r].description;if(v&&navigator.mimeTypes&&navigator.mimeTypes[s]&&navigator.mimeTypes[s].enabledPlugin)u=v.match(/\d+/g);}if(!u)try{u=(new ActiveXObject(t)).GetVariable('$version').match(/(\d+),(\d+),(\d+),(\d+)/);u=Array.prototype.slice.call(u,1);}catch(w){}return u;},checkMinVersion:function(r){var s=q.getVersion();if(!s)return false;return o(s.join('.'))>=o(r);},isAvailable:function(){return !!q.getVersion();}};e.exports=q;});
+__d("ua",[],function(a,b,c,d,e,f){var g=false,h,i,j,k,l,m,n,o,p,q;function r(){if(g)return;g=true;var t=navigator.userAgent,u=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))/.exec(t),v=/(Mac OS X)|(Windows)|(Linux)/.exec(t),w=/\b(iPhone|iP[ao]d)/.exec(t);p=!!(/Win64/.exec(t));if(u){h=u[1]?parseFloat(u[1]):NaN;if(h&&document.documentMode)h=document.documentMode;i=u[2]?parseFloat(u[2]):NaN;j=u[3]?parseFloat(u[3]):NaN;k=u[4]?parseFloat(u[4]):NaN;if(k){u=/(?:Chrome\/(\d+\.\d+))/.exec(t);l=u&&u[1]?parseFloat(u[1]):NaN;}else l=NaN;}else h=i=j=l=k=NaN;if(v){if(v[1]){var x=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(t);m=x?parseFloat(x[1].replace('_','.')):true;}else m=false;n=!!v[2];o=!!v[3];}else m=n=o=false;q=w;}var s={ie:function(){return r()||h;},ie64:function(){return s.ie()&&p;},firefox:function(){return r()||i;},opera:function(){return r()||j;},safari:function(){return r()||k;},chrome:function(){return r()||l;},windows:function(){return r()||n;},osx:function(){return r()||m;},linux:function(){return r()||o;},iphone:function(){return r()||q;}};a.ua=e.exports=s;},3);
+__d("copyProperties",[],function(a,b,c,d,e,f){function g(h,i){h=h||{};i=i||{};for(var j in i)h[j]=i[j];if(i.hasOwnProperty&&i.hasOwnProperty('toString')&&(typeof i.toString!='undefined')&&(h.toString!==i.toString))h.toString=i.toString;return h;}e.exports=g;});
+__d("guid",[],function(a,b,c,d,e,f){function g(){return 'f'+(Math.random()*(1<<30)).toString(16).replace('.','');}e.exports=g;});
+__d("DOMEventListener",[],function(a,b,c,d,e,f){var g,h;if(window.addEventListener){g=function(j,k,l){j.addEventListener(k,l,false);};h=function(j,k,l){j.removeEventListener(k,l,false);};}else if(window.attachEvent){g=function(j,k,l){j.attachEvent('on'+k,l);};h=function(j,k,l){j.detachEvent('on'+k,l);};}var i={add:function(j,k,l){g(j,k,l);return {remove:function(){h(j,k,l);j=null;}};},remove:h};e.exports=i;});
+require("initXdArbiter");</script></body></html>
Oops, something went wrong.

0 comments on commit 06a7fd6

Please sign in to comment.