diff --git a/spec/contexts_spec.rb b/spec/contexts_spec.rb index 2fe477d1..dda3fcaf 100644 --- a/spec/contexts_spec.rb +++ b/spec/contexts_spec.rb @@ -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