Path: blob/trunk/rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb
4211 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: :macosx,47reason: 'showing half resolution of what expected'}] do48viewport_width = driver.execute_script('return window.innerWidth;')49viewport_height = driver.execute_script('return window.innerHeight;')5051path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.png"52screenshot = driver.save_full_page_screenshot(path)53width, height = png_size(screenshot)5455expect(width).to be >= viewport_width56expect(height).to be > viewport_height57ensure58FileUtils.rm_rf(path)59end60end6162describe '#install_addon' do63it 'install and uninstall xpi file' do64ext = File.expand_path("#{extensions}/webextensions-selenium-example.xpi", __dir__)65id = driver.install_addon(ext)6667expect(id).to eq '[email protected]'68driver.navigate.to url_for('blank.html')6970injected = driver.find_element(id: 'webextensions-selenium-example')71expect(injected.text).to eq 'Content injected by webextensions-selenium-example'7273driver.uninstall_addon(id)74driver.navigate.refresh75expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty76end7778it 'install and uninstall signed zip file' do79ext = File.expand_path("#{extensions}/webextensions-selenium-example.zip", __dir__)80id = driver.install_addon(ext)8182expect(id).to eq '[email protected]'83driver.navigate.to url_for('blank.html')8485injected = driver.find_element(id: 'webextensions-selenium-example')86expect(injected.text).to eq 'Content injected by webextensions-selenium-example'8788driver.uninstall_addon(id)89driver.navigate.refresh90expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty91end9293it 'install and uninstall unsigned zip file' do94ext = File.expand_path("#{extensions}/webextensions-selenium-example-unsigned.zip", __dir__)95id = driver.install_addon(ext, true)9697expect(id).to eq '[email protected]'98driver.navigate.to url_for('blank.html')99100injected = driver.find_element(id: 'webextensions-selenium-example')101expect(injected.text).to eq 'Content injected by webextensions-selenium-example'102103driver.uninstall_addon(id)104driver.navigate.refresh105expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty106end107108it 'install and uninstall signed directory', except: {browser: :firefox,109platform: :windows,110reason: 'signature must be different for windows,111skipping everywhere until Firefox 127 is released'} do112ext = File.expand_path("#{extensions}/webextensions-selenium-example-signed/", __dir__)113id = driver.install_addon(ext)114115expect(id).to eq '[email protected]'116driver.navigate.to url_for('blank.html')117118injected = driver.find_element(id: 'webextensions-selenium-example')119expect(injected.text).to eq 'Content injected by webextensions-selenium-example'120121driver.uninstall_addon(id)122driver.navigate.refresh123expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty124end125126it 'install and uninstall unsigned directory' do127ext = File.expand_path("#{extensions}/webextensions-selenium-example/", __dir__)128id = driver.install_addon(ext, true)129130expect(id).to eq '[email protected]'131driver.navigate.to url_for('blank.html')132133injected = driver.find_element(id: 'webextensions-selenium-example')134expect(injected.text).to eq 'Content injected by webextensions-selenium-example'135136driver.uninstall_addon(id)137driver.navigate.refresh138expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty139end140end141142it 'can get and set context' do143reset_driver!(args: ['-remote-allow-system-access'],144prefs: {'browser.download.dir': 'foo/bar'}) do |driver|145expect(driver.context).to eq 'content'146147driver.context = 'chrome'148expect(driver.context).to eq 'chrome'149150# This call can not be made when context is set to 'content'151dir = driver.execute_script("return Services.prefs.getStringPref('browser.download.dir')")152expect(dir).to eq 'foo/bar'153end154end155end156end # Firefox157end # WebDriver158end # Selenium159160161