Skip to content

Commit

Permalink
Browser should be able to submit forms
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed Sep 19, 2012
1 parent 78376be commit 61e8da9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/zombie/eventloop.coffee
Expand Up @@ -107,7 +107,7 @@ class EventLoop
# Cleanup listeners and times before calling callback
done = (error, timedOut)=>
clearTimeout(timer)
@listeners.splice(@listeners.indexOf(listener), 1)
@listeners = @listeners.filter((l)-> l != listener)
callback(error, !!timedOut)

return
Expand Down
2 changes: 1 addition & 1 deletion lib/zombie/forms.coffee
Expand Up @@ -65,7 +65,7 @@ HTML.HTMLFormElement.prototype.submit = (button)->
data.push [button.name, button.value]

document.window._submit
url: HTML.resourceLoader.resolve(document, @getAttribute("action"))
url: @getAttribute("action")
method: @getAttribute("method")
encoding: @getAttribute("enctype")
data: data
Expand Down
20 changes: 18 additions & 2 deletions lib/zombie/history.coffee
Expand Up @@ -104,7 +104,7 @@ class History
addEntry: (window, url, pushState)->
url ||= window.location
entry = new Entry(window, url, pushState)
this.updateLocation(window, url)
@updateLocation(window, url)
@current.append(entry)
@current = entry
@focus(window)
Expand All @@ -113,7 +113,7 @@ class History
replaceEntry: (window, url, pushState)->
url ||= window.location
entry = new Entry(window, url, pushState)
this.updateLocation(window, url)
@updateLocation(window, url)
if @current == @first
@current.dispose(window)
@current = @first = entry
Expand All @@ -135,6 +135,22 @@ class History
@prototype.__defineGetter__ "url", ->
return @current?.url

# Form submission
submit: ({ url, method, encoding, data })->
window = @current.window
url = HTML.resourceLoader.resolve(window.document, url || "/")
params =
browser: @browser
history: this
name: window.name
parent: window.parent
url: url
method: method
encoding: encoding
data: data
newWindow = createWindow(params)
@addEntry(newWindow, url)


# -- Implementation of window.history --

Expand Down
7 changes: 2 additions & 5 deletions lib/zombie/window.coffee
Expand Up @@ -272,10 +272,7 @@ createWindow = ({ browser, data, encoding, history, method, name, opener, parent
# Load the document associated with this window.
loadDocument document: document, history: history, url: url, method: method, encoding: encoding, data: data
# Form submission uses this
# FIXME
window._submit = ({ url, method, encoding, data })->
loadDocument document: document, history: history, url: url, method: method, encoding: encoding, data: data

window._submit = history.submit.bind(history)
return window


Expand Down Expand Up @@ -362,7 +359,7 @@ loadDocument = ({ document, history, url, method, encoding, data })->
request =
url: url
method: (method || "GET").toUpperCase()
headers: (headers && Object.create(headers)) || {}
headers: (headers || {})
data: data
if referer
request.headers.referer = referer
Expand Down
2 changes: 1 addition & 1 deletion test/cookies_test.coffee
Expand Up @@ -146,7 +146,7 @@ describe "Cookies", ->
assert.equal @cookies.get("_expires4"), "3s"


describe.skip "duplicates", ->
describe "duplicates", ->

before (done)->
brains.get "/cookies2", (req, res)->
Expand Down
6 changes: 3 additions & 3 deletions test/forms_test.coffee
Expand Up @@ -698,7 +698,7 @@ describe "Forms", ->


# Submitting form
describe.skip "submit form", ->
describe "submit form", ->

describe "by calling submit", ->
before (done)->
Expand Down Expand Up @@ -877,7 +877,7 @@ describe "Forms", ->


# File upload
describe.skip "file upload", ->
describe "file upload", ->
before ->
brains.get "/forms/upload", (req, res)->
res.send """
Expand Down Expand Up @@ -1046,7 +1046,7 @@ describe "Forms", ->
assert.equal @browser.text("#is_file"), "true"


describe.skip "content length", ->
describe "content length", ->
before ->
brains.post "/forms/urlencoded", (req, res)->
text = req.body.text
Expand Down

0 comments on commit 61e8da9

Please sign in to comment.