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

Commit

Permalink
Changed browser option windowName to just name.
Browse files Browse the repository at this point in the history
Setting browser option to `undefined` no longer resets it to default (that was a
stupid idea).
  • Loading branch information
assaf committed May 9, 2012
1 parent 808f35d commit 943787f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,17 @@ zombie.js-changelog(7) -- Changelog
===================================


## Version 0.13.14 2012-05-09

Changed browser option `windowName` to just `name.`

Setting browser option to `undefined` no longer resets it to default (that was a
stupid idea).

469 tests
11.6 sec to complete


## Version 0.13.13 2012-05-09

Should be `windows.select` not `windows.switch`.
Expand Down
25 changes: 15 additions & 10 deletions lib/zombie/browser.coffee
Expand Up @@ -20,13 +20,20 @@ Windows = require("./windows")
XHR = require("./xhr")


HTML = JSDOM.dom.level3.html
MOUSE_EVENT_NAMES = ["mousedown", "mousemove", "mouseup"]
BROWSER_OPTIONS = ["credentials", "debug", "htmlParser", "loadCSS", "proxy", "referer", "runScripts", "silent", "site", "userAgent", "waitFor", "windowName"]
# Browser options you can set when creating new browser, or on browser instance.
BROWSER_OPTIONS = ["credentials", "debug", "htmlParser", "loadCSS", "proxy",
"referer", "runScripts", "silent", "site", "userAgent",
"waitFor", "name"]

# Global options you can set on Browser and will be inherited by each new browser.
GLOBAL_OPTIONS = ["debug", "htmlParser", "loadCSS", "proxy", "runScripts",
"silent", "site", "userAgent", "waitFor"]


PACKAGE = JSON.parse(require("fs").readFileSync(__dirname + "/../../package.json"))
VERSION = PACKAGE.version
HTML = JSDOM.dom.level3.html
MOUSE_EVENT_NAMES = ["mousedown", "mousemove", "mouseup"]


# Use the browser to open up new windows and load documents.
Expand Down Expand Up @@ -104,17 +111,15 @@ class Browser extends EventEmitter
@waitFor = 500

# You can set the browser window.name property
@windowName = "nodejs"
@name = "nodejs"

# Sets the browser options.
for name in BROWSER_OPTIONS
value = options[name]
if typeof value == "undefined"
value = Browser[name]
unless typeof value == "undefined"
if options.hasOwnProperty(name)
@[name] = options[name]
if !@[name] && ~GLOBAL_OPTIONS.indexOf(name)
if value = Browser[name]
@[name] = value
else
@[name] = value

# Returns all errors reported while loading this window.
@errors = []
Expand Down
12 changes: 6 additions & 6 deletions lib/zombie/windows.coffee
Expand Up @@ -42,15 +42,15 @@ class Windows
# parent - Parent window (for frames)
# url - If specified, opens that document
open: (options = {})->
name = options.name || @_browser.name || ""
# If this is an iframe, create a named window but don't keep a reference
# to it here. Let the document handle that,
# If window name is _blank, we always create a new window.
# Otherwise, we return existing window and allow lookup by name.
if options.name == "_blank" || options.parent
window = @_create(options)
if name == "_blank" || options.parent
window = @_create(name, options)
else
name = options.name || ""
window = @_named[name] ||= @_create(options)
window = @_named[name] ||= @_create(name, options)

# If caller supplies URL, use it. If this is existing window, return
# without changing location (or contents). Otherwise, start with empty
Expand Down Expand Up @@ -80,7 +80,7 @@ class Windows

# Close the specified window (last window if unspecified)
close: (window)->
window ||= @_current
window = @_named[window] || @_stack[window] || window || @_current
# Make sure we only close an existing window, and we need index if we're
# closing the current window
index = @_stack.indexOf(window)
Expand Down Expand Up @@ -108,7 +108,7 @@ class Windows
return @_current

# This actually handles creation of a new window.
_create: ({ name, parent, opener })->
_create: (name, { parent, opener })->
window = JSDOM.createWindow(HTML)
global = window.getGlobal()
@_stack.push window
Expand Down
6 changes: 3 additions & 3 deletions test/browser_test.coffee
Expand Up @@ -462,7 +462,7 @@ describe "Browser", ->

it "should open both windows", ->
assert.equal browser.windows.all().length, 2
assert.equal browser.windows.get(0).name, ""
assert.equal browser.windows.get(0).name, "nodejs"
assert.equal browser.windows.get(1).name, "popup"

it "should switch to last window", ->
Expand All @@ -478,7 +478,7 @@ describe "Browser", ->

it "should lose that window", ->
assert.equal browser.windows.all().length, 1
assert.equal browser.windows.get(0).name, ""
assert.equal browser.windows.get(0).name, "nodejs"
assert !browser.windows.get(1)

it "should switch to last window", ->
Expand All @@ -491,7 +491,7 @@ describe "Browser", ->

it "should keep that window", ->
assert.equal browser.windows.all().length, 1
assert.equal browser.windows.get(0).name, ""
assert.equal browser.windows.get(0).name, "nodejs"
assert.equal browser.window, browser.windows.get(0)


Expand Down
43 changes: 43 additions & 0 deletions test/window_test.coffee
Expand Up @@ -176,3 +176,46 @@ describe "Window", ->
it ".javaEnabled should be false", ->
assert.equal browser.window.navigator.javaEnabled(), false


describe "windows", ->
browser = new Browser(name: "first")

before ->
browser.open(name: "second")
browser.open(name: "third")
assert.equal browser.windows.count, 3

describe "select", ->
it "should pick window by name", ->
browser.windows.select("second")
assert.equal browser.window.name, "second"

it "should pick window by index", ->
browser.windows.select(2)
assert.equal browser.window.name, "third"

it "should be able to select specific window", ->
browser.windows.select(browser.windows.all()[0])
assert.equal browser.window.name, "first"

describe "close", ->
before ->
browser.windows.close(1)

it "should discard one window", ->
assert.equal browser.windows.count, 2

it "should discard specified window", ->
assert.deepEqual browser.windows.all().map((w)-> w.name), ["first", "third"]

it "should select previous window", ->
assert.equal browser.window.name, "first"

describe "close first", ->
before ->
browser.windows.close()
assert.equal browser.windows.count, 1

it "should select next available window", ->
assert.equal browser.window.name, "third"

0 comments on commit 943787f

Please sign in to comment.