Skip to content
Closed
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
30 changes: 11 additions & 19 deletions spec/contexts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
# frozen_string_literal: true

describe Ferrum::Contexts do
# Chrome opens two `chrome://omnibox-popup.top-chrome/` (`browser_ui`) targets per
# browser context. Auto-attach runs with `waitForDebuggerOnStart`, so they arrive
# paused, and nothing resumes a type we don't track: left alone they stay attached
# and paused for the lifetime of the browser.
# Chrome opens `chrome://omnibox-popup.top-chrome/` (`browser_ui`) targets in every
# browser context (two up to Chrome 156, one since 157). Auto-attach runs with
# `waitForDebuggerOnStart`, so they arrive paused, and nothing resumes a type we don't
# track: left alone they stay attached and paused for the lifetime of the browser.
describe ".new" do
it "detaches from attached targets of a type it doesn't track" do
untracked = Concurrent::Array.new
detached = Concurrent::Array.new

attached_id = browser.client.on("Target.attachedToTarget") do |params|
type = params["targetInfo"]["type"]
untracked << params["sessionId"] unless described_class::ALLOWED_TARGET_TYPES.include?(type)
end
detached_id = browser.client.on("Target.detachedFromTarget") { |params| detached << params["sessionId"] }

browser.contexts.create.create_page
context = browser.contexts.create
context.create_page

wait(5).for { untracked.size }.to be >= 2
wait(5).for { untracked - detached }.to be_empty
ensure
browser.client.off("Target.attachedToTarget", attached_id)
browser.client.off("Target.detachedFromTarget", detached_id)
wait(5).for do
browser.client.command("Target.getTargets")["targetInfos"]
.select { |info| info["browserContextId"] == context.id && info["type"] == "browser_ui" }
.map { |info| info["attached"] }
end.to include(false).and(all(be(false)))
end
end

Expand Down