Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset with data url #1215

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class UnselectNotAllowed < CapybaraError; end
class NotSupportedByDriverError < CapybaraError; end
class InfiniteRedirectError < CapybaraError; end

EMPTY_HTML_FILE_PATH = File.expand_path('./capybara/empty.html', File.dirname(__FILE__))

class << self
attr_accessor :asset_host, :app_host, :run_server, :default_host, :always_include_port
attr_accessor :server_port, :exact, :match, :exact_options, :visible_text_only
Expand Down
4 changes: 0 additions & 4 deletions lib/capybara/empty.html

This file was deleted.

5 changes: 2 additions & 3 deletions lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
:browser => :firefox
}
SPECIAL_OPTIONS = [:browser]
EMPTY_HTML = "data:text/html,<html></html>"

attr_reader :app, :options

Expand Down Expand Up @@ -97,9 +98,7 @@ def reset!
# to about:blank, so we rescue this error and do nothing
# instead.
end
uri = URI(Capybara::EMPTY_HTML_FILE_PATH)
uri.scheme = "file"
@browser.navigate.to(uri.to_s)
@browser.navigate.to(EMPTY_HTML)
end
end

Expand Down
21 changes: 15 additions & 6 deletions lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Session
:title, :has_title?, :has_no_title?, :current_scope
]
DSL_METHODS = NODE_METHODS + SESSION_METHODS
SCHEME_REGEXP = /^(https?|data):/

attr_reader :mode, :app, :server
attr_accessor :synchronized
Expand Down Expand Up @@ -122,17 +123,25 @@ def html
# @return [String] Path of the current page, without any domain information
#
def current_path
path = URI.parse(current_url).path
path if path and not path.empty?
url = current_url
if url.start_with?("data:")
url
else
path = URI.parse(url).path
path if path and not path.empty?
end
end

##
#
# @return [String] Host of the current page
#
def current_host
uri = URI.parse(current_url)
"#{uri.scheme}://#{uri.host}" if uri.host
url = current_url
unless url.start_with?("data:")
uri = URI.parse(current_url)
"#{uri.scheme}://#{uri.host}" if uri.host
end
end

##
Expand Down Expand Up @@ -180,12 +189,12 @@ def title
def visit(url)
@touched = true

if url !~ /^http/ and Capybara.app_host
if url !~ SCHEME_REGEXP and Capybara.app_host
url = Capybara.app_host + url.to_s
end

if @server
url = "http://#{@server.host}:#{@server.port}" + url.to_s unless url =~ /^http/
url = "http://#{@server.host}:#{@server.port}" + url.to_s if url !~ SCHEME_REGEXP

if Capybara.always_include_port
uri = URI.parse(url)
Expand Down
7 changes: 7 additions & 0 deletions lib/capybara/spec/session/current_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ def visit_host_links
@session.execute_script("window.history.replaceState({}, '', '/replaced')")
@session.current_path.should == "/replaced"
end

it "returns data url", :requires => [:js] do
@session.visit("data:text/html,<h1>Hello</h1>")
@session.current_url.should == "data:text/html,<h1>Hello</h1>"
@session.current_path.should == "data:text/html,<h1>Hello</h1>"
@session.current_host.should be_nil
end
end
4 changes: 2 additions & 2 deletions lib/capybara/spec/session/reset_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
->(v) { v == nil },
->(v) { v == '' },
->(v) { v == 'about:blank' },
->(v) { v.end_with? Capybara::EMPTY_HTML_FILE_PATH } # allow file:// protocol
->(v) { v.start_with? "data:text/html" }
].any? { |p| p.(@session.current_url) }.should be_true
[
->(v) { v == '' },
->(v) { v == nil },
->(v) { v == Capybara::EMPTY_HTML_FILE_PATH }
->(v) { v.start_with? "data:text/html" }
].any? { |p| p.(@session.current_path) }.should be_true
@session.current_host.should be_nil
end
Expand Down