1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/win32ole/test_win32ole_event.rb
suke 38321af30c avoid Argument Error.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-25 08:16:44 +00:00

99 lines
2.3 KiB
Ruby

begin
require 'win32ole'
rescue LoadError
end
require 'test/unit'
if defined?(WIN32OLE_EVENT)
class TestWIN32OLE_EVENT < Test::Unit::TestCase
def setup
@ie = WIN32OLE.new("InternetExplorer.Application")
@ie.visible = true
@event = ""
@event2 = ""
@event3 = ""
end
def default_handler(event, *args)
@event += event
end
def test_on_event
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event {|*args| default_handler(*args)}
@ie.gohome
while @ie.busy
WIN32OLE_EVENT.message_loop
end
assert_match(/BeforeNavigate/, @event)
assert_match(/NavigateComplete/, @event)
end
def test_on_event2
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event('BeforeNavigate') {|*args| handler1}
ev.on_event('BeforeNavigate') {|*args| handler2}
@ie.gohome
while @ie.busy
WIN32OLE_EVENT.message_loop
end
assert_equal("handler2", @event2)
end
def test_on_event3
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event {|*args| handler1}
ev.on_event {|*args| handler2}
@ie.gohome
while @ie.busy
WIN32OLE_EVENT.message_loop
end
assert_equal("handler2", @event2)
end
def test_on_event4
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event{|*args| handler1}
ev.on_event{|*args| handler2}
ev.on_event('NavigateComplete'){|*args| handler3(*args)}
@ie.gohome
while @ie.busy
WIN32OLE_EVENT.message_loop
end
assert(@event3!="")
assert("handler2", @event2)
end
def test_on_event5
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event {|*args| default_handler(*args)}
ev.on_event('NavigateComplete'){|*args| handler3(*args)}
@ie.gohome
while @ie.busy
WIN32OLE_EVENT.message_loop
end
assert_match(/BeforeNavigate/, @event)
assert(/NavigateComplete/ !~ @event)
assert(@event!="")
end
def handler1
@event2 = "handler1"
end
def handler2
@event2 = "handler2"
end
def handler3(url)
@event3 += url
end
def teardown
@ie.quit
@ie = nil
GC.start
sleep 1
end
end
end