Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb
1865 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require File.expand_path('../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
module Firefox
25
describe Extension do
26
before do
27
allow(File).to receive(:exist?).and_return(true)
28
end
29
30
let(:extension) do
31
ext = described_class.new('/foo')
32
def ext.read_id(dir)
33
read_id_from_install_rdf(dir)
34
end
35
36
ext
37
end
38
39
it 'finds the rdf extension id as attribute' do
40
allow(File).to receive(:read).with('/foo/install.rdf').and_return <<~XML
41
<?xml version="1.0"?>
42
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
43
<Description about="urn:mozilla:install-manifest">
44
<em:id>{f5198635-4eb3-47a5-b6a5-366b15cd2107}</em:id>
45
</Description>
46
</RDF>
47
XML
48
49
expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')
50
end
51
52
it 'finds the rdf extension id as text' do
53
allow(File).to receive(:read).with('/foo/install.rdf').and_return <<~XML
54
<?xml version="1.0"?>
55
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
56
<Description about="urn:mozilla:install-manifest" em:id="{f5198635-4eb3-47a5-b6a5-366b15cd2107}">
57
</Description>
58
</RDF>
59
XML
60
61
expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')
62
end
63
64
it 'finds the rdf extension id regardless of namespace' do
65
allow(File).to receive(:read).with('/foo/install.rdf').and_return <<~XML
66
<?xml version="1.0"?>
67
<r:RDF xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.mozilla.org/2004/em-rdf#">
68
<r:Description about="urn:mozilla:install-manifest">
69
<id>{f5198635-4eb3-47a5-b6a5-366b15cd2107}</id>
70
</r:Description>
71
</r:RDF>
72
XML
73
74
expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')
75
end
76
77
it 'raises if the node id is not found' do
78
allow(File).to receive(:read).with('/foo/install.rdf').and_return <<~XML
79
<?xml version="1.0"?>
80
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"></RDF>
81
XML
82
83
expect { extension.read_id('/foo') }.to raise_error(Error::WebDriverError)
84
end
85
end
86
end # Firefox
87
end # WebDriver
88
end # Selenium
89
90