module Support
  module Browser
    module Options
      # Profiles are Firefox's preferences/capabilities.
      # TODO: Get this to work.
      class FirefoxProfile
        def initialize
          @profile = default_profile
        end

        def default
          @profile
        end

        # Remote drivers need profiles passed in via desired_capabilities.
        def as_capabilities
          Selenium::WebDriver::Remote::Capabilities.firefox(
            firefox_profile: @profile
          )
        end

        private

        def default_profile
          p = Selenium::WebDriver::Firefox::Profile.new
          plugin_path = File.join(
            Support::Paths.cucumber_root, "features", "support", "plugins", "JSErrorCollector.xpi"
          )
          p.add_extension(plugin_path)
          p
        end
      end
    end
  end
end
