Class: TestWIN32OLE_EVENT
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TestWIN32OLE_EVENT
- Defined in:
- tests/test_win32ole_event.rb
Instance Method Summary collapse
- #create_temp_html ⇒ Object
- #default_handler(event, *args) ⇒ Object
- #handler1 ⇒ Object
- #handler2 ⇒ Object
- #handler3(url) ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_on_event ⇒ Object
- #test_on_event2 ⇒ Object
- #test_on_event3 ⇒ Object
- #test_on_event4 ⇒ Object
- #test_on_event5 ⇒ Object
- #test_unadvise ⇒ Object
Instance Method Details
#create_temp_html ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'tests/test_win32ole_event.rb', line 9 def create_temp_html fso = WIN32OLE.new('Scripting.FileSystemObject') dummy_file = fso.GetTempName + ".html" cfolder = fso.getFolder(".") f = cfolder.CreateTextFile(dummy_file) f.writeLine("<html><body>This is test HTML file for Win32OLE.</body></html>") f.close dummy_path = cfolder.path + "\\" + dummy_file dummy_path end |
#default_handler(event, *args) ⇒ Object
29 30 31 |
# File 'tests/test_win32ole_event.rb', line 29 def default_handler(event, *args) @event += event end |
#handler1 ⇒ Object
114 115 116 |
# File 'tests/test_win32ole_event.rb', line 114 def handler1 @event2 = "handler1" end |
#handler2 ⇒ Object
118 119 120 |
# File 'tests/test_win32ole_event.rb', line 118 def handler2 @event2 = "handler2" end |
#handler3(url) ⇒ Object
122 123 124 |
# File 'tests/test_win32ole_event.rb', line 122 def handler3(url) @event3 += url end |
#setup ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'tests/test_win32ole_event.rb', line 20 def setup @ie = WIN32OLE.new("InternetExplorer.Application") @ie.visible = true @event = "" @event2 = "" @event3 = "" @f = create_temp_html end |
#teardown ⇒ Object
126 127 128 129 130 131 |
# File 'tests/test_win32ole_event.rb', line 126 def teardown @ie.quit @ie = nil File.unlink(@f) GC.start end |
#test_on_event ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'tests/test_win32ole_event.rb', line 33 def test_on_event ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') ev.on_event {|*args| default_handler(*args)} @ie.navigate("file:///#{@f}") while @ie.busy WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') GC.start sleep 0.1 end assert_match(/BeforeNavigate/, @event) assert_match(/NavigateComplete/, @event) end |
#test_on_event2 ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'tests/test_win32ole_event.rb', line 46 def test_on_event2 ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') ev.on_event('BeforeNavigate') {|*args| handler1} ev.on_event('BeforeNavigate') {|*args| handler2} @ie.navigate("file:///#{@f}") while @ie.busy sleep 0.1 end assert_equal("handler2", @event2) end |
#test_on_event3 ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'tests/test_win32ole_event.rb', line 57 def test_on_event3 ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') ev.on_event {|*args| handler1} ev.on_event {|*args| handler2} @ie.navigate("file:///#{@f}") while @ie.busy sleep 0.1 end assert_equal("handler2", @event2) end |
#test_on_event4 ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'tests/test_win32ole_event.rb', line 68 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.navigate("file:///#{@f}") while @ie.busy sleep 0.1 end assert(@event3!="") assert("handler2", @event2) end |
#test_on_event5 ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'tests/test_win32ole_event.rb', line 81 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.navigate("file:///#{@f}") while @ie.busy sleep 0.1 end assert_match(/BeforeNavigate/, @event) assert(/NavigateComplete/ !~ @event) assert(@event!="") end |
#test_unadvise ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'tests/test_win32ole_event.rb', line 94 def test_unadvise ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') ev.on_event {|*args| default_handler(*args)} @ie.navigate("file:///#{@f}") while @ie.busy sleep 0.1 end assert_match(/BeforeNavigate/, @event) ev.unadvise @event = "" @ie.navigate("file:///#{@f}") while @ie.busy sleep 0.1 end assert_equal("", @event); assert_raise(WIN32OLERuntimeError) { ev.on_event {|*args| default_handler(*args)} } end |