<commit_before># frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

require_relative 'spec_helper'

module Selenium
  module WebDriver
    describe Manager do
      describe 'logs', except: [{browser: %i[firefox ie safari safari_preview]},
                                {driver: :remote, browser: %i[chrome edge]}] do
        it 'can fetch remote log types', only: {driver: :remote} do
          expect(driver.manage.logs.available_types).to include(:server, :browser, :driver)
        end

        it 'can fetch available log types', except: {driver: :remote} do
          expect(driver.manage.logs.available_types).to include(:browser, :driver)
          expect(driver.manage.logs.available_types).not_to include(:server)
        end

        it 'can get the browser log' do
          driver.navigate.to url_for('errors.html')
          driver.find_element(tag_name: 'input').click

          entries = driver.manage.logs.get(:browser)
          expect(entries).not_to be_empty
          expect(entries.first).to be_kind_of(LogEntry)
        end

        # Chrome - turned off by default
        it 'can get the driver log', except: {browser: %i[chrome edge]} do
          driver.navigate.to url_for('simpleTest.html')

          entries = driver.manage.logs.get(:driver)
          expect(entries).not_to be_empty
          expect(entries.first).to be_kind_of(LogEntry)
        end
      end

      describe 'cookie management' do
        after { driver.manage.delete_all_cookies }

        it 'should show http only when insecure' do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'security',
                                   value: 'insecure',
                                   http_only: true

          expect(driver.manage.cookie_named('security')[:http_only]).to eq true
        end

        it 'should not show secure when insecure' do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'security',
                                   value: 'secure',
                                   secure: true

          cookies = driver.manage.all_cookies
          expect(cookies.size).to eq(0)
        end

        it 'should respect path' do<commit_msg>[rb] guard spec for Firefox secure cookie handling pending https://github.com/mozilla/geckodriver/issues/1840<commit_after># frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

require_relative 'spec_helper'

module Selenium
  module WebDriver
    describe Manager do
      describe 'logs', except: [{browser: %i[firefox ie safari safari_preview]},
                                {driver: :remote, browser: %i[chrome edge]}] do
        it 'can fetch remote log types', only: {driver: :remote} do
          expect(driver.manage.logs.available_types).to include(:server, :browser, :driver)
        end

        it 'can fetch available log types', except: {driver: :remote} do
          expect(driver.manage.logs.available_types).to include(:browser, :driver)
          expect(driver.manage.logs.available_types).not_to include(:server)
        end

        it 'can get the browser log' do
          driver.navigate.to url_for('errors.html')
          driver.find_element(tag_name: 'input').click

          entries = driver.manage.logs.get(:browser)
          expect(entries).not_to be_empty
          expect(entries.first).to be_kind_of(LogEntry)
        end

        # Chrome - turned off by default
        it 'can get the driver log', except: {browser: %i[chrome edge]} do
          driver.navigate.to url_for('simpleTest.html')

          entries = driver.manage.logs.get(:driver)
          expect(entries).not_to be_empty
          expect(entries.first).to be_kind_of(LogEntry)
        end
      end

      describe 'cookie management' do
        after { driver.manage.delete_all_cookies }

        it 'should show http only when insecure' do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'security',
                                   value: 'insecure',
                                   http_only: true

          expect(driver.manage.cookie_named('security')[:http_only]).to eq true
        end

        it 'should not add secure when http', except: {browser: :firefox,
                                                       reason: 'https://github.com/mozilla/geckodriver/issues/1840'} do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'security',
                                   value: 'secure',
                                   secure: true

          cookies = driver.manage.all_cookies
          expect(cookies.size).to eq(0)
        end

        it 'should respect path' do
{'fraction_non_alphanumeric': 0.08666560458817907, 'fraction_numerical': 0.002867611916520631, 'mean_word_length': 2.400866738894908, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1367251', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1605, 'n_words': 547}