<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 Options do
      describe 'logs', only: {browser: %i[ff_esr chrome]} 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: :chrome} 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
        it 'should get all' do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'foo', value: 'bar'

          cookies = driver.manage.all_cookies

          expect(cookies.size).to eq(1)
          expect(cookies.first[:name]).to eq('foo')
          expect(cookies.first[:value]).to eq('bar')
        end

        it 'should get named cookie' do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'foo', value: 'bar'

          expect(driver.manage.cookie_named('foo')[:value]).to eq('bar')
        end

        # Edge BUG - https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5751773/
        it 'should delete one', except: {browser: :edge} do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'foo', value: 'bar'

          driver.manage.delete_cookie('foo')
          expect(driver.manage.all_cookies.find { |c| c[:name] == 'foo' }).to be_nil
        end

        it 'should delete all', except: {browser: :edge} do
          driver.navigate.to url_for('xhtmlTest.html')

          driver.manage.add_cookie name: 'foo', value: 'bar'
          driver.manage.add_cookie name: 'bar', value: 'foo'
          driver.manage.delete_all_cookies
          expect(driver.manage.all_cookies).to be_empty
        end

        it 'should use DateTime for expires', except: {browser: %i[safari safari_preview]} do
          driver.navigate.to url_for('xhtmlTest.html')

          expected = DateTime.new(2039)
          driver.manage.add_cookie name: 'foo',
                                   value: 'bar',
                                   expires: expected

          actual = driver.manage.cookie_named('foo')[:expires]
          expect(actual).to be_kind_of(DateTime)
          expect(actual).to eq(expected)
        end
      end

      describe 'new_window', only: {browser: %i[safari_preview firefox ie]} do
        types = [:tab, :window] # Stores the valid type values for new_window
        types.each do |type|
          it "should be able to open a new #{type}" do
            # Store the count of window handles before executing action
            before_window_handles = driver.window_handles.length
            # Open a new window
            driver.manage.new_window(type)
            # Store the count of window handles after executing action
            after_window_handles = driver.window_handles.length
            # 1 window handle should have been added
            expect(after_window_handles).to eq(before_window_handles + 1)
          end
        end

        it "returns an exception if an invalid type is provided" do
          invalid_types = [:invalid, 'invalid', 'tab', 'window']
          invalid_types.each do |type|<commit_msg>Ensure failing new_window tests are not pending<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 Options do
      describe 'logs', only: {browser: %i[ff_esr chrome]} 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: :chrome} 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
        it 'should get all' do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'foo', value: 'bar'

          cookies = driver.manage.all_cookies

          expect(cookies.size).to eq(1)
          expect(cookies.first[:name]).to eq('foo')
          expect(cookies.first[:value]).to eq('bar')
        end

        it 'should get named cookie' do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'foo', value: 'bar'

          expect(driver.manage.cookie_named('foo')[:value]).to eq('bar')
        end

        # Edge BUG - https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5751773/
        it 'should delete one', except: {browser: :edge} do
          driver.navigate.to url_for('xhtmlTest.html')
          driver.manage.add_cookie name: 'foo', value: 'bar'

          driver.manage.delete_cookie('foo')
          expect(driver.manage.all_cookies.find { |c| c[:name] == 'foo' }).to be_nil
        end

        it 'should delete all', except: {browser: :edge} do
          driver.navigate.to url_for('xhtmlTest.html')

          driver.manage.add_cookie name: 'foo', value: 'bar'
          driver.manage.add_cookie name: 'bar', value: 'foo'
          driver.manage.delete_all_cookies
          expect(driver.manage.all_cookies).to be_empty
        end

        it 'should use DateTime for expires', except: {browser: %i[safari safari_preview]} do
          driver.navigate.to url_for('xhtmlTest.html')

          expected = DateTime.new(2039)
          driver.manage.add_cookie name: 'foo',
                                   value: 'bar',
                                   expires: expected

          actual = driver.manage.cookie_named('foo')[:expires]
          expect(actual).to be_kind_of(DateTime)
          expect(actual).to eq(expected)
        end
      end

      describe 'new_window' do
        types = [:tab, :window] # Stores the valid type values for new_window
        types.each do |type|
          it "should be able to open a new #{type}", only: {browser: %i[safari_preview firefox ie]} do
            # Store the count of window handles before executing action
            before_window_handles = driver.window_handles.length
            # Open a new window
            driver.manage.new_window(type)
            # Store the count of window handles after executing action
            after_window_handles = driver.window_handles.length
            # 1 window handle should have been added
            expect(after_window_handles).to eq(before_window_handles + 1)
          end
        end

        it "returns an exception if an invalid type is provided" do
          invalid_types = [:invalid, 'invalid', 'tab', 'window']
          invalid_types.each do |type|
{'fraction_non_alphanumeric': 0.09701037217815742, 'fraction_numerical': 0.0036607687614399025, 'mean_word_length': 2.513754912468739, '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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4819498', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2667, 'n_words': 835}