Skip to content

Commit b511a7d

Browse files
committed
[rb] use addon instead of path for moz/addon/install to avoid needing to use upload
1 parent 965e528 commit b511a7d

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

‎rb/lib/selenium/webdriver/firefox/features.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ def commands(command)
3535
end
3636

3737
def install_addon(path, temporary)
38-
if @file_detector
39-
local_file = @file_detector.call(path)
40-
path = upload(local_file) if local_file
41-
end
38+
addon = File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
4239

43-
payload = {path: path}
40+
payload = {addon: addon}
4441
payload[:temporary] = temporary unless temporary.nil?
4542
execute :install_addon, {}, payload
4643
end

‎rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,48 @@ module Firefox
4242
page: {width: 30})).to include(magic_number)
4343
end
4444

45-
it 'can add and remove addons' do
46-
ext = File.expand_path('../../../../../../third_party/firebug/favourite_colour-1.1-an+fx.xpi', __dir__)
47-
driver.install_addon(ext)
48-
driver.uninstall_addon('favourite-colour-examples@mozilla.org')
49-
end
50-
5145
it 'should print full page' do
5246
path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.png"
5347
screenshot = driver.save_full_page_screenshot(path)
5448
expect(IO.read(screenshot)[0x10..0x18].unpack('NN').last).to be > 2600
5549
ensure
5650
File.delete(path) if File.exist?(path)
5751
end
52+
end
53+
54+
describe '#install_addon' do
55+
let(:extension) { '../../../../../../third_party/firebug/favourite_colour-1.1-an+fx.xpi' }
56+
57+
it 'with path as parameter' do
58+
ext = File.expand_path(extension, __dir__)
59+
driver.install_addon(ext)
60+
end
61+
62+
it 'with temporary as parameter' do
63+
ext = File.expand_path(extension, __dir__)
64+
driver.install_addon(ext, true)
65+
end
66+
end
67+
68+
describe '#uninstall_addon' do
69+
it 'uninstalls based on id' do
70+
ext = File.expand_path('../../../../../../third_party/firebug/favourite_colour-1.1-an+fx.xpi', __dir__)
71+
id = driver.install_addon(path: ext)
72+
driver.uninstall_addon(id)
73+
end
74+
end
5875

59-
it 'can get and set context' do
60-
options = Options.new(prefs: {'browser.download.dir': 'foo/bar'})
61-
create_driver!(capabilities: options) do |driver|
62-
expect(driver.context).to eq 'content'
76+
it 'can get and set context' do
77+
options = Options.new(prefs: {'browser.download.dir': 'foo/bar'})
78+
create_driver!(capabilities: options) do |driver|
79+
expect(driver.context).to eq 'content'
6380

64-
driver.context = 'chrome'
65-
expect(driver.context).to eq 'chrome'
81+
driver.context = 'chrome'
82+
expect(driver.context).to eq 'chrome'
6683

67-
# This call can not be made when context is set to 'content'
68-
dir = driver.execute_script("return Services.prefs.getStringPref('browser.download.dir')")
69-
expect(dir).to eq 'foo/bar'
70-
end
84+
# This call can not be made when context is set to 'content'
85+
dir = driver.execute_script("return Services.prefs.getStringPref('browser.download.dir')")
86+
expect(dir).to eq 'foo/bar'
7187
end
7288
end
7389
end

0 commit comments

Comments
 (0)