-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rb] Add Bidi Network Response Handler (#14900)
- Loading branch information
Showing
29 changed files
with
1,217 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
class BiDi | ||
class Cookies < Hash | ||
def initialize(cookies = {}) | ||
super() | ||
merge!(cookies) | ||
end | ||
|
||
def as_json | ||
self[:name] = self[:name].to_s | ||
self[:value] = {type: 'string', value: self[:value].to_s} | ||
|
||
[compact] | ||
end | ||
end | ||
end # BiDi | ||
end # WebDriver | ||
end # Selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
class BiDi | ||
class Credentials | ||
attr_accessor :username, :password | ||
|
||
def initialize(username: nil, password: nil) | ||
@username = username | ||
@password = password | ||
end | ||
|
||
def as_json | ||
return nil unless username && password | ||
|
||
{ | ||
type: 'password', | ||
username: username, | ||
password: password | ||
} | ||
end | ||
end | ||
end # BiDi | ||
end # WebDriver | ||
end # Selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
class BiDi | ||
class Headers < Hash | ||
def as_json | ||
map do |name, val| | ||
{ | ||
name: name.to_s, | ||
value: { | ||
type: 'string', | ||
value: val.to_s | ||
} | ||
} | ||
end | ||
end | ||
end | ||
end # BiDi | ||
end # WebDriver | ||
end # Selenium |
38 changes: 38 additions & 0 deletions
38
rb/lib/selenium/webdriver/bidi/network/intercepted_auth.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
class BiDi | ||
class InterceptedAuth < InterceptedItem | ||
def authenticate(username, password) | ||
network.continue_with_auth(id, username, password) | ||
end | ||
|
||
def skip | ||
network.continue_without_auth(id) | ||
end | ||
|
||
def cancel | ||
network.cancel_auth(id) | ||
end | ||
end | ||
end # BiDi | ||
end # WebDriver | ||
end # Selenium |
37 changes: 37 additions & 0 deletions
37
rb/lib/selenium/webdriver/bidi/network/intercepted_item.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
class BiDi | ||
class InterceptedItem | ||
attr_reader :network, :request | ||
|
||
def initialize(network, request) | ||
@network = network | ||
@request = request | ||
end | ||
|
||
def id | ||
@id ||= @request['request'] | ||
end | ||
end | ||
end # BiDi | ||
end # WebDriver | ||
end # Selenium |
69 changes: 69 additions & 0 deletions
69
rb/lib/selenium/webdriver/bidi/network/intercepted_request.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
require_relative 'cookies' | ||
require_relative 'headers' | ||
|
||
module Selenium | ||
module WebDriver | ||
class BiDi | ||
class InterceptedRequest < InterceptedItem | ||
attr_accessor :method, :url | ||
attr_reader :body | ||
|
||
def initialize(network, request) | ||
super | ||
@method = nil | ||
@url = nil | ||
@body = nil | ||
end | ||
|
||
def continue | ||
network.continue_request( | ||
id: id, | ||
body: body, | ||
cookies: cookies.as_json, | ||
headers: headers.as_json, | ||
method: method, | ||
url: url | ||
) | ||
end | ||
|
||
def fail | ||
network.fail_request(id) | ||
end | ||
|
||
def body=(value) | ||
@body = { | ||
type: 'string', | ||
value: value.to_json | ||
} | ||
end | ||
|
||
def headers | ||
@headers ||= Headers.new | ||
end | ||
|
||
def cookies(cookies = {}) | ||
@cookies ||= Cookies.new(cookies) | ||
end | ||
end | ||
end # BiDi | ||
end # WebDriver | ||
end # Selenium |
Oops, something went wrong.