Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/bidi/intercepted_request_spec.rb
4043 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
require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/cookies', __dir__)
22
require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/headers', __dir__)
23
require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/intercepted_request', __dir__)
24
25
module Selenium
26
module WebDriver
27
class BiDi
28
describe InterceptedRequest do
29
let(:mock_network) { instance_double(Network) }
30
let(:mock_request) { {'request' => 'req-123'} }
31
let(:request_id) { 'req-123' }
32
let(:intercepted_request) { described_class.new(mock_network, mock_request) }
33
let(:mock_headers) { [{name: 'Auth', value: 'token'}] }
34
let(:mock_cookies) { [{name: 'session', value: {type: 'string', value: '123'}}] }
35
36
describe '#continue' do
37
before do
38
allow(mock_network).to receive(:continue_request)
39
end
40
41
it 'sends only the mandatory ID when no optional fields are set' do
42
expected_payload = {id: request_id, body: nil, cookies: nil, headers: nil, method: nil, url: nil}
43
intercepted_request.continue
44
45
expect(mock_network).to have_received(:continue_request).with(expected_payload)
46
end
47
48
it 'sends headers payload when headers are explicitly set' do
49
intercepted_request.headers = mock_headers
50
51
expected_payload = {
52
id: request_id,
53
body: nil,
54
cookies: nil,
55
headers: Headers.new(mock_headers).as_json,
56
method: nil,
57
url: nil
58
}
59
60
intercepted_request.continue
61
62
expect(mock_network).to have_received(:continue_request).with(expected_payload)
63
end
64
65
it 'sends cookies payload when cookies are explicitly set' do
66
intercepted_request.cookies = mock_cookies
67
68
expected_payload = {
69
id: request_id,
70
body: nil,
71
cookies: Cookies.new(mock_cookies).as_json,
72
headers: nil,
73
method: nil,
74
url: nil
75
}
76
77
intercepted_request.continue
78
79
expect(mock_network).to have_received(:continue_request).with(expected_payload)
80
end
81
82
it 'sends full custom payload when all fields are set' do
83
intercepted_request.headers = mock_headers
84
intercepted_request.cookies = mock_cookies
85
intercepted_request.method = 'POST'
86
87
expected_payload = {
88
id: request_id,
89
body: nil,
90
cookies: Cookies.new(mock_cookies).as_json,
91
headers: Headers.new(mock_headers).as_json,
92
method: 'POST',
93
url: nil
94
}
95
96
intercepted_request.continue
97
98
expect(mock_network).to have_received(:continue_request).with(expected_payload)
99
end
100
end
101
end
102
end
103
end
104
end
105
106