celerity_thingista 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +9 -0
- data/.gitmodules +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE +278 -0
- data/README.rdoc +84 -0
- data/Rakefile +15 -0
- data/benchmark/bm_2000_spans.rb +48 -0
- data/benchmark/bm_digg.rb +26 -0
- data/benchmark/bm_google_images.rb +36 -0
- data/benchmark/bm_input_locator.rb +69 -0
- data/benchmark/bm_text_input.rb +19 -0
- data/benchmark/loader.rb +14 -0
- data/celerity.gemspec +26 -0
- data/lib/celerity.rb +75 -0
- data/lib/celerity/browser.rb +924 -0
- data/lib/celerity/clickable_element.rb +73 -0
- data/lib/celerity/collections.rb +164 -0
- data/lib/celerity/container.rb +802 -0
- data/lib/celerity/default_viewer.rb +14 -0
- data/lib/celerity/disabled_element.rb +40 -0
- data/lib/celerity/element.rb +314 -0
- data/lib/celerity/element_collection.rb +115 -0
- data/lib/celerity/element_locator.rb +164 -0
- data/lib/celerity/elements/button.rb +54 -0
- data/lib/celerity/elements/file_field.rb +29 -0
- data/lib/celerity/elements/form.rb +22 -0
- data/lib/celerity/elements/frame.rb +86 -0
- data/lib/celerity/elements/image.rb +89 -0
- data/lib/celerity/elements/label.rb +16 -0
- data/lib/celerity/elements/link.rb +43 -0
- data/lib/celerity/elements/meta.rb +14 -0
- data/lib/celerity/elements/non_control_elements.rb +124 -0
- data/lib/celerity/elements/option.rb +38 -0
- data/lib/celerity/elements/radio_check.rb +114 -0
- data/lib/celerity/elements/select_list.rb +146 -0
- data/lib/celerity/elements/table.rb +154 -0
- data/lib/celerity/elements/table_cell.rb +36 -0
- data/lib/celerity/elements/table_elements.rb +42 -0
- data/lib/celerity/elements/table_row.rb +54 -0
- data/lib/celerity/elements/text_field.rb +168 -0
- data/lib/celerity/exception.rb +83 -0
- data/lib/celerity/htmlunit.rb +64 -0
- data/lib/celerity/htmlunit/commons-codec-1.7.jar +0 -0
- data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
- data/lib/celerity/htmlunit/commons-io-2.4.jar +0 -0
- data/lib/celerity/htmlunit/commons-lang3-3.1.jar +0 -0
- data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
- data/lib/celerity/htmlunit/cssparser-0.9.9.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.12.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.12.jar +0 -0
- data/lib/celerity/htmlunit/httpclient-4.2.3.jar +0 -0
- data/lib/celerity/htmlunit/httpcore-4.2.2.jar +0 -0
- data/lib/celerity/htmlunit/httpmime-4.2.3.jar +0 -0
- data/lib/celerity/htmlunit/jetty-http-8.1.9.v20130131.jar +0 -0
- data/lib/celerity/htmlunit/jetty-io-8.1.9.v20130131.jar +0 -0
- data/lib/celerity/htmlunit/jetty-util-8.1.9.v20130131.jar +0 -0
- data/lib/celerity/htmlunit/jetty-websocket-8.1.9.v20130131.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.18.jar +0 -0
- data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
- data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
- data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
- data/lib/celerity/htmlunit/xercesImpl-2.10.0.jar +0 -0
- data/lib/celerity/htmlunit/xml-apis-1.4.01.jar +0 -0
- data/lib/celerity/identifier.rb +28 -0
- data/lib/celerity/ignoring_web_connection.rb +15 -0
- data/lib/celerity/input_element.rb +25 -0
- data/lib/celerity/javascript_debugger.rb +32 -0
- data/lib/celerity/listener.rb +143 -0
- data/lib/celerity/resources/no_viewer.png +0 -0
- data/lib/celerity/short_inspect.rb +29 -0
- data/lib/celerity/util.rb +129 -0
- data/lib/celerity/version.rb +3 -0
- data/lib/celerity/viewer_connection.rb +89 -0
- data/lib/celerity/watir_compatibility.rb +70 -0
- data/lib/celerity/xpath_support.rb +50 -0
- data/spec/browser_authentication_spec.rb +16 -0
- data/spec/browser_spec.rb +439 -0
- data/spec/button_spec.rb +24 -0
- data/spec/clickable_element_spec.rb +39 -0
- data/spec/default_viewer_spec.rb +23 -0
- data/spec/element_spec.rb +77 -0
- data/spec/filefield_spec.rb +18 -0
- data/spec/htmlunit_spec.rb +63 -0
- data/spec/implementation.rb +7 -0
- data/spec/index_offset_spec.rb +24 -0
- data/spec/link_spec.rb +16 -0
- data/spec/listener_spec.rb +142 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/table_spec.rb +41 -0
- data/spec/watir_compatibility_spec.rb +32 -0
- data/tasks/benchmark.rake +4 -0
- data/tasks/check.rake +24 -0
- data/tasks/clean.rake +3 -0
- data/tasks/fix.rake +25 -0
- data/tasks/jar.rake +55 -0
- data/tasks/rdoc.rake +4 -0
- data/tasks/snapshot.rake +25 -0
- data/tasks/spec.rake +27 -0
- data/tasks/website.rake +10 -0
- data/tasks/yard.rake +16 -0
- data/website/benchmarks.html +237 -0
- data/website/css/color.css +153 -0
- data/website/css/hacks.css +3 -0
- data/website/css/layout.css +179 -0
- data/website/css/screen.css +5 -0
- data/website/css/textmate.css +226 -0
- data/website/css/typography.css +72 -0
- data/website/gfx/body_bg.gif +0 -0
- data/website/gfx/button_bg.jpg +0 -0
- data/website/gfx/header_bg.jpg +0 -0
- data/website/gfx/header_left.jpg +0 -0
- data/website/gfx/header_right.jpg +0 -0
- data/website/gfx/nav_bg.jpg +0 -0
- data/website/index.html +125 -0
- data/website/yard/index.html +1 -0
- metadata +246 -0
data/spec/button_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "Button" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#click_and_attach" do
|
10
|
+
it "returns a new browser instance with the popup page" do
|
11
|
+
b = browser.button(:name, 'new_popup_window').click_and_attach
|
12
|
+
b.should_not == browser
|
13
|
+
b.title.should == "Tables"
|
14
|
+
browser.title.should == "Forms with input elements"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns a new browser with same log_level as original" do
|
18
|
+
b = browser.button(:name, 'new_popup_window').click_and_attach
|
19
|
+
b.should_not == browser
|
20
|
+
b.log_level.should == browser.log_level
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "ClickableElement" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#click_and_attach" do
|
10
|
+
it 'opens a page in a new browser with the same options' do
|
11
|
+
b = browser.link(:name, /bad_attribute/).click_and_attach
|
12
|
+
b.text.include?("User administration").should be_true # to make sure it is open.
|
13
|
+
b.options.should == browser.options
|
14
|
+
b.cookies.should == browser.cookies
|
15
|
+
end
|
16
|
+
|
17
|
+
it "opens the page in a new browser with the same cookies" do
|
18
|
+
browser.add_cookie("localhost", "foo", "bar")
|
19
|
+
old_cookies = browser.cookies
|
20
|
+
old_cookies.should_not be_empty
|
21
|
+
|
22
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
23
|
+
b = browser.link(:name, /bad_attribute/).click_and_attach
|
24
|
+
|
25
|
+
b.should_not == browser
|
26
|
+
b.cookies.should == old_cookies
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#download" do
|
31
|
+
it 'returns a click-opened page as io' do
|
32
|
+
expected = File.read "#{WatirSpec.files}/forms_with_input_elements.html".sub("file://", '')
|
33
|
+
|
34
|
+
browser.link(:name, /bad_attribute/).download.read.should == expected
|
35
|
+
browser.link(:name, /bad_attribute/).should exist
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "DefaultViewer" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
browser.goto(WatirSpec.files + "/definition_lists.html")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".save" do
|
10
|
+
it "saves the default image to the given path" do
|
11
|
+
fail("don't run specs with CelerityViewer") if browser.viewer != Celerity::DefaultViewer
|
12
|
+
fname = File.expand_path "default_viewer_test.png"
|
13
|
+
default = "#{File.dirname(__FILE__)}/../lib/celerity/resources/no_viewer.png"
|
14
|
+
|
15
|
+
browser.viewer.save(fname)
|
16
|
+
File.exist?(fname).should be_true
|
17
|
+
File.read(fname).should == File.read(default)
|
18
|
+
|
19
|
+
File.delete(fname)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
3
|
+
|
4
|
+
describe "Element" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#identifier_string" do
|
11
|
+
it "doesn't make the next locate find the wrong element" do
|
12
|
+
elem = browser.div(:id, 'hidden_parent')
|
13
|
+
elem.should exist
|
14
|
+
elem.__send__(:identifier_string)
|
15
|
+
elem.id.should == 'hidden_parent'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "uses the user specified identifier_string if one is present" do
|
19
|
+
elem = browser.div(:id, 'hidden_parent')
|
20
|
+
elem.identifier_string = "this is it"
|
21
|
+
elem.__send__(:identifier_string).should == "this is it"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#method_missing" do
|
26
|
+
it "magically returns the requested attribute if the attribute is defined in the attribute list" do
|
27
|
+
browser.form(:index, Celerity.index_offset).action.should == 'post_to_me'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises NoMethodError if the requested method isn't among the attributes" do
|
31
|
+
lambda { browser.button(:index, Celerity.index_offset).no_such_attribute_or_method }.should raise_error(NoMethodError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#xpath" do
|
36
|
+
it "gets the canonical xpath of this element" do
|
37
|
+
browser.text_field(:id, "new_user_email").xpath.should == '/html/body/form[1]/fieldset[1]/input[3]'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#javascript_object" do
|
42
|
+
it "should return the JavaScript object representing the receiver" do
|
43
|
+
obj = browser.div(:id, "onfocus_test").javascript_object
|
44
|
+
obj.should be_kind_of(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)
|
45
|
+
obj.should be_instance_of(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDivElement)
|
46
|
+
obj.client_width.should be_kind_of(Integer)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#locate" do
|
51
|
+
it "raises ArgumentError when used with :object and the object given isn't an HtmlElement subclass" do
|
52
|
+
lambda { Link.new(browser, :object, "foo").locate }.should raise_error(ArgumentError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#focused?" do
|
57
|
+
it "returns true if the element has focus" do
|
58
|
+
tf = browser.text_field(:id, "delete_user_comment")
|
59
|
+
tf.should_not be_focused
|
60
|
+
|
61
|
+
tf.focus
|
62
|
+
tf.should be_focused
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#==" do
|
68
|
+
it "returns true if passed the same element" do
|
69
|
+
browser.label(:id, 'first_label').should == browser.labels.first
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns false if passed a different element" do
|
73
|
+
browser.label(:id, 'first_label').should_not == browser.labels.last
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
3
|
+
|
4
|
+
describe "FileField" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#set" do
|
11
|
+
it "sends content as correct content type for common file types" do
|
12
|
+
browser.file_field(:name, "new_user_portrait").set("foo.doc")
|
13
|
+
obj = browser.file_field(:name, "new_user_portrait").locate
|
14
|
+
obj.getContentType.should == "application/msword"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "HtmlUnit bugs" do
|
4
|
+
describe "HtmlUnit bug 1968686: https://sourceforge.net/tracker/index.php?func=detail&aid=1968686&group_id=47038&atid=448266" do
|
5
|
+
it "does not raise NativeException: java.lang.StackOverflowError when going to a page where Javascripts prints a <body> tag inside another <body> tag" do
|
6
|
+
lambda { browser.goto(WatirSpec.files + "/bug_javascript_001.html") }.should_not raise_error(NativeException)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "HtmlUnit bug 1968708: https://sourceforge.net/tracker/index.php?func=detail&aid=1968708&group_id=47038&atid=448266" do
|
11
|
+
it "only considers the first attribute if there are duplicate attributes" do
|
12
|
+
browser.goto(WatirSpec.files + "/bug_duplicate_attributes.html")
|
13
|
+
browser.text_field(:index, Celerity.index_offset).id.should == "org_id"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "NekoHtml parser bug: https://sourceforge.net/tracker/?func=detail&aid=2824922&group_id=47038&atid=448266" do
|
18
|
+
it "does not run out of java heap space" do
|
19
|
+
lambda { browser.goto(WatirSpec.files + "/parser_bug_001.html") }.should_not raise_error
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# disabled for CI - need fix from HtmlUnit
|
24
|
+
# describe "HtmlUnit bug XXXXXX" do
|
25
|
+
# it "returns strings as UTF-8 when there's a charset mismatch between HTTP response header and <meta> tag" do
|
26
|
+
# browser.goto(WatirSpec.host + "/charset_mismatch")
|
27
|
+
# browser.h1(:index, 1).text.should == "\303\270"
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
|
31
|
+
it "evaluates <script> tags injected in the DOM through JQuery's replaceWith() - fixed in rev. 3598" do
|
32
|
+
browser.goto(WatirSpec.files + "/jquery.html")
|
33
|
+
browser.link(:class, 'editLink').click
|
34
|
+
browser.div(:id, 'content').text.should == "typeof update: function"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "doesn't return the TinyMCE DOM when executing javascript functions" do
|
38
|
+
b = WatirSpec.new_browser
|
39
|
+
|
40
|
+
b.goto(WatirSpec.files + "/tiny_mce.html")
|
41
|
+
b.text.should include("Beskrivelse")
|
42
|
+
b.checkbox(:id, "exemption").set
|
43
|
+
b.text.should include("Beskrivelse")
|
44
|
+
|
45
|
+
b.close
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "HtmlUnit bug 2811607: https://sourceforge.net/tracker/?func=detail&aid=2811607&group_id=47038&atid=448266" do
|
49
|
+
it "correctly prevents default on <form>#submit()" do
|
50
|
+
browser.goto(WatirSpec.files + "/prevent_form_submit.html")
|
51
|
+
browser.button(:id, "next").click
|
52
|
+
browser.title.should == "preventDefault() on form submission"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "HtmlUnit bug 2974355: https://sourceforge.net/tracker/index.php?func=detail&aid=2974355&group_id=47038&atid=448266" do
|
57
|
+
it "accesses pages with characters in URI that need encoding" do
|
58
|
+
browser.goto(WatirSpec.host + '/encodable_%3Cstuff%3E')
|
59
|
+
browser.text.should include('page with characters in URI that need encoding')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "Celerity.index_offset" do
|
4
|
+
|
5
|
+
# before :all do
|
6
|
+
# browser.goto(WatirSpec.files + "/non_control_elements.html")
|
7
|
+
#
|
8
|
+
# Celerity.index_offset = 0
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# it "returns the correct divs" do
|
12
|
+
# divs = browser.divs.to_a
|
13
|
+
#
|
14
|
+
# divs.each_with_index do |div, idx|
|
15
|
+
# browser.div(:index, idx).id.should == div.id
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# after :all do
|
20
|
+
# Celerity.index_offset = 1
|
21
|
+
# end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
data/spec/link_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
3
|
+
|
4
|
+
describe "Link" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "absolute_url" do
|
11
|
+
it "returns the absolute URL for a link with a relative href attribute" do
|
12
|
+
browser.link(:index, Celerity.index_offset + 1).absolute_url.should include("#{WatirSpec.files}/non_control_elements.html".gsub("file://", ''))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "Listener" do
|
4
|
+
before(:each) do
|
5
|
+
@web_client = mock("WebClient").as_null_object
|
6
|
+
@listener = Celerity::Listener.new(@web_client)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "implements the StatusHandler interface" do
|
10
|
+
@listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.StatusHandler)
|
11
|
+
|
12
|
+
@listener.should respond_to(:statusMessageChanged)
|
13
|
+
lambda { @listener.statusMessageChanged('page', 'message') }.should_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "implements the ConfirmHandler interface" do
|
17
|
+
@listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.ConfirmHandler)
|
18
|
+
|
19
|
+
@listener.should respond_to(:handleConfirm)
|
20
|
+
lambda { @listener.handleConfirm('page', 'message') }.should_not raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it "implements the AttachmentHandler interface" do
|
24
|
+
@listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.attachment.AttachmentHandler)
|
25
|
+
|
26
|
+
@listener.should respond_to(:handleAttachment)
|
27
|
+
lambda { @listener.handleAttachment('page') }.should_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it "implements the AlertHandler interface" do
|
31
|
+
@listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.AlertHandler)
|
32
|
+
|
33
|
+
@listener.should respond_to(:handleAlert)
|
34
|
+
lambda { @listener.handleAlert('page', 'message') }.should_not raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it "implements the HTMLParserListener interface" do
|
38
|
+
@listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.html.HTMLParserListener)
|
39
|
+
|
40
|
+
@listener.should respond_to(:error)
|
41
|
+
@listener.should respond_to(:warning)
|
42
|
+
|
43
|
+
lambda { @listener.error('message', 'url', 1, 2, "key") }.should_not raise_error
|
44
|
+
lambda { @listener.warning('message', 'url', 1, 2, "key") }.should_not raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it "implements the WebWindowListener interface" do
|
48
|
+
@listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.WebWindowListener)
|
49
|
+
|
50
|
+
@listener.should respond_to(:webWindowClosed)
|
51
|
+
@listener.should respond_to(:webWindowContentChanged)
|
52
|
+
@listener.should respond_to(:webWindowOpened)
|
53
|
+
|
54
|
+
lambda { @listener.webWindowClosed('event') }.should_not raise_error
|
55
|
+
lambda { @listener.webWindowContentChanged('event') }.should_not raise_error
|
56
|
+
lambda { @listener.webWindowOpened('event') }.should_not raise_error
|
57
|
+
end
|
58
|
+
|
59
|
+
it "implements the IncorrectnessListener interface" do
|
60
|
+
@listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.IncorrectnessListener)
|
61
|
+
|
62
|
+
@listener.should respond_to(:notify)
|
63
|
+
lambda { @listener.notify('message', 'origin') }.should_not raise_error
|
64
|
+
end
|
65
|
+
|
66
|
+
it "implements the PromptHandler interface" do
|
67
|
+
@listener.should be_a_kind_of(com.gargoylesoftware.htmlunit.PromptHandler)
|
68
|
+
|
69
|
+
@listener.should respond_to(:handlePrompt)
|
70
|
+
lambda { @listener.handlePrompt('page', 'message') }.should_not raise_error
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
describe "#add_listener" do
|
75
|
+
it "adds itself as a listener for the :status type" do
|
76
|
+
@web_client.should_receive('setStatusHandler').with(@listener)
|
77
|
+
@listener.add_listener(:status) {}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "adds itself as a listener for the :alert type" do
|
81
|
+
@web_client.should_receive('setAlertHandler').with(@listener)
|
82
|
+
@listener.add_listener(:alert) {}
|
83
|
+
end
|
84
|
+
|
85
|
+
it "adds itself as a listener for the :confirm type" do
|
86
|
+
@web_client.should_receive('setConfirmHandler').with(@listener)
|
87
|
+
@listener.add_listener(:confirm) {}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "adds itself as a listener for the :prompt type" do
|
91
|
+
@web_client.should_receive('setPromptHandler').with(@listener)
|
92
|
+
@listener.add_listener(:prompt) {}
|
93
|
+
end
|
94
|
+
|
95
|
+
it "adds itself as a listener for the :web_window_event type" do
|
96
|
+
@web_client.should_receive('addWebWindowListener').with(@listener)
|
97
|
+
@listener.add_listener(:web_window_event) {}
|
98
|
+
end
|
99
|
+
|
100
|
+
it "adds itself as a listener for the :html_parser type" do
|
101
|
+
@web_client.should_receive('setHTMLParserListener').with(@listener)
|
102
|
+
@listener.add_listener(:html_parser) {}
|
103
|
+
end
|
104
|
+
|
105
|
+
it "adds itself as a listener for the :incorrectness type" do
|
106
|
+
@web_client.should_receive('setIncorrectnessListener').with(@listener)
|
107
|
+
@listener.add_listener(:incorrectness) {}
|
108
|
+
end
|
109
|
+
|
110
|
+
it "adds itself as a listener for the :attachment type" do
|
111
|
+
@web_client.should_receive('setAttachmentHandler').with(@listener)
|
112
|
+
@listener.add_listener(:attachment) {}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#remove_listener" do
|
117
|
+
it "removes the listener at the given index" do
|
118
|
+
updates = []
|
119
|
+
first, second = lambda { updates << :first }, lambda { updates << :second }
|
120
|
+
|
121
|
+
@listener.add_listener(:prompt, &first)
|
122
|
+
@listener.add_listener(:prompt, &second)
|
123
|
+
|
124
|
+
@listener.remove_listener(:prompt, 0)
|
125
|
+
@listener.handlePrompt('foo', 'bar')
|
126
|
+
updates.should == [:second]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "handles several invocations of all registered listeners" do
|
131
|
+
updates = []
|
132
|
+
@listener.add_listener(:alert) { updates << :first }
|
133
|
+
@listener.add_listener(:alert) { updates << :second }
|
134
|
+
|
135
|
+
@listener.handleAlert('foo', 'bar')
|
136
|
+
updates.should == [:first, :second]
|
137
|
+
|
138
|
+
@listener.handleAlert('foo', 'bar')
|
139
|
+
updates.should == [:first, :second, :first, :second]
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|