webkit_remote 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb3ccfba70d3f677946e7aea83a46d515858b56a
4
- data.tar.gz: c35c1614ca83eecbd4ab0259227221aec466bee5
3
+ metadata.gz: 2c7efaac54ca9f1f022c45be4f54666443e45595
4
+ data.tar.gz: 83ef9a7212ab08c395bf4a8f3d4feb498557f7e4
5
5
  SHA512:
6
- metadata.gz: 1cfc3b83187a5d4d6d36ee3fb5113471027ef8f522f7a7434f685315774fd8353edeadba6285c0575a1d4602af7ba3e244a1c94ac392722f5b022f8d5c8f7d09
7
- data.tar.gz: 14960e8733fec9ebba3563c620800b93415d5fa18a96b5b6919b6f4d58eb39c014227c62908cb26d31e7cb72564943b7428d9ddeb510f4fa467e62adc97a9062
6
+ metadata.gz: 0d557b4e62206aa1eef4a668b0bb859831857c38f1ef601fbd8b9555ace7e17e4d720d75cedd6c1ed67d1a19e72da65e24aced159d05921a1e1e78f77dc411f0
7
+ data.tar.gz: 710126dd348769ff3d7eebcac1cbc800a3e70b69515e5124930cec12bf29546ad7451b1e4be777ac0f9a748e49d5f0ee14a50732c94d5adf68ad416aa40fa6fe
data/README.md CHANGED
@@ -26,6 +26,7 @@ have been implemented:
26
26
 
27
27
  * Console
28
28
  * DOM (incomplete)
29
+ * Input
29
30
  * Network
30
31
  * Page
31
32
  * Remote
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
data/lib/webkit_remote.rb CHANGED
@@ -11,6 +11,7 @@ require 'webkit_remote/client/console.rb'
11
11
  require 'webkit_remote/client/console_events.rb'
12
12
  require 'webkit_remote/client/dom.rb'
13
13
  require 'webkit_remote/client/dom_events.rb'
14
+ require 'webkit_remote/client/input.rb'
14
15
  require 'webkit_remote/client/network.rb'
15
16
  require 'webkit_remote/client/network_events.rb'
16
17
  require 'webkit_remote/client/page.rb'
@@ -0,0 +1,136 @@
1
+ module WebkitRemote
2
+
3
+ class Client
4
+
5
+ # API for the Input domain.
6
+ module Input
7
+ # Dispatches a mouse event.
8
+ #
9
+ # @param [Symbol] type the event type (:move, :down, :up)
10
+ # @param [Integer] x the X coordinate, relative to the main frame's viewport
11
+ # @param [Integer] y the Y coordinate, relative to the main frame's viewport
12
+ # @param [Hash] opts optional information
13
+ # @option opts [Symbol] button :left, :right, :middle, or nil (none); nil by
14
+ # default
15
+ # @option opts [Array<Symbol>] modifiers combination of :alt, :ctrl, :shift,
16
+ # and :command / :meta (empty by default)
17
+ # @option opts [Number] time the event's time, as a JavaScript timestamp
18
+ # @option opts [Number] clicks number of times the mouse button was clicked
19
+ # (0 by default)
20
+ # @return [WebkitRemote::Client] self
21
+ def mouse_event(type, x, y, opts = {})
22
+ options = { x: x, y: y }
23
+ options[:type] = case type
24
+ when :move
25
+ 'mouseMoved'
26
+ when :down
27
+ 'mousePressed'
28
+ when :up
29
+ 'mouseReleased'
30
+ else
31
+ raise RuntimeError, "Unsupported mouse event type #{type}"
32
+ end
33
+
34
+ options[:timestamp] = opts[:time] if opts[:time]
35
+ options[:clickCount] = opts[:clicks] if opts[:clicks]
36
+ if opts[:modifiers]
37
+ flags = 0
38
+ opts[:modifiers].each do |modifier|
39
+ flags |= case modifier
40
+ when :alt
41
+ 1
42
+ when :ctrl
43
+ 2
44
+ when :command, :meta
45
+ 4
46
+ when :shift
47
+ 8
48
+ end
49
+ end
50
+ options[:modifiers] = flags
51
+ end
52
+
53
+ @rpc.call 'Input.dispatchMouseEvent', options
54
+ self
55
+ end
56
+
57
+ # Dispatches a keyboard event.
58
+ #
59
+ # @param [Symbol] type the event type (:char, :down, :up, :raw_down)
60
+ # @param [Hash] opts optional information
61
+ # @option opts [Array<Symbol>] modifiers combination of :alt, :ctrl, :shift,
62
+ # and :command / :meta (empty by default)
63
+ # @option opts [Number] time the event's time, as a JavaScript timestamp
64
+ # @option opts [Number] clicks number of times the mouse button was clicked
65
+ # (0 by default)
66
+ # @option opts [String] text as generated by processing a virtual key code
67
+ # with a keyboard layout; not needed for :up and :raw_down events;
68
+ # ('' by default)
69
+ # @option opts [String] unmodified_text text that would have been generated
70
+ # by the keyboard if no modifiers were pressed (except for shift);
71
+ # useful for shortcut (accelerator) key handling; ('' by default)
72
+ # @option opts [Number] vkey the Windows virtual key code for the key;
73
+ # see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Virtual_key_codes
74
+ # @option opts [Number] key_id the unique key identifier (e.g., 'U+0041');
75
+ # ('' by default)
76
+ # @option opts [Boolean] auto_repeat true if the event was generated by an
77
+ # auto-repeat while the key was being held down
78
+ # @option opts [Boolean] keypad true if the event was generated from the
79
+ # keypad
80
+ # @option opts [Boolean] system_key true if the event was a system key event
81
+ # @return [WebkitRemote::Client] self
82
+ def key_event(type, opts)
83
+ options = {}
84
+ options[:type] = case type
85
+ when :char
86
+ 'char'
87
+ when :down
88
+ 'keyDown'
89
+ when :up
90
+ 'keyUp'
91
+ when :raw_down
92
+ 'rawKeyDown'
93
+ else
94
+ raise RuntimeError, "Unsupported keyboard event type #{type}"
95
+ end
96
+
97
+ options[:timestamp] = opts[:time] if opts[:time]
98
+ if opts[:modifiers]
99
+ flags = 0
100
+ opts[:modifiers].each do |modifier|
101
+ flags |= case modifier
102
+ when :alt
103
+ 1
104
+ when :ctrl
105
+ 2
106
+ when :command, :meta
107
+ 4
108
+ when :shift
109
+ 8
110
+ end
111
+ end
112
+ options[:modifiers] = flags
113
+ end
114
+
115
+ options[:keyIdentifier] = opts[:key_id] if opts[:key_id]
116
+ options[:windowsVirtualKeyCode] = opts[:vkey] if opts[:vkey]
117
+ options[:unmodifiedText] = opts[:unmodified_text] if opts[:unmodified_text]
118
+ if opts[:text]
119
+ options[:text] = opts[:text]
120
+ options[:unmodifiedText] ||= opts[:text]
121
+ end
122
+ options[:autoRepeat] = true if opts[:auto_repeat]
123
+ options[:isKeypad] = true if opts[:keypad]
124
+ options[:isSystemKey] = true if opts[:system_key]
125
+
126
+ @rpc.call 'Input.dispatchKeyEvent', options
127
+ self
128
+ end
129
+ end # module WebkitRemote::Client::Input
130
+
131
+ include WebkitRemote::Client::Input
132
+
133
+ end # namespace WebkitRemote::Client
134
+
135
+ end # namespace WebkitRemote
136
+
@@ -88,7 +88,7 @@ end # module WebkitRemote::Client::Runtime
88
88
 
89
89
  initializer :initialize_runtime
90
90
  clearer :clear_runtime
91
- include Runtime
91
+ include WebkitRemote::Client::Runtime
92
92
 
93
93
  # The class of the JavaScript undefined object.
94
94
  class UndefinedClass
@@ -0,0 +1,55 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>WebkitRemote Input test</title>
5
+ <style type="text/css">
6
+ input[type=text] {
7
+ width: 150px;
8
+ height: 150px;
9
+ position: absolute;
10
+ left: 0;
11
+ top: 0;
12
+ }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <form action="#">
17
+ <input type="text" placeholder="Input test" autofocus="autofocus" />
18
+ </form>
19
+ <script type="text/javascript">
20
+ var mouseEventDetails = function (event) {
21
+ return "x: " + event.clientX + " y: " + event.clientY +
22
+ " button: " + event.button + " detail: " + event.detail +
23
+ " shift: " + event.shiftKey + " ctrl: " + event.ctrlKey + " alt: " +
24
+ event.altKey + " meta: " + event.metaKey;
25
+ };
26
+ var keyEventDetails = function (event) {
27
+ return "keyCode: " + event.keyCode + " charCode: " + event.charCode +
28
+ " keyIdentifier: " + event.keyIdentifier + " text: " + event.text +
29
+ " repeat: " + event.repeat + " shift: " + event.shiftKey +
30
+ " ctrl: " + event.ctrlKey + " alt: " + event.altKey +
31
+ " meta: " + event.metaKey;
32
+ };
33
+ var node = document.querySelector("input[type=text]");
34
+ node.addEventListener('mousedown', function (event) {
35
+ console.log("Down. " + mouseEventDetails(event));
36
+ });
37
+ node.addEventListener('mouseup', function (event) {
38
+ console.log("Up. " + mouseEventDetails(event));
39
+ });
40
+ node.addEventListener('mousemove', function (event) {
41
+ console.log("Move. " + mouseEventDetails(event));
42
+ });
43
+ window.addEventListener('keydown', function (event) {
44
+ console.log("KDown. " + keyEventDetails(event));
45
+ });
46
+ window.addEventListener('keyup', function (event) {
47
+ console.log("KUp. " + keyEventDetails(event));
48
+ });
49
+ window.addEventListener('keypress', function (event) {
50
+ console.log("KPress. " + keyEventDetails(event));
51
+ });
52
+ </script>
53
+ </body>
54
+ </html>
55
+
@@ -0,0 +1,99 @@
1
+ require File.expand_path('../../helper.rb', File.dirname(__FILE__))
2
+
3
+ describe WebkitRemote::Client::Console do
4
+ before :all do
5
+ @client = WebkitRemote.local port: 9669
6
+ @client.page_events = true
7
+ @client.navigate_to fixture_url(:input)
8
+ @client.wait_for type: WebkitRemote::Event::PageLoaded
9
+ @client.console_events = true
10
+ end
11
+ after :all do
12
+ @client.close
13
+ end
14
+
15
+ describe '#mouse_event' do
16
+ it 'generates a move correctly' do
17
+ @client.mouse_event :move, 50, 50
18
+ events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
19
+
20
+ events.last.message.text.must_equal(
21
+ 'Move. x: 50 y: 50 button: 0 detail: 0 shift: false ctrl: false ' +
22
+ 'alt: false meta: false')
23
+ end
24
+
25
+ it 'generates a press correctly' do
26
+ @client.mouse_event :down, 51, 52, button: :left, modifiers: [:shift]
27
+ events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
28
+
29
+ events.last.message.text.must_equal(
30
+ 'Down. x: 51 y: 52 button: 0 detail: 0 shift: true ctrl: false ' +
31
+ 'alt: false meta: false')
32
+ end
33
+
34
+ it 'generates a second press correctly' do
35
+ @client.mouse_event :down, 51, 52, button: :left, clicks: 2,
36
+ modifiers: [:alt, :ctrl]
37
+ events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
38
+
39
+ events.last.message.text.must_equal(
40
+ 'Down. x: 51 y: 52 button: 0 detail: 2 shift: false ctrl: true ' +
41
+ 'alt: true meta: false')
42
+ end
43
+
44
+ it 'generates a release correctly' do
45
+ @client.mouse_event :up, 51, 52, button: :middle, modifiers: [:command]
46
+ events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
47
+
48
+ events.last.message.text.must_equal(
49
+ 'Up. x: 51 y: 52 button: 0 detail: 0 shift: false ctrl: false ' +
50
+ 'alt: false meta: true')
51
+ end
52
+ end
53
+
54
+ describe '#key_event' do
55
+ it 'generates a char correctly' do
56
+ @client.key_event :char, text: 'a'
57
+
58
+ events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
59
+
60
+ events.last.message.text.must_equal(
61
+ 'KPress. keyCode: 97 charCode: 97 keyIdentifier: text: undefined ' +
62
+ 'repeat: false shift: false ctrl: false alt: false meta: false')
63
+ end
64
+
65
+ it 'generates a down correctly' do
66
+ @client.key_event :down, vkey: 0x41, key_id: 'U+0041'
67
+
68
+ events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
69
+
70
+ events.last.message.text.must_equal(
71
+ 'KDown. keyCode: 65 charCode: 0 keyIdentifier: U+0041 ' +
72
+ 'text: undefined ' +
73
+ 'repeat: false shift: false ctrl: false alt: false meta: false')
74
+ end
75
+
76
+ it 'generates an up correctly' do
77
+ @client.key_event :up, vkey: 0x41, key_id: 'U+0041'
78
+
79
+ events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
80
+
81
+ events.last.message.text.must_equal(
82
+ 'KUp. keyCode: 65 charCode: 0 keyIdentifier: U+0041 ' +
83
+ 'text: undefined ' +
84
+ 'repeat: false shift: false ctrl: false alt: false meta: false')
85
+ end
86
+
87
+ it 'generates a raw_down correctly' do
88
+ @client.key_event :raw_down, vkey: 0x41, key_id: 'U+0041'
89
+
90
+ events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
91
+
92
+ events.last.message.text.must_equal(
93
+ 'KDown. keyCode: 65 charCode: 0 keyIdentifier: U+0041 ' +
94
+ 'text: undefined ' +
95
+ 'repeat: false shift: false ctrl: false alt: false meta: false')
96
+ end
97
+ end
98
+ end
99
+
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "webkit_remote"
8
- s.version = "0.5.3"
8
+ s.version = "0.5.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Victor Costan"]
12
- s.date = "2014-03-19"
12
+ s.date = "2014-03-23"
13
13
  s.description = "Launches Google Chrome instances and controls them via the Remote Debugging server"
14
14
  s.email = "victor@costan.us"
15
15
  s.extra_rdoc_files = [
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/webkit_remote/client/dom.rb",
34
34
  "lib/webkit_remote/client/dom_events.rb",
35
35
  "lib/webkit_remote/client/dom_runtime.rb",
36
+ "lib/webkit_remote/client/input.rb",
36
37
  "lib/webkit_remote/client/network.rb",
37
38
  "lib/webkit_remote/client/network_events.rb",
38
39
  "lib/webkit_remote/client/page.rb",
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
45
46
  "test/fixtures/config.ru",
46
47
  "test/fixtures/html/console.html",
47
48
  "test/fixtures/html/dom.html",
49
+ "test/fixtures/html/input.html",
48
50
  "test/fixtures/html/load.html",
49
51
  "test/fixtures/html/network.html",
50
52
  "test/fixtures/html/popup.html",
@@ -56,6 +58,7 @@ Gem::Specification.new do |s|
56
58
  "test/webkit_remote/browser_test.rb",
57
59
  "test/webkit_remote/client/console_test.rb",
58
60
  "test/webkit_remote/client/dom_test.rb",
61
+ "test/webkit_remote/client/input_test.rb",
59
62
  "test/webkit_remote/client/js_object_group_test.rb",
60
63
  "test/webkit_remote/client/js_object_test.rb",
61
64
  "test/webkit_remote/client/network_test.rb",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webkit_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-19 00:00:00.000000000 Z
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ws_sync_client
@@ -203,6 +203,7 @@ files:
203
203
  - lib/webkit_remote/client/dom.rb
204
204
  - lib/webkit_remote/client/dom_events.rb
205
205
  - lib/webkit_remote/client/dom_runtime.rb
206
+ - lib/webkit_remote/client/input.rb
206
207
  - lib/webkit_remote/client/network.rb
207
208
  - lib/webkit_remote/client/network_events.rb
208
209
  - lib/webkit_remote/client/page.rb
@@ -215,6 +216,7 @@ files:
215
216
  - test/fixtures/config.ru
216
217
  - test/fixtures/html/console.html
217
218
  - test/fixtures/html/dom.html
219
+ - test/fixtures/html/input.html
218
220
  - test/fixtures/html/load.html
219
221
  - test/fixtures/html/network.html
220
222
  - test/fixtures/html/popup.html
@@ -226,6 +228,7 @@ files:
226
228
  - test/webkit_remote/browser_test.rb
227
229
  - test/webkit_remote/client/console_test.rb
228
230
  - test/webkit_remote/client/dom_test.rb
231
+ - test/webkit_remote/client/input_test.rb
229
232
  - test/webkit_remote/client/js_object_group_test.rb
230
233
  - test/webkit_remote/client/js_object_test.rb
231
234
  - test/webkit_remote/client/network_test.rb