Skip to content

Commit

Permalink
Ruby: Fix for extensions whose install.rdf uses an attribute for em:i…
Browse files Browse the repository at this point in the history
…d (issue 5978)
  • Loading branch information
jarib committed May 10, 2014
1 parent 50c8fa6 commit a0b26dc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
6 changes: 6 additions & 0 deletions rb/CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.42.0 (???)
============

Firefox:
* Fix for extensions whose install.rdf uses an attribute for em:id (#5978)

2.41.0 (2014-03-28)
===================

Expand Down
14 changes: 13 additions & 1 deletion rb/lib/selenium/webdriver/firefox/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,19 @@ def read_id_from_install_rdf(directory)
rdf_path = File.join(directory, "install.rdf")
doc = REXML::Document.new(File.read(rdf_path))

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

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

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

attr_node.value
end
end

end # Extension
Expand Down
58 changes: 58 additions & 0 deletions rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require File.expand_path("../../spec_helper", __FILE__)

module Selenium
module WebDriver
module Firefox

describe Extension do
before do
File.stub(:exist? => true)
end

let(:extension) {
ext = Extension.new('/foo')
def ext.read_id(dir); read_id_from_install_rdf(dir); end

ext
}

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

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

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

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

it 'raises if the node id is not found' do
File.stub(:read).with('/foo/install.rdf').and_return <<-XML
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"></RDF>
XML

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

end

end # Firefox
end # WebDriver
end # Selenium

0 comments on commit a0b26dc

Please sign in to comment.