Browse files

added window.title accessor

  • Loading branch information...
1 parent 1c0ff12 commit 8b9a5e400d59887e2e2ac7ab1f122223db48706f @boblail boblail committed Jan 10, 2011
Showing with 19 additions and 0 deletions.
  1. +16 −0 spec/browser-spec.coffee
  2. +3 −0 src/zombie/browser.coffee
View
16 spec/browser-spec.coffee
@@ -2,6 +2,14 @@ require "./helpers"
{ vows: vows, assert: assert, zombie: zombie, brains: brains } = require("vows")
jsdom = require("jsdom")
+brains.get "/static", (req, res)-> res.send """
+ <html>
+ <head>
+ <title>Whatever</title>
+ </head>
+ <body>Hello World</body>
+ </html>
+ """
brains.get "/scripted", (req, res)-> res.send """
<html>
@@ -37,6 +45,7 @@ brains.get "/living", (req, res)-> res.send """
</body>
</html>
"""
+
brains.get "/app.js", (req, res)-> res.send """
Sammy("#main", function(app) {
app.get("#/", function(context) {
@@ -76,6 +85,13 @@ brains.get "/useragent", (req, res)-> res.send "<body>#{req.headers["user-agent"
vows.describe("Browser").addBatch(
+ "window.title":
+ zombie.wants "http://localhost:3003/static"
+ "should return the document's title": (browser)-> assert.equal browser.window.title, "Whatever"
+ "should set the document's title": (browser)->
+ browser.window.title = "Overwritten"
+ assert.equal browser.window.title, browser.document.title
+
"open page":
zombie.wants "http://localhost:3003/scripted"
"should create HTML document": (browser)-> assert.instanceOf browser.document, jsdom.dom.level3.html.HTMLDocument
View
3 src/zombie/browser.coffee
@@ -26,6 +26,8 @@ class Browser extends require("events").EventEmitter
this.open = ->
window = jsdom.createWindow(html)
window.__defineGetter__ "browser", => this
+ window.__defineGetter__ "title", => @window?.document?.title
+ window.__defineSetter__ "title", (title)=> @window?.document?.title = title
cookies.extend window
storage.extend window
eventloop.extend window
@@ -37,6 +39,7 @@ class Browser extends require("events").EventEmitter
# TODO: Fix
window.Image = ->
return window
+
# Always start with an open window.
@open()

0 comments on commit 8b9a5e4

Please sign in to comment.