webkit_remote 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,8 +36,8 @@ module Page
36
36
  def page_events=(new_page_events)
37
37
  new_page_events = !!new_page_events
38
38
  if new_page_events != page_events
39
+ @rpc.call(new_page_events ? 'Page.enable' : 'Page.disable')
39
40
  @page_events = new_page_events
40
- @rpc.call(@page_events ? 'Page.enable' : 'Page.disable')
41
41
  end
42
42
  new_page_events
43
43
  end
@@ -47,7 +47,7 @@ module Page
47
47
 
48
48
  # @private Called by the Client constructor to set up Page data structures.
49
49
  def initialize_page
50
- @page_events = nil
50
+ @page_events = false
51
51
  end
52
52
 
53
53
  end # module WebkitRemote::Client::Page
@@ -31,7 +31,8 @@ module Runtime
31
31
  # Retrieves a group of remote objects by its name.
32
32
  #
33
33
  # @param [String, Symbol] group_name name given to remote_eval when the
34
- # object was created
34
+ # object was created; nil obtains the anonymous group containing the
35
+ # un-grouped objects created by Console#MessageReceived
35
36
  # @param [Boolean] create if true, fetching a group that does not exist will
36
37
  # create the group; this parameter should only be used internally
37
38
  # @return [WebkitRemote::Client::RemoteObject, Boolean, Number, String, nil]
@@ -64,9 +65,20 @@ module Runtime
64
65
  def initialize_runtime()
65
66
  @runtime_groups = {}
66
67
  end
68
+
69
+ # Releases all the objects allocated to this runtime.
70
+ #
71
+ # @return [WebkitRemote::Client] self
72
+ def clear_runtime
73
+ @runtime_groups.each do |name, group|
74
+ group.release_all
75
+ end
76
+ self
77
+ end
67
78
  end # module WebkitRemote::Client::Runtime
68
79
 
69
80
  initializer :initialize_runtime
81
+ clearer :clear_runtime
70
82
  include Runtime
71
83
 
72
84
  # The class of the JavaScript undefined object.
@@ -310,7 +322,16 @@ class RemoteObjectGroup
310
322
  # @return [Webkit::Client::RemoteObjectGroup] self
311
323
  def release_all
312
324
  return if @objects.empty?
313
- @rpc.call 'Runtime.releaseObjectGroup', objectGroup: name
325
+
326
+ if @name == nil
327
+ # This is the special group that contains un-grouped objects.
328
+ @objects.values.each do |object|
329
+ object.release
330
+ end
331
+ else
332
+ @rpc.call 'Runtime.releaseObjectGroup', objectGroup: name
333
+ end
334
+
314
335
  @released = true
315
336
  @objects.each_value { |object| object.released! }
316
337
  @objects.clear
@@ -116,7 +116,13 @@ class Process
116
116
  "--user-data-dir=#{@data_dir}", # really ensure a clean slate
117
117
  '--window-position=0,0', # remove randomness source
118
118
  '--window-size=128,128', # remove randomness source
119
- 'about:blank' # don't load the homepage
119
+ 'about:blank', # don't load the homepage
120
+ {
121
+ chdir: @data_dir,
122
+ in: '/dev/null',
123
+ out: File.join(@data_dir, '.stdout'),
124
+ err: File.join(@data_dir, '.stderr'),
125
+ },
120
126
  ]
121
127
  end
122
128
 
@@ -1,12 +1,25 @@
1
1
  require 'bundler'
2
2
  Bundler.setup :default, :development
3
3
 
4
- use Rack::Static, urls: ['/html'], root: 'test/fixtures'
4
+ require 'json'
5
+ require 'rack/contrib'
6
+
7
+ # Compression for Network domain testing.
8
+ use Rack::Deflater
9
+
10
+ # Custom header for Network domain testing.
11
+ use Rack::ResponseHeaders do |headers|
12
+ headers['X-Unit-Test'] = 'webkit-remote'
13
+ end
14
+
15
+ # Cache headers for Network domain testing.
16
+ use Rack::StaticCache, urls: ['/html'], root: 'test/fixtures',
17
+ versioning: false
5
18
  app = lambda do |env|
6
19
  [
7
20
  200,
8
- {'Content-Type' => 'text/plain'},
9
- ['Fixture app catch-all page. Invalid test URL.']
21
+ {'Content-Type' => 'application/json'},
22
+ [JSON.dump(env)]
10
23
  ]
11
24
  end
12
25
  run app
@@ -20,6 +20,6 @@
20
20
  </script>
21
21
  </head>
22
22
  <body>
23
- <p>Runtime test loaded</p>
23
+ <p>Console test loaded</p>
24
24
  </body>
25
25
  </html>
@@ -0,0 +1,10 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>WebkitRemote Network test</title>
5
+ <script type="text/javascript" src="../network.js"></script>
6
+ </head>
7
+ <body>
8
+ <p>Network test loaded</p>
9
+ </body>
10
+ </html>
@@ -26,6 +26,12 @@ describe WebkitRemote::Client::Console do
26
26
  lambda {
27
27
  @client.wait_for type: WebkitRemote::Event::ConsoleMessage
28
28
  }.must_raise ArgumentError
29
+ lambda {
30
+ @client.wait_for type: WebkitRemote::Event::ConsoleMessageRepeated
31
+ }.must_raise ArgumentError
32
+ lambda {
33
+ @client.wait_for type: WebkitRemote::Event::ConsoleCleared
34
+ }.must_raise ArgumentError
29
35
  end
30
36
  end
31
37
 
@@ -40,7 +46,7 @@ describe WebkitRemote::Client::Console do
40
46
  end
41
47
 
42
48
  after :all do
43
- @messages.each(&:release_params)
49
+ @client.clear_all
44
50
  end
45
51
 
46
52
  it 'receives console events' do
@@ -58,7 +64,6 @@ describe WebkitRemote::Client::Console do
58
64
  @messages[0].source_line.must_equal 7
59
65
  end
60
66
 
61
-
62
67
  it 'parses the stack trace correctly' do
63
68
  @messages[1].text.must_equal 'stack test'
64
69
  @messages[1].level.must_equal :log
@@ -91,5 +96,20 @@ describe WebkitRemote::Client::Console do
91
96
  @events.last.must_be_kind_of WebkitRemote::Event::ConsoleCleared
92
97
  end
93
98
  end
99
+
100
+ describe 'clear_all' do
101
+ before :all do
102
+ @client.clear_all
103
+ @events = @client.wait_for type: WebkitRemote::Event::ConsoleCleared
104
+ end
105
+
106
+ it 'calls clear_console, which emits a ConsoleCleared event' do
107
+ @events.last.must_be_kind_of WebkitRemote::Event::ConsoleCleared
108
+ end
109
+
110
+ it 'releases the objects in ConsoleMessage instances' do
111
+ @messages[2].params[3].released?.must_equal true
112
+ end
113
+ end
94
114
  end
95
115
  end
@@ -0,0 +1,123 @@
1
+ require File.expand_path('../../helper.rb', File.dirname(__FILE__))
2
+
3
+ describe WebkitRemote::Client::Network do
4
+ before :all do
5
+ @client = WebkitRemote.local port: 9669
6
+ @client.page_events = true
7
+ end
8
+ after :all do
9
+ @client.close
10
+ end
11
+
12
+ describe 'without network events enabled' do
13
+ before :all do
14
+ @client.disable_cache = true
15
+ @client.network_events = false
16
+ @client.navigate_to fixture_url(:console)
17
+ @events = @client.wait_for type: WebkitRemote::Event::PageLoaded
18
+ end
19
+
20
+ it 'does not receive any network event' do
21
+ @events.each do |event|
22
+ @event.wont_be_kind_of WebkitRemote::Event::NetworkResponse
23
+ end
24
+ end
25
+
26
+ it 'cannot wait for network events' do
27
+ lambda {
28
+ @client.wait_for type: WebkitRemote::Event::NetworkRequest
29
+ }.must_raise ArgumentError
30
+ lambda {
31
+ @client.wait_for type: WebkitRemote::Event::NetworkResponse
32
+ }.must_raise ArgumentError
33
+ end
34
+ end
35
+
36
+ describe 'with network events enabled' do
37
+ before :all do
38
+ @client.disable_cache = true
39
+ @client.network_events = true
40
+ @client.navigate_to fixture_url(:console)
41
+ @events = @client.wait_for type: WebkitRemote::Event::PageLoaded
42
+ @requests = @events.select do |event|
43
+ event.kind_of? WebkitRemote::Event::NetworkRequest
44
+ end
45
+ @responses = @events.select do |event|
46
+ event.kind_of? WebkitRemote::Event::NetworkResponse
47
+ end
48
+ @resources = @client.network_resources
49
+ end
50
+
51
+ it 'receives NetworkRequest events' do
52
+ @requests.wont_be :empty?
53
+ end
54
+
55
+ it 'parses initial requests inside NetworkRequest events correctly' do
56
+ @requests[0].request.must_be_kind_of WebkitRemote::Client::NetworkRequest
57
+ @requests[0].request.url.must_equal fixture_url(:console)
58
+ @requests[0].request.method.must_equal :get
59
+ @requests[0].request.headers.must_include 'User-Agent'
60
+ @requests[0].request.headers['User-Agent'].must_match(/webkit/i)
61
+ @requests[0].request.initiator.type.must_equal :other
62
+ @requests[0].request.initiator.stack_trace.must_equal nil
63
+ end
64
+
65
+ it 'parses derived requests inside NetworkRequest events correctly' do
66
+ @requests[1].document_url.must_equal
67
+ @requests[1].request.must_be_kind_of WebkitRemote::Client::NetworkRequest
68
+ @requests[1].request.url.must_equal fixture_url(:console)
69
+ @requests[0].request.method.must_equal :get
70
+ @requests[0].request.headers.must_include 'User-Agent'
71
+ @requests[0].request.headers['User-Agent'].must_match(/webkit/i)
72
+ @requests[0].request.initiator.type.must_equal :other
73
+ @requests[0].request.initiator.stack_trace.must_equal nil
74
+
75
+ end
76
+
77
+ it 'receives NetworkResponse events' do
78
+ @responses.wont_be :empty?
79
+ end
80
+
81
+ it 'parses initial NetworkRequest and NetworkResponse events correctly' do
82
+ @responses[0].type.must_equal :document
83
+ @requests[0].initiator.type.must_equal :other
84
+ @requests[0].loader_id.wont_be :empty?
85
+ @requests[0].loader_id.must_equal @responses[0].loader_id
86
+ @requests[0].resource.remote_id.wont_be :empty?
87
+ @requests[0].resource.must_equal @responses[0].resource
88
+ @requests[0].timestamp.must_be :<, @responses[0].timestamp
89
+ end
90
+
91
+ it 'parses derived NetworkRequest and NetworkResponse events correctly' do
92
+ @responses[1].type.must_equal :script
93
+ @responses[2].type.must_equal :image
94
+ end
95
+
96
+ it 'parses the response inside NetworkResponse events correctly' do
97
+ @responses[0].type.must_equal :document
98
+ @responses[0].response.
99
+ must_be_kind_of WebkitRemote::Client::NetworkResponse
100
+ @responses[0].response.url.must_equal fixture_url(:console)
101
+ @responses[0].response.status.must_equal 200
102
+ @responses[0].response.status_text.must_equal 'OK'
103
+ @responses[0].response.headers.must_include 'X-Unit-Test'
104
+ @responses[0].response.headers['X-Unit-Test'].must_equal 'webkit-remote'
105
+ @responses[0].response.mime_type.must_equal 'text/html'
106
+ @responses[0].response.request_headers.must_include 'User-Agent'
107
+ @responses[0].response.request_headers['User-Agent']
108
+ .must_match(/webkit/i)
109
+ @responses[0].response.from_cache.must_equal false
110
+ @responses[0].response.connection_reused.must_equal false
111
+ end
112
+
113
+ it 'collects request and response data in a NetworkResource' do
114
+ @resources.wont_be :empty?
115
+
116
+ @resources[0].request.must_equal @requests[0].request
117
+ @resources[0].initiator.must_equal @requests[0].initiator
118
+ @resources[0].response.must_equal @responses[0].response
119
+ @resources[0].type.must_equal :document
120
+ @resources[0].client.must_equal @client
121
+ end
122
+ end
123
+ end
@@ -8,6 +8,7 @@ describe WebkitRemote::Client::Runtime do
8
8
  @client.wait_for type: WebkitRemote::Event::PageLoaded
9
9
  end
10
10
  after :all do
11
+ @client.clear_all
11
12
  @client.close
12
13
  end
13
14
 
@@ -154,4 +155,24 @@ describe WebkitRemote::Client::Runtime do
154
155
  end
155
156
  end
156
157
  end
158
+
159
+
160
+ describe 'clear_all' do
161
+ describe 'with a named allocated object' do
162
+ before :each do
163
+ @object = @client.remote_eval '({hello: "ruby", answer: 42})',
164
+ group: 'yes'
165
+ end
166
+ after :each do
167
+ group = @client.object_group('yes')
168
+ group.release_all if group
169
+ end
170
+
171
+ it 'releases the object and its group' do
172
+ @client.clear_all
173
+ @object.released?.must_equal true
174
+ @client.object_group('yes').must_equal nil
175
+ end
176
+ end
177
+ end
157
178
  end
@@ -96,5 +96,11 @@ describe WebkitRemote::Client do
96
96
  end
97
97
  end
98
98
  end
99
+
100
+ describe 'clear_all' do
101
+ it 'does not crash' do
102
+ @client.clear_all
103
+ end
104
+ end
99
105
  end
100
106
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "webkit_remote"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
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 = "2012-10-31"
12
+ s.date = "2012-11-08"
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 = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".travis.yml",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
23
24
  "LICENSE.txt",
@@ -29,6 +30,8 @@ Gem::Specification.new do |s|
29
30
  "lib/webkit_remote/client.rb",
30
31
  "lib/webkit_remote/client/console.rb",
31
32
  "lib/webkit_remote/client/console_events.rb",
33
+ "lib/webkit_remote/client/network.rb",
34
+ "lib/webkit_remote/client/network_events.rb",
32
35
  "lib/webkit_remote/client/page.rb",
33
36
  "lib/webkit_remote/client/page_events.rb",
34
37
  "lib/webkit_remote/client/runtime.rb",
@@ -39,10 +42,12 @@ Gem::Specification.new do |s|
39
42
  "test/fixtures/config.ru",
40
43
  "test/fixtures/html/console.html",
41
44
  "test/fixtures/html/load.html",
45
+ "test/fixtures/html/network.html",
42
46
  "test/fixtures/html/runtime.html",
43
47
  "test/helper.rb",
44
48
  "test/webkit_remote/browser_test.rb",
45
49
  "test/webkit_remote/client/console_test.rb",
50
+ "test/webkit_remote/client/network_test.rb",
46
51
  "test/webkit_remote/client/page_test.rb",
47
52
  "test/webkit_remote/client/remote_object_group_test.rb",
48
53
  "test/webkit_remote/client/remote_object_test.rb",
@@ -72,6 +77,7 @@ Gem::Specification.new do |s|
72
77
  s.add_development_dependency(%q<minitest>, [">= 4.1.0"])
73
78
  s.add_development_dependency(%q<puma>, [">= 1.6.3"])
74
79
  s.add_development_dependency(%q<rack>, [">= 1.4.1"])
80
+ s.add_development_dependency(%q<rack-contrib>, [">= 1.1.0"])
75
81
  s.add_development_dependency(%q<rdoc>, [">= 3.12"])
76
82
  s.add_development_dependency(%q<ruby-prof>, [">= 0.11.2"])
77
83
  s.add_development_dependency(%q<simplecov>, [">= 0.7.1"])
@@ -85,6 +91,7 @@ Gem::Specification.new do |s|
85
91
  s.add_dependency(%q<minitest>, [">= 4.1.0"])
86
92
  s.add_dependency(%q<puma>, [">= 1.6.3"])
87
93
  s.add_dependency(%q<rack>, [">= 1.4.1"])
94
+ s.add_dependency(%q<rack-contrib>, [">= 1.1.0"])
88
95
  s.add_dependency(%q<rdoc>, [">= 3.12"])
89
96
  s.add_dependency(%q<ruby-prof>, [">= 0.11.2"])
90
97
  s.add_dependency(%q<simplecov>, [">= 0.7.1"])
@@ -99,6 +106,7 @@ Gem::Specification.new do |s|
99
106
  s.add_dependency(%q<minitest>, [">= 4.1.0"])
100
107
  s.add_dependency(%q<puma>, [">= 1.6.3"])
101
108
  s.add_dependency(%q<rack>, [">= 1.4.1"])
109
+ s.add_dependency(%q<rack-contrib>, [">= 1.1.0"])
102
110
  s.add_dependency(%q<rdoc>, [">= 3.12"])
103
111
  s.add_dependency(%q<ruby-prof>, [">= 0.11.2"])
104
112
  s.add_dependency(%q<simplecov>, [">= 0.7.1"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webkit_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-31 00:00:00.000000000 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -139,6 +139,22 @@ dependencies:
139
139
  - - ! '>='
140
140
  - !ruby/object:Gem::Version
141
141
  version: 1.4.1
142
+ - !ruby/object:Gem::Dependency
143
+ name: rack-contrib
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: 1.1.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: 1.1.0
142
158
  - !ruby/object:Gem::Dependency
143
159
  name: rdoc
144
160
  requirement: !ruby/object:Gem::Requirement
@@ -213,6 +229,7 @@ extra_rdoc_files:
213
229
  - README.md
214
230
  files:
215
231
  - .document
232
+ - .travis.yml
216
233
  - Gemfile
217
234
  - Gemfile.lock
218
235
  - LICENSE.txt
@@ -224,6 +241,8 @@ files:
224
241
  - lib/webkit_remote/client.rb
225
242
  - lib/webkit_remote/client/console.rb
226
243
  - lib/webkit_remote/client/console_events.rb
244
+ - lib/webkit_remote/client/network.rb
245
+ - lib/webkit_remote/client/network_events.rb
227
246
  - lib/webkit_remote/client/page.rb
228
247
  - lib/webkit_remote/client/page_events.rb
229
248
  - lib/webkit_remote/client/runtime.rb
@@ -234,10 +253,12 @@ files:
234
253
  - test/fixtures/config.ru
235
254
  - test/fixtures/html/console.html
236
255
  - test/fixtures/html/load.html
256
+ - test/fixtures/html/network.html
237
257
  - test/fixtures/html/runtime.html
238
258
  - test/helper.rb
239
259
  - test/webkit_remote/browser_test.rb
240
260
  - test/webkit_remote/client/console_test.rb
261
+ - test/webkit_remote/client/network_test.rb
241
262
  - test/webkit_remote/client/page_test.rb
242
263
  - test/webkit_remote/client/remote_object_group_test.rb
243
264
  - test/webkit_remote/client/remote_object_test.rb
@@ -263,7 +284,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
263
284
  version: '0'
264
285
  segments:
265
286
  - 0
266
- hash: -1503511080774862725
287
+ hash: 40721145812420836
267
288
  required_rubygems_version: !ruby/object:Gem::Requirement
268
289
  none: false
269
290
  requirements: