Path: blob/trunk/rb/spec/unit/selenium/webdriver/bidi/network_spec.rb
4020 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__)20# Adjust the require path as necessary for your project structure21require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network', __dir__)2223module Selenium24module WebDriver25class BiDi26describe Network do27let(:mock_bidi) { instance_double(BiDi, 'Bidi') }28let(:network) { described_class.new(mock_bidi) }29let(:request_id) { '12345-request-id' }3031before { allow(mock_bidi).to receive(:send_cmd).and_return({}) }3233describe '#continue_request' do34it 'sends only the mandatory request ID when all optional args are nil' do35expected_payload = {request: request_id}3637network.continue_request(id: request_id)3839expect(mock_bidi).to have_received(:send_cmd).with('network.continueRequest', expected_payload)40end4142it 'sends only provided optional args' do43expected_payload = {44request: request_id,45body: {type: 'string', value: 'new body'},46method: 'POST'47}4849network.continue_request(50id: request_id,51body: {type: 'string', value: 'new body'},52cookies: nil,53headers: nil,54method: 'POST'55)5657expect(mock_bidi).to have_received(:send_cmd).with('network.continueRequest', expected_payload)58end59end6061describe '#continue_response' do62it 'sends only the mandatory request ID when all optional args are nil' do63expected_payload = {request: request_id}6465network.continue_response(id: request_id)6667expect(mock_bidi).to have_received(:send_cmd).with('network.continueResponse', expected_payload)68end6970it 'sends only provided optional args' do71expected_headers = [{name: 'Auth', value: {type: 'string', value: 'Token'}}]72expected_payload = {73request: request_id,74headers: expected_headers,75statusCode: 20276}7778network.continue_response(79id: request_id,80cookies: nil,81credentials: nil,82headers: expected_headers,83reason: nil,84status: 20285)8687expect(mock_bidi).to have_received(:send_cmd).with('network.continueResponse', expected_payload)88end89end9091describe '#provide_response' do92it 'sends only the mandatory request ID when all optional args are nil' do93expected_payload = {request: request_id}9495network.provide_response(id: request_id)9697expect(mock_bidi).to have_received(:send_cmd).with('network.provideResponse', expected_payload)98end99100it 'sends only provided optional args' do101expected_payload = {102request: request_id,103body: {type: 'string', value: 'Hello'},104reasonPhrase: 'OK-Custom'105}106107network.provide_response(108id: request_id,109body: {type: 'string', value: 'Hello'},110cookies: nil,111headers: nil,112reason: 'OK-Custom',113status: nil114)115116expect(mock_bidi).to have_received(:send_cmd).with('network.provideResponse', expected_payload)117end118end119end120end121end122end123124125