Path: blob/trunk/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require File.expand_path('../spec_helper', __dir__)2021module Selenium22module WebDriver23module Firefox24describe Extension do25before do26allow(File).to receive(:exist?).and_return(true)27end2829let(:extension) do30ext = described_class.new('/foo')31def ext.read_id(dir)32read_id_from_install_rdf(dir)33end3435ext36end3738it 'finds the rdf extension id as attribute' do39allow(File).to receive(:read).with('/foo/install.rdf').and_return <<~XML40<?xml version="1.0"?>41<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">42<Description about="urn:mozilla:install-manifest">43<em:id>{f5198635-4eb3-47a5-b6a5-366b15cd2107}</em:id>44</Description>45</RDF>46XML4748expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')49end5051it 'finds the rdf extension id as text' do52allow(File).to receive(:read).with('/foo/install.rdf').and_return <<~XML53<?xml version="1.0"?>54<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">55<Description about="urn:mozilla:install-manifest" em:id="{f5198635-4eb3-47a5-b6a5-366b15cd2107}">56</Description>57</RDF>58XML5960expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')61end6263it 'finds the rdf extension id regardless of namespace' do64allow(File).to receive(:read).with('/foo/install.rdf').and_return <<~XML65<?xml version="1.0"?>66<r:RDF xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.mozilla.org/2004/em-rdf#">67<r:Description about="urn:mozilla:install-manifest">68<id>{f5198635-4eb3-47a5-b6a5-366b15cd2107}</id>69</r:Description>70</r:RDF>71XML7273expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')74end7576it 'raises if the node id is not found' do77allow(File).to receive(:read).with('/foo/install.rdf').and_return <<~XML78<?xml version="1.0"?>79<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"></RDF>80XML8182expect { extension.read_id('/foo') }.to raise_error(Error::WebDriverError)83end84end85end # Firefox86end # WebDriver87end # Selenium888990