operawatir 0.4.3.pre1-jruby → 0.5-jruby
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitmodules +1 -1
- data/CHANGES +230 -0
- data/Gemfile +4 -0
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/bin/desktopwatir +1 -1
- data/bin/operawatir +16 -4
- data/lib/operadriver/guava-r09.jar +0 -0
- data/lib/operadriver/operadriver-v0.7.2.jar +0 -0
- data/lib/operadriver/selenium-nodeps-20100909.jar +0 -0
- data/lib/operawatir.rb +10 -3
- data/lib/operawatir/actions.rb +111 -0
- data/lib/operawatir/browser.rb +24 -20
- data/lib/operawatir/clickable_item.rb +68 -0
- data/lib/operawatir/compat.rb +4 -4
- data/lib/operawatir/compat/collection.rb +1 -1
- data/lib/operawatir/compat/element.rb +1 -1
- data/lib/operawatir/compat/window.rb +4 -3
- data/lib/operawatir/desktop_browser.rb +299 -95
- data/lib/operawatir/desktop_common.rb +88 -23
- data/lib/operawatir/desktop_container.rb +103 -34
- data/lib/operawatir/desktop_enums.rb +4 -4
- data/lib/operawatir/desktop_exceptions.rb +2 -2
- data/lib/operawatir/desktop_helper.rb +31 -8
- data/lib/operawatir/element.rb +6 -2
- data/lib/operawatir/exceptions.rb +4 -4
- data/lib/operawatir/helper.rb +6 -6
- data/lib/operawatir/keys.rb +4 -4
- data/lib/operawatir/preferences.rb +126 -155
- data/lib/operawatir/quickwidgets.rb +3 -3
- data/lib/operawatir/quickwidgets/quick_addressfield.rb +12 -5
- data/lib/operawatir/quickwidgets/quick_button.rb +39 -53
- data/lib/operawatir/quickwidgets/quick_checkbox.rb +6 -6
- data/lib/operawatir/quickwidgets/quick_dialogtab.rb +5 -5
- data/lib/operawatir/quickwidgets/quick_dropdown.rb +28 -4
- data/lib/operawatir/quickwidgets/quick_dropdownitem.rb +46 -0
- data/lib/operawatir/quickwidgets/quick_editfield.rb +16 -13
- data/lib/operawatir/quickwidgets/quick_label.rb +1 -1
- data/lib/operawatir/quickwidgets/quick_menu.rb +155 -0
- data/lib/operawatir/quickwidgets/quick_menuitem.rb +387 -0
- data/lib/operawatir/quickwidgets/quick_searchfield.rb +7 -4
- data/lib/operawatir/quickwidgets/quick_tab.rb +23 -12
- data/lib/operawatir/quickwidgets/quick_thumbnail.rb +4 -4
- data/lib/operawatir/quickwidgets/quick_toolbar.rb +1 -1
- data/lib/operawatir/quickwidgets/quick_treeitem.rb +45 -29
- data/lib/operawatir/quickwidgets/quick_treeview.rb +2 -2
- data/lib/operawatir/quickwidgets/quick_widget.rb +267 -77
- data/lib/operawatir/quickwidgets/quick_window.rb +64 -38
- data/lib/operawatir/screenshot.rb +1 -1
- data/lib/operawatir/utils.rb +31 -0
- data/lib/operawatir/window.rb +1 -1
- data/operawatir.gemspec +38 -132
- data/spec/operawatir/core/actions_spec.rb +202 -0
- data/spec/operawatir/core/browser_spec.rb +8 -8
- data/spec/operawatir/core/element_spec.rb +11 -2
- data/spec/operawatir/core/keys_spec.rb +50 -2
- data/spec/operawatir/core/preferences_spec.rb +44 -128
- data/spec/operawatir/core/spatnav_spec.rb +16 -16
- data/spec/operawatir/core/utils_spec.rb +47 -0
- data/spec/operawatir/core/window_spec.rb +1 -1
- data/spec/operawatir/desktop/desktopbrowser_spec.rb +191 -22
- data/spec/operawatir/desktop/quickbutton_spec.rb +197 -164
- data/spec/operawatir/desktop/quickcheckbox_spec.rb +12 -12
- data/spec/operawatir/desktop/quickdialogtab_spec.rb +11 -11
- data/spec/operawatir/desktop/quickdropdown_spec.rb +25 -25
- data/spec/operawatir/desktop/quickeditfield_spec.rb +31 -31
- data/spec/operawatir/desktop/quickmenu_spec.rb +57 -0
- data/spec/operawatir/desktop/quickmenuitem_spec.rb +168 -0
- data/spec/operawatir/desktop/quicktab_spec.rb +26 -15
- data/spec/operawatir/desktop/quickthumbnail_spec.rb +18 -4
- data/spec/operawatir/desktop/quicktreeitem_spec.rb +72 -72
- data/spec/operawatir/desktop/quicktreeview_spec.rb +13 -13
- data/spec/operawatir/desktop/quickwidget_spec.rb +51 -13
- data/spec/operawatir/desktop/quickwindow_spec.rb +4 -0
- data/spec/operawatir/desktop/shared/shared.rb +25 -9
- data/spec/operawatir/fixtures/draggableLists.html +67 -0
- data/spec/operawatir/fixtures/formSelectionPage.html +46 -0
- data/spec/operawatir/fixtures/js/jquery-1.4.4.min.js +167 -0
- data/spec/operawatir/fixtures/js/jquery-ui-1.8.10.custom.min.js +782 -0
- data/spec/operawatir/fixtures/keys.html +40 -0
- data/spec/operawatir/fixtures/label_submit.html +5 -0
- data/spec/operawatir/fixtures/mouse.html +59 -0
- data/spec/operawatir/fixtures/simple.html +10 -0
- data/spec/operawatir/matchers.rb +20 -19
- data/spec/operawatir/watirspec_desktophelper.rb +51 -3
- data/spec/operawatir/watirspec_helper.rb +0 -2
- metadata +91 -220
- data/lib/operadriver/client-combined-nodeps.jar +0 -0
- data/lib/operadriver/webdriver-opera.jar +0 -0
- data/spec/watir3/browser_spec.rb +0 -190
- data/spec/watir3/clipboard_spec.rb +0 -64
- data/spec/watir3/collection_spec.rb +0 -387
- data/spec/watir3/element_spec.rb +0 -474
- data/spec/watir3/guards.rb +0 -39
- data/spec/watir3/keys_spec.rb +0 -204
- data/spec/watir3/server.rb +0 -91
- data/spec/watir3/watirspec_helper.rb +0 -62
- data/spec/watir3/window_spec.rb +0 -295
@@ -8,7 +8,7 @@ module OperaWatir
|
|
8
8
|
acc[const.to_s.downcase.to_sym] = SystemInputProtos::ModifierPressed.const_get(const)
|
9
9
|
acc
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
# Enum for the mouse buttons
|
13
13
|
MOUSEBUTTON_ENUM_MAP = SystemInputProtos::MouseInfo::MouseButton.constants.inject({}) do |acc, const|
|
14
14
|
acc[const.to_s.downcase.to_sym] = SystemInputProtos::MouseInfo::MouseButton.const_get(const)
|
@@ -20,13 +20,13 @@ module OperaWatir
|
|
20
20
|
acc[const.to_s.downcase.to_sym] = DesktopWmProtos::QuickWidgetInfo::QuickWidgetType.const_get(const)
|
21
21
|
acc
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# Enum for window types
|
25
25
|
WINDOW_ENUM_MAP = DesktopWmProtos::DesktopWindowInfo::DesktopWindowType.constants.inject({}) do |acc, const|
|
26
26
|
acc[const.to_s.downcase.to_sym] = DesktopWmProtos::DesktopWindowInfo::DesktopWindowType.const_get(const)
|
27
27
|
acc
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Enum for search types
|
31
31
|
WIDGET_SEARCHTYPE_ENUM_MAP = DesktopWmProtos::QuickWidgetSearch::QuickWidgetSearchType.constants.inject({}) do |acc, const|
|
32
32
|
acc[const.to_s.downcase.to_sym] = DesktopWmProtos::QuickWidgetSearch::QuickWidgetSearchType.const_get(const)
|
@@ -37,6 +37,6 @@ module OperaWatir
|
|
37
37
|
DROPPOSITION_ENUM_MAP = QuickWidget::DropPosition.constants.inject({}) do |acc, const|
|
38
38
|
acc[const.to_s.downcase.to_sym] = QuickWidget::DropPosition.const_get(const)
|
39
39
|
acc
|
40
|
-
end
|
40
|
+
end
|
41
41
|
end
|
42
42
|
end
|
@@ -6,11 +6,11 @@ module OperaWatir::DesktopExceptions
|
|
6
6
|
# ...
|
7
7
|
# rescue OperaWatirException
|
8
8
|
# end
|
9
|
-
|
9
|
+
|
10
10
|
# Raised when a method is called on a control that is not visible
|
11
11
|
# corresponding element.
|
12
12
|
class WidgetNotVisibleException < OperaWatirException; end
|
13
13
|
class UnsupportedActionException < OperaWatirException; end
|
14
14
|
class WidgetDisabledException < OperaWatirException; end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
@@ -12,28 +12,50 @@ require File.expand_path('../../../spec/operawatir/matchers', __FILE__)
|
|
12
12
|
|
13
13
|
module OperaWatir::DesktopHelper
|
14
14
|
extend self
|
15
|
-
|
15
|
+
@@files = []
|
16
|
+
|
16
17
|
def settings
|
17
18
|
OperaWatir::DesktopBrowser.settings
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
def browser
|
21
22
|
@browser ||= OperaWatir::DesktopBrowser.new
|
22
23
|
end
|
23
|
-
|
24
|
+
|
25
|
+
def mac?
|
26
|
+
Config::CONFIG['target_os'] == "darwin"
|
27
|
+
end
|
28
|
+
|
29
|
+
def linux?
|
30
|
+
Config::CONFIG['target_os'] == "linux"
|
31
|
+
end
|
32
|
+
|
24
33
|
def configure_rspec!
|
25
34
|
RSpec.configure do |config|
|
26
|
-
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
if mac?
|
39
|
+
config.filter_run_excluding :nonmac? => true
|
40
|
+
end
|
41
|
+
|
42
|
+
if linux? == false
|
43
|
+
config.filter_run_excluding :nix? => true
|
44
|
+
end
|
45
|
+
|
27
46
|
# Set every RSpec option
|
28
47
|
settings.each do |key, value|
|
29
48
|
config.send("#{key}=", value) if config.respond_to?("#{key}=")
|
30
49
|
if key.to_s.eql?("files_to_run")
|
31
50
|
@@files = value
|
32
51
|
end
|
52
|
+
if key.to_s.eql?("files_or_directories_to_run")
|
53
|
+
@@files = value
|
54
|
+
end
|
33
55
|
end
|
34
|
-
|
56
|
+
|
35
57
|
config.include SpecHelpers
|
36
|
-
|
58
|
+
|
37
59
|
config.before(:all) {
|
38
60
|
if OperaWatir::DesktopHelper::settings[:no_restart] == false
|
39
61
|
unless @@files.empty?
|
@@ -46,9 +68,10 @@ module OperaWatir::DesktopHelper
|
|
46
68
|
# test is run before Opera has been launched
|
47
69
|
browser
|
48
70
|
end
|
71
|
+
browser.set_preference("User Prefs", "Enable UI Animations", 0)
|
49
72
|
}
|
50
73
|
|
51
|
-
config.after(:suite) {
|
74
|
+
config.after(:suite) {
|
52
75
|
# Use the @browser directly because we don't want
|
53
76
|
# to launch Opera here if it's not running
|
54
77
|
if @browser
|
@@ -71,7 +94,7 @@ module OperaWatir::DesktopHelper
|
|
71
94
|
configure_rspec!
|
72
95
|
RSpec::Core::Runner.autorun
|
73
96
|
end
|
74
|
-
|
97
|
+
|
75
98
|
private
|
76
99
|
|
77
100
|
module SpecHelpers
|
data/lib/operawatir/element.rb
CHANGED
@@ -125,7 +125,7 @@ class OperaWatir::Element
|
|
125
125
|
# @param [Integer] y The offset from the top of the element.
|
126
126
|
#
|
127
127
|
|
128
|
-
def click(x=
|
128
|
+
def click(x=1, y=1)
|
129
129
|
node.click(x.to_i, y.to_i)
|
130
130
|
end
|
131
131
|
|
@@ -149,6 +149,10 @@ class OperaWatir::Element
|
|
149
149
|
node.rightClick
|
150
150
|
end
|
151
151
|
|
152
|
+
def middle_click
|
153
|
+
node.middleClick
|
154
|
+
end
|
155
|
+
|
152
156
|
def drag_and_drop_on(other)
|
153
157
|
node.dragAndDropOn other.node
|
154
158
|
end
|
@@ -196,7 +200,7 @@ class OperaWatir::Element
|
|
196
200
|
init = "initEvent(\"#{event.to_s}\", true, true)"
|
197
201
|
when :click, :dblclick, :mousedown, :mousemove, :mouseout, :mouseover, :mouseup
|
198
202
|
type = 'MouseEvents'
|
199
|
-
init = "initMouseEvent(\"#{event.to_s}\", true, true, window, 1, 0, 0,
|
203
|
+
init = "initMouseEvent(\"#{event.to_s}\", true, true, window, 1, 0, 0, #{x}, #{y}, false, false, false, false, 0, null)"
|
200
204
|
else
|
201
205
|
raise Exceptions::NotImplementedException, "Event on#{event} is not a valid ECMAscript event for OperaWatir."
|
202
206
|
end
|
@@ -8,7 +8,7 @@ module OperaWatir::Exceptions
|
|
8
8
|
# rescue OperaWatirException
|
9
9
|
# end
|
10
10
|
class OperaWatirException < RuntimeError; end
|
11
|
-
|
11
|
+
|
12
12
|
# Raised when a method is called on an object which doesn't have a
|
13
13
|
# corresponding element.
|
14
14
|
class UnknownObjectException < OperaWatirException; end
|
@@ -17,7 +17,7 @@ module OperaWatir::Exceptions
|
|
17
17
|
#
|
18
18
|
# @example browser.divs(:weird_method, 10)
|
19
19
|
class MissingWayOfFindingObjectException < OperaWatirException; end
|
20
|
-
|
20
|
+
|
21
21
|
# Raised when trying to switch to an unknown frame.
|
22
22
|
class UnknownFrameException < OperaWatirException; end
|
23
23
|
|
@@ -31,7 +31,7 @@ module OperaWatir::Exceptions
|
|
31
31
|
# Raised when trying to perform an action on an element which is
|
32
32
|
# disabled.
|
33
33
|
class ObjectDisabledException < OperaWatirException; end
|
34
|
-
|
34
|
+
|
35
35
|
# Raised when trying to access a table cell that doesn't exist.
|
36
36
|
class UnknownCellException < OperaWatirException; end
|
37
37
|
|
@@ -40,5 +40,5 @@ module OperaWatir::Exceptions
|
|
40
40
|
|
41
41
|
# Raised when an exception occurs in Preferences.
|
42
42
|
class PreferencesException < OperaWatirException; end
|
43
|
-
|
43
|
+
|
44
44
|
end
|
data/lib/operawatir/helper.rb
CHANGED
@@ -10,25 +10,25 @@ require 'rbconfig'
|
|
10
10
|
|
11
11
|
module OperaWatir::Helper
|
12
12
|
extend self
|
13
|
-
|
13
|
+
|
14
14
|
def settings
|
15
15
|
OperaWatir::Browser.settings
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def browser
|
19
19
|
@browser ||= OperaWatir::Browser.new
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def configure_rspec!
|
23
23
|
RSpec.configure do |config|
|
24
|
-
|
24
|
+
|
25
25
|
# Set every RSpec option
|
26
26
|
settings.each do |key, value|
|
27
27
|
config.send("#{key}=", value) if config.respond_to?("#{key}=")
|
28
28
|
end
|
29
29
|
|
30
30
|
config.include SpecHelpers
|
31
|
-
|
31
|
+
|
32
32
|
config.after(:suite) do
|
33
33
|
browser.quit if @browser
|
34
34
|
abort
|
@@ -41,7 +41,7 @@ module OperaWatir::Helper
|
|
41
41
|
configure_rspec!
|
42
42
|
RSpec::Core::Runner.autorun
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
private
|
46
46
|
|
47
47
|
module SpecHelpers
|
data/lib/operawatir/keys.rb
CHANGED
@@ -13,16 +13,16 @@ class OperaWatir::Keys
|
|
13
13
|
# @param [Symbol, String] *args Arbitrary list of symbols (modification)
|
14
14
|
# keys or strings (regular keys) to be
|
15
15
|
# pressed down.
|
16
|
-
#
|
16
|
+
#
|
17
17
|
# @example
|
18
18
|
#
|
19
19
|
# browser.keys.down 'a'
|
20
20
|
# browser.keys.down 'a', :right
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# @seealso up
|
23
23
|
# @seealso send
|
24
24
|
#
|
25
|
-
|
25
|
+
|
26
26
|
def down(*args)
|
27
27
|
args.each { |key| driver.keyDown(key) }
|
28
28
|
end
|
@@ -109,7 +109,7 @@ class OperaWatir::Keys
|
|
109
109
|
private
|
110
110
|
|
111
111
|
def driver
|
112
|
-
browser.driver
|
112
|
+
browser.driver
|
113
113
|
end
|
114
114
|
|
115
115
|
def key(key)
|
@@ -106,19 +106,6 @@ class OperaWatir::Preferences
|
|
106
106
|
|
107
107
|
attr_accessor :browser, :driver
|
108
108
|
|
109
|
-
# FIXME This should be retrievable from OperaDriver
|
110
|
-
SECTIONS = ['Author Display Mode', 'Auto Update', 'BitTorrent',
|
111
|
-
'CSS Generic Font Family', 'Cache', 'Clear Private Data Dialog',
|
112
|
-
'Colors', 'Developer Tools', 'Disk Cache', 'Extensions',
|
113
|
-
'File Selector', 'File Types Section Info', 'Fonts', 'Geolocation',
|
114
|
-
'Handheld', 'HotListWindow', 'ISP', 'Install', 'Interface Colors',
|
115
|
-
'Java', 'Link', 'Mail', 'MailBox', 'Multimedia', 'Network', 'News',
|
116
|
-
'OEM', 'Opera Account', 'Opera Sync', 'Performance', 'Persistent Storage',
|
117
|
-
'Personal Info', 'Printer', 'Proxy', 'SVG', 'Saved Settings',
|
118
|
-
'Security Prefs', 'Sounds', 'Special', 'Transfer Window',
|
119
|
-
'User Agent', 'User Display Mode', 'User Prefs', 'Visited Link',
|
120
|
-
'Visited Link', 'Web Server', 'Widgets', 'Workspace']
|
121
|
-
|
122
109
|
#
|
123
110
|
# The OperaWatir::Preferences object is created automatically when you
|
124
111
|
# create an OperaWatir::Browser object, and is available as
|
@@ -133,8 +120,22 @@ class OperaWatir::Preferences
|
|
133
120
|
|
134
121
|
def initialize(browser)
|
135
122
|
self.browser, self.driver = browser, browser.driver
|
123
|
+
|
124
|
+
raw_prefs = driver.listAllPrefs.to_a
|
125
|
+
@_prefs = {}
|
126
|
+
@_prefs = raw_prefs.map { |s| Section.new(self, s) }.sort_by { |s| s.key }
|
127
|
+
|
128
|
+
@old_prefs = _prefs
|
136
129
|
end
|
137
130
|
|
131
|
+
def_delegators :_prefs, :[],
|
132
|
+
:each,
|
133
|
+
:length,
|
134
|
+
:size,
|
135
|
+
:first,
|
136
|
+
:last,
|
137
|
+
:empty?
|
138
|
+
|
138
139
|
#
|
139
140
|
# When calling Preferences#any_method_name, the `any_method_name` will
|
140
141
|
# be caught by this method.
|
@@ -149,34 +150,25 @@ class OperaWatir::Preferences
|
|
149
150
|
# browser.preferences.interface_colors
|
150
151
|
# # will return section “Interface Colors”
|
151
152
|
#
|
152
|
-
# @param section
|
153
|
-
# @return [Object]
|
153
|
+
# @param section method to look up in preferences
|
154
|
+
# @return [Object] a Preferences::Section object
|
154
155
|
#
|
155
156
|
|
156
|
-
def method_missing(
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
_prefs
|
161
|
-
_prefs.last
|
157
|
+
def method_missing(method)
|
158
|
+
method = method.to_s
|
159
|
+
|
160
|
+
if _prefs.any? { |s| s.method == method }
|
161
|
+
_prefs.find { |s| s.method == method }
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
-
def_delegators :_prefs, :[],
|
166
|
-
:each,
|
167
|
-
:length,
|
168
|
-
:size,
|
169
|
-
:first,
|
170
|
-
:last,
|
171
|
-
:empty?
|
172
|
-
|
173
165
|
#
|
174
166
|
# Retrieves a human-readable list of Opera preferences available.
|
175
167
|
# This is used for convenience and should never be parsed. Consider
|
176
168
|
# using the built-in Ruby iterator #each (with friends) or
|
177
169
|
# Preferences#to_a for that.
|
178
170
|
#
|
179
|
-
# @return [String]
|
171
|
+
# @return [String] list of preferences
|
180
172
|
#
|
181
173
|
|
182
174
|
def to_s
|
@@ -190,7 +182,10 @@ class OperaWatir::Preferences
|
|
190
182
|
text << " type: #{k.type.inspect}\n"
|
191
183
|
text << " value: #{k.value.inspect}\n"
|
192
184
|
text << " default: #{k.default.inspect}\n"
|
185
|
+
text << " enabled: #{k.enabled?.inspect}\n"
|
193
186
|
end
|
187
|
+
|
188
|
+
text << "\n"
|
194
189
|
end
|
195
190
|
|
196
191
|
text
|
@@ -199,10 +194,10 @@ class OperaWatir::Preferences
|
|
199
194
|
#
|
200
195
|
# Returns a list of all preferences in array form. This can be used
|
201
196
|
# for external parsing. If you wish to manipulate or iterate through
|
202
|
-
# the list of preferences consider using the built-in Ruby iterator
|
197
|
+
# the list of preferences, consider using the built-in Ruby iterator
|
203
198
|
# #each (with friends).
|
204
199
|
#
|
205
|
-
# @return [Array]
|
200
|
+
# @return [Array] list of preferences
|
206
201
|
#
|
207
202
|
|
208
203
|
def to_a
|
@@ -213,48 +208,70 @@ class OperaWatir::Preferences
|
|
213
208
|
# Checks if any preferences exists in your Opera build. If true,
|
214
209
|
# there are preferences available, false otherwise.
|
215
210
|
#
|
216
|
-
# @return [Boolean]
|
211
|
+
# @return [Boolean] whether any preference exists
|
217
212
|
#
|
218
213
|
|
219
214
|
def exists?
|
220
215
|
!_prefs.empty?
|
221
216
|
end
|
222
|
-
|
217
|
+
|
223
218
|
alias_method :exist?, :exists? # LOL Ruby
|
224
219
|
|
220
|
+
=begin
|
221
|
+
def cleanup
|
222
|
+
@old_prefs.dup
|
223
|
+
end
|
224
|
+
|
225
|
+
def cleanup!
|
226
|
+
@old_prefs.each do |old_section|
|
227
|
+
old_section.each do |old_key|
|
228
|
+
#self.send(old_section.method).send(old_key.method).send(:value, old_key.value)
|
229
|
+
puts "#{old_section.method}.#{old_key.method}.value = #{old_key.value}"
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
_prefs
|
234
|
+
end
|
235
|
+
=end
|
236
|
+
|
225
237
|
private
|
226
238
|
|
227
239
|
def _prefs
|
228
|
-
@_prefs
|
240
|
+
@_prefs
|
229
241
|
end
|
230
242
|
|
243
|
+
#
|
244
|
+
# OperaWatir::Preferences::Section represents a section in Opera
|
245
|
+
# configuration.
|
246
|
+
#
|
231
247
|
|
232
|
-
class
|
248
|
+
class Section
|
233
249
|
extend Forwardable
|
234
250
|
include Enumerable
|
235
251
|
|
236
|
-
attr_accessor :parent, :
|
252
|
+
attr_accessor :parent, :driver, :method, :key
|
237
253
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
#
|
242
|
-
# It's created automatically when you query for entries using the
|
243
|
-
# Preference object itself.
|
244
|
-
#
|
245
|
-
# @return [Object] An OperaWatir::Preferences::Entry object.
|
246
|
-
#
|
254
|
+
def initialize(parent, raw_section)
|
255
|
+
self.parent, self.driver = parent, parent.driver
|
256
|
+
self.method, self.key = raw_section.first.methodize, raw_section.first
|
247
257
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
258
|
+
@_keys = raw_section[1].map { |k| Key.new(self, k) }.sort_by { |k| k.key }
|
259
|
+
end
|
260
|
+
|
261
|
+
def_delegators :_keys, :[],
|
262
|
+
:length,
|
263
|
+
:size,
|
264
|
+
:first,
|
265
|
+
:last,
|
266
|
+
:empty?
|
267
|
+
|
268
|
+
def each
|
269
|
+
return unless block_given?
|
270
|
+
_keys.each { |k| yield k }
|
254
271
|
end
|
255
272
|
|
256
273
|
#
|
257
|
-
# When calling Preferences::
|
274
|
+
# When calling Preferences::Section#any_method_name, the
|
258
275
|
# `any_method_name` will be caught by this method.
|
259
276
|
#
|
260
277
|
# This is the standard way of looking up preference entries.
|
@@ -267,135 +284,89 @@ private
|
|
267
284
|
# browser.preferences.interface_colors.background
|
268
285
|
# # will return the “Background” entry in section “Interface Colors”
|
269
286
|
#
|
270
|
-
# @param method
|
271
|
-
# @return [Object]
|
287
|
+
# @param method method to look up in section
|
288
|
+
# @return [Object] a Preferences::Section::Key (entry) object
|
272
289
|
#
|
273
290
|
|
274
291
|
def method_missing(method)
|
275
292
|
method = method.to_s
|
276
|
-
|
293
|
+
|
277
294
|
if _keys.any? { |k| k.method == method }
|
278
295
|
_keys.find { |k| k.method == method }
|
279
|
-
else
|
280
|
-
_keys << Entry.new(self, method)
|
281
|
-
_keys.last
|
282
296
|
end
|
283
297
|
end
|
284
298
|
|
285
|
-
|
286
|
-
# Returns the value of an entry in a section. Note that it's not
|
287
|
-
# possible to retrieve the value for sections.
|
288
|
-
#
|
289
|
-
# @return [String] Value of the entry.
|
290
|
-
#
|
291
|
-
|
292
|
-
def value
|
293
|
-
raise OperaWatir::Exceptions::PreferencesException, 'Sections do not have values' if section?
|
294
|
-
@value ||= driver.getPref(parent.key, key)
|
295
|
-
end
|
296
|
-
|
297
|
-
#
|
298
|
-
# Sets the entry's value to the specified string. Note that it's
|
299
|
-
# not possible to set a section's value.
|
300
|
-
#
|
301
|
-
# @param [String] value Value you wish to set for the entry.
|
302
|
-
#
|
299
|
+
private
|
303
300
|
|
304
|
-
def
|
305
|
-
|
306
|
-
value = value.truthy? ? '1' : '0' if type.include?('Boolean')
|
307
|
-
driver.setPref parent.key, key, value.to_s
|
308
|
-
@value = value
|
301
|
+
def _keys
|
302
|
+
@_keys
|
309
303
|
end
|
310
304
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
#
|
315
|
-
# @return [String] The default value of the entry.
|
316
|
-
#
|
305
|
+
class Key
|
306
|
+
extend Forwardable
|
307
|
+
include Enumerable
|
317
308
|
|
318
|
-
|
319
|
-
raise OperaWatir::Exceptions::PreferencesException, 'Sections do not have defaults' if section?
|
320
|
-
@default ||= driver.getDefaultPref parent.key, key
|
321
|
-
end
|
309
|
+
attr_accessor :parent, :driver, :method, :key, :type, :value
|
322
310
|
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
# @return [String] The default value of the entry.
|
328
|
-
#
|
311
|
+
def initialize(parent, raw_key)
|
312
|
+
self.parent, self.driver = parent, parent.driver
|
313
|
+
self.method, self.key = raw_key.first.methodize, raw_key.first
|
314
|
+
raw_data = raw_key[1].to_s
|
329
315
|
|
330
|
-
|
331
|
-
|
332
|
-
end
|
316
|
+
raw_data =~ /^type: ([A-Z]+)$/
|
317
|
+
self.type = $1.to_s.capitalize
|
333
318
|
|
334
|
-
|
335
|
-
|
336
|
-
#
|
337
|
-
# @return [Boolean] True/false based on whether you're
|
338
|
-
# interacting with a section or entry.
|
339
|
-
#
|
319
|
+
raw_data =~ /^value: \"(.*)\"$/
|
320
|
+
@value = $1.to_s
|
340
321
|
|
341
|
-
|
342
|
-
|
343
|
-
|
322
|
+
# Ruby doesn't support attr_accessor's with question mark in their
|
323
|
+
# name.
|
324
|
+
raw_data =~ /^enabled: (true|false)$/
|
325
|
+
@enabled = $1.truthy?
|
326
|
+
end
|
344
327
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
# preference entry/section.
|
351
|
-
#
|
328
|
+
#
|
329
|
+
# Whether the current key entry is enabled inside Opera or not.
|
330
|
+
#
|
331
|
+
# @return [Boolean] true if enabled, false if otherwise
|
332
|
+
#
|
352
333
|
|
353
|
-
|
354
|
-
|
355
|
-
|
334
|
+
def enabled?
|
335
|
+
!!@enabled
|
336
|
+
end
|
356
337
|
|
357
|
-
|
338
|
+
#
|
339
|
+
# Sets the key's value to the specified string.
|
340
|
+
#
|
341
|
+
# @param [String] value the value you wish to set for the key
|
342
|
+
#
|
358
343
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
344
|
+
def value=(value)
|
345
|
+
value = value.truthy? ? '1' : '0' if type.include?('Boolean')
|
346
|
+
driver.setPref parent.key, key, value.to_s
|
347
|
+
@value = value
|
348
|
+
end
|
363
349
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
:empty?
|
350
|
+
#
|
351
|
+
# Returns key's default value.
|
352
|
+
#
|
353
|
+
# @return [String] the default value of the key
|
354
|
+
#
|
370
355
|
|
371
|
-
|
356
|
+
def default
|
357
|
+
@default ||= driver.getDefaultPref parent.key, key
|
358
|
+
end
|
372
359
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
360
|
+
#
|
361
|
+
# Returns and sets the default value of the key.
|
362
|
+
#
|
363
|
+
# @return [String] the default value of the key
|
364
|
+
#
|
377
365
|
|
378
|
-
|
379
|
-
|
380
|
-
keys = []
|
381
|
-
|
382
|
-
driver.listPrefs(true, key).to_a.each do |p|
|
383
|
-
p = p.to_s
|
384
|
-
|
385
|
-
p =~ /^key: \"([a-zA-Z0-9\(\)\\\.\-\s]*)\"$/
|
386
|
-
key = $1.to_s.gsub(/^\\t/, "\t") # Workaround for double-encoded tabs:
|
387
|
-
# We get \\t, but it only accepts \t.
|
388
|
-
|
389
|
-
p =~ /^type: ([A-Z]+)$/
|
390
|
-
type = $1.to_s.capitalize
|
391
|
-
|
392
|
-
next if key.empty? # “Opera Widgets/Unite Style File” is bugged, workaround.
|
393
|
-
keys << Entry.new(self, key.methodize, key, type)
|
366
|
+
def default!
|
367
|
+
self.value=(default)
|
394
368
|
end
|
395
|
-
|
396
|
-
keys
|
397
369
|
end
|
398
|
-
|
399
370
|
end
|
400
371
|
|
401
372
|
end
|