Path: blob/trunk/rb/spec/unit/selenium/webdriver/bidi/intercepted_request_spec.rb
4043 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require File.expand_path('../spec_helper', __dir__)20require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/cookies', __dir__)21require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/headers', __dir__)22require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/intercepted_request', __dir__)2324module Selenium25module WebDriver26class BiDi27describe InterceptedRequest do28let(:mock_network) { instance_double(Network) }29let(:mock_request) { {'request' => 'req-123'} }30let(:request_id) { 'req-123' }31let(:intercepted_request) { described_class.new(mock_network, mock_request) }32let(:mock_headers) { [{name: 'Auth', value: 'token'}] }33let(:mock_cookies) { [{name: 'session', value: {type: 'string', value: '123'}}] }3435describe '#continue' do36before do37allow(mock_network).to receive(:continue_request)38end3940it 'sends only the mandatory ID when no optional fields are set' do41expected_payload = {id: request_id, body: nil, cookies: nil, headers: nil, method: nil, url: nil}42intercepted_request.continue4344expect(mock_network).to have_received(:continue_request).with(expected_payload)45end4647it 'sends headers payload when headers are explicitly set' do48intercepted_request.headers = mock_headers4950expected_payload = {51id: request_id,52body: nil,53cookies: nil,54headers: Headers.new(mock_headers).as_json,55method: nil,56url: nil57}5859intercepted_request.continue6061expect(mock_network).to have_received(:continue_request).with(expected_payload)62end6364it 'sends cookies payload when cookies are explicitly set' do65intercepted_request.cookies = mock_cookies6667expected_payload = {68id: request_id,69body: nil,70cookies: Cookies.new(mock_cookies).as_json,71headers: nil,72method: nil,73url: nil74}7576intercepted_request.continue7778expect(mock_network).to have_received(:continue_request).with(expected_payload)79end8081it 'sends full custom payload when all fields are set' do82intercepted_request.headers = mock_headers83intercepted_request.cookies = mock_cookies84intercepted_request.method = 'POST'8586expected_payload = {87id: request_id,88body: nil,89cookies: Cookies.new(mock_cookies).as_json,90headers: Headers.new(mock_headers).as_json,91method: 'POST',92url: nil93}9495intercepted_request.continue9697expect(mock_network).to have_received(:continue_request).with(expected_payload)98end99end100end101end102end103end104105106