Path: blob/trunk/rb/spec/unit/selenium/webdriver/firefox/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_relative '../spec_helper'2021module Selenium22module WebDriver23module Firefox24describe Profile, only: {browser: %i[firefox]} do25let(:profile) { described_class.new }2627def read_generated_prefs(from = nil)28prof = from || profile29dir = prof.layout_on_disk3031File.read(File.join(dir, 'user.js'))32end3334it '#from_name' do35ini = instance_double(ProfilesIni)36allow(described_class).to receive(:ini).and_return(ini)37allow(ini).to receive(:[]).and_return('not nil')38described_class.from_name('default')3940expect(ini).to have_received(:[]).with('default')41end4243it 'uses default preferences' do44expect(read_generated_prefs).to include('user_pref("browser.newtabpage.enabled", false)',45'user_pref("browser.startup.homepage", "about:blank")',46'user_pref("startup.homepage_welcome_url", "about:blank")',47'user_pref("browser.usedOnWindows10.introURL", "about:blank")',48'user_pref("network.captive-portal-service.enabled", false)',49'user_pref("security.csp.enable", false)')50end5152it 'can override welcome page' do53profile['startup.homepage_welcome_url'] = 'http://google.com'5455expect(read_generated_prefs).to include('user_pref("browser.startup.homepage", "about:blank")',56'user_pref("startup.homepage_welcome_url", "http://google.com")')57end5859it 'sets additional preferences' do60profile['foo.number'] = 12361profile['foo.boolean'] = true62profile['foo.string'] = 'bar'6364expect(read_generated_prefs).to include('user_pref("foo.number", 123)',65'user_pref("foo.boolean", true)',66'user_pref("foo.string", "bar")')67end6869it 'is serializable to JSON' do70profile['foo.boolean'] = true7172new_profile = described_class.from_json(profile.to_json)73expect(read_generated_prefs(new_profile)).to include('user_pref("foo.boolean", true)')74end7576it 'properlies handle escaped characters' do77profile['foo'] = 'C:\\r\\n'7879expect(read_generated_prefs).to include('user_pref("foo", "C:\\\\r\\\\n");')80end8182it 'lets the user override some specific prefs' do83profile['browser.startup.page'] = 'http://example.com'8485expect(read_generated_prefs).to include(%{user_pref("browser.startup.page", "http://example.com")})86end8788it 'raises an error if the value given is not a string, number or boolean' do89expect { profile['foo.bar'] = [] }.to raise_error(TypeError)90end9192it 'raises an error if the value is already stringified' do93expect { profile['foo.bar'] = '"stringified"' }.to raise_error(ArgumentError)94end9596it 'can configure a manual proxy' do97proxy = Proxy.new(98http: 'foo:123',99ftp: 'bar:234',100ssl: 'baz:345',101no_proxy: 'localhost'102)103104profile.proxy = proxy105expect(read_generated_prefs).to include('user_pref("network.proxy.http", "foo")',106'user_pref("network.proxy.http_port", 123)',107'user_pref("network.proxy.ftp", "bar")',108'user_pref("network.proxy.ftp_port", 234)',109'user_pref("network.proxy.ssl", "baz")',110'user_pref("network.proxy.ssl_port", 345)',111'user_pref("network.proxy.no_proxies_on", "localhost")',112'user_pref("network.proxy.type", 1)')113end114115it 'can configure a PAC proxy' do116profile.proxy = Proxy.new(pac: 'http://foo/bar.pac')117118expect(read_generated_prefs).to include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac"',119'user_pref("network.proxy.type", 2)')120end121122it 'can configure an auto-detected proxy' do123profile.proxy = Proxy.new(auto_detect: true)124125expect(read_generated_prefs).to include('user_pref("network.proxy.type", 4)')126end127128it 'can install extension' do129firebug = File.expand_path('../../../../../../third_party/firebug/firebug-1.5.0-fx.xpi', __dir__)130profile.add_extension(firebug)131extension_directory = File.expand_path('extensions/[email protected]', profile.layout_on_disk)132expect(Dir.exist?(extension_directory)).to be(true)133end134135it 'can install web extension without id' do136mooltipass = File.expand_path('../../../../../../third_party/firebug/mooltipass-1.1.87.xpi', __dir__)137profile.add_extension(mooltipass)138extension_directory = File.expand_path('extensions/[email protected]', profile.layout_on_disk)139expect(Dir.exist?(extension_directory)).to be(true)140end141142it 'can install web extension with id' do143ext = File.expand_path('../../../../../../third_party/firebug/favourite_colour-1.1-an+fx.xpi', __dir__)144profile.add_extension(ext)145extension_directory = File.expand_path('extensions/[email protected]',146profile.layout_on_disk)147expect(Dir.exist?(extension_directory)).to be(true)148end149end150end # Firefox151end # WebDriver152end # Selenium153154155