Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
added window.title accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
boblail committed Jan 11, 2011
1 parent 1c0ff12 commit 8b9a5e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/browser-spec.coffee
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/zombie/browser.coffee
Expand Up @@ -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
Expand All @@ -37,6 +39,7 @@ class Browser extends require("events").EventEmitter
# TODO: Fix
window.Image = ->
return window

# Always start with an open window.
@open()

Expand Down

0 comments on commit 8b9a5e4

Please sign in to comment.