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.



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

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

Instance Method Details

#[](key) ⇒ Object



58
59
60
61
# File 'lib/selenium/webdriver/chrome/profile.rb', line 58

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



53
54
55
56
# File 'lib/selenium/webdriver/chrome/profile.rb', line 53

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

#add_encoded_extension(encoded) ⇒ Object



43
44
45
# File 'lib/selenium/webdriver/chrome/profile.rb', line 43

def add_encoded_extension(encoded)
  @encoded_extensions << encoded
end

#add_extension(path) ⇒ Object



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

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



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

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



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

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

  write_prefs_to dir

  dir
end