<commit_before># frozen_string_literal: true

module ActionDispatch
  module SystemTesting
    class Driver # :nodoc:
      def initialize(name, **options)
        @name = name
        @browser = options[:using]
        @screen_size = options[:screen_size]
        @options = options[:options]
      end

      def use
        register if registerable?

        setup
      end

      private
        def registerable?
          [:selenium, :poltergeist, :webkit].include?(@name)
        end

        def register
          Capybara.register_driver @name do |app|
            case @name
            when :selenium then register_selenium(app)
            when :poltergeist then register_poltergeist(app)
            when :webkit then register_webkit(app)
            end
          end
        end

        def browser_options
          if @browser == :headless_chrome
            browser_options = Selenium::WebDriver::Chrome::Options.new
            browser_options.args << "--headless"
            browser_options.args << "--disable-gpu"

            @options.merge(options: browser_options)
          else
            @options
          end
        end

        def browser
          @browser == :headless_chrome ? :chrome : @browser
        end

        def register_selenium(app)
          Capybara::Selenium::Driver.new(app, { browser: browser }.merge(browser_options)).tap do |driver|
            driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
          end
        end

        def register_poltergeist(app)
          Capybara::Poltergeist::Driver.new(app, @options.merge(window_size: @screen_size))
        end

        def register_webkit(app)
          Capybara::Webkit::Driver.new(app, Capybara::Webkit::Configuration.to_hash.merge(@options)).tap do |driver|
            driver.resize_window_to(*@screen_size)
          end
        end

        def setup
          Capybara.current_driver = @name
        end
    end<commit_msg>Explicitly pass window handle to `resize_window_to`<commit_after># frozen_string_literal: true

module ActionDispatch
  module SystemTesting
    class Driver # :nodoc:
      def initialize(name, **options)
        @name = name
        @browser = options[:using]
        @screen_size = options[:screen_size]
        @options = options[:options]
      end

      def use
        register if registerable?

        setup
      end

      private
        def registerable?
          [:selenium, :poltergeist, :webkit].include?(@name)
        end

        def register
          Capybara.register_driver @name do |app|
            case @name
            when :selenium then register_selenium(app)
            when :poltergeist then register_poltergeist(app)
            when :webkit then register_webkit(app)
            end
          end
        end

        def browser_options
          if @browser == :headless_chrome
            browser_options = Selenium::WebDriver::Chrome::Options.new
            browser_options.args << "--headless"
            browser_options.args << "--disable-gpu"

            @options.merge(options: browser_options)
          else
            @options
          end
        end

        def browser
          @browser == :headless_chrome ? :chrome : @browser
        end

        def register_selenium(app)
          Capybara::Selenium::Driver.new(app, { browser: browser }.merge(browser_options)).tap do |driver|
            driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
          end
        end

        def register_poltergeist(app)
          Capybara::Poltergeist::Driver.new(app, @options.merge(window_size: @screen_size))
        end

        def register_webkit(app)
          Capybara::Webkit::Driver.new(app, Capybara::Webkit::Configuration.to_hash.merge(@options)).tap do |driver|
            driver.resize_window_to(driver.current_window_handle, *@screen_size)
          end
        end

        def setup
          Capybara.current_driver = @name
        end
    end
{'fraction_non_alphanumeric': 0.08946322067594434, 'fraction_numerical': 0.0, 'mean_word_length': 2.035444947209653, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4736368', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1086, 'n_words': 237}