Permalink
Browse files

Use Browser.create() instead of new Browser()

  • Loading branch information...
1 parent 802f099 commit d9bc31ecaae80d30832343b883a14240071cf7c1 @assaf committed Dec 25, 2012
View
@@ -170,9 +170,6 @@ class Browser extends EventEmitter
else if Browser.default.hasOwnProperty(name)
@[name] = Browser.default[name]
- for extensionFunction in extensionFunctions
- extensionFunction(this)
-
# Returns true if the given feature is enabled.
#
@@ -207,7 +204,7 @@ class Browser extends EventEmitter
# Return a new browser with a snapshot of this browser's state.
# Any changes to the forked browser's state do not affect this browser.
fork: ->
- forked = new Browser()
+ forked = Browser.create()
forked.loadCookies @saveCookies()
forked.loadStorage @saveStorage()
forked.loadHistory @saveHistory()
@@ -1072,9 +1069,10 @@ Browser.default =
waitDuration: "5s"
-extensionFunctions = []
-Browser.extend = (fn)->
- extensionFunctions.push(fn)
+
+# Use this function to create a new Browser instance.
+Browser.create = (options)->
+ return new Browser(options)
# Represents credentials for a given host.
View
@@ -25,7 +25,7 @@ Path = require("path")
# * options -- Initialize the browser with these options
# * callback -- Called with error, browser
visit = (url, options, callback)->
- new Browser(options).visit(url, options, callback)
+ Browser.create(options).visit(url, options, callback)
# ### listen port, callback
@@ -32,11 +32,13 @@ class Interaction
this.extend = (window)->
# Implements window.alert: show message.
window.alert = (message)->
+ browser.emit("alert", message)
prompts.push message
fn message for fn in alertFns
return
# Implements window.confirm: show question and return true/false.
window.confirm = (question)->
+ browser.emit("confirm", question)
prompts.push question
response = confirmCanned[question]
unless response || response == false
@@ -45,16 +47,17 @@ class Interaction
break if response || response == false
return !!response
# Implements window.prompt: show message and return value of null.
- window.prompt = (message, def)->
+ window.prompt = (message, defaultValue)->
+ browser.emit("prompt", message)
prompts.push message
response = promptCanned[message]
unless response || response == false
for fn in promptFns
- response = fn(message, def)
+ response = fn(message, defaultValue)
break if response || response == false
return response.toString() if response
return null if response == false
- return def || ""
+ return defaultValue || ""
exports.use = (browser)->
@@ -2,7 +2,12 @@
describe "angularjs", ->
+ browser = null
before (done)->
+ browser = Browser.create()
+ brains.ready(done)
+
+ before ->
brains.get "/angular/show.html", (req, res)->
res.send """
<h1>{{title}}</h1>
@@ -44,20 +49,15 @@ describe "angularjs", ->
</body>
</html>
"""
- brains.ready done
-
- describe "routing system", ->
- browser = null
- before (done)->
- browser = new Browser()
- browser.visit "/angular", ->
- browser.clickLink("my link")
- browser.wait(duration: 100, done)
+ before (done)->
+ browser.visit "/angular", ->
+ browser.clickLink("my link")
+ browser.wait(duration: 100, done)
- it "should follow the link to the detail", ->
- assert.equal browser.text("h1"), "my title"
+ it "should follow the link to the detail", ->
+ assert.equal browser.text("h1"), "my title"
- after ->
- browser.destroy()
+ after ->
+ browser.destroy()
@@ -3,9 +3,12 @@
describe "Authentication", ->
browser = null
+ before (done)->
+ browser = Browser.create()
+ brains.ready(done)
describe "basic", ->
- before (done)->
+ before ->
brains.get "/auth/basic", (req, res) ->
if auth = req.headers.authorization
if auth == "Basic dXNlcm5hbWU6cGFzczEyMw=="
@@ -15,9 +18,6 @@ describe "Authentication", ->
else
res.send "Missing credentials", 401
- browser = new Browser()
- brains.ready done
-
describe "without credentials", ->
before (done)->
@@ -47,7 +47,7 @@ describe "Authentication", ->
describe "OAuth bearer", ->
- before (done)->
+ before ->
brains.get "/auth/oauth2", (req, res) ->
if auth = req.headers.authorization
if auth == "Bearer 12345"
@@ -56,7 +56,6 @@ describe "Authentication", ->
res.send("Invalid token", 401)
else
res.send("Missing token", 401)
- brains.ready done
describe "without credentials", ->
before (done)->
@@ -85,7 +84,7 @@ describe "Authentication", ->
describe "Scripts on secure pages", ->
- before (done) ->
+ before ->
brains.get "/auth/script", (req, res) ->
if auth = req.headers.authorization
res.send """
@@ -106,6 +105,7 @@ describe "Authentication", ->
else
res.send("No Credentials on the javascript", 401)
+ before (done)->
browser.authenticate("localhost:3003").basic("username", "pass123")
browser.visit("/auth/script", done)
@@ -7,11 +7,10 @@ describe "Browser events", ->
console: []
log: []
resource: []
- browser = new Browser()
-
+ browser = null
before (done)->
- brains.ready done
-
+ browser = Browser.create()
+ brains.ready(done)
describe "sending output to console", ->
before ->
@@ -30,6 +29,7 @@ describe "Browser events", ->
describe "logging a message", ->
+ before ->
# Zombie log
browser.on "log", (message)->
events.log.push(message)
Oops, something went wrong.

0 comments on commit d9bc31e

Please sign in to comment.