webkit_remote 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -11,8 +11,8 @@ GEM
11
11
  rake
12
12
  rdoc
13
13
  json (1.7.5)
14
- minitest (4.1.0)
15
- multi_json (1.3.6)
14
+ minitest (4.2.0)
15
+ multi_json (1.3.7)
16
16
  posix-spawn (0.3.6)
17
17
  puma (1.6.3)
18
18
  rack (~> 1.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -182,6 +182,7 @@ class NetworkRequest < WebkitRemote::Event
182
182
  # @private Use Event#for instead of calling this constructor directly.
183
183
  def initialize(rpc_event, client)
184
184
  super
185
+ @document_url = raw_data['documentURL']
185
186
  if raw_data['initiator']
186
187
  @initiator = WebkitRemote::Client::NetworkRequestInitiator.new(
187
188
  raw_data['initiator'])
@@ -204,6 +205,7 @@ class NetworkRequest < WebkitRemote::Event
204
205
  @timestamp = raw_data['timestamp']
205
206
 
206
207
  @resource = client.network_resource raw_data['requestId']
208
+ @resource.set_document_url @document_url
207
209
  @resource.set_initiator @initiator
208
210
  @resource.set_request @request
209
211
  # TODO(pwnall): consider tracking redirects
@@ -56,6 +56,8 @@ class Event
56
56
  value.can_reach?(client)
57
57
  when :name
58
58
  class_for(value).can_reach?(client)
59
+ else
60
+ true
59
61
  end
60
62
  end
61
63
  end
@@ -13,7 +13,7 @@ use Rack::ResponseHeaders do |headers|
13
13
  end
14
14
 
15
15
  # Cache headers for Network domain testing.
16
- use Rack::StaticCache, urls: ['/html'], root: 'test/fixtures',
16
+ use Rack::StaticCache, urls: ['/html', '/js', '/png'], root: 'test/fixtures',
17
17
  versioning: false
18
18
  app = lambda do |env|
19
19
  [
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>WebkitRemote Network test</title>
5
- <script type="text/javascript" src="../network.js"></script>
5
+ <script type="text/javascript" src="../js/network.js"></script>
6
6
  </head>
7
7
  <body>
8
8
  <p>Network test loaded</p>
@@ -0,0 +1,11 @@
1
+ (function () {
2
+ var xhr = new XMLHttpRequest();
3
+ xhr.responseType = "blob";
4
+ xhr.onreadystatechange = function () {
5
+ if (xhr.readyState === 4) {
6
+ console.log("Test done");
7
+ }
8
+ };
9
+ xhr.open("GET", "../png/network.png", true);
10
+ xhr.send();
11
+ })();
Binary file
data/test/helper.rb CHANGED
@@ -17,6 +17,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
17
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
18
  require 'webkit_remote'
19
19
 
20
+ require 'pp'
20
21
  require 'thread'
21
22
  Thread.abort_on_exception = true
22
23
 
@@ -36,8 +37,12 @@ end
36
37
 
37
38
  class MiniTest::Unit::TestCase
38
39
  # URL for a file in the test/fixtures directory.
39
- def fixture_url(name)
40
- "http://localhost:9969/html/#{name}.html"
40
+ def fixture_url(name, type = :html)
41
+ "http://localhost:9969/#{type}/#{name}.#{type}"
42
+ end
43
+ # Path to a file in the test/fixtures directory.
44
+ def fixture_path(name, type = :html)
45
+ File.join File.dirname(__FILE__), "fixtures/#{type}/#{name}.#{type}"
41
46
  end
42
47
  end
43
48
 
@@ -3,7 +3,8 @@ require File.expand_path('../../helper.rb', File.dirname(__FILE__))
3
3
  describe WebkitRemote::Client::Network do
4
4
  before :all do
5
5
  @client = WebkitRemote.local port: 9669
6
- @client.page_events = true
6
+ @client.console_events = true
7
+ @client.disable_cache = true
7
8
  end
8
9
  after :all do
9
10
  @client.close
@@ -11,10 +12,9 @@ describe WebkitRemote::Client::Network do
11
12
 
12
13
  describe 'without network events enabled' do
13
14
  before :all do
14
- @client.disable_cache = true
15
15
  @client.network_events = false
16
- @client.navigate_to fixture_url(:console)
17
- @events = @client.wait_for type: WebkitRemote::Event::PageLoaded
16
+ @client.navigate_to fixture_url(:network)
17
+ @events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
18
18
  end
19
19
 
20
20
  it 'does not receive any network event' do
@@ -37,14 +37,20 @@ describe WebkitRemote::Client::Network do
37
37
  before :all do
38
38
  @client.disable_cache = true
39
39
  @client.network_events = true
40
- @client.navigate_to fixture_url(:console)
41
- @events = @client.wait_for type: WebkitRemote::Event::PageLoaded
40
+ @client.navigate_to fixture_url(:network)
41
+ @events = @client.wait_for type: WebkitRemote::Event::ConsoleMessage
42
42
  @requests = @events.select do |event|
43
43
  event.kind_of? WebkitRemote::Event::NetworkRequest
44
44
  end
45
45
  @responses = @events.select do |event|
46
46
  event.kind_of? WebkitRemote::Event::NetworkResponse
47
47
  end
48
+ @loads = @events.select do |event|
49
+ event.kind_of? WebkitRemote::Event::NetworkLoad
50
+ end
51
+ @chunks = @events.select do |event|
52
+ event.kind_of? WebkitRemote::Event::NetworkData
53
+ end
48
54
  @resources = @client.network_resources
49
55
  end
50
56
 
@@ -54,24 +60,29 @@ describe WebkitRemote::Client::Network do
54
60
 
55
61
  it 'parses initial requests inside NetworkRequest events correctly' do
56
62
  @requests[0].request.must_be_kind_of WebkitRemote::Client::NetworkRequest
57
- @requests[0].request.url.must_equal fixture_url(:console)
63
+ @requests[0].request.url.must_equal fixture_url(:network)
58
64
  @requests[0].request.method.must_equal :get
59
65
  @requests[0].request.headers.must_include 'User-Agent'
60
66
  @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
67
+ @requests[0].initiator.type.must_equal :other
68
+ @requests[0].initiator.stack_trace.must_equal nil
63
69
  end
64
70
 
65
71
  it 'parses derived requests inside NetworkRequest events correctly' do
66
- @requests[1].document_url.must_equal
72
+ @requests[1].document_url.must_equal fixture_url(:network)
67
73
  @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
+ @requests[1].request.url.must_equal fixture_url(:network, :js)
75
+ @requests[1].initiator.type.must_equal :parser
76
+ @requests[1].initiator.stack_trace.must_equal nil
74
77
 
78
+ @requests[2].document_url.must_equal fixture_url(:network)
79
+ @requests[2].request.must_be_kind_of WebkitRemote::Client::NetworkRequest
80
+ @requests[2].request.url.must_equal fixture_url(:network, :png)
81
+ @requests[2].initiator.type.must_equal :script
82
+ @requests[2].initiator.stack_trace.must_equal [
83
+ {column: 7, line: 10, function: "", url: fixture_url(:network, :js)},
84
+ {column: 3, line: 11, function: "", url: fixture_url(:network, :js)},
85
+ ]
75
86
  end
76
87
 
77
88
  it 'receives NetworkResponse events' do
@@ -88,16 +99,11 @@ describe WebkitRemote::Client::Network do
88
99
  @requests[0].timestamp.must_be :<, @responses[0].timestamp
89
100
  end
90
101
 
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
102
+ it 'parses the initial response inside NetworkResponse events correctly' do
97
103
  @responses[0].type.must_equal :document
98
104
  @responses[0].response.
99
105
  must_be_kind_of WebkitRemote::Client::NetworkResponse
100
- @responses[0].response.url.must_equal fixture_url(:console)
106
+ @responses[0].response.url.must_equal fixture_url(:network)
101
107
  @responses[0].response.status.must_equal 200
102
108
  @responses[0].response.status_text.must_equal 'OK'
103
109
  @responses[0].response.headers.must_include 'X-Unit-Test'
@@ -110,14 +116,44 @@ describe WebkitRemote::Client::Network do
110
116
  @responses[0].response.connection_reused.must_equal false
111
117
  end
112
118
 
113
- it 'collects request and response data in a NetworkResource' do
114
- @resources.wont_be :empty?
119
+ it 'parses derived responses inside NetworkResponse events correctly' do
120
+ @responses[1].type.must_equal :script
121
+ @responses[2].type.must_equal :xhr
122
+ end
123
+
124
+ it 'receives NetworkData events' do
125
+ @chunks.wont_be :empty?
126
+ end
127
+
128
+ it 'parses NetworkData events correctly' do
129
+ @chunks[0].resource.must_equal @chunks[0].resource
130
+ @chunks[0].data_length.
131
+ must_equal File.read(fixture_path(:network)).length
132
+ @chunks[0].bytes_received.must_be :>, 0
133
+ end
134
+
135
+ it 'receives NetworkLoad events' do
136
+ @loads.wont_be :empty?
137
+ end
138
+
139
+ it 'parses NetworkLoad events correctly' do
140
+ @loads[0].resource.must_equal @requests[0].resource
141
+ @loads[1].resource.must_equal @requests[1].resource
142
+ end
143
+
144
+ it 'collects request and response data in NetworkResources' do
145
+ @resources[1].must_equal @requests[1].resource
146
+ @resources[1].request.must_equal @requests[1].request
147
+ @resources[1].response.must_equal @responses[1].response
148
+ @resources[1].type.must_equal :script
149
+ @resources[1].document_url.must_equal fixture_url(:network)
150
+ @resources[1].initiator.must_equal @requests[1].initiator
151
+ @resources[1].canceled.must_equal false
152
+ @resources[1].error.must_equal nil
153
+ @resources[1].last_event.must_equal @loads[1]
154
+ @resources[1].client.must_equal @client
115
155
 
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
156
+ @resources[-1].last_event.must_equal @chunks[-1]
121
157
  end
122
158
  end
123
159
  end
@@ -63,6 +63,10 @@ describe WebkitRemote::Event do
63
63
  WebkitRemote::Event.can_receive?(@client, name: 'Page.loadEventFired').
64
64
  must_equal false
65
65
  end
66
+ it 'should ignore extra properties' do
67
+ WebkitRemote::Event.can_receive?(@client, name: 'Page.loadEventFired',
68
+ other_property: true).must_equal false
69
+ end
66
70
  end
67
71
 
68
72
  describe 'when page_events is true' do
@@ -77,6 +81,10 @@ describe WebkitRemote::Event do
77
81
  WebkitRemote::Event.can_receive?(@client, name: 'Page.loadEventFired').
78
82
  must_equal true
79
83
  end
84
+ it 'should ignore extra properties' do
85
+ WebkitRemote::Event.can_receive?(@client, name: 'Page.loadEventFired',
86
+ other_property: true).must_equal true
87
+ end
80
88
  end
81
89
  end
82
90
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "webkit_remote"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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"]
@@ -44,6 +44,8 @@ Gem::Specification.new do |s|
44
44
  "test/fixtures/html/load.html",
45
45
  "test/fixtures/html/network.html",
46
46
  "test/fixtures/html/runtime.html",
47
+ "test/fixtures/js/network.js",
48
+ "test/fixtures/png/network.png",
47
49
  "test/helper.rb",
48
50
  "test/webkit_remote/browser_test.rb",
49
51
  "test/webkit_remote/client/console_test.rb",
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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -255,6 +255,8 @@ files:
255
255
  - test/fixtures/html/load.html
256
256
  - test/fixtures/html/network.html
257
257
  - test/fixtures/html/runtime.html
258
+ - test/fixtures/js/network.js
259
+ - test/fixtures/png/network.png
258
260
  - test/helper.rb
259
261
  - test/webkit_remote/browser_test.rb
260
262
  - test/webkit_remote/client/console_test.rb
@@ -284,7 +286,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
284
286
  version: '0'
285
287
  segments:
286
288
  - 0
287
- hash: 40721145812420836
289
+ hash: 2944886604051237369
288
290
  required_rubygems_version: !ruby/object:Gem::Requirement
289
291
  none: false
290
292
  requirements: