Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/chrome/profile_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 Chrome
25
describe Profile do
26
let(:profile) { described_class.new }
27
let(:model) { '/some/path' }
28
let(:model_profile) { described_class.new(model) }
29
30
before do
31
allow(File).to receive(:exist?).with(model).and_return true
32
allow(File).to receive(:directory?).with(model).and_return true
33
34
allow(Dir).to receive(:mktmpdir).and_return('/tmp/some/path')
35
allow(FileUtils).to receive(:rm_rf)
36
allow(FileUtils).to receive(:mkdir_p)
37
allow(FileUtils).to receive(:cp_r)
38
end
39
40
it 'sets and get preference paths' do
41
profile['foo.bar.baz'] = true
42
expect(profile['foo.bar.baz']).to be(true)
43
end
44
45
it 'reads existing prefs' do
46
allow(File).to receive(:read).and_return('{"autofill": {"enabled": false}}')
47
48
expect(model_profile['autofill.enabled']).to be(false)
49
expect(File).to have_received(:read).with('/some/path/Default/Preferences')
50
end
51
52
it 'writes out prefs' do
53
allow(File).to receive(:read).and_return('{"autofill": {"enabled": false}}')
54
55
model_profile['some.other.pref'] = 123
56
57
mock_io = StringIO.new
58
allow(FileUtils).to receive(:mkdir_p)
59
allow(File).to receive(:open).with('/tmp/some/path/Default/Preferences', 'w').and_yield(mock_io)
60
61
model_profile.layout_on_disk
62
63
result = JSON.parse(mock_io.string)
64
65
expect(result['autofill']['enabled']).to be(false)
66
expect(result['some']['other']['pref']).to eq(123)
67
expect(File).to have_received(:read).with('/some/path/Default/Preferences')
68
expect(FileUtils).to have_received(:mkdir_p).with('/tmp/some/path/Default')
69
end
70
end
71
end # Chrome
72
end # WebDriver
73
end # Selenium
74
75