Skip to content

Commit f33e38e

Browse files
committed
chore: Move tests for debug_url from Cuprite
1 parent 9959f23 commit f33e38e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/ferrum/browser.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ def debug_url
295295
end
296296

297297
def build_remote_debug_url(path:)
298+
return path if Addressable::URI.parse(path).absolute?
299+
298300
"http://#{process.host}:#{process.port}#{path}"
299301
end
300302
end

spec/browser_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,30 @@
632632
end
633633
end
634634

635+
describe "#debug_url" do
636+
it "parses the devtools frontend url correctly when devtoolsFrontendUrl is relative" do
637+
browser = Ferrum::Browser.new(port: 12_345)
638+
uri = instance_double(URI)
639+
640+
allow(browser).to receive(:URI).with("http://127.0.0.1:12345/json").and_return(uri)
641+
allow(Net::HTTP).to receive(:get).with(uri).and_return(%([{"devtoolsFrontendUrl":"/works"}]))
642+
643+
expect(browser.send(:debug_url)).to eq("http://127.0.0.1:12345/works")
644+
end
645+
646+
it "parses the devtools frontend url correctly when devtoolsFrontendUrl is fully qualified" do
647+
browser = Ferrum::Browser.new(port: 12_346)
648+
uri = instance_double(URI)
649+
650+
allow(browser).to receive(:URI).with("http://127.0.0.1:12346/json").and_return(uri)
651+
allow(Net::HTTP).to receive(:get).with(uri).and_return(
652+
%([{"devtoolsFrontendUrl":"https://chrome-devtools-frontend.appspot.com/serve_rev?ws=123"}])
653+
)
654+
655+
expect(browser.send(:debug_url)).to eq("https://chrome-devtools-frontend.appspot.com/serve_rev?ws=123")
656+
end
657+
end
658+
635659
context "with pty", if: Ferrum::Utils::Platform.mri? && !Ferrum::Utils::Platform.windows? do
636660
require "pty"
637661
require "timeout"

0 commit comments

Comments
 (0)