webkit_remote_unstable 0.1.1 → 0.1.2

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: 484a5b3e3e676e39784355b98fb8f2af4314d961
4
- data.tar.gz: da3586c9f9f985e39b336cf2556e493d54c59459
3
+ metadata.gz: 92207ab762337f22db4f10bcd26525d254c02f4d
4
+ data.tar.gz: d22bb09a90c7c0c0978657b0ffcab3549054588d
5
5
  SHA512:
6
- metadata.gz: 96cb133e49bae96fc65589219e277da8ce6c10dfd82062aa8e0da1ac893d61f797fafcf0d45750eefb8e9252a781a72be75eeeec5232f5d40999a8990365145f
7
- data.tar.gz: c79cb1b179f4cfaa34f4e6ba557906b3fe1cd0833e95cfbba4ac05f0377be5ccfc65a9f1bf29e174a1092a45c35cf7351b3311e3467fa2bcef69cd6fc48dc58a
6
+ metadata.gz: a15fc42945c824463215ec5573e5c19c8788562c78cc901816155b9ed8ad0c258e7125b3ccb3b2639aee13ffad76106953ff0ef3e01f0c2396e6248901f7f895
7
+ data.tar.gz: 001ec141a3a3ad5e44957a3e44e76ee9f67ad437f8c36e7295ffe65fc2e293cb6f1100a83d5f992fdfe480aa0c754318a9545b38248ec04043809cfe172744a7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -3,4 +3,5 @@ require 'webkit_remote'
3
3
 
4
4
  require 'webkit_remote_unstable/css.rb'
5
5
  require 'webkit_remote_unstable/css_events.rb'
6
+ require 'webkit_remote_unstable/dom.rb'
6
7
  require 'webkit_remote_unstable/page.rb'
@@ -0,0 +1,98 @@
1
+ module WebkitRemote
2
+
3
+ class Client
4
+
5
+ # Unstable API for the DOM domain.
6
+ module Dom
7
+ # Retrieves the node at a given location.
8
+ #
9
+ # @param [Integer] x the X coordinate, in window coordinates
10
+ # @param [Integer] y the Y coordinate, in window coordinates
11
+ def dom_node_at(x, y)
12
+ result = @rpc.call 'DOM.getNodeForLocation', x: x.to_i, y: y.to_i
13
+ dom_node result['nodeId']
14
+ end
15
+
16
+ # @private Called by the Client constructor to set up unsupported DOM data.
17
+ def initialize_dom_unstable
18
+ end
19
+ end # module WebkitRemote::Client::Dom
20
+
21
+ initializer :initialize_dom_unstable
22
+
23
+ # Unstable cached information about a DOM node.
24
+ class DomNode
25
+ # This node's box model information.
26
+ #
27
+ # @return [WebkitRemote::Client::BoxModel] the node's box model layout
28
+ def box_model
29
+ @box_model ||= box_model!
30
+ end
31
+
32
+ # Retrieves this node's box model, bypassing the cache.
33
+ #
34
+ # @return [WebkitRemote::Client::BoxModel] the node's box model layout
35
+ def box_model!
36
+ result = @client.rpc.call 'DOM.getBoxModel', nodeId: @remote_id
37
+ WebkitRemote::Client::DomBoxModel.new result['model']
38
+ end
39
+
40
+ # @private Called by the DomNode constructor.
41
+ def initialize_unstable
42
+ @box_model = nil
43
+ end
44
+ initializer :initialize_unstable
45
+ end # class WebkitRemote::Client::DomNode
46
+
47
+ # Box model layout information for an element.
48
+ class DomBoxModel
49
+ # @return [DomQuad] the margin's boundary
50
+ attr_reader :margin
51
+ # @return [DomQuad] the border's boundary
52
+ attr_reader :border
53
+ # @return [DomQuad] the padding's boundary
54
+ attr_reader :padding
55
+ # @return [DomQuad] the content's boundary
56
+ attr_reader :content
57
+
58
+ # @return [Number] the box's width
59
+ attr_reader :width
60
+ # @return [Number] the box's height
61
+ attr_reader :height
62
+
63
+ # Wraps raw box model data received via a RPC call.
64
+ #
65
+ # @param [Hash<Symbol, Object>] raw_box_model a BoxModel instance, according
66
+ # to the Webkit remote debugging protocol; this is the return value of a
67
+ # 'DOM.getBoxModel' call
68
+ def initialize(raw_box_model)
69
+ @width = raw_box_model['width']
70
+ @height = raw_box_model['height']
71
+ @margin = WebkitRemote::Client::DomQuad.new raw_box_model['margin']
72
+ @border = WebkitRemote::Client::DomQuad.new raw_box_model['border']
73
+ @padding = WebkitRemote::Client::DomQuad.new raw_box_model['padding']
74
+ @content = WebkitRemote::Client::DomQuad.new raw_box_model['content']
75
+ end
76
+ end # class WebkitRemote::Client::DomBoxModel
77
+
78
+ # Coordinates for 4 points that make up a box's boundary.
79
+ class DomQuad
80
+ # @return [Array<Number>] x coordinates for the 4 points, in clockwise order
81
+ attr_reader :x
82
+
83
+ # @return [Array<Number>] y coordinates for the 4 points, in clockwise order
84
+ attr_reader :y
85
+
86
+ # Wraps raw box model data received via a RPC call.
87
+ #
88
+ # @param [Array<Number>] raw_quad a Quad instance, according to the Webkit
89
+ # remote debugging protocol
90
+ def initialize(raw_quad)
91
+ @x = [raw_quad[0], raw_quad[2], raw_quad[4], raw_quad[6]].freeze
92
+ @y = [raw_quad[1], raw_quad[3], raw_quad[5], raw_quad[7]].freeze
93
+ end
94
+ end # class WebKitRemote::Client::DomQuad
95
+
96
+ end # namespace WebkitRemote::Client
97
+
98
+ end # namespace WebkitRemote
@@ -0,0 +1,26 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>WebkitRemote DOM test</title>
5
+ <style type="text/css">
6
+ #box_test {
7
+ margin: 1px 2px 3px 4px;
8
+ border: solid black;
9
+ border-top: 5px;
10
+ border-right: 6px;
11
+ border-bottom: 7px;
12
+ border-left: 8px;
13
+ padding: 9px 10px 11px 12px;
14
+ width: 67px;
15
+ height: 73px;
16
+
17
+ position: absolute;
18
+ left: 100px;
19
+ top: 100px;
20
+ }
21
+ </style>
22
+ </head>
23
+ <body>
24
+ <p id="box_test">Box model test</p>
25
+ </body>
26
+ </html>
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../helper.rb', File.dirname(__FILE__))
2
+
3
+ describe WebkitRemote::Client::Dom do
4
+ before :all do
5
+ @client = WebkitRemote.local port: 9669
6
+ @client.page_events = true
7
+ @client.navigate_to fixture_url(:dom)
8
+ @client.wait_for type: WebkitRemote::Event::PageLoaded
9
+ end
10
+ after :all do
11
+ @client.close
12
+ end
13
+
14
+ describe 'DomNode#box_model' do
15
+ before do
16
+ @node = @client.dom_root.query_selector '#box_test'
17
+ @box = @node.box_model
18
+ end
19
+
20
+ it 'has correct numbers' do
21
+ @box.width.must_equal 89
22
+ @box.height.must_equal 93
23
+ @box.margin.x.must_equal [100, 195, 195, 100]
24
+ @box.margin.y.must_equal [100, 100, 197, 197]
25
+ @box.border.x.must_equal [104, 193, 193, 104]
26
+ @box.border.y.must_equal [101, 101, 194, 194]
27
+ @box.padding.x.must_equal [104, 193, 193, 104]
28
+ @box.padding.y.must_equal [101, 101, 194, 194]
29
+ @box.content.x.must_equal [116, 183, 183, 116]
30
+ @box.content.y.must_equal [110, 110, 183, 183]
31
+ end
32
+ end
33
+
34
+ describe '#dom_node_at' do
35
+ before do
36
+ @node = @client.dom_root.query_selector '#box_test'
37
+ end
38
+
39
+ it 'identifies the test box correctly' do
40
+ node = @client.dom_node_at 150, 150
41
+ node.must_equal @node
42
+ end
43
+ end
44
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "webkit_remote_unstable"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
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-18"
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 = [
@@ -27,12 +27,15 @@ Gem::Specification.new do |s|
27
27
  "lib/webkit_remote_unstable.rb",
28
28
  "lib/webkit_remote_unstable/css.rb",
29
29
  "lib/webkit_remote_unstable/css_events.rb",
30
+ "lib/webkit_remote_unstable/dom.rb",
30
31
  "lib/webkit_remote_unstable/page.rb",
31
32
  "test/fixtures/config.ru",
32
33
  "test/fixtures/html/css.html",
34
+ "test/fixtures/html/dom.html",
33
35
  "test/fixtures/html/page.html",
34
36
  "test/helper.rb",
35
37
  "test/webkit_remote_unstable/css_test.rb",
38
+ "test/webkit_remote_unstable/dom_test.rb",
36
39
  "test/webkit_remote_unstable/page_test.rb",
37
40
  "webkit_remote_unstable.gemspec"
38
41
  ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webkit_remote_unstable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-18 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: webkit_remote
@@ -183,12 +183,15 @@ files:
183
183
  - lib/webkit_remote_unstable.rb
184
184
  - lib/webkit_remote_unstable/css.rb
185
185
  - lib/webkit_remote_unstable/css_events.rb
186
+ - lib/webkit_remote_unstable/dom.rb
186
187
  - lib/webkit_remote_unstable/page.rb
187
188
  - test/fixtures/config.ru
188
189
  - test/fixtures/html/css.html
190
+ - test/fixtures/html/dom.html
189
191
  - test/fixtures/html/page.html
190
192
  - test/helper.rb
191
193
  - test/webkit_remote_unstable/css_test.rb
194
+ - test/webkit_remote_unstable/dom_test.rb
192
195
  - test/webkit_remote_unstable/page_test.rb
193
196
  - webkit_remote_unstable.gemspec
194
197
  homepage: http://github.com/pwnall/webkit_remote_unstable