jscmd 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ # require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/jscmd'
@@ -0,0 +1,94 @@
1
+ $port = 19000
2
+
3
+ $proxy_stdin, $proxy_stdin_writer = IO.pipe
4
+ $proxy_stdout_reader, $proxy_stdout = IO.pipe
5
+
6
+ $shell_pid = fork do
7
+ at_exit {} # prevent TestRunner from running
8
+ $stdin.reopen($proxy_stdin)
9
+ $stdout.reopen($proxy_stdout)
10
+ require File.dirname(__FILE__) + '/test_helper.rb'
11
+ server = JSCommander::Broker.new(:Port => $port, :AccessLog => [])
12
+ server.start
13
+ end
14
+
15
+ require "net/http"
16
+ require "open-uri"
17
+ require "test/unit"
18
+ require "zlib"
19
+
20
+ # wait until the server starts up
21
+ 60.times do
22
+ begin
23
+ Net::HTTP.get("localhost", "/", $port)
24
+ break
25
+ rescue Exception => e
26
+ end
27
+ puts "waiting..."
28
+ sleep 0.5
29
+ end
30
+
31
+ class TestJscmd < Test::Unit::TestCase
32
+ def test_proxy
33
+ open("http://www.google.co.jp/", :proxy => "http://localhost:#{$port}/") do |f|
34
+ assert_match %r{/_remote_js_proxy/agent.js}, f.read
35
+ end
36
+ end
37
+
38
+ def test_proxy_with_gzip_compression
39
+ body = Net::HTTP.start("www.google.co.jp", 80, "localhost", $port) do |h|
40
+ res = h.get("/",
41
+ "Accept-Encoding" => "gzip",
42
+ "User-Agent" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; ja-JP-mac; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3")
43
+ assert_equal "gzip", res["content-encoding"]
44
+ assert_match %r{/_remote_js_proxy/agent.js},
45
+ Zlib::GzipReader.new(StringIO.new(res.body)).read
46
+ end
47
+ end
48
+
49
+ def test_get_script
50
+ open("http://www.google.com/_remote_js_proxy/agent.js", :proxy => "http://localhost:#{$port}/") do |f|
51
+ assert_equal File.read("lib/jscmd/agent.js"), f.read
52
+ end
53
+ end
54
+
55
+ def test_poll_and_get_command
56
+ $proxy_stdin_writer.puts "window"
57
+ # assert_equal "> window\n", $proxy_stdout_reader.readline
58
+ open("http://www.google.com/_remote_js_proxy/poll", :proxy => "http://localhost:#{$port}/") do |f|
59
+ assert_equal "Ewindow", f.read
60
+ end
61
+ end
62
+
63
+ def test_poll_and_post_value
64
+ begin
65
+ body = nil
66
+ t = Thread.start do
67
+ # browser thread
68
+ begin
69
+ Net::HTTP.start("www.google.com", 80, "localhost", $port) do |h|
70
+ # (1) send value from browser to shell
71
+ body = h.post("/_remote_js_proxy/poll", "Vabc",
72
+ "Content-Type" => "application/x-www-form-urlencoded").body
73
+ # (4) received another command and long-poll terminates
74
+ end
75
+ rescue Exception => e
76
+ p e
77
+ end
78
+ end
79
+ assert_match(/(sleep|run)/, t.status)
80
+ # (2) read value sent from browser
81
+ assert_equal "abc\n", $proxy_stdout_reader.readline
82
+ assert_match(/(sleep|run)/, t.status)
83
+ ensure
84
+ # (3) send another command to finish long-poll in browser
85
+ $proxy_stdin_writer.puts "window"
86
+ t.join
87
+ assert_equal "Ewindow", body
88
+ end
89
+ end
90
+ end
91
+
92
+ END { Process.kill "TERM", $shell_pid; Process.waitall }
93
+
94
+ exit Test::Unit::AutoRunner.run
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: jscmd
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.2
7
+ date: 2007-05-08 00:00:00 +09:00
8
+ summary: JavaScript console for any browser
9
+ require_paths:
10
+ - lib
11
+ email: kasatani@gmail.com
12
+ homepage: http://jscmd.rubyforge.org
13
+ rubyforge_project: jscmd
14
+ description: JavaScript console for any browser
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Shinya Kasatani
31
+ files:
32
+ - COPYING
33
+ - GPL
34
+ - History.txt
35
+ - Manifest.txt
36
+ - README.txt
37
+ - Rakefile
38
+ - bin/jscmd
39
+ - lib/jscmd.rb
40
+ - lib/jscmd/version.rb
41
+ - lib/jscmd/jscommander.rb
42
+ - lib/jscmd/asynchttpproxy.rb
43
+ - lib/jscmd/agent.js
44
+ - scripts/txt2html
45
+ - setup.rb
46
+ - test/test_helper.rb
47
+ - test/test_jscmd.rb
48
+ test_files:
49
+ - test/test_helper.rb
50
+ - test/test_jscmd.rb
51
+ rdoc_options: []
52
+
53
+ extra_rdoc_files: []
54
+
55
+ executables:
56
+ - jscmd
57
+ extensions: []
58
+
59
+ requirements: []
60
+
61
+ dependencies: []
62
+