Skip to content

Commit

Permalink
Simplify methods and have general callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
aguspe committed Nov 16, 2024
1 parent eacb7d7 commit f07a38a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
16 changes: 3 additions & 13 deletions rb/lib/selenium/webdriver/common/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def add_authentication_handler(username, password)
auth_id
end

def remove_authentication_handler(id)
def remove_handler(id)
intercept = @callbacks[id]
@network.remove_intercept(intercept['intercept'])
@callbacks.delete(id)
end

def clear_authentication_handlers
@callbacks.each_key { |id| remove_authentication_handler(id) }
def clear_handlers
@callbacks.each_key { |id| remove_handler(id) }
end

def add_request_handler
Expand All @@ -59,16 +59,6 @@ def add_request_handler

request_id
end

def remove_request_handler(id)
intercept = @callbacks[id]
@network.remove_intercept(intercept['intercept'])
@callbacks.delete(id)
end

def clear_request_handlers
@callbacks.each_key { |id| remove_request_handler(id) }
end
end # Network
end # WebDriver
end # Selenium
8 changes: 2 additions & 6 deletions rb/sig/lib/selenium/webdriver/common/network.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ module Selenium

def add_request_handler: -> Integer

def clear_authentication_handlers: -> Hash[nil, nil]
def clear_handlers: -> Hash[nil, nil]

def clear_request_handlers: -> Hash[nil, nil]

def remove_authentication_handler: (Integer id) -> nil

def remove_request_handler: (Integer id) -> nil
def remove_handler: (Integer id) -> nil
end
end
end
11 changes: 5 additions & 6 deletions rb/spec/integration/selenium/webdriver/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

module Selenium
module WebDriver
describe Network, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'},
only: {browser: %i[chrome edge firefox]} do
describe Network do
let(:username) { SpecSupport::RackServer::TestApp::BASIC_AUTH_CREDENTIALS.first }
let(:password) { SpecSupport::RackServer::TestApp::BASIC_AUTH_CREDENTIALS.last }

Expand All @@ -39,7 +38,7 @@ module WebDriver
reset_driver!(web_socket_url: true) do |driver|
network = described_class.new(driver)
id = network.add_authentication_handler(username, password)
network.remove_authentication_handler(id)
network.remove_handler(id)
expect(network.callbacks.count).to be 0
end
end
Expand All @@ -49,7 +48,7 @@ module WebDriver
network = described_class.new(driver)
network.add_authentication_handler(username, password)
network.add_authentication_handler(username, password)
network.clear_authentication_handlers
network.clear_handlers
expect(network.callbacks.count).to be 0
end
end
Expand All @@ -66,7 +65,7 @@ module WebDriver
reset_driver!(web_socket_url: true) do |driver|
network = described_class.new(driver)
id = network.add_request_handler
network.remove_request_handler(id)
network.remove_handler(id)
expect(network.callbacks.count).to be 0
end
end
Expand All @@ -76,7 +75,7 @@ module WebDriver
network = described_class.new(driver)
network.add_request_handler
network.add_request_handler
network.clear_request_handlers
network.clear_handlers
expect(network.callbacks.count).to be 0
end
end
Expand Down

0 comments on commit f07a38a

Please sign in to comment.