Skip to content

Commit

Permalink
Add support for getting/setting permissions for Safari
Browse files Browse the repository at this point in the history
Copies Python bindings commands added in 619a02f
  • Loading branch information
p0deje committed Mar 31, 2018
1 parent 9e743aa commit f6f0064
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rb/lib/selenium/webdriver/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
require 'selenium/webdriver/common/driver_extensions/has_touch_screen'
require 'selenium/webdriver/common/driver_extensions/has_remote_status'
require 'selenium/webdriver/common/driver_extensions/has_network_conditions'
require 'selenium/webdriver/common/driver_extensions/has_network_connection'
require 'selenium/webdriver/common/driver_extensions/has_network_conditions'
require 'selenium/webdriver/common/driver_extensions/has_permissions'
require 'selenium/webdriver/common/driver_extensions/uploads_files'
require 'selenium/webdriver/common/driver_extensions/has_addons'
require 'selenium/webdriver/common/interactions/interactions'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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.

module Selenium
module WebDriver
module DriverExtensions
module HasPermissions

#
# Returns permissions.
#
# @return [Hash]
#

def permissions
@bridge.permissions
end

#
# Sets permissions.
#
# @example
# driver.permissions = {'getUserMedia' => true}
#
# @param [Hash<Symbol, Boolean>] permissions
#

def permissions=(permissions)
@bridge.permissions = permissions
end

end # HasPermissions
end # DriverExtensions
end # WebDriver
end # Selenium
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/safari.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

require 'selenium/webdriver/safari/bridge'
require 'selenium/webdriver/safari/driver'
require 'selenium/webdriver/safari/service'

Expand Down
44 changes: 44 additions & 0 deletions rb/lib/selenium/webdriver/safari/bridge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.

module Selenium
module WebDriver
module Safari
module Bridge

# https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/WebDriverEndpointDoc/Commands/Commands.html
COMMANDS = {
get_permissions: [:get, '/session/:session_id/apple/permissions'.freeze],
set_permissions: [:post, '/session/:session_id/apple/permissions'.freeze]
}.freeze

def commands(command)
COMMANDS[command] || super
end

def permissions
execute(:get_permissions)['permissions']
end

def permissions=(permissions)
execute :set_permissions, {}, {permissions: permissions}
end

end # Bridge
end # Safari
end # WebDriver
end # Selenium
3 changes: 3 additions & 0 deletions rb/lib/selenium/webdriver/safari/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Safari
#

class Driver < WebDriver::Driver
include DriverExtensions::HasPermissions
include DriverExtensions::TakesScreenshot

def initialize(opts = {})
Expand All @@ -42,6 +43,8 @@ def initialize(opts = {})

listener = opts.delete(:listener)
@bridge = Remote::Bridge.handshake(opts)
@bridge.extend Bridge

super(@bridge, listener: listener)
end

Expand Down
31 changes: 31 additions & 0 deletions rb/spec/integration/selenium/webdriver/safari/driver_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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 Safari
describe Driver, only: {driver: :safari_preview} do
it 'gets and sets permissions' do
driver.permissions = {'getUserMedia' => false}
expect(driver.permissions).to eq('getUserMedia' => false)
end
end
end # Safari
end # WebDriver
end # Selenium

0 comments on commit f6f0064

Please sign in to comment.