 
   ".confirm":
     topic: ->
-      browser = new zombie.Browser
+      brains.get "/confirm", (req, res)-> res.send """
+        <script>
+          window.first = confirm("continue?");
+          window.second = confirm("more?");
+          window.third = confirm("silent?");
+        </script>
+        """
+      browser = new Browser
       browser.onconfirm "continue?", true
       browser.onconfirm (prompt)-> true if prompt == "more?"
       browser.wants "http://localhost:3003/confirm", @callback

      assert.ok !browser.prompted("not asked")

  ".screen":
    zombie.wants "http://localhost:3003/screen"
      "should have a screen object available": (browser)->
        assert.match browser.document.title, /width=1280/
        assert.match browser.document.title, /height=800/
        assert.match browser.document.title, /left=0/
        assert.match browser.document.title, /top=0/
        assert.match browser.document.title, /availLeft=0/
        assert.match browser.document.title, /availTop=0/
        assert.match browser.document.title, /availWidth=1280/
        assert.match browser.document.title, /availHeight=800/
        assert.match browser.document.title, /colorDepth=24/
        assert.match browser.document.title, /pixelDepth=24/

  ".navigator":
    zombie.wants "http://localhost:3003/static"
      "should exist": (browser)-> assert.isNotNull browser.window.navigator
      ".javaEnabled should be false": (browser)-> assert.equal browser.window.navigator.javaEnabled(), false

).export(module)

require "./helpers"
{ vows: vows, assert: assert, zombie: zombie, brains: brains } = require("vows")
Browser = zombie.Browser


vows.describe("Window").addBatch(
  ".title":
    topic: ->
      brains.get "/title", (req, res)-> res.send """
        <html>
          <head>
            <title>Whatever</title>
          </head>
          <body>Hello World</body>
        </html>
        """
      browser = new Browser
      browser.wants "http://localhost:3003/title", @callback
    "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

  ".alert":
    topic: ->
      brains.get "/alert", (req, res)-> res.send """
        <script>
          alert("Hi");
          alert("Me again");
        </script>
        """
      browser = new Browser
      browser.onalert (message)-> browser.window.first = true if message = "Me again"
      browser.wants "http://localhost:3003/alert", @callback
    "should record last alert show to user": (browser)-> assert.ok browser.prompted("Me again")
