capybara-webkit 0.13.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/.travis.yml +10 -0
  2. data/Gemfile.lock +20 -18
  3. data/NEWS.md +20 -1
  4. data/README.md +12 -10
  5. data/capybara-webkit.gemspec +3 -2
  6. data/lib/capybara/webkit/browser.rb +10 -19
  7. data/lib/capybara/webkit/connection.rb +13 -34
  8. data/lib/capybara/webkit/driver.rb +5 -22
  9. data/lib/capybara/webkit/node.rb +10 -2
  10. data/lib/capybara/webkit/version.rb +1 -1
  11. data/lib/capybara_webkit_builder.rb +10 -1
  12. data/spec/browser_spec.rb +1 -1
  13. data/spec/connection_spec.rb +4 -2
  14. data/spec/driver_rendering_spec.rb +2 -2
  15. data/spec/driver_resize_window_spec.rb +29 -40
  16. data/spec/driver_spec.rb +368 -125
  17. data/spec/integration/session_spec.rb +100 -6
  18. data/spec/spec_helper.rb +6 -9
  19. data/spec/support/app_runner.rb +2 -12
  20. data/src/Authenticate.cpp +2 -2
  21. data/src/ClearCookies.cpp +1 -1
  22. data/src/ClearPromptText.cpp +1 -1
  23. data/src/Command.cpp +13 -0
  24. data/src/Command.h +6 -0
  25. data/src/CommandFactory.cpp +1 -3
  26. data/src/Connection.cpp +4 -3
  27. data/src/ConsoleMessages.cpp +4 -1
  28. data/src/CurrentUrl.cpp +1 -16
  29. data/src/CurrentUrl.h +0 -6
  30. data/src/EnableLogging.cpp +1 -1
  31. data/src/Evaluate.cpp +3 -74
  32. data/src/Evaluate.h +0 -8
  33. data/src/Execute.cpp +2 -2
  34. data/src/Find.cpp +2 -2
  35. data/src/FrameFocus.cpp +3 -3
  36. data/src/GetCookies.cpp +1 -1
  37. data/src/GetTimeout.cpp +1 -1
  38. data/src/GetWindowHandle.cpp +1 -1
  39. data/src/GetWindowHandles.cpp +6 -5
  40. data/src/Header.cpp +2 -2
  41. data/src/Headers.cpp +1 -1
  42. data/src/IgnoreSslErrors.cpp +1 -1
  43. data/src/JavascriptAlertMessages.cpp +4 -1
  44. data/src/JavascriptConfirmMessages.cpp +4 -1
  45. data/src/JavascriptPromptMessages.cpp +4 -1
  46. data/src/JsonSerializer.cpp +116 -0
  47. data/src/JsonSerializer.h +20 -0
  48. data/src/NetworkAccessManager.cpp +58 -17
  49. data/src/NetworkAccessManager.h +6 -0
  50. data/src/NoOpReply.cpp +32 -0
  51. data/src/NoOpReply.h +18 -0
  52. data/src/Node.cpp +1 -1
  53. data/src/NullCommand.cpp +1 -1
  54. data/src/PageLoadingCommand.cpp +5 -4
  55. data/src/Render.cpp +1 -1
  56. data/src/Reset.cpp +1 -1
  57. data/src/ResizeWindow.cpp +1 -1
  58. data/src/Response.cpp +3 -3
  59. data/src/Response.h +13 -4
  60. data/src/SetConfirmAction.cpp +1 -1
  61. data/src/SetCookie.cpp +1 -1
  62. data/src/SetPromptAction.cpp +1 -1
  63. data/src/SetPromptText.cpp +1 -1
  64. data/src/SetProxy.cpp +2 -2
  65. data/src/SetSkipImageLoading.cpp +1 -1
  66. data/src/SetTimeout.cpp +2 -2
  67. data/src/SetUrlBlacklist.cpp +15 -0
  68. data/src/SetUrlBlacklist.h +11 -0
  69. data/src/Status.cpp +1 -1
  70. data/src/TimeoutCommand.cpp +6 -6
  71. data/src/TimeoutCommand.h +0 -3
  72. data/src/UnsupportedContentHandler.cpp +1 -4
  73. data/src/Visit.cpp +1 -1
  74. data/src/WebPage.cpp +41 -31
  75. data/src/WebPage.h +14 -12
  76. data/src/WebPageManager.cpp +13 -8
  77. data/src/WebPageManager.h +3 -2
  78. data/src/WindowFocus.cpp +2 -2
  79. data/src/body.cpp +7 -2
  80. data/src/capybara.js +10 -2
  81. data/src/find_command.h +1 -3
  82. data/src/webkit_server.pro +7 -7
  83. metadata +47 -82
  84. checksums.yaml +0 -7
  85. data/spec/integration/driver_spec.rb +0 -21
  86. data/src/RequestedUrl.cpp +0 -13
  87. data/src/RequestedUrl.h +0 -10
  88. data/src/Source.cpp +0 -19
  89. data/src/Source.h +0 -18
  90. data/src/Url.cpp +0 -13
  91. data/src/Url.h +0 -10
@@ -1,7 +1,7 @@
1
1
  module Capybara
2
2
  module Driver
3
3
  class Webkit
4
- VERSION = '0.13.2'.freeze
4
+ VERSION = '0.14.0'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -12,13 +12,22 @@ module CapybaraWebkitBuilder
12
12
  end
13
13
 
14
14
  def qmake_bin
15
- ENV['QMAKE'] || 'qmake'
15
+ ENV['QMAKE'] || default_qmake_binary
16
16
  end
17
17
 
18
18
  def spec
19
19
  ENV['SPEC'] || os_spec
20
20
  end
21
21
 
22
+ def default_qmake_binary
23
+ case RbConfig::CONFIG['host_os']
24
+ when /freebsd/
25
+ "qmake-qt4"
26
+ else
27
+ "qmake"
28
+ end
29
+ end
30
+
22
31
  def os_spec
23
32
  case RbConfig::CONFIG['host_os']
24
33
  when /linux/
@@ -231,7 +231,7 @@ describe Capybara::Webkit::Browser do
231
231
  end
232
232
 
233
233
  it 'uses original URL' do
234
- browser.url.should == @url
234
+ browser.current_url.should == @url
235
235
  end
236
236
 
237
237
  it 'uses URLs changed by javascript' do
@@ -3,7 +3,7 @@ require 'capybara/webkit/connection'
3
3
 
4
4
  describe Capybara::Webkit::Connection do
5
5
  it "boots a server to talk to" do
6
- url = @rack_server.url("/")
6
+ url = "http://#{@rack_server.host}:#{@rack_server.port}/"
7
7
  connection.puts "Visit"
8
8
  connection.puts 1
9
9
  connection.puts url.to_s.bytesize
@@ -22,12 +22,14 @@ describe Capybara::Webkit::Connection do
22
22
  io = StringIO.new
23
23
  redirected_connection = Capybara::Webkit::Connection.new(:stdout => io)
24
24
  script = 'console.log("hello world")'
25
+ redirected_connection.puts "EnableLogging"
26
+ redirected_connection.puts 0
25
27
  redirected_connection.puts "Execute"
26
28
  redirected_connection.puts 1
27
29
  redirected_connection.puts script.to_s.bytesize
28
30
  redirected_connection.print script
29
31
  sleep(0.5)
30
- io.string.should include "hello world\n"
32
+ io.string.should include "hello world \n"
31
33
  end
32
34
 
33
35
  it "returns the server port" do
@@ -20,12 +20,12 @@ describe Capybara::Webkit::Driver, "rendering an image" do
20
20
  tmp_dir = File.join(PROJECT_ROOT, 'tmp')
21
21
  FileUtils.mkdir_p tmp_dir
22
22
  @file_name = File.join(tmp_dir, 'render-test.png')
23
- driver.visit '/'
23
+ driver.visit("#{AppRunner.app_host}/")
24
24
  end
25
25
 
26
26
  def render(options)
27
27
  FileUtils.rm_f @file_name
28
- driver.render @file_name, options
28
+ driver.save_screenshot @file_name, options
29
29
 
30
30
  @image = MiniMagick::Image.open @file_name
31
31
  end
@@ -2,58 +2,47 @@ require 'spec_helper'
2
2
  require 'capybara/webkit/driver'
3
3
 
4
4
  describe Capybara::Webkit::Driver, "#resize_window(width, height)" do
5
-
6
- before(:all) do
7
- app = lambda do |env|
8
- body = <<-HTML
9
- <html>
10
- <body>
11
- <h1 id="dimentions">UNKNOWN</h1>
12
-
13
- <script>
14
- window.onload = window.onresize = function(){
15
- document.getElementById("dimentions").innerHTML = "[" + window.innerWidth + "x" + window.innerHeight + "]";
16
- };
17
- </script>
18
-
19
- </body>
20
- </html>
21
- HTML
22
-
23
- [
24
- 200,
25
- { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
26
- [body]
27
- ]
28
- end
29
-
30
- @driver = Capybara::Webkit::Driver.new(app, :browser => $webkit_browser)
5
+ include AppRunner
6
+
7
+ let(:driver) do
8
+ driver_for_html(<<-HTML)
9
+ <html>
10
+ <body>
11
+ <h1 id="dimentions">UNKNOWN</h1>
12
+
13
+ <script>
14
+ window.onload = window.onresize = function(){
15
+ document.getElementById("dimentions").innerHTML = "[" + window.innerWidth + "x" + window.innerHeight + "]";
16
+ };
17
+ </script>
18
+
19
+ </body>
20
+ </html>
21
+ HTML
31
22
  end
32
23
 
33
24
  DEFAULT_DIMENTIONS = "[1680x1050]"
34
25
 
35
26
  it "resizes the window to the specified size" do
36
- @driver.visit("/")
27
+ driver.visit("#{AppRunner.app_host}/")
37
28
 
38
- @driver.resize_window(800, 600)
39
- @driver.body.should include("[800x600]")
29
+ driver.resize_window(800, 600)
30
+ driver.html.should include("[800x600]")
40
31
 
41
- @driver.resize_window(300, 100)
42
- @driver.body.should include("[300x100]")
32
+ driver.resize_window(300, 100)
33
+ driver.html.should include("[300x100]")
43
34
  end
44
35
 
45
36
  it "resizes the window to the specified size even before the document has loaded" do
46
- @driver.resize_window(800, 600)
47
- @driver.visit("/")
48
- @driver.body.should include("[800x600]")
37
+ driver.resize_window(800, 600)
38
+ driver.visit("#{AppRunner.app_host}/")
39
+ driver.html.should include("[800x600]")
49
40
  end
50
41
 
51
42
  it "resets the window to the default size when the driver is reset" do
52
- @driver.resize_window(800, 600)
53
- @driver.reset!
54
- @driver.visit("/")
55
- @driver.body.should include(DEFAULT_DIMENTIONS)
43
+ driver.resize_window(800, 600)
44
+ driver.reset!
45
+ driver.visit("#{AppRunner.app_host}/")
46
+ driver.html.should include(DEFAULT_DIMENTIONS)
56
47
  end
57
-
58
- after(:all) { @driver.reset! }
59
48
  end
@@ -1,3 +1,5 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
1
3
  require 'spec_helper'
2
4
  require 'capybara/webkit/driver'
3
5
  require 'base64'
@@ -5,19 +7,37 @@ require 'base64'
5
7
  describe Capybara::Webkit::Driver do
6
8
  include AppRunner
7
9
 
10
+ def visit(url, driver=driver)
11
+ driver.visit("#{AppRunner.app_host}#{url}")
12
+ end
13
+
8
14
  context "iframe app" do
9
15
  let(:driver) do
10
16
  driver_for_app do
11
17
  get "/" do
12
- if in_iframe_request?
13
- p_id = "farewell"
14
- msg = "goodbye"
15
- iframe = nil
18
+ if params[:iframe] == "true"
19
+ redirect '/iframe'
16
20
  else
17
- p_id = "greeting"
18
- msg = "hello"
19
- iframe = "<iframe id=\"f\" src=\"/?iframe=true\"></iframe>"
21
+ <<-HTML
22
+ <html>
23
+ <head>
24
+ <style type="text/css">
25
+ #display_none { display: none }
26
+ </style>
27
+ </head>
28
+ <body>
29
+ <iframe id="f" src="/?iframe=true"></iframe>
30
+ <script type="text/javascript">
31
+ document.write("<p id='greeting'>hello</p>");
32
+ </script>
33
+ </body>
34
+ </html>
35
+ HTML
20
36
  end
37
+ end
38
+
39
+ get '/iframe' do
40
+ headers 'X-Redirected' => 'true'
21
41
  <<-HTML
22
42
  <html>
23
43
  <head>
@@ -26,23 +46,18 @@ describe Capybara::Webkit::Driver do
26
46
  </style>
27
47
  </head>
28
48
  <body>
29
- #{iframe}
30
49
  <script type="text/javascript">
31
- document.write("<p id='#{p_id}'>#{msg}</p>");
50
+ document.write("<p id='farewell'>goodbye</p>");
32
51
  </script>
33
52
  </body>
34
53
  </html>
35
54
  HTML
36
55
  end
37
-
38
- def in_iframe_request?
39
- params[:iframe] == "true"
40
- end
41
56
  end
42
57
  end
43
58
 
44
59
  before do
45
- driver.visit("/")
60
+ visit("/")
46
61
  end
47
62
 
48
63
  it "finds frames by index" do
@@ -90,13 +105,7 @@ describe Capybara::Webkit::Driver do
90
105
 
91
106
  it "returns the current URL" do
92
107
  driver.within_frame("f") do
93
- driver.current_url.should == driver_url(driver, "/?iframe=true")
94
- end
95
- end
96
-
97
- it "returns the source code for the page" do
98
- driver.within_frame("f") do
99
- driver.source.should =~ %r{<html>.*farewell.*}m
108
+ driver.current_url.should == driver_url(driver, "/iframe")
100
109
  end
101
110
  end
102
111
 
@@ -113,6 +122,26 @@ describe Capybara::Webkit::Driver do
113
122
  driver.find("//p[contains(., 'yo')]").should_not be_empty
114
123
  end
115
124
  end
125
+
126
+ it "returns focus to parent" do
127
+ original_url = driver.current_url
128
+
129
+ driver.within_frame("f") {}
130
+
131
+ driver.current_url.should == original_url
132
+ end
133
+
134
+ it "returns the headers for the page" do
135
+ driver.within_frame("f") do
136
+ driver.response_headers['X-Redirected'].should == "true"
137
+ end
138
+ end
139
+
140
+ it "returns the status code for the page" do
141
+ driver.within_frame("f") do
142
+ driver.status_code.should == 200
143
+ end
144
+ end
116
145
  end
117
146
 
118
147
  context "error iframe app" do
@@ -135,15 +164,17 @@ describe Capybara::Webkit::Driver do
135
164
  end
136
165
 
137
166
  it "raises error whose message references the actual missing url" do
138
- expect { driver.visit("/") }.to raise_error(Capybara::Webkit::InvalidResponseError, /inner-not-found/)
167
+ expect { visit("/") }.to raise_error(Capybara::Webkit::InvalidResponseError, /inner-not-found/)
139
168
  end
140
169
  end
141
170
 
142
171
  context "redirect app" do
143
172
  let(:driver) do
144
173
  driver_for_app do
174
+ enable :sessions
175
+
145
176
  get '/target' do
146
- headers 'X-Redirected' => 'true'
177
+ headers 'X-Redirected' => (session.delete(:redirected) || false).to_s
147
178
  "<p>#{env['CONTENT_TYPE']}</p>"
148
179
  end
149
180
 
@@ -164,41 +195,49 @@ describe Capybara::Webkit::Driver do
164
195
  end
165
196
 
166
197
  get '/redirect-me' do
167
- redirect '/target'
198
+ if session[:redirected]
199
+ redirect '/target'
200
+ else
201
+ session[:redirected] = true
202
+ redirect '/redirect-me'
203
+ end
168
204
  end
169
205
  end
170
206
  end
171
207
 
172
208
  it "should redirect without content type" do
173
- driver.visit("/form")
209
+ visit("/form")
174
210
  driver.find("//input").first.click
175
211
  driver.find("//p").first.text.should == ""
176
212
  end
177
213
 
178
214
  it "returns the current URL when changed by pushState after a redirect" do
179
- driver.visit("/redirect-me")
215
+ visit("/redirect-me")
180
216
  driver.current_url.should == driver_url(driver, "/target")
181
217
  driver.execute_script("window.history.pushState({}, '', '/pushed-after-redirect')")
182
218
  driver.current_url.should == driver_url(driver, "/pushed-after-redirect")
183
219
  end
184
220
 
185
221
  it "returns the current URL when changed by replaceState after a redirect" do
186
- driver.visit("/redirect-me")
222
+ visit("/redirect-me")
187
223
  driver.current_url.should == driver_url(driver, "/target")
188
224
  driver.execute_script("window.history.replaceState({}, '', '/replaced-after-redirect')")
189
225
  driver.current_url.should == driver_url(driver, "/replaced-after-redirect")
190
226
  end
191
227
 
192
228
  it "should make headers available through response_headers" do
193
- driver.visit('/redirect-me')
229
+ visit('/redirect-me')
194
230
  driver.response_headers['X-Redirected'].should == "true"
231
+ visit('/target')
232
+ driver.response_headers['X-Redirected'].should == "false"
195
233
  end
196
234
 
197
235
  it "should make the status code available through status_code" do
198
- driver.visit('/redirect-me')
236
+ visit('/redirect-me')
237
+ driver.status_code.should == 200
238
+ visit('/target')
199
239
  driver.status_code.should == 200
200
240
  end
201
-
202
241
  end
203
242
 
204
243
  context "css app" do
@@ -211,15 +250,40 @@ describe Capybara::Webkit::Driver do
211
250
  end
212
251
  end
213
252
 
214
- before { driver.visit("/") }
253
+ before { visit("/") }
215
254
 
216
255
  it "renders unsupported content types gracefully" do
217
- driver.body.should =~ /css/
256
+ driver.html.should =~ /css/
218
257
  end
219
258
 
220
259
  it "sets the response headers with respect to the unsupported request" do
221
260
  driver.response_headers["Content-Type"].should == "text/css"
222
261
  end
262
+
263
+ it "does not wrap the content in HTML tags" do
264
+ driver.html.should_not =~ /<html>/
265
+ end
266
+ end
267
+
268
+ context "html app" do
269
+ let(:driver) do
270
+ driver_for_html(<<-HTML)
271
+ <html>
272
+ <head>
273
+ <title>Hello HTML</title>
274
+ </head>
275
+ <body>
276
+ <h1>This Is HTML!</h1>
277
+ </body>
278
+ </html>
279
+ HTML
280
+ end
281
+
282
+ before { visit("/") }
283
+
284
+ it "does not strip HTML tags" do
285
+ driver.html.should =~ /<html>/
286
+ end
223
287
  end
224
288
 
225
289
  context "hello app" do
@@ -250,12 +314,12 @@ describe Capybara::Webkit::Driver do
250
314
  HTML
251
315
  end
252
316
 
253
- before { driver.visit("/") }
317
+ before { visit("/") }
254
318
 
255
319
  it "handles anchor tags" do
256
- driver.visit("#test")
320
+ visit("#test")
257
321
  driver.find("//*[contains(., 'hello')]").should_not be_empty
258
- driver.visit("#test")
322
+ visit("#test")
259
323
  driver.find("//*[contains(., 'hello')]").should_not be_empty
260
324
  end
261
325
 
@@ -295,7 +359,7 @@ describe Capybara::Webkit::Driver do
295
359
  end
296
360
 
297
361
  it "returns the current URL" do
298
- driver.visit "/hello/world?success=true"
362
+ visit "/hello/world?success=true"
299
363
  driver.current_url.should == driver_url(driver, "/hello/world?success=true")
300
364
  end
301
365
 
@@ -310,19 +374,15 @@ describe Capybara::Webkit::Driver do
310
374
  end
311
375
 
312
376
  it "does not double-encode URLs" do
313
- driver.visit("/hello/world?success=%25true")
377
+ visit("/hello/world?success=%25true")
314
378
  driver.current_url.should =~ /success=\%25true/
315
379
  end
316
380
 
317
381
  it "visits a page with an anchor" do
318
- driver.visit("/hello#display_none")
382
+ visit("/hello#display_none")
319
383
  driver.current_url.should =~ /hello#display_none/
320
384
  end
321
385
 
322
- it "returns the source code for the page" do
323
- driver.source.should =~ %r{<html>.*greeting.*}m
324
- end
325
-
326
386
  it "evaluates Javascript and returns a string" do
327
387
  result = driver.evaluate_script(%<document.getElementById('greeting').innerText>)
328
388
  result.should == "hello"
@@ -348,6 +408,11 @@ describe Capybara::Webkit::Driver do
348
408
  result.should == nil
349
409
  end
350
410
 
411
+ it "evaluates Infinity and returns null" do
412
+ result = driver.evaluate_script(%<Infinity>)
413
+ result.should == nil
414
+ end
415
+
351
416
  it "evaluates Javascript and returns an object" do
352
417
  result = driver.evaluate_script(%<({ 'one' : 1 })>)
353
418
  result.should == { 'one' => 1 }
@@ -412,11 +477,14 @@ describe Capybara::Webkit::Driver do
412
477
  driver_for_html(<<-HTML)
413
478
  <html>
414
479
  <head>
480
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
415
481
  </head>
416
482
  <body>
417
483
  <script type="text/javascript">
418
484
  console.log("hello");
419
485
  console.log("hello again");
486
+ console.log("hello\\nnewline");
487
+ console.log("𝄞");
420
488
  oops
421
489
  </script>
422
490
  </body>
@@ -424,26 +492,40 @@ describe Capybara::Webkit::Driver do
424
492
  HTML
425
493
  end
426
494
 
427
- before { driver.visit("/") }
495
+ before { visit("/") }
428
496
 
429
497
  it "collects messages logged to the console" do
430
498
  url = driver_url(driver, "/")
431
499
  message = driver.console_messages.first
432
500
  message.should include :source => url, :message => "hello"
433
- # QtWebKit returns different line numbers depending on the version
434
- [5, 6].should include(message[:line_number])
435
- driver.console_messages.length.should eq 3
501
+ message[:line_number].should == 6
502
+ driver.console_messages.length.should eq 5
436
503
  end
437
504
 
438
505
  it "logs errors to the console" do
439
506
  driver.error_messages.length.should eq 1
440
507
  end
441
508
 
509
+ it "supports multi-line console messages" do
510
+ message = driver.console_messages[2]
511
+ message[:message].should == "hello\nnewline"
512
+ end
513
+
442
514
  it "empties the array when reset" do
443
515
  driver.reset!
444
516
  driver.console_messages.should be_empty
445
517
  end
446
518
 
519
+ it "supports console messages from an unknown source" do
520
+ driver.execute_script("console.log('hello')")
521
+ driver.console_messages.last[:message].should == 'hello'
522
+ driver.console_messages.last[:source].should be_nil
523
+ driver.console_messages.last[:line_number].should be_nil
524
+ end
525
+
526
+ it "escapes unicode console messages" do
527
+ driver.console_messages[3][:message].should == '𝄞'
528
+ end
447
529
  end
448
530
 
449
531
  context "javascript dialog interaction" do
@@ -455,17 +537,17 @@ describe Capybara::Webkit::Driver do
455
537
  </head>
456
538
  <body>
457
539
  <script type="text/javascript">
458
- alert("Alert Text Goes Here");
540
+ alert("Alert Text\\nGoes Here");
459
541
  </script>
460
542
  </body>
461
543
  </html>
462
544
  HTML
463
545
  end
464
546
 
465
- before { driver.visit("/") }
547
+ before { visit("/") }
466
548
 
467
549
  it "should let me read my alert messages" do
468
- driver.alert_messages.first.should == "Alert Text Goes Here"
550
+ driver.alert_messages.first.should == "Alert Text\nGoes Here"
469
551
  end
470
552
 
471
553
  it "empties the array when reset" do
@@ -495,7 +577,7 @@ describe Capybara::Webkit::Driver do
495
577
  HTML
496
578
  end
497
579
 
498
- before { driver.visit("/") }
580
+ before { visit("/") }
499
581
 
500
582
  it "should default to accept the confirm" do
501
583
  driver.find("//input").first.click
@@ -529,10 +611,16 @@ describe Capybara::Webkit::Driver do
529
611
  it "resets to the default of accepting confirms" do
530
612
  driver.dismiss_js_confirms!
531
613
  driver.reset!
532
- driver.visit("/")
614
+ visit("/")
533
615
  driver.find("//input").first.click
534
616
  driver.console_messages.first[:message].should == "hello"
535
617
  end
618
+
619
+ it "supports multi-line confirmation messages" do
620
+ driver.execute_script("confirm('Hello\\nnewline')")
621
+ driver.confirm_messages.first.should == "Hello\nnewline"
622
+ end
623
+
536
624
  end
537
625
 
538
626
  context "on a prompt app" do
@@ -557,7 +645,7 @@ describe Capybara::Webkit::Driver do
557
645
  HTML
558
646
  end
559
647
 
560
- before { driver.visit("/") }
648
+ before { visit("/") }
561
649
 
562
650
  it "should default to dismiss the prompt" do
563
651
  driver.find("//input").first.click
@@ -608,10 +696,16 @@ describe Capybara::Webkit::Driver do
608
696
  it "returns the prompt action to dismiss on reset" do
609
697
  driver.accept_js_prompts!
610
698
  driver.reset!
611
- driver.visit("/")
699
+ visit("/")
612
700
  driver.find("//input").first.click
613
701
  driver.console_messages.first[:message].should == "goodbye"
614
702
  end
703
+
704
+ it "supports multi-line prompt messages" do
705
+ driver.execute_script("prompt('Hello\\nnewline')")
706
+ driver.prompt_messages.first.should == "Hello\nnewline"
707
+ end
708
+
615
709
  end
616
710
  end
617
711
 
@@ -650,7 +744,7 @@ describe Capybara::Webkit::Driver do
650
744
  HTML
651
745
  end
652
746
 
653
- before { driver.visit("/") }
747
+ before { visit("/") }
654
748
 
655
749
  it "returns a textarea's value" do
656
750
  driver.find("//textarea").first.value.should == "what a wonderful area for text"
@@ -728,7 +822,7 @@ describe Capybara::Webkit::Driver do
728
822
  end
729
823
 
730
824
  it "does not modify the selected attribute of a new selection" do
731
- monkey_option['selected'].should be_empty
825
+ monkey_option['selected'].should be_nil
732
826
  end
733
827
 
734
828
  it "returns the old value when a reset button is clicked" do
@@ -859,7 +953,7 @@ describe Capybara::Webkit::Driver do
859
953
  HTML
860
954
  end
861
955
 
862
- before { driver.visit("/") }
956
+ before { visit("/") }
863
957
 
864
958
  it "triggers mouse events" do
865
959
  driver.find("//a").first.click
@@ -911,7 +1005,7 @@ describe Capybara::Webkit::Driver do
911
1005
  HTML
912
1006
  end
913
1007
 
914
- before { driver.visit("/") }
1008
+ before { visit("/") }
915
1009
 
916
1010
  let(:newtext) { 'newvalue' }
917
1011
 
@@ -980,7 +1074,7 @@ describe Capybara::Webkit::Driver do
980
1074
  HTML
981
1075
  end
982
1076
 
983
- before { driver.visit("/") }
1077
+ before { visit("/") }
984
1078
 
985
1079
  it "clicks an element" do
986
1080
  driver.find("//a").first.click
@@ -1028,7 +1122,7 @@ describe Capybara::Webkit::Driver do
1028
1122
  HTML
1029
1123
  end
1030
1124
 
1031
- before { driver.visit("/") }
1125
+ before { visit("/") }
1032
1126
 
1033
1127
  it "evaluates nested xpath expressions" do
1034
1128
  parent = driver.find("//*[@id='parent']").first
@@ -1050,7 +1144,7 @@ describe Capybara::Webkit::Driver do
1050
1144
  %{<html><body><a href="/result">Go</a></body></html>}
1051
1145
  end
1052
1146
  end
1053
- driver.visit("/")
1147
+ visit("/", driver)
1054
1148
  driver.find("//a").first.click
1055
1149
  result.should == "finished"
1056
1150
  end
@@ -1073,7 +1167,7 @@ describe Capybara::Webkit::Driver do
1073
1167
  end
1074
1168
  end
1075
1169
 
1076
- before { driver.visit("/") }
1170
+ before { visit("/") }
1077
1171
 
1078
1172
  it "raises a webkit error for the requested url" do
1079
1173
  expect {
@@ -1108,12 +1202,12 @@ describe Capybara::Webkit::Driver do
1108
1202
  end
1109
1203
  end
1110
1204
 
1111
- before { driver.visit("/") }
1205
+ before { visit("/") }
1112
1206
 
1113
1207
  it "raises a webkit error and then continues" do
1114
1208
  driver.find("//input").first.click
1115
1209
  expect { driver.find("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError)
1116
- driver.visit("/")
1210
+ visit("/")
1117
1211
  driver.find("//p").first.text.should == "hello"
1118
1212
  end
1119
1213
  end
@@ -1137,7 +1231,7 @@ describe Capybara::Webkit::Driver do
1137
1231
  end
1138
1232
  end
1139
1233
 
1140
- before { driver.visit("/") }
1234
+ before { visit("/") }
1141
1235
 
1142
1236
  it "doesn't crash from alerts" do
1143
1237
  driver.find("//p").first.text.should == "success"
@@ -1160,13 +1254,13 @@ describe Capybara::Webkit::Driver do
1160
1254
  end
1161
1255
  end
1162
1256
 
1163
- before { driver.visit("/") }
1257
+ before { visit("/") }
1164
1258
 
1165
1259
  before do
1166
1260
  driver.header('user-agent', 'capybara-webkit/custom-user-agent')
1167
1261
  driver.header('x-capybara-webkit-header', 'x-capybara-webkit-header')
1168
1262
  driver.header('accept', 'text/html')
1169
- driver.visit('/')
1263
+ visit('/')
1170
1264
  end
1171
1265
 
1172
1266
  it "can set user_agent" do
@@ -1190,7 +1284,7 @@ describe Capybara::Webkit::Driver do
1190
1284
 
1191
1285
  it "can reset all custom header" do
1192
1286
  driver.reset!
1193
- driver.visit('/')
1287
+ visit('/')
1194
1288
  driver.find('id("user-agent")').first.text.should_not == 'capybara-webkit/custom-user-agent'
1195
1289
  driver.evaluate_script('navigator.userAgent').should_not == 'capybara-webkit/custom-user-agent'
1196
1290
  driver.find('id("x-capybara-webkit-header")').first.text.should be_empty
@@ -1207,7 +1301,7 @@ describe Capybara::Webkit::Driver do
1207
1301
  HTML
1208
1302
  end
1209
1303
 
1210
- before { driver.visit("/") }
1304
+ before { visit("/") }
1211
1305
 
1212
1306
  it "raises a webkit error for the requested url" do
1213
1307
  make_the_server_go_away
@@ -1238,16 +1332,22 @@ describe Capybara::Webkit::Driver do
1238
1332
  <head>
1239
1333
  <style type="text/css">
1240
1334
  p { font-family: "Verdana"; }
1335
+ p:before { font-family: "Verdana"; }
1336
+ p:after { font-family: "Verdana"; }
1337
+ #first-line-div:first-line { font-family: "Verdana"; }
1338
+ #first-letter-div:first-letter { font-family: "Verdana"; }
1241
1339
  </style>
1242
1340
  </head>
1243
1341
  <body>
1244
1342
  <p id="text">Hello</p>
1343
+ <p id="first-line-div">Hello first line.</p>
1344
+ <p id="first-letter-div">Hello first letter.</p>
1245
1345
  </body>
1246
1346
  </html>
1247
1347
  HTML
1248
1348
  end
1249
1349
 
1250
- before { driver.visit("/") }
1350
+ before { visit("/") }
1251
1351
 
1252
1352
  it "ignores custom fonts" do
1253
1353
  font_family = driver.evaluate_script(<<-SCRIPT)
@@ -1256,6 +1356,38 @@ describe Capybara::Webkit::Driver do
1256
1356
  SCRIPT
1257
1357
  font_family.should == "Arial"
1258
1358
  end
1359
+
1360
+ it "ignores custom fonts before an element" do
1361
+ font_family = driver.evaluate_script(<<-SCRIPT)
1362
+ var element = document.getElementById("text");
1363
+ element.ownerDocument.defaultView.getComputedStyle(element, 'before').getPropertyValue("font-family");
1364
+ SCRIPT
1365
+ font_family.should == "Arial"
1366
+ end
1367
+
1368
+ it "ignores custom fonts after an element" do
1369
+ font_family = driver.evaluate_script(<<-SCRIPT)
1370
+ var element = document.getElementById("text");
1371
+ element.ownerDocument.defaultView.getComputedStyle(element, 'after').getPropertyValue("font-family");
1372
+ SCRIPT
1373
+ font_family.should == "Arial"
1374
+ end
1375
+
1376
+ it "ignores custom fonts applied to the first-line pseudo element" do
1377
+ font_family = driver.evaluate_script(<<-SCRIPT)
1378
+ var element = document.getElementById("first-line-div");
1379
+ element.ownerDocument.defaultView.getComputedStyle(element, 'first-line').getPropertyValue("font-family");
1380
+ SCRIPT
1381
+ font_family.should == "Arial"
1382
+ end
1383
+
1384
+ it "ignores custom fonts applied to the first-letter pseudo element" do
1385
+ font_family = driver.evaluate_script(<<-SCRIPT)
1386
+ var element = document.getElementById("first-letter-div");
1387
+ element.ownerDocument.defaultView.getComputedStyle(element, 'first-letter').getPropertyValue("font-family");
1388
+ SCRIPT
1389
+ font_family.should == "Arial"
1390
+ end
1259
1391
  end
1260
1392
 
1261
1393
  context "cookie-based app" do
@@ -1272,7 +1404,7 @@ describe Capybara::Webkit::Driver do
1272
1404
  end
1273
1405
  end
1274
1406
 
1275
- before { driver.visit("/") }
1407
+ before { visit("/") }
1276
1408
 
1277
1409
  def echoed_cookie
1278
1410
  driver.find('id("cookie")').first.text
@@ -1280,19 +1412,19 @@ describe Capybara::Webkit::Driver do
1280
1412
 
1281
1413
  it "remembers the cookie on second visit" do
1282
1414
  echoed_cookie.should == ""
1283
- driver.visit "/"
1415
+ visit "/"
1284
1416
  echoed_cookie.should == "abc"
1285
1417
  end
1286
1418
 
1287
1419
  it "uses a custom cookie" do
1288
1420
  driver.browser.set_cookie 'cookie=abc; domain=127.0.0.1; path=/'
1289
- driver.visit "/"
1421
+ visit "/"
1290
1422
  echoed_cookie.should == "abc"
1291
1423
  end
1292
1424
 
1293
1425
  it "clears cookies" do
1294
1426
  driver.browser.clear_cookies
1295
- driver.visit "/"
1427
+ visit "/"
1296
1428
  echoed_cookie.should == ""
1297
1429
  end
1298
1430
 
@@ -1323,7 +1455,7 @@ describe Capybara::Webkit::Driver do
1323
1455
  HTML
1324
1456
  end
1325
1457
 
1326
- before { driver.visit("/") }
1458
+ before { visit("/") }
1327
1459
 
1328
1460
  before { set_automatic_reload false }
1329
1461
  after { set_automatic_reload true }
@@ -1382,7 +1514,7 @@ describe Capybara::Webkit::Driver do
1382
1514
  HTML
1383
1515
  end
1384
1516
 
1385
- before { driver.visit("/") }
1517
+ before { visit("/") }
1386
1518
 
1387
1519
  it "builds up node paths correctly" do
1388
1520
  cases = {
@@ -1420,7 +1552,7 @@ describe Capybara::Webkit::Driver do
1420
1552
  HTML
1421
1553
  end
1422
1554
 
1423
- before { driver.visit("/") }
1555
+ before { visit("/") }
1424
1556
 
1425
1557
  it "handles overflow hidden" do
1426
1558
  driver.find("//div[@id='overflow']").first.text.should == "Overflow"
@@ -1448,7 +1580,7 @@ describe Capybara::Webkit::Driver do
1448
1580
 
1449
1581
  it "loads a page without error" do
1450
1582
  10.times do
1451
- driver.visit("/redirect")
1583
+ visit("/redirect")
1452
1584
  driver.find("//p").first.text.should == "finished"
1453
1585
  end
1454
1586
  end
@@ -1475,11 +1607,11 @@ describe Capybara::Webkit::Driver do
1475
1607
  HTML
1476
1608
  end
1477
1609
 
1478
- before { driver.visit("/") }
1610
+ before { visit("/") }
1479
1611
 
1480
1612
  it "displays the message on subsequent page loads" do
1481
1613
  driver.find("//span[contains(.,'localStorage is enabled')]").should be_empty
1482
- driver.visit "/"
1614
+ visit "/"
1483
1615
  driver.find("//span[contains(.,'localStorage is enabled')]").should_not be_empty
1484
1616
  end
1485
1617
  end
@@ -1507,11 +1639,11 @@ describe Capybara::Webkit::Driver do
1507
1639
  end
1508
1640
  end
1509
1641
 
1510
- before { driver.visit("/") }
1642
+ before { visit("/") }
1511
1643
 
1512
1644
  it "submits a form without clicking" do
1513
1645
  driver.find("//form")[0].submit
1514
- driver.body.should include "Congrats"
1646
+ driver.html.should include "Congrats"
1515
1647
  end
1516
1648
  end
1517
1649
 
@@ -1563,7 +1695,7 @@ describe Capybara::Webkit::Driver do
1563
1695
  context "keypress app" do
1564
1696
  let(:driver) { driver_for_key_body "keypress" }
1565
1697
 
1566
- before { driver.visit("/") }
1698
+ before { visit("/") }
1567
1699
 
1568
1700
  it "returns the charCode for the keypressed" do
1569
1701
  charCode_for("a").should == "97"
@@ -1624,28 +1756,16 @@ describe Capybara::Webkit::Driver do
1624
1756
 
1625
1757
  context "keydown app" do
1626
1758
  let(:driver) { driver_for_key_body "keydown" }
1627
- before { driver.visit("/") }
1759
+ before { visit("/") }
1628
1760
  it_behaves_like "a keyupdown app"
1629
1761
  end
1630
1762
 
1631
1763
  context "keyup app" do
1632
1764
  let(:driver) { driver_for_key_body "keyup" }
1633
- before { driver.visit("/") }
1765
+ before { visit("/") }
1634
1766
  it_behaves_like "a keyupdown app"
1635
1767
  end
1636
1768
 
1637
- context "null byte app" do
1638
- let(:driver) do
1639
- driver_for_html("Hello\0World")
1640
- end
1641
-
1642
- before { driver.visit("/") }
1643
-
1644
- it "should include all the bytes in the source" do
1645
- driver.source.should == "Hello\0World"
1646
- end
1647
- end
1648
-
1649
1769
  context "javascript new window app" do
1650
1770
  let(:driver) do
1651
1771
  driver_for_app do
@@ -1667,24 +1787,24 @@ describe Capybara::Webkit::Driver do
1667
1787
  end
1668
1788
  end
1669
1789
 
1670
- before { driver.visit("/") }
1790
+ before { visit("/") }
1671
1791
 
1672
1792
  it "has the expected text in the new window" do
1673
- driver.visit("/new_window")
1793
+ visit("/new_window")
1674
1794
  driver.within_window(driver.window_handles.last) do
1675
1795
  driver.find("//p").first.text.should == "finished"
1676
1796
  end
1677
1797
  end
1678
1798
 
1679
1799
  it "waits for the new window to load" do
1680
- driver.visit("/new_window?sleep=1")
1800
+ visit("/new_window?sleep=1")
1681
1801
  driver.within_window(driver.window_handles.last) do
1682
1802
  driver.find("//p").first.text.should == "finished"
1683
1803
  end
1684
1804
  end
1685
1805
 
1686
1806
  it "waits for the new window to load when the window location has changed" do
1687
- driver.visit("/new_window?sleep=2")
1807
+ visit("/new_window?sleep=2")
1688
1808
  driver.execute_script("setTimeout(function() { window.location = 'about:blank' }, 1000)")
1689
1809
  driver.within_window(driver.window_handles.last) do
1690
1810
  driver.find("//p").first.text.should == "finished"
@@ -1692,27 +1812,27 @@ describe Capybara::Webkit::Driver do
1692
1812
  end
1693
1813
 
1694
1814
  it "switches back to the original window" do
1695
- driver.visit("/new_window")
1815
+ visit("/new_window")
1696
1816
  driver.within_window(driver.window_handles.last) { }
1697
1817
  driver.find("//p").first.text.should == "bananas"
1698
1818
  end
1699
1819
 
1700
1820
  it "supports finding a window by name" do
1701
- driver.visit("/new_window")
1821
+ visit("/new_window")
1702
1822
  driver.within_window('myWindow') do
1703
1823
  driver.find("//p").first.text.should == "finished"
1704
1824
  end
1705
1825
  end
1706
1826
 
1707
1827
  it "supports finding a window by title" do
1708
- driver.visit("/new_window?sleep=5")
1828
+ visit("/new_window?sleep=5")
1709
1829
  driver.within_window('My New Window') do
1710
1830
  driver.find("//p").first.text.should == "finished"
1711
1831
  end
1712
1832
  end
1713
1833
 
1714
1834
  it "supports finding a window by url" do
1715
- driver.visit("/new_window?test")
1835
+ visit("/new_window?test")
1716
1836
  driver.within_window(driver_url(driver, "/?test")) do
1717
1837
  driver.find("//p").first.text.should == "finished"
1718
1838
  end
@@ -1725,12 +1845,12 @@ describe Capybara::Webkit::Driver do
1725
1845
 
1726
1846
  it "has a number of window handles equal to the number of open windows" do
1727
1847
  driver.window_handles.size.should == 1
1728
- driver.visit("/new_window")
1848
+ visit("/new_window")
1729
1849
  driver.window_handles.size.should == 2
1730
1850
  end
1731
1851
 
1732
1852
  it "closes new windows on reset" do
1733
- driver.visit("/new_window")
1853
+ visit("/new_window")
1734
1854
  last_handle = driver.window_handles.last
1735
1855
  driver.reset!
1736
1856
  driver.window_handles.should_not include(last_handle)
@@ -1755,7 +1875,7 @@ describe Capybara::Webkit::Driver do
1755
1875
  end
1756
1876
  end
1757
1877
 
1758
- driver.visit("/new_window")
1878
+ visit("/new_window", driver)
1759
1879
  driver.cookies['session_id'].should == session_id
1760
1880
  end
1761
1881
 
@@ -1792,11 +1912,11 @@ describe Capybara::Webkit::Driver do
1792
1912
  end
1793
1913
  end
1794
1914
 
1795
- before { driver.visit("/") }
1915
+ before { visit("/") }
1796
1916
 
1797
1917
  it "raises error for any loadFinished failure" do
1798
1918
  expect do
1799
- driver.visit("/outer")
1919
+ visit("/outer")
1800
1920
  sleep 1
1801
1921
  driver.find("//body")
1802
1922
  end.to raise_error(Capybara::Webkit::InvalidResponseError)
@@ -1807,7 +1927,7 @@ describe Capybara::Webkit::Driver do
1807
1927
  let(:driver) do
1808
1928
  driver_for_app do
1809
1929
  get "/" do
1810
- if env["HTTP_AUTHORIZATION"]
1930
+ if env["HTTP_AUTHORIZATION"] == "Basic #{Base64.encode64("user:password").strip}"
1811
1931
  env["HTTP_AUTHORIZATION"]
1812
1932
  else
1813
1933
  headers "WWW-Authenticate" => 'Basic realm="Secure Area"'
@@ -1820,8 +1940,95 @@ describe Capybara::Webkit::Driver do
1820
1940
 
1821
1941
  it "can authenticate a request" do
1822
1942
  driver.browser.authenticate('user', 'password')
1823
- driver.visit("/")
1824
- driver.body.should include("Basic "+Base64.encode64("user:password").strip)
1943
+ visit("/")
1944
+ driver.html.should include("Basic "+Base64.encode64("user:password").strip)
1945
+ end
1946
+
1947
+ it "returns 401 for incorrectly authenticated request" do
1948
+ driver.browser.authenticate('user1', 'password1')
1949
+ driver.browser.timeout = 2
1950
+ lambda { visit("/") }.should_not raise_error(Timeout::Error)
1951
+ driver.status_code.should == 401
1952
+ end
1953
+
1954
+ it "returns 401 for unauthenticated request" do
1955
+ driver.browser.timeout = 2
1956
+ lambda { visit("/") }.should_not raise_error(Timeout::Error)
1957
+ driver.status_code.should == 401
1958
+ end
1959
+ end
1960
+
1961
+ describe "url blacklisting" do
1962
+ let(:driver) do
1963
+ driver_for_app do
1964
+ get "/" do
1965
+ <<-HTML
1966
+ <html>
1967
+ <body>
1968
+ <script src="/script"></script>
1969
+ <iframe src="http://example.com/path" id="frame1"></iframe>
1970
+ <iframe src="http://example.org/path/to/file" id="frame2"></iframe>
1971
+ <iframe src="/frame" id="frame3"></iframe>
1972
+ </body>
1973
+ </html>
1974
+ HTML
1975
+ end
1976
+
1977
+ get "/frame" do
1978
+ <<-HTML
1979
+ <html>
1980
+ <body>
1981
+ <p>Inner</p>
1982
+ </body>
1983
+ </html>
1984
+ HTML
1985
+ end
1986
+
1987
+ get "/script" do
1988
+ <<-JS
1989
+ document.write('<p>Script Run</p>')
1990
+ JS
1991
+ end
1992
+ end
1993
+ end
1994
+
1995
+ before do
1996
+ driver.browser.url_blacklist = ["http://example.org/path/to/file",
1997
+ "http://example.com",
1998
+ "#{AppRunner.app_host}/script"]
1999
+ end
2000
+
2001
+ it "should not fetch urls blocked by host" do
2002
+ visit("/")
2003
+ driver.within_frame('frame1') do
2004
+ driver.find("//body").first.text.should be_empty
2005
+ end
2006
+ end
2007
+
2008
+ it "should not fetch urls blocked by path" do
2009
+ visit('/')
2010
+ driver.within_frame('frame2') do
2011
+ driver.find("//body").first.text.should be_empty
2012
+ end
2013
+ end
2014
+
2015
+ it "should not fetch blocked scripts" do
2016
+ visit("/")
2017
+ driver.html.should_not include("Script Run")
2018
+ end
2019
+
2020
+ it "should fetch unblocked urls" do
2021
+ visit('/')
2022
+ driver.within_frame('frame3') do
2023
+ driver.find("//p").first.text.should == "Inner"
2024
+ end
2025
+ end
2026
+
2027
+ it "returns a status code for blocked urls" do
2028
+ visit("/")
2029
+ driver.within_frame('frame1') do
2030
+ driver.status_code.should == 200
2031
+ end
1825
2032
  end
1826
2033
  end
1827
2034
 
@@ -1852,41 +2059,41 @@ describe Capybara::Webkit::Driver do
1852
2059
 
1853
2060
  it "should not raise a timeout error when zero" do
1854
2061
  driver.browser.timeout = 0
1855
- lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError)
2062
+ lambda { visit("/") }.should_not raise_error(Timeout::Error)
1856
2063
  end
1857
2064
 
1858
2065
  it "should raise a timeout error" do
1859
2066
  driver.browser.timeout = 1
1860
- lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError, "Request timed out after 1 second")
2067
+ lambda { visit("/") }.should raise_error(Timeout::Error, "Request timed out after 1 second")
1861
2068
  end
1862
2069
 
1863
2070
  it "should not raise an error when the timeout is high enough" do
1864
2071
  driver.browser.timeout = 10
1865
- lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError)
2072
+ lambda { visit("/") }.should_not raise_error(Timeout::Error)
1866
2073
  end
1867
2074
 
1868
2075
  it "should set the timeout for each request" do
1869
2076
  driver.browser.timeout = 10
1870
- lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError)
2077
+ lambda { visit("/") }.should_not raise_error(Timeout::Error)
1871
2078
  driver.browser.timeout = 1
1872
- lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError)
2079
+ lambda { visit("/") }.should raise_error(Timeout::Error)
1873
2080
  end
1874
2081
 
1875
2082
  it "should set the timeout for each request" do
1876
2083
  driver.browser.timeout = 1
1877
- lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError)
2084
+ lambda { visit("/") }.should raise_error(Timeout::Error)
1878
2085
  driver.reset!
1879
2086
  driver.browser.timeout = 10
1880
- lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError)
2087
+ lambda { visit("/") }.should_not raise_error(Timeout::Error)
1881
2088
  end
1882
2089
 
1883
2090
  it "should raise a timeout on a slow form" do
1884
2091
  driver.browser.timeout = 3
1885
- driver.visit("/")
2092
+ visit("/")
1886
2093
  driver.status_code.should == 200
1887
2094
  driver.browser.timeout = 1
1888
2095
  driver.find("//input").first.click
1889
- lambda { driver.status_code }.should raise_error(Capybara::TimeoutError)
2096
+ lambda { driver.status_code }.should raise_error(Timeout::Error)
1890
2097
  end
1891
2098
 
1892
2099
  it "get timeout" do
@@ -1899,19 +2106,18 @@ describe Capybara::Webkit::Driver do
1899
2106
 
1900
2107
  describe "logger app" do
1901
2108
  it "logs nothing before turning on the logger" do
1902
- driver.visit("/")
2109
+ visit("/")
1903
2110
  log.should == ""
1904
2111
  end
1905
2112
 
1906
2113
  it "logs its commands after turning on the logger" do
1907
2114
  driver.enable_logging
1908
- driver.visit("/")
2115
+ visit("/")
1909
2116
  log.should_not == ""
1910
2117
  end
1911
2118
 
1912
2119
  let(:driver) do
1913
- command = "#{Capybara::Webkit::Connection::SERVER_PATH} 2>&1"
1914
- connection = Capybara::Webkit::Connection.new(:command => command, :stdout => output)
2120
+ connection = Capybara::Webkit::Connection.new(:stdout => output)
1915
2121
  browser = Capybara::Webkit::Browser.new(connection)
1916
2122
  Capybara::Webkit::Driver.new(AppRunner.app, :browser => browser)
1917
2123
  end
@@ -1924,6 +2130,43 @@ describe Capybara::Webkit::Driver do
1924
2130
  end
1925
2131
  end
1926
2132
 
2133
+ context "synchronous ajax app" do
2134
+ let(:driver) do
2135
+ driver_for_app do
2136
+ get '/' do
2137
+ <<-HTML
2138
+ <html>
2139
+ <body>
2140
+ <form id="theForm">
2141
+ <input type="submit" value="Submit" />
2142
+ </form>
2143
+ <script>
2144
+ document.getElementById('theForm').onsubmit = function() {
2145
+ xhr = new XMLHttpRequest();
2146
+ xhr.open('POST', '/', false);
2147
+ xhr.setRequestHeader('Content-Type', 'text/plain');
2148
+ xhr.send('hello');
2149
+ console.log(xhr.response);
2150
+ }
2151
+ </script>
2152
+ </body>
2153
+ </html>
2154
+ HTML
2155
+ end
2156
+
2157
+ post '/' do
2158
+ request.body.read
2159
+ end
2160
+ end
2161
+ end
2162
+
2163
+ it 'should not hang the server' do
2164
+ visit('/')
2165
+ driver.find('//input').first.click
2166
+ driver.console_messages.first[:message].should == "hello"
2167
+ end
2168
+ end
2169
+
1927
2170
  def driver_url(driver, path)
1928
2171
  URI.parse(driver.current_url).merge(path).to_s
1929
2172
  end