Skip to content

Commit

Permalink
[rb] rearrange specs
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jul 15, 2020
1 parent 8ad5109 commit 39e03c8
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 167 deletions.
4 changes: 1 addition & 3 deletions rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ Metrics/AbcSize:
Metrics/BlockLength:
Max: 18
Exclude:
- "**/*_spec.rb"
- "**/spec_helper.rb"
- 'spec/rspec_matchers.rb'
- 'spec/**/*.rb'
- 'selenium-webdriver.gemspec'

Metrics/ClassLength:
Expand Down
15 changes: 15 additions & 0 deletions rb/spec/integration/selenium/webdriver/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ module WebDriver
describe Driver do
it_behaves_like 'driver that can be started concurrently', except: {browser: %i[safari safari_preview]}

it 'creates default capabilities' do
reset_driver! do |driver|
caps = driver.capabilities
expect(caps.proxy).to be_nil
expect(caps.browser_version).to match(/^\d\d\./)
expect(caps.platform_name).not_to be_nil

expect(caps.accept_insecure_certs).to be == false
expect(caps.page_load_strategy).to be == 'normal'
expect(caps.implicit_timeout).to be_zero
expect(caps.page_load_timeout).to be == 300000
expect(caps.script_timeout).to be == 30000
end
end

it 'should get the page title' do
driver.navigate.to url_for('xhtmlTest.html')
expect(driver.title).to eq('XHTML Test Page')
Expand Down
47 changes: 0 additions & 47 deletions rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb

This file was deleted.

131 changes: 14 additions & 117 deletions rb/spec/integration/selenium/webdriver/firefox/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,127 +32,24 @@ def read_generated_prefs(from = nil)
File.read(File.join(dir, 'user.js'))
end

it 'should set additional preferences' do
profile['foo.number'] = 123
profile['foo.boolean'] = true
profile['foo.string'] = 'bar'

string = read_generated_prefs
expect(string).to include('user_pref("foo.number", 123)')
expect(string).to include('user_pref("foo.boolean", true)')
expect(string).to include(%{user_pref("foo.string", "bar")})
end

it 'should be serializable to JSON' do
profile['foo.boolean'] = true

new_profile = Profile.from_json(profile.to_json)
string = read_generated_prefs(new_profile)
expect(string).to include('user_pref("foo.boolean", true)')
end

it 'should properly handle escaped characters' do
profile['foo'] = 'C:\\r\\n'

string = read_generated_prefs
expect(string).to include('user_pref("foo", "C:\\\\r\\\\n");')
end

it 'should let the user override some specific prefs' do
profile['browser.startup.page'] = 'http://example.com'

string = read_generated_prefs
expect(string).to include(%{user_pref("browser.startup.page", "http://example.com")})
before do
quit_driver
sleep 2
profile['browser.startup.homepage'] = url_for('simpleTest.html')
profile['browser.startup.page'] = 1
end

it 'should raise an error if the value given is not a string, number or boolean' do
expect { profile['foo.bar'] = [] }.to raise_error(TypeError)
end

it 'should raise an error if the value is already stringified' do
expect { profile['foo.bar'] = '"stringified"' }.to raise_error(ArgumentError)
end

it 'can configure a manual proxy' do
proxy = Proxy.new(
http: 'foo:123',
ftp: 'bar:234',
ssl: 'baz:345',
no_proxy: 'localhost'
)

profile.proxy = proxy
string = read_generated_prefs

expect(string).to include('user_pref("network.proxy.http", "foo")')
expect(string).to include('user_pref("network.proxy.http_port", 123)')

expect(string).to include('user_pref("network.proxy.ftp", "bar")')
expect(string).to include('user_pref("network.proxy.ftp_port", 234)')

expect(string).to include('user_pref("network.proxy.ssl", "baz")')
expect(string).to include('user_pref("network.proxy.ssl_port", 345)')

expect(string).to include('user_pref("network.proxy.no_proxies_on", "localhost")')
expect(string).to include('user_pref("network.proxy.type", 1)')
end

it 'can configure a PAC proxy' do
profile.proxy = Proxy.new(pac: 'http://foo/bar.pac')
string = read_generated_prefs

expect(string).to include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac")')
expect(string).to include('user_pref("network.proxy.type", 2)')
end

it 'can configure an auto-detected proxy' do
profile.proxy = Proxy.new(auto_detect: true)
string = read_generated_prefs

expect(string).to include('user_pref("network.proxy.type", 4)')
end

it 'can install extension' do
firebug = File.expand_path('../../../../../../third_party/firebug/firebug-1.5.0-fx.xpi', __dir__)
profile.add_extension(firebug)
extension_directory = File.expand_path('extensions/firebug@software.joehewitt.com', profile.layout_on_disk)
expect(Dir.exist?(extension_directory)).to eq(true)
end

it 'can install web extension without id' do
mooltipass = File.expand_path('../../../../../../third_party/firebug/mooltipass-1.1.87.xpi', __dir__)
profile.add_extension(mooltipass)
extension_directory = File.expand_path('extensions/MooltipassExtension@1.1.87', profile.layout_on_disk)
expect(Dir.exist?(extension_directory)).to eq(true)
end

it 'can install web extension with id' do
ext = File.expand_path('../../../../../../third_party/firebug/favourite_colour-1.1-an+fx.xpi', __dir__)
profile.add_extension(ext)
extension_directory = File.expand_path('extensions/favourite-colour-examples@mozilla.org', profile.layout_on_disk)
expect(Dir.exist?(extension_directory)).to eq(true)
end

describe 'with browser' do
before do
quit_driver
sleep 2
profile['browser.startup.homepage'] = url_for('simpleTest.html')
profile['browser.startup.page'] = 1
end

it 'should instantiate the browser with the correct profile' do
create_driver!(capabilities: Options.new(profile: profile)) do |driver|
expect { wait(5).until { driver.find_element(id: 'oneline') } }.not_to raise_error
end
it 'should instantiate the browser with the correct profile' do
create_driver!(capabilities: Options.new(profile: profile)) do |driver|
expect { wait(5).until { driver.find_element(id: 'oneline') } }.not_to raise_error
end
end

it 'should be able to use the same profile more than once' do
create_driver!(capabilities: Options.new(profile: profile)) do |driver1|
expect { wait(5).until { driver1.find_element(id: 'oneline') } }.not_to raise_error
create_driver!(capabilities: Options.new(profile: profile)) do |driver2|
expect { wait(5).until { driver2.find_element(id: 'oneline') } }.not_to raise_error
end
it 'should be able to use the same profile more than once' do
create_driver!(capabilities: Options.new(profile: profile)) do |driver1|
expect { wait(5).until { driver1.find_element(id: 'oneline') } }.not_to raise_error
create_driver!(capabilities: Options.new(profile: profile)) do |driver2|
expect { wait(5).until { driver2.find_element(id: 'oneline') } }.not_to raise_error
end
end
end
Expand Down
138 changes: 138 additions & 0 deletions rb/spec/unit/selenium/webdriver/firefox/profile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

require_relative '../spec_helper'

module Selenium
module WebDriver
module Firefox
describe Profile, only: {browser: %i[firefox]} do
let(:profile) { Profile.new }

def read_generated_prefs(from = nil)
prof = from || profile
dir = prof.layout_on_disk

File.read(File.join(dir, 'user.js'))
end

it 'should set additional preferences' do
profile['foo.number'] = 123
profile['foo.boolean'] = true
profile['foo.string'] = 'bar'

string = read_generated_prefs
expect(string).to include('user_pref("foo.number", 123)')
expect(string).to include('user_pref("foo.boolean", true)')
expect(string).to include(%{user_pref("foo.string", "bar")})
end

it 'should be serializable to JSON' do
profile['foo.boolean'] = true

new_profile = Profile.from_json(profile.to_json)
string = read_generated_prefs(new_profile)
expect(string).to include('user_pref("foo.boolean", true)')
end

it 'should properly handle escaped characters' do
profile['foo'] = 'C:\\r\\n'

string = read_generated_prefs
expect(string).to include('user_pref("foo", "C:\\\\r\\\\n");')
end

it 'should let the user override some specific prefs' do
profile['browser.startup.page'] = 'http://example.com'

string = read_generated_prefs
expect(string).to include(%{user_pref("browser.startup.page", "http://example.com")})
end

it 'should raise an error if the value given is not a string, number or boolean' do
expect { profile['foo.bar'] = [] }.to raise_error(TypeError)
end

it 'should raise an error if the value is already stringified' do
expect { profile['foo.bar'] = '"stringified"' }.to raise_error(ArgumentError)
end

it 'can configure a manual proxy' do
proxy = Proxy.new(
http: 'foo:123',
ftp: 'bar:234',
ssl: 'baz:345',
no_proxy: 'localhost'
)

profile.proxy = proxy
string = read_generated_prefs

expect(string).to include('user_pref("network.proxy.http", "foo")')
expect(string).to include('user_pref("network.proxy.http_port", 123)')

expect(string).to include('user_pref("network.proxy.ftp", "bar")')
expect(string).to include('user_pref("network.proxy.ftp_port", 234)')

expect(string).to include('user_pref("network.proxy.ssl", "baz")')
expect(string).to include('user_pref("network.proxy.ssl_port", 345)')

expect(string).to include('user_pref("network.proxy.no_proxies_on", "localhost")')
expect(string).to include('user_pref("network.proxy.type", 1)')
end

it 'can configure a PAC proxy' do
profile.proxy = Proxy.new(pac: 'http://foo/bar.pac')
string = read_generated_prefs

expect(string).to include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac")')
expect(string).to include('user_pref("network.proxy.type", 2)')
end

it 'can configure an auto-detected proxy' do
profile.proxy = Proxy.new(auto_detect: true)
string = read_generated_prefs

expect(string).to include('user_pref("network.proxy.type", 4)')
end

it 'can install extension' do
firebug = File.expand_path('../../../../../../third_party/firebug/firebug-1.5.0-fx.xpi', __dir__)
profile.add_extension(firebug)
extension_directory = File.expand_path('extensions/firebug@software.joehewitt.com', profile.layout_on_disk)
expect(Dir.exist?(extension_directory)).to eq(true)
end

it 'can install web extension without id' do
mooltipass = File.expand_path('../../../../../../third_party/firebug/mooltipass-1.1.87.xpi', __dir__)
profile.add_extension(mooltipass)
extension_directory = File.expand_path('extensions/MooltipassExtension@1.1.87', profile.layout_on_disk)
expect(Dir.exist?(extension_directory)).to eq(true)
end

it 'can install web extension with id' do
ext = File.expand_path('../../../../../../third_party/firebug/favourite_colour-1.1-an+fx.xpi', __dir__)
profile.add_extension(ext)
extension_directory = File.expand_path('extensions/favourite-colour-examples@mozilla.org', profile.layout_on_disk)
expect(Dir.exist?(extension_directory)).to eq(true)
end
end
end # Firefox
end # WebDriver
end # Selenium

0 comments on commit 39e03c8

Please sign in to comment.