diff --git a/rb/CHANGES b/rb/CHANGES index 7d93eee494cf0..c989013b66eb9 100644 --- a/rb/CHANGES +++ b/rb/CHANGES @@ -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) =================== diff --git a/rb/lib/selenium/webdriver/firefox/extension.rb b/rb/lib/selenium/webdriver/firefox/extension.rb index d52be4d1cab3a..c2175c3dddb06 100644 --- a/rb/lib/selenium/webdriver/firefox/extension.rb +++ b/rb/lib/selenium/webdriver/firefox/extension.rb @@ -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}" @@ -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 diff --git a/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb b/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb index 0adbf45a135e0..f5fcaf521af43 100644 --- a/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb +++ b/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb @@ -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 + + + + {f5198635-4eb3-47a5-b6a5-366b15cd2107} + + + 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 @@ -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 -