Path: blob/trunk/rb/spec/integration/selenium/webdriver/firefox/driver_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 Driver, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {browser: :firefox}] do25let(:extensions) { '../../../../../../common/extensions/' }2627describe '#print_options' do28let(:magic_number) { 'JVBER' }2930before { driver.navigate.to url_for('printPage.html') }3132it 'returns base64 for print command' do33expect(driver.print_page).to include(magic_number)34end3536it 'prints with orientation' do37expect(driver.print_page(orientation: 'landscape')).to include(magic_number)38end3940it 'prints with valid params' do41expect(driver.print_page(orientation: 'landscape',42page_ranges: ['1-2'],43page: {width: 30})).to include(magic_number)44end4546it 'prints full page', except: [{platform: :windows,47reason: 'Some issues with resolution?'},48{platform: :macosx,49reason: 'showing half resolution of what expected'}] do50viewport_width = driver.execute_script('return window.innerWidth;')51viewport_height = driver.execute_script('return window.innerHeight;')5253path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.png"54screenshot = driver.save_full_page_screenshot(path)55width, height = png_size(screenshot)5657expect(width).to be >= viewport_width58expect(height).to be > viewport_height59ensure60FileUtils.rm_rf(path)61end62end6364describe '#install_addon' do65it 'install and uninstall xpi file' do66ext = File.expand_path("#{extensions}/webextensions-selenium-example.xpi", __dir__)67id = driver.install_addon(ext)6869expect(id).to eq '[email protected]'70driver.navigate.to url_for('blank.html')7172injected = driver.find_element(id: 'webextensions-selenium-example')73expect(injected.text).to eq 'Content injected by webextensions-selenium-example'7475driver.uninstall_addon(id)76driver.navigate.refresh77expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty78end7980it 'install and uninstall signed zip file' do81ext = File.expand_path("#{extensions}/webextensions-selenium-example.zip", __dir__)82id = driver.install_addon(ext)8384expect(id).to eq '[email protected]'85driver.navigate.to url_for('blank.html')8687injected = driver.find_element(id: 'webextensions-selenium-example')88expect(injected.text).to eq 'Content injected by webextensions-selenium-example'8990driver.uninstall_addon(id)91driver.navigate.refresh92expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty93end9495it 'install and uninstall unsigned zip file' do96ext = File.expand_path("#{extensions}/webextensions-selenium-example-unsigned.zip", __dir__)97id = driver.install_addon(ext, true)9899expect(id).to eq '[email protected]'100driver.navigate.to url_for('blank.html')101102injected = driver.find_element(id: 'webextensions-selenium-example')103expect(injected.text).to eq 'Content injected by webextensions-selenium-example'104105driver.uninstall_addon(id)106driver.navigate.refresh107expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty108end109110it 'install and uninstall signed directory', except: {browser: :firefox,111platform: :windows,112reason: 'signature must be different for windows,113skipping everywhere until Firefox 127 is released'} do114ext = File.expand_path("#{extensions}/webextensions-selenium-example-signed/", __dir__)115id = driver.install_addon(ext)116117expect(id).to eq '[email protected]'118driver.navigate.to url_for('blank.html')119120injected = driver.find_element(id: 'webextensions-selenium-example')121expect(injected.text).to eq 'Content injected by webextensions-selenium-example'122123driver.uninstall_addon(id)124driver.navigate.refresh125expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty126end127128it 'install and uninstall unsigned directory' do129ext = File.expand_path("#{extensions}/webextensions-selenium-example/", __dir__)130id = driver.install_addon(ext, true)131132expect(id).to eq '[email protected]'133driver.navigate.to url_for('blank.html')134135injected = driver.find_element(id: 'webextensions-selenium-example')136expect(injected.text).to eq 'Content injected by webextensions-selenium-example'137138driver.uninstall_addon(id)139driver.navigate.refresh140expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty141end142end143144it 'can get and set context' do145reset_driver!(args: ['-remote-allow-system-access'],146prefs: {'browser.download.dir': 'foo/bar'}) do |driver|147expect(driver.context).to eq 'content'148149driver.context = 'chrome'150expect(driver.context).to eq 'chrome'151152# This call can not be made when context is set to 'content'153dir = driver.execute_script("return Services.prefs.getStringPref('browser.download.dir')")154expect(dir).to eq 'foo/bar'155end156end157end158end # Firefox159end # WebDriver160end # Selenium161162163