Sha256: 39548d0838f6e292956d71b9efce1dccd467234d2cc45ee5b4109997ff15fe42

Contents?: true

Size: 1.67 KB

Versions: 21

Compression:

Stored size: 1.67 KB

Contents

module Selenium
  module WebDriver

    #
    # @api private
    #
    # Common methods for Chrome::Profile and Firefox::Profile
    # Includers must implement #layout_on_disk
    #

    module ProfileHelper

      def self.included(base)
        base.extend ClassMethods
      end

      def as_json(opts = nil)
        {'zip' => Zipper.zip(layout_on_disk)}
      end

      def to_json(*args)
        MultiJson.encode as_json
      end

      private

      def create_tmp_copy(directory)
        tmp_directory = Dir.mktmpdir("webdriver-rb-profilecopy")

        # TODO: must be a better way..
        FileUtils.rm_rf tmp_directory
        FileUtils.mkdir_p File.dirname(tmp_directory), :mode => 0700
        FileUtils.cp_r directory, tmp_directory

        tmp_directory
      end

      def verify_model(model)
        return unless model

        raise Errno::ENOENT, model unless File.exist?(model)
        raise Errno::ENOTDIR, model unless File.directory?(model)

        model
      end

      module ClassMethods
        def from_json(json)
          data = MultiJson.decode(json).fetch('zip')

          # can't use Tempfile here since it doesn't support File::BINARY mode on 1.8
          # can't use Dir.mktmpdir(&blk) because of http://jira.codehaus.org/browse/JRUBY-4082
          tmp_dir = Dir.mktmpdir
          begin
            zip_path = File.join(tmp_dir, "webdriver-profile-duplicate-#{json.hash}.zip")
            File.open(zip_path, "wb") { |zip_file| zip_file << Base64.decode64(data) }

            new Zipper.unzip(zip_path)
          ensure
            FileUtils.rm_rf tmp_dir
          end
        end
      end # ClassMethods

    end # ProfileHelper
  end # WebDriver
end # Selenium

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
selenium-webdriver-2.21.1 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.21.0 lib/selenium/webdriver/common/profile_helper.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/profile_helper.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/profile_helper.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/profile_helper.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/profile_helper.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.20.0 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.20.0.rc1 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.19.0 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.19.0.rc2 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.19.0.rc1 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.18.0 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.18.0.rc3 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.18.0.rc2 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.18.0.rc1 lib/selenium/webdriver/common/profile_helper.rb
bbc-selenium-webdriver-1.17.0 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.17.0 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.16.0 lib/selenium/webdriver/common/profile_helper.rb
selenium-webdriver-2.15.0 lib/selenium/webdriver/common/profile_helper.rb