Path: blob/trunk/rb/spec/unit/selenium/webdriver/chrome/profile_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 Chrome24describe Profile do25let(:profile) { described_class.new }26let(:model) { '/some/path' }27let(:model_profile) { described_class.new(model) }2829before do30allow(File).to receive(:exist?).with(model).and_return true31allow(File).to receive(:directory?).with(model).and_return true3233allow(Dir).to receive(:mktmpdir).and_return('/tmp/some/path')34allow(FileUtils).to receive(:rm_rf)35allow(FileUtils).to receive(:mkdir_p)36allow(FileUtils).to receive(:cp_r)37end3839it 'sets and get preference paths' do40profile['foo.bar.baz'] = true41expect(profile['foo.bar.baz']).to be(true)42end4344it 'reads existing prefs' do45allow(File).to receive(:read).and_return('{"autofill": {"enabled": false}}')4647expect(model_profile['autofill.enabled']).to be(false)48expect(File).to have_received(:read).with('/some/path/Default/Preferences')49end5051it 'writes out prefs' do52allow(File).to receive(:read).and_return('{"autofill": {"enabled": false}}')5354model_profile['some.other.pref'] = 1235556mock_io = StringIO.new57allow(FileUtils).to receive(:mkdir_p)58allow(File).to receive(:open).with('/tmp/some/path/Default/Preferences', 'w').and_yield(mock_io)5960model_profile.layout_on_disk6162result = JSON.parse(mock_io.string)6364expect(result['autofill']['enabled']).to be(false)65expect(result['some']['other']['pref']).to eq(123)66expect(File).to have_received(:read).with('/some/path/Default/Preferences')67expect(FileUtils).to have_received(:mkdir_p).with('/tmp/some/path/Default')68end69end70end # Chrome71end # WebDriver72end # Selenium737475