diff --git a/CHANGELOG.md b/CHANGELOG.md index 1612385a2..43e230873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/lib/zombie/browser.coffee b/lib/zombie/browser.coffee index 5b10535cf..efbe1563d 100644 --- a/lib/zombie/browser.coffee +++ b/lib/zombie/browser.coffee @@ -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. @@ -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 = [] diff --git a/lib/zombie/windows.coffee b/lib/zombie/windows.coffee index dfa35959f..df390ed13 100644 --- a/lib/zombie/windows.coffee +++ b/lib/zombie/windows.coffee @@ -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 @@ -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) @@ -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 diff --git a/test/browser_test.coffee b/test/browser_test.coffee index a42d2188a..f45f4c87f 100644 --- a/test/browser_test.coffee +++ b/test/browser_test.coffee @@ -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", -> @@ -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", -> @@ -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) diff --git a/test/window_test.coffee b/test/window_test.coffee index 450482b6f..b03fc43cd 100644 --- a/test/window_test.coffee +++ b/test/window_test.coffee @@ -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" +