Skip to content

Commit 160f21d

Browse files
committed
Implement single type of callbacks
1 parent ed3bb23 commit 160f21d

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

rb/lib/selenium/webdriver/common/network.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
module Selenium
2121
module WebDriver
2222
class Network
23-
attr_reader :auth_callbacks, :request_callbacks
23+
attr_reader :callbacks
2424

2525
def initialize(bridge)
2626
@network = BiDi::Network.new(bridge.bidi)
27-
@auth_callbacks = {}
28-
@request_callbacks = {}
27+
@callbacks = {}
2928
end
3029

3130
def add_authentication_handler(username, password)
@@ -34,19 +33,19 @@ def add_authentication_handler(username, password)
3433
request_id = event['requestId']
3534
@network.continue_with_auth(request_id, username, password)
3635
end
37-
@auth_callbacks[auth_id] = intercept
36+
@callbacks[auth_id] = intercept
3837

3938
auth_id
4039
end
4140

4241
def remove_authentication_handler(id)
43-
intercept = @auth_callbacks[id]
42+
intercept = @callbacks[id]
4443
@network.remove_intercept(intercept['intercept'])
45-
@auth_callbacks.delete(id)
44+
@callbacks.delete(id)
4645
end
4746

4847
def clear_authentication_handlers
49-
@auth_callbacks.each_key { |id| remove_authentication_handler(id) }
48+
@callbacks.each_key { |id| remove_authentication_handler(id) }
5049
end
5150

5251
def add_request_handler
@@ -56,19 +55,19 @@ def add_request_handler
5655
@network.continue_with_request(request_id: request_id)
5756
end
5857

59-
@request_callbacks[request_id] = intercept
58+
@callbacks[request_id] = intercept
6059

6160
request_id
6261
end
6362

6463
def remove_request_handler(id)
65-
intercept = @request_callbacks[id]
64+
intercept = @callbacks[id]
6665
@network.remove_intercept(intercept['intercept'])
67-
@request_callbacks.delete(id)
66+
@callbacks.delete(id)
6867
end
6968

7069
def clear_request_handlers
71-
@request_callbacks.each_key { |id| remove_request_handler(id) }
70+
@callbacks.each_key { |id| remove_request_handler(id) }
7271
end
7372
end # Network
7473
end # WebDriver

rb/sig/lib/selenium/webdriver/common/network.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module Selenium
33
class Network
44
@network: BiDi::Network
55

6-
@request_callbacks: untyped
6+
@callbacks: Hash[String, String]
77

8-
attr_reader auth_callbacks: Hash[String, String]
8+
attr_reader callbacks: Hash[String, String]
99

1010
def initialize: (Remote::Bridge bridge) -> void
1111

rb/spec/integration/selenium/webdriver/network_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module WebDriver
3131
reset_driver!(web_socket_url: true) do |driver|
3232
network = described_class.new(driver)
3333
network.add_authentication_handler(username, password)
34-
expect(network.auth_callbacks.count).to be 1
34+
expect(network.callbacks.count).to be 1
3535
end
3636
end
3737

@@ -40,7 +40,7 @@ module WebDriver
4040
network = described_class.new(driver)
4141
id = network.add_authentication_handler(username, password)
4242
network.remove_authentication_handler(id)
43-
expect(network.auth_callbacks.count).to be 0
43+
expect(network.callbacks.count).to be 0
4444
end
4545
end
4646

@@ -50,15 +50,15 @@ module WebDriver
5050
network.add_authentication_handler(username, password)
5151
network.add_authentication_handler(username, password)
5252
network.clear_authentication_handlers
53-
expect(network.auth_callbacks.count).to be 0
53+
expect(network.callbacks.count).to be 0
5454
end
5555
end
5656

5757
it 'adds a request handler' do
5858
reset_driver!(web_socket_url: true) do |driver|
5959
network = described_class.new(driver)
6060
network.add_request_handler
61-
expect(network.request_callbacks.count).to be 1
61+
expect(network.callbacks.count).to be 1
6262
end
6363
end
6464

@@ -67,7 +67,7 @@ module WebDriver
6767
network = described_class.new(driver)
6868
id = network.add_request_handler
6969
network.remove_request_handler(id)
70-
expect(network.request_callbacks.count).to be 0
70+
expect(network.callbacks.count).to be 0
7171
end
7272
end
7373

@@ -77,7 +77,7 @@ module WebDriver
7777
network.add_request_handler
7878
network.add_request_handler
7979
network.clear_request_handlers
80-
expect(network.request_callbacks.count).to be 0
80+
expect(network.callbacks.count).to be 0
8181
end
8282
end
8383
end

0 commit comments

Comments
 (0)