Path: blob/trunk/rb/spec/unit/selenium/webdriver/bidi/cookies_spec.rb
1865 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__)2122module Selenium23module WebDriver24class BiDi25describe Cookies do26it 'returns the cookies as json' do27cookies = described_class.new28cookies['key4'] = 'value4'29cookies['session_id'] = 'xyz123'3031formatted_cookies = cookies.as_json32expect(formatted_cookies).to be_an(Array)33expect(formatted_cookies.first['key4']).to eq('value4')34expect(formatted_cookies.first['session_id']).to eq('xyz123')35end3637it 'serializes the cookies needed for request' do38cookies =39described_class.new(40{41name: 'test',42value: 'value4',43domain: 'example.com',44path: '/path',45size: 1234,46httpOnly: true,47secure: true,48sameSite: 'Strict',49expiry: 123450}51)5253formatted_cookies = cookies.as_json54expect(formatted_cookies).to be_an(Array)55expect(formatted_cookies.size).to eq(1)5657request_cookies = formatted_cookies.first58expect(request_cookies[:name]).to eq('test')59expect(request_cookies[:value][:type]).to eq('string')60expect(request_cookies[:value][:value]).to eq('value4')61expect(request_cookies[:domain]).to eq('example.com')62expect(request_cookies[:path]).to eq('/path')63expect(request_cookies[:expiry]).to eq(1234)64expect(request_cookies[:httpOnly]).to be(true)65expect(request_cookies[:secure]).to be(true)66expect(request_cookies[:sameSite]).to eq('Strict')67expect(request_cookies[:size]).to eq(1234)68end6970it 'serializes the cookies needed for response' do71cookies = described_class.new({72name: 'test',73value: 'bar',74domain: 'localhost',75httpOnly: true,76expiry: '1_000_000',77maxAge: 1_000,78path: '/',79sameSite: 'lax',80secure: false81})8283formatted_cookies = cookies.as_json84expect(formatted_cookies).to be_an(Array)85expect(formatted_cookies.size).to eq(1)86response_cookies = formatted_cookies.first87expect(response_cookies[:value][:type]).to eq('string')88expect(response_cookies[:value][:value]).to eq('bar')89expect(response_cookies[:domain]).to eq('localhost')90expect(response_cookies[:path]).to eq('/')91expect(response_cookies[:expiry]).to eq('1_000_000')92expect(response_cookies[:httpOnly]).to be(true)93expect(response_cookies[:secure]).to be(false)94expect(response_cookies[:sameSite]).to eq('lax')95expect(response_cookies[:maxAge]).to eq(1_000)96end97end98end99end100end101102103