Class: Selenium::WebDriver::Chrome::Profile

Inherits:
Object
  • Object
show all
Includes:
ProfileHelper
Defined in:
lib/selenium/webdriver/chrome/profile.rb

Instance Method Summary collapse

Methods included from ProfileHelper

included, #to_json

Constructor Details

#initialize(model = nil) ⇒ Profile

Returns a new instance of Profile.



31
32
33
34
35
# File 'lib/selenium/webdriver/chrome/profile.rb', line 31

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

Instance Method Details

#[](key) ⇒ Object



60
61
62
63
# File 'lib/selenium/webdriver/chrome/profile.rb', line 60

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

#[]=(key, value) ⇒ Object

Set a preference in the profile.

See src.chromium.org/svn/trunk/src/chrome/common/pref_names.cc



55
56
57
58
# File 'lib/selenium/webdriver/chrome/profile.rb', line 55

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

#add_encoded_extension(encoded) ⇒ Object



45
46
47
# File 'lib/selenium/webdriver/chrome/profile.rb', line 45

def add_encoded_extension(encoded)
  @encoded_extensions << encoded
end

#add_extension(path) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/selenium/webdriver/chrome/profile.rb', line 37

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

  @extensions << path
end

#as_json(opts = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/selenium/webdriver/chrome/profile.rb', line 74

def as_json(opts = nil)
  extensions = @extensions.map do |crx_path|
    File.open(crx_path, "rb") { |crx_file| Base64.strict_encode64 crx_file.read }
  end

  extensions.concat(@encoded_extensions)

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

#layout_on_diskObject



65
66
67
68
69
70
71
72
# File 'lib/selenium/webdriver/chrome/profile.rb', line 65

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

  write_prefs_to dir

  dir
end