Sha256: 2da72187eac465ffd9ae992308e8ba703d787a68a42de7f18f79b17b31af552d

Contents?: true

Size: 1.93 KB

Versions: 32

Compression:

Stored size: 1.93 KB

Contents

module Selenium
  module WebDriver
    module Chrome

      #
      # @private
      #

      class Profile
        include ProfileHelper

        def initialize(model = nil)
          @model      = verify_model(model)
          @extensions = []
        end

        def add_extension(path)
          unless File.file?(path)
            raise Error::WebDriverError, "could not find extension at #{path.inspect}"
          end

          @extensions << path
        end

        #
        # Set a preference in the profile.
        #
        # See http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/chrome/common/pref_names.cc&exact_package=chromium
        #

        def []=(key, value)
          parts = key.split(".")
          parts[0..-2].inject(prefs) { |pr, k| pr[k] ||= {} }[parts.last] = value
        end

        def [](key)
          parts = key.split(".")
          parts.inject(prefs) { |pr, k| pr.fetch(k) }
        end

        def layout_on_disk
          dir = @model ? create_tmp_copy(@model) : Dir.mktmpdir("webdriver-chrome-profile")
          FileReaper << dir

          write_prefs_to dir

          dir
        end

        def as_json(opts = nil)
          extensions = @extensions.map do |crx_path|
            Base64.strict_encode64 File.read(crx_path)
          end

          super.merge('extensions' => extensions)
        end

        private

        def write_prefs_to(dir)
          prefs_file = prefs_file_for(dir)

          FileUtils.mkdir_p File.dirname(prefs_file)
          File.open(prefs_file, "w") { |file| file << WebDriver.json_dump(prefs)  }
        end

        def prefs
          @prefs ||= read_model_prefs
        end

        def read_model_prefs
          return {} unless @model
          WebDriver.json_load File.read(prefs_file_for(@model))
        end

        def prefs_file_for(dir)
          File.join dir, 'Default', 'Preferences'
        end
      end # Profile

    end # Chrome
  end # WebDriver
end # Selenium

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
selenium-webdriver-2.34.0 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.33.0 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.32.1 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.32.0 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.31.0 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.30.0 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.29.0 lib/selenium/webdriver/chrome/profile.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.27.2 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.27.1 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.27.0 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.27.0.rc1 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.26.0 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.26.0.rc1 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.25.0 lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.25.0.rc1 lib/selenium/webdriver/chrome/profile.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/chrome/profile.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/chrome/profile.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/chrome/profile.rb
selenium-webdriver-2.24.0 lib/selenium/webdriver/chrome/profile.rb