Skip to content

Commit

Permalink
rb: Handle namespaces in install manifest of Firefox addon
Browse files Browse the repository at this point in the history
Closes #1145
  • Loading branch information
p0deje committed Mar 15, 2016
1 parent 7beb574 commit 000621a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions rb/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Ruby:
* Removed dependency on "multi_json" (issue 1632)
* Properly handle namespaces in install manifest of Firefox add-ons (issue 1143)

2.52.0 (2016-02-12)
===================
Expand Down
24 changes: 13 additions & 11 deletions rb/lib/selenium/webdriver/firefox/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ module Selenium
module WebDriver
module Firefox

#
# @api private
#

class Extension
NAMESPACE = 'http://www.mozilla.org/2004/em-rdf#'

def initialize(path)
unless File.exist?(path)
raise Error::WebDriverError, "could not find extension at #{path.inspect}"
Expand Down Expand Up @@ -61,20 +66,17 @@ def create_root
def read_id_from_install_rdf(directory)
rdf_path = File.join(directory, "install.rdf")
doc = REXML::Document.new(File.read(rdf_path))
namespace = doc.root.namespaces.key(NAMESPACE)

id_node = REXML::XPath.first(doc, "//em:id")

if id_node
id_node.text
else
attr_node = REXML::XPath.first(doc, "//@em:id")
if namespace
id_node = REXML::XPath.first(doc, "//#{namespace}:id")
return id_node.text if id_node

if attr_node.nil?
raise Error::WebDriverError, "cannot locate extension id in #{rdf_path}"
end

attr_node.value
attr_node = REXML::XPath.first(doc, "//@#{namespace}:id")
return attr_node.value if attr_node
end

raise Error::WebDriverError, "cannot locate extension id in #{rdf_path}"
end

end # Extension
Expand Down
15 changes: 13 additions & 2 deletions rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ def ext.read_id(dir); read_id_from_install_rdf(dir); end
expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')
end

it 'finds the rdf extension id regardless of namespace' do
allow(File).to receive(:read).with('/foo/install.rdf').and_return <<-XML
<?xml version="1.0"?>
<r:RDF xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.mozilla.org/2004/em-rdf#">
<r:Description about="urn:mozilla:install-manifest">
<id>{f5198635-4eb3-47a5-b6a5-366b15cd2107}</id>
</r:Description>
</r:RDF>
XML

expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')
end

it 'raises if the node id is not found' do
allow(File).to receive(:read).with('/foo/install.rdf').and_return <<-XML
<?xml version="1.0"?>
Expand All @@ -68,10 +81,8 @@ def ext.read_id(dir); read_id_from_install_rdf(dir); end

expect { extension.read_id('/foo') }.to raise_error(Error::WebDriverError)
end

end

end # Firefox
end # WebDriver
end # Selenium

1 comment on commit 000621a

@p0deje
Copy link
Member Author

@p0deje p0deje commented on 000621a Mar 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually fixes #1143, sorry.

Please sign in to comment.