Permalink
Browse files

Base support for forking a browser.

Still need to add snapshooting the cookies, storage, cache and history.
  • Loading branch information...
1 parent 719fd7d commit c22994aa5682f7062698bad5de92b0bdbc053803 @jadell jadell committed Jan 28, 2011
Showing with 30 additions and 0 deletions.
  1. +20 −0 spec/browser-spec.coffee
  2. +10 −0 src/zombie/browser.coffee
View
20 spec/browser-spec.coffee
@@ -313,4 +313,24 @@ vows.describe("Browser").addBatch(
assert.match browser.document.title, /colorDepth=24/
assert.match browser.document.title, /pixelDepth=24/
+ "fork":
+ zombie.wants "http://localhost:3003/living"
+ "new browser":
+ topic: (browser)->
+ forked = browser.fork()
+ [forked, browser]
+ "should have two browser objects": (browsers)->
+ [forked, browser] = browsers
+ assert.isNotNull forked
+ assert.isNotNull browser
+ "should not be the same object": (browsers)->
+ [forked, browser] = browsers
+ assert.notStrictEqual browser, forked
+ "should navigate independently": (browsers)->
+ [forked, browser] = browsers
+ forked.visit "http://localhost:3003/dead"
+ forked.wait()
+ assert.equal browser.location.href, "http://localhost:3003/living#/"
+ assert.equal forked.location, "http://localhost:3003/dead"
+
).export(module)
View
10 src/zombie/browser.coffee
@@ -63,6 +63,16 @@ class Browser extends require("events").EventEmitter
else
throw "I don't recognize the option #{k}"
+ # Fork
+ # ----
+
+ # ### browser.fork() => Browser
+ #
+ # Return a new browser with a snapshot of this browser's data.
+ # Any changes to the forked browser's state do not affect this browser.
+ this.fork = ->
+ forked = new Browser()
+ return forked
# Windows
# -------

0 comments on commit c22994a

Please sign in to comment.