Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/bidi/network_spec.rb
4020 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require File.expand_path('../spec_helper', __dir__)
21
# Adjust the require path as necessary for your project structure
22
require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network', __dir__)
23
24
module Selenium
25
module WebDriver
26
class BiDi
27
describe Network do
28
let(:mock_bidi) { instance_double(BiDi, 'Bidi') }
29
let(:network) { described_class.new(mock_bidi) }
30
let(:request_id) { '12345-request-id' }
31
32
before { allow(mock_bidi).to receive(:send_cmd).and_return({}) }
33
34
describe '#continue_request' do
35
it 'sends only the mandatory request ID when all optional args are nil' do
36
expected_payload = {request: request_id}
37
38
network.continue_request(id: request_id)
39
40
expect(mock_bidi).to have_received(:send_cmd).with('network.continueRequest', expected_payload)
41
end
42
43
it 'sends only provided optional args' do
44
expected_payload = {
45
request: request_id,
46
body: {type: 'string', value: 'new body'},
47
method: 'POST'
48
}
49
50
network.continue_request(
51
id: request_id,
52
body: {type: 'string', value: 'new body'},
53
cookies: nil,
54
headers: nil,
55
method: 'POST'
56
)
57
58
expect(mock_bidi).to have_received(:send_cmd).with('network.continueRequest', expected_payload)
59
end
60
end
61
62
describe '#continue_response' do
63
it 'sends only the mandatory request ID when all optional args are nil' do
64
expected_payload = {request: request_id}
65
66
network.continue_response(id: request_id)
67
68
expect(mock_bidi).to have_received(:send_cmd).with('network.continueResponse', expected_payload)
69
end
70
71
it 'sends only provided optional args' do
72
expected_headers = [{name: 'Auth', value: {type: 'string', value: 'Token'}}]
73
expected_payload = {
74
request: request_id,
75
headers: expected_headers,
76
statusCode: 202
77
}
78
79
network.continue_response(
80
id: request_id,
81
cookies: nil,
82
credentials: nil,
83
headers: expected_headers,
84
reason: nil,
85
status: 202
86
)
87
88
expect(mock_bidi).to have_received(:send_cmd).with('network.continueResponse', expected_payload)
89
end
90
end
91
92
describe '#provide_response' do
93
it 'sends only the mandatory request ID when all optional args are nil' do
94
expected_payload = {request: request_id}
95
96
network.provide_response(id: request_id)
97
98
expect(mock_bidi).to have_received(:send_cmd).with('network.provideResponse', expected_payload)
99
end
100
101
it 'sends only provided optional args' do
102
expected_payload = {
103
request: request_id,
104
body: {type: 'string', value: 'Hello'},
105
reasonPhrase: 'OK-Custom'
106
}
107
108
network.provide_response(
109
id: request_id,
110
body: {type: 'string', value: 'Hello'},
111
cookies: nil,
112
headers: nil,
113
reason: 'OK-Custom',
114
status: nil
115
)
116
117
expect(mock_bidi).to have_received(:send_cmd).with('network.provideResponse', expected_payload)
118
end
119
end
120
end
121
end
122
end
123
end
124
125