sleipnir-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/License.txt +20 -0
- data/Manifest.txt +41 -0
- data/README.txt +56 -0
- data/Rakefile +201 -0
- data/TODO.txt +11 -0
- data/examples/reload.rb +18 -0
- data/helper/helper.rb +3 -0
- data/helper/rake.rb +58 -0
- data/helper/rake_sh_filter.rb +23 -0
- data/helper/util.rb +19 -0
- data/lib/sleipnir_api.rb +177 -0
- data/lib/sleipnir_api/dialog.rb +155 -0
- data/lib/sleipnir_api/key_state.rb +49 -0
- data/lib/sleipnir_api/output.rb +319 -0
- data/lib/sleipnir_api/process.rb +69 -0
- data/lib/sleipnir_api/profile.rb +332 -0
- data/lib/sleipnir_api/registry.rb +30 -0
- data/lib/sleipnir_api/security.rb +263 -0
- data/lib/sleipnir_api/sleipnir.rb +489 -0
- data/lib/sleipnir_api/tab.rb +359 -0
- data/lib/sleipnir_api/util.rb +16 -0
- data/lib/sleipnir_api/version.rb +9 -0
- data/lib/sleipnir_api/win32api.rb +17 -0
- data/scripts/rdoc_filter.rb +74 -0
- data/setup.rb +1585 -0
- data/spec/matchers/path_eql.rb +41 -0
- data/spec/sleipnir_api/dialog_mock_spec.rb +99 -0
- data/spec/sleipnir_api/key_state_mock_spec.rb +72 -0
- data/spec/sleipnir_api/output_spec.rb +242 -0
- data/spec/sleipnir_api/profile_mock_spec.rb +128 -0
- data/spec/sleipnir_api/registry_spec.rb +13 -0
- data/spec/sleipnir_api/security_mock_spec.rb +82 -0
- data/spec/sleipnir_api/security_spec.rb +129 -0
- data/spec/sleipnir_api/sleipnir_mock_spec.rb +70 -0
- data/spec/sleipnir_api/sleipnir_spec.rb +295 -0
- data/spec/sleipnir_api/tab_mock_spec.rb +98 -0
- data/spec/sleipnir_api/tab_spec.rb +105 -0
- data/spec/sleipnir_api_spec.rb +17 -0
- data/spec/spec.opts +0 -0
- data/spec/spec_helper.rb +8 -0
- metadata +91 -0
@@ -0,0 +1,128 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
|
+
|
3
|
+
describe SleipnirAPI::Profile do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@pnir = SleipnirAPI.connect
|
7
|
+
@profile = @pnir.profile
|
8
|
+
@user_path = @pnir.user_path
|
9
|
+
@api = @pnir.instance_variable_get(:@api)
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
@pnir.instance_variable_set(:@api, @api)
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
@mock = mock("Sleipnir.API")
|
18
|
+
@pnir.instance_variable_set(:@api, @mock)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# get string
|
23
|
+
|
24
|
+
it "#get_string should send GetProfileString" do
|
25
|
+
@mock.should_receive(:GetProfileString).with("section", "key", nil)
|
26
|
+
@profile.get_string("section", "key")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "#get_string(:default) should send GetProfileString" do
|
30
|
+
@mock.should_receive(:GetProfileString).with("section", "key", "default value")
|
31
|
+
@profile.get_string("section", "key", :default => "default value")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "#get_string(:cipher) should send GetProfileStringCipher" do
|
35
|
+
@mock.should_receive(:GetProfileStringCipher).with("section", "key", nil)
|
36
|
+
@profile.get_string("section", "key", :cipher => true)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "#get_string(:cipher, :default) should send GetProfileStringCipher" do
|
40
|
+
@mock.should_receive(:GetProfileStringCipher).with("section", "key", "default value")
|
41
|
+
@profile.get_string("section", "key", :cipher => true, :default => "default value")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "#get_string(:ini) should send GetProfileStringEx" do
|
45
|
+
@mock.should_receive(:UserPath).and_return(@user_path)
|
46
|
+
@mock.should_receive(:GetProfileStringEx).with(
|
47
|
+
"section", "key", nil, File.expand_path("foo.ini", @user_path))
|
48
|
+
@profile.get_string("section", "key", :ini => "foo.ini")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#get_string(:ini, :default) should send GetProfileStringEx" do
|
52
|
+
@mock.should_receive(:UserPath).and_return(@user_path)
|
53
|
+
@mock.should_receive(:GetProfileStringEx).with(
|
54
|
+
"section", "key", "default value", "c:/foo.ini")
|
55
|
+
@profile.get_string("section", "key", :ini => "c:/foo.ini", :default => "default value")
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# get int
|
60
|
+
|
61
|
+
it "#get_int should send GetProfileInt" do
|
62
|
+
@mock.should_receive(:GetProfileInt).with("section", "key", nil)
|
63
|
+
@profile.get_int("section", "key")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "#get_int(:default) should send GetProfileInt" do
|
67
|
+
@mock.should_receive(:GetProfileInt).with("section", "key", "default value")
|
68
|
+
@profile.get_int("section", "key", :default => "default value")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "#get_int(:cipher) should send GetProfileIntCipher" do
|
72
|
+
@mock.should_receive(:GetProfileIntCipher).with("section", "key", nil)
|
73
|
+
@profile.get_int("section", "key", :cipher => true)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "#get_int(:cipher, :default) should send GetProfileIntCipher" do
|
77
|
+
@mock.should_receive(:GetProfileIntCipher).with("section", "key", 123)
|
78
|
+
@profile.get_int("section", "key", :cipher => true, :default => 123)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "#get_int(:ini) should send GetProfileIntEx" do
|
82
|
+
@mock.should_receive(:UserPath).and_return(@user_path)
|
83
|
+
@mock.should_receive(:GetProfileIntEx).with(
|
84
|
+
"section", "key", nil, File.expand_path("foo.ini", @user_path))
|
85
|
+
@profile.get_int("section", "key", :ini => "foo.ini")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "#get_int(:ini, :default) should send GetProfileIntEx" do
|
89
|
+
@mock.should_receive(:UserPath).and_return(@user_path)
|
90
|
+
@mock.should_receive(:GetProfileIntEx).with(
|
91
|
+
"section", "key", 123, "c:/foo.ini")
|
92
|
+
@profile.get_int("section", "key", :ini => "c:/foo.ini", :default => 123)
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
# write string
|
98
|
+
|
99
|
+
it "#write_int should send WriteProfileString" do
|
100
|
+
@mock.should_receive(:WriteProfileString).with("section", "key", "data")
|
101
|
+
@profile.write_string("section", "key", "data")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "#write_int(:cipher) should send WriteProfileStringCipher" do
|
105
|
+
@mock.should_receive(:WriteProfileStringCipher).with("section", "key", "data")
|
106
|
+
@profile.write_string("section", "key", "data", :cipher => true)
|
107
|
+
end
|
108
|
+
|
109
|
+
# write int
|
110
|
+
|
111
|
+
it "#write_int should send WriteProfileInt" do
|
112
|
+
@mock.should_receive(:WriteProfileInt).with("section", "key", 123)
|
113
|
+
@profile.write_int("section", "key", 123)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "#write_int(:cipher) should send WriteProfileIntCipher" do
|
117
|
+
@mock.should_receive(:WriteProfileIntCipher).with("section", "key", 123)
|
118
|
+
@profile.write_int("section", "key", 123, :cipher => true)
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# delete
|
123
|
+
it "#delete should send DeleteProfileKey" do
|
124
|
+
@mock.should_receive(:DeleteProfileKey).with("section", "key")
|
125
|
+
@profile.delete("section", "key")
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
|
+
|
3
|
+
describe SleipnirAPI::Registry do
|
4
|
+
it "#clsid should return HKCL\\Sleipnir.API\\CLSID" do
|
5
|
+
SleipnirAPI::Registry.clsid.should match(/\{[0-9a-fA-F-]+\}/)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "#local_server should return sleipnir.exe path" do
|
9
|
+
path = SleipnirAPI::Registry.local_server
|
10
|
+
File.basename(path).downcase.should eql("sleipnir.exe")
|
11
|
+
File.exist?(path).should be_true
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
|
+
|
3
|
+
describe SleipnirAPI::Security do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@pnir = SleipnirAPI.connect
|
7
|
+
@blank = @pnir.new_tab
|
8
|
+
@security = @blank.security
|
9
|
+
@api = @pnir.instance_variable_get(:@api)
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
@pnir.instance_variable_set(:@api, @api)
|
14
|
+
@blank.close
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
@mock = mock("Sleipnir.API")
|
19
|
+
@pnir.instance_variable_set(:@api, @mock)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
it "#enable?(:javascript) should send IsXXXEnabled" do
|
24
|
+
@mock.should_receive(:IsJavaScriptEnabled).with(@blank.id)
|
25
|
+
@security.enable?(:javascript)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#enable?(:java) should send IsXXXEnabled" do
|
29
|
+
@mock.should_receive(:IsJavaEnabled).with(@blank.id)
|
30
|
+
@security.enable?(:java)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "#enable?(:run_activex) should send IsXXXEnabled" do
|
34
|
+
@mock.should_receive(:IsRunActiveXEnabled).with(@blank.id)
|
35
|
+
@security.enable?(:run_activex)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "#enable?(:download_activex) should send IsXXXEnabled" do
|
39
|
+
@mock.should_receive(:IsDownloadActiveXEnabled).with(@blank.id)
|
40
|
+
@security.enable?(:download_activex)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "#enable?(:picture) should send IsXXXEnabled" do
|
44
|
+
@mock.should_receive(:IsPictureEnabled).with(@blank.id)
|
45
|
+
@security.enable?(:picture)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "#enable?(:sound) should send IsXXXEnabled" do
|
49
|
+
@mock.should_receive(:IsSoundEnabled).with(@blank.id)
|
50
|
+
@security.enable?(:sound)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "#enable?(:video) should send IsXXXEnabled" do
|
54
|
+
@mock.should_receive(:IsVideoEnabled).with(@blank.id)
|
55
|
+
@security.enable?(:video)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "#enable? can take String" do
|
59
|
+
@mock.should_receive(:IsVideoEnabled).with(@blank.id)
|
60
|
+
@security.enable?("video")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "#set_security should send SetSecurity" do
|
64
|
+
@mock.should_receive(:IsJavaScriptEnabled).with(@blank.id)
|
65
|
+
@mock.should_receive(:IsJavaEnabled).with(@blank.id)
|
66
|
+
@mock.should_receive(:IsRunActiveXEnabled).with(@blank.id)
|
67
|
+
@mock.should_receive(:IsDownloadActiveXEnabled).with(@blank.id)
|
68
|
+
@mock.should_receive(:IsPictureEnabled).with(@blank.id)
|
69
|
+
@mock.should_receive(:IsSoundEnabled).with(@blank.id)
|
70
|
+
@mock.should_receive(:IsVideoEnabled).with(@blank.id)
|
71
|
+
@mock.should_receive(:SetSecurity).with(@blank.id, true, false, false, false, false, false, false)
|
72
|
+
@security.set_security(
|
73
|
+
:javascript => true,
|
74
|
+
:java => false,
|
75
|
+
:run_activex => false,
|
76
|
+
:download_activex => false,
|
77
|
+
:picture => false,
|
78
|
+
:sound => false,
|
79
|
+
:video => false)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
|
+
|
3
|
+
describe SleipnirAPI::Security do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@pnir = SleipnirAPI.connect
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
@blank = @pnir.new_tab
|
11
|
+
@security = @blank.security
|
12
|
+
@security.set_security(
|
13
|
+
:javascript => true,
|
14
|
+
:java => false,
|
15
|
+
:run_activex => true,
|
16
|
+
:download_activex => false,
|
17
|
+
:picture => true,
|
18
|
+
:sound => false,
|
19
|
+
:video => true)
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
@blank.close
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
it "is Enumerable" do
|
28
|
+
@security.should respond_to(:each)
|
29
|
+
@security.should be_kind_of(Enumerable)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "#each should enumerate all security config" do
|
33
|
+
configs = []
|
34
|
+
@security.each do |e|
|
35
|
+
e.should be_an_instance_of(SleipnirAPI::Security::Config)
|
36
|
+
configs << e
|
37
|
+
end
|
38
|
+
|
39
|
+
configs.size.should == 7
|
40
|
+
configs.should == [
|
41
|
+
@security.javascript,
|
42
|
+
@security.java,
|
43
|
+
@security.run_activex,
|
44
|
+
@security.download_activex,
|
45
|
+
@security.picture,
|
46
|
+
@security.sound,
|
47
|
+
@security.video,
|
48
|
+
]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#keys should return all security name." do
|
52
|
+
@security.keys.should == [:javascript, :java, :run_activex, :download_activex, :picture, :sound, :video]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "#get_security should return properly." do
|
56
|
+
@security.get_security.should == {
|
57
|
+
:javascript => true,
|
58
|
+
:java => false,
|
59
|
+
:run_activex => true,
|
60
|
+
:download_activex => false,
|
61
|
+
:picture => true,
|
62
|
+
:sound => false,
|
63
|
+
:video => true,
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
it "#set_security should update security config" do
|
68
|
+
def @security.select_enable
|
69
|
+
select{|e| e.enable? }.map{|e| e.name }
|
70
|
+
end
|
71
|
+
|
72
|
+
@security.each{|e| e.disable! }
|
73
|
+
@security.select_enable.should be_empty
|
74
|
+
|
75
|
+
@security.update(:javascript => true)
|
76
|
+
@security.select_enable.should == [:javascript]
|
77
|
+
|
78
|
+
@security.update(:java => true, :run_activex => true)
|
79
|
+
@security.select_enable.should == [:javascript, :java, :run_activex]
|
80
|
+
|
81
|
+
@security.update(:picture => true, :sound => true, :video => true)
|
82
|
+
@security.select_enable.should == [:javascript, :java, :run_activex, :picture, :sound, :video]
|
83
|
+
|
84
|
+
@security.update(:javascript => false, :run_activex => false, :download_activex => true)
|
85
|
+
@security.select_enable.should == [:java, :download_activex, :picture, :sound, :video]
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
it "#enable? should return properly." do
|
90
|
+
@security.enable?(:javascript).should be_true
|
91
|
+
@security.enable?(:java).should be_false
|
92
|
+
@security.enable?(:run_activex).should be_true
|
93
|
+
@security.enable?(:download_activex).should be_false
|
94
|
+
@security.enable?(:picture).should be_true
|
95
|
+
@security.enable?(:sound).should be_false
|
96
|
+
@security.enable?(:video).should be_true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "#disable? should return properly." do
|
100
|
+
@security.disable?(:javascript).should be_false
|
101
|
+
@security.disable?(:java).should be_true
|
102
|
+
@security.disable?(:run_activex).should be_false
|
103
|
+
@security.disable?(:download_activex).should be_true
|
104
|
+
@security.disable?(:picture).should be_false
|
105
|
+
@security.disable?(:sound).should be_true
|
106
|
+
@security.disable?(:video).should be_false
|
107
|
+
end
|
108
|
+
|
109
|
+
it "#<security> should return Security::Config." do
|
110
|
+
@security.javascript.should be_an_instance_of(SleipnirAPI::Security::Config)
|
111
|
+
@security.java.should be_an_instance_of(SleipnirAPI::Security::Config)
|
112
|
+
@security.run_activex.should be_an_instance_of(SleipnirAPI::Security::Config)
|
113
|
+
@security.download_activex.should be_an_instance_of(SleipnirAPI::Security::Config)
|
114
|
+
@security.picture.should be_an_instance_of(SleipnirAPI::Security::Config)
|
115
|
+
@security.sound.should be_an_instance_of(SleipnirAPI::Security::Config)
|
116
|
+
@security.video.should be_an_instance_of(SleipnirAPI::Security::Config)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "#[:<security>] should return Security::Config." do
|
120
|
+
@security[:javascript].should equal?(@security.javascript)
|
121
|
+
@security[:java].should equal?(@security.java)
|
122
|
+
@security[:run_activex].should equal?(@security.run_activex)
|
123
|
+
@security[:download_activex].should equal?(@security.download_activex)
|
124
|
+
@security[:picture].should equal?(@security.picture)
|
125
|
+
@security[:sound].should equal?(@security.sound)
|
126
|
+
@security[:video].should equal?(@security.video)
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
|
+
|
3
|
+
describe SleipnirAPI::Sleipnir, "(with mock)" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@pnir = SleipnirAPI.connect
|
7
|
+
@api = @pnir.instance_variable_get(:@api)
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
@pnir.instance_variable_set(:@api, @api)
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
@mock = mock("Sleipnir.API")
|
16
|
+
@pnir.instance_variable_set(:@api, @mock)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
it "#result should send Result" do
|
21
|
+
@mock.should_receive(:Result).with(no_args())
|
22
|
+
@pnir.result
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#app_path should send AppPath" do
|
26
|
+
@mock.should_receive(:AppPath).with(no_args())
|
27
|
+
@pnir.app_path
|
28
|
+
end
|
29
|
+
|
30
|
+
it "#script_path should send ScriptPath" do
|
31
|
+
@mock.should_receive(:ScriptPath).with(no_args())
|
32
|
+
@pnir.script_path
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#resource_path should send ResourcePath" do
|
36
|
+
@mock.should_receive(:ResourcePath).with(no_args())
|
37
|
+
@pnir.resource_path
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#user_path should send UserPath" do
|
41
|
+
@mock.should_receive(:UserPath).with(no_args())
|
42
|
+
@pnir.user_path
|
43
|
+
end
|
44
|
+
|
45
|
+
it "#save_favorite should send SaveFavorite" do
|
46
|
+
@mock.should_receive(:SaveFavorite).with("c:/foo.sfv")
|
47
|
+
@pnir.save_favorite("c:/foo.sfv")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "#save_closed_url should send SaveClosedURL" do
|
51
|
+
@mock.should_receive(:SaveClosedURL).with(no_args())
|
52
|
+
@pnir.save_closed_url
|
53
|
+
end
|
54
|
+
|
55
|
+
it "#reload_closed_url should send ReloadClosedURL" do
|
56
|
+
@mock.should_receive(:ReloadClosedURL).with(no_args())
|
57
|
+
@pnir.reload_closed_url
|
58
|
+
end
|
59
|
+
|
60
|
+
it "#add_search_bar_history should send AddSearchBarHistory" do
|
61
|
+
@mock.should_receive(:AddSearchBarHistory).with(no_args())
|
62
|
+
@pnir.add_search_bar_history
|
63
|
+
end
|
64
|
+
|
65
|
+
it "#exec_command_history should send ExecCommand" do
|
66
|
+
@mock.should_receive(:ExecCommand).with(123)
|
67
|
+
@pnir.exec_command(123)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,295 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
|
+
|
3
|
+
describe SleipnirAPI::Sleipnir, "(with blank page)" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@pnir = SleipnirAPI.connect
|
7
|
+
|
8
|
+
@xxxx = @pnir.open("about:xxxx", true)
|
9
|
+
@test = @pnir.open("about:test", true)
|
10
|
+
sleep(0.1) while @test.busy?
|
11
|
+
sleep(0.1) while @xxxx.busy?
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
@test.close
|
16
|
+
@xxxx.close
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
it "is Enumerable" do
|
21
|
+
@pnir.should respond_to(:each)
|
22
|
+
@pnir.should be_kind_of(Enumerable)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "include Dialog/KeyState" do
|
26
|
+
@pnir.should be_kind_of(SleipnirAPI::Dialog)
|
27
|
+
@pnir.should be_kind_of(SleipnirAPI::KeyState)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "#api should return WIN32OLE" do
|
31
|
+
@pnir.should be_an_instance_of(SleipnirAPI::Sleipnir)
|
32
|
+
@pnir.api.should be_an_instance_of(WIN32OLE)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#handle, #version should return properly." do
|
36
|
+
@pnir.handle.should be_a_kind_of(Integer)
|
37
|
+
@pnir.version.should be_a_kind_of(Integer)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#address_bar_string can set/get AddressBar" do
|
41
|
+
saved = @pnir.address_bar_string
|
42
|
+
begin
|
43
|
+
@pnir.address_bar_string = "http://foobar"
|
44
|
+
@pnir.address_bar_string.should eql("http://foobar")
|
45
|
+
@pnir.address_bar_string = "file://c:/barbaz"
|
46
|
+
@pnir.address_bar_string.should eql("file://c:/barbaz")
|
47
|
+
ensure
|
48
|
+
@pnir.address_bar_string = saved
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "#search_bar_string can set/get SearchBar" do
|
53
|
+
saved = @pnir.search_bar_string
|
54
|
+
begin
|
55
|
+
@pnir.search_bar_string = "foobar"
|
56
|
+
@pnir.search_bar_string.should eql("foobar")
|
57
|
+
@pnir.search_bar_string = "barbaz"
|
58
|
+
@pnir.search_bar_string.should eql("barbaz")
|
59
|
+
ensure
|
60
|
+
@pnir.search_bar_string = saved
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "#favorite_file can set/get FaviriteFile" do
|
65
|
+
next if @pnir.v2?
|
66
|
+
|
67
|
+
saved = @pnir.favorite_file
|
68
|
+
begin
|
69
|
+
@pnir.favorite_file = "foobar"
|
70
|
+
@pnir.favorite_file.should eql(@pnir.user_path + "foobar")
|
71
|
+
@pnir.favorite_file = "c:\\barbaz"
|
72
|
+
@pnir.favorite_file.should eql("c:\\barbaz")
|
73
|
+
ensure
|
74
|
+
@pnir.favorite_file = saved
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "#user_agent can set/get UserAgent" do
|
79
|
+
next if @pnir.v2?
|
80
|
+
|
81
|
+
saved = @pnir.user_agent
|
82
|
+
begin
|
83
|
+
@pnir.user_agent = "foobar"
|
84
|
+
@pnir.user_agent.should eql("foobar")
|
85
|
+
@pnir.user_agent = "barbaz"
|
86
|
+
@pnir.user_agent.should eql("barbaz")
|
87
|
+
ensure
|
88
|
+
@pnir.user_agent = saved
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "#app_path should return exe directory" do
|
93
|
+
File.exist?(File.join(@pnir.app_path, "sleipnir.exe")).should be_true
|
94
|
+
end
|
95
|
+
|
96
|
+
it "#script_path should return script directory" do
|
97
|
+
File.exist?(@pnir.script_path).should be_true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "#resource_path should return resouce directory" do
|
101
|
+
File.exist?(@pnir.resource_path).should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "#user_path should return user directory" do
|
105
|
+
File.exist?(@pnir.user_path).should be_true
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
it "#new_tab() should create new active blank tab" do
|
110
|
+
t = @pnir.new_tab
|
111
|
+
begin
|
112
|
+
t.should be_an_instance_of(SleipnirAPI::Tab)
|
113
|
+
t.location.href.should eql("about:blank")
|
114
|
+
t.should be_active
|
115
|
+
ensure
|
116
|
+
t.close
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "#new_tab take url argument" do
|
121
|
+
t = @pnir.new_tab("about:new_tab1")
|
122
|
+
begin
|
123
|
+
t.location.href.should eql("about:new_tab1")
|
124
|
+
t.should be_active
|
125
|
+
ensure
|
126
|
+
t.close
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "#new_tab take active flag" do
|
131
|
+
t = @pnir.new_tab("about:new_tab2", false)
|
132
|
+
sleep(0.1) while t.busy?
|
133
|
+
begin
|
134
|
+
t.should_not be_active
|
135
|
+
ensure
|
136
|
+
t.close
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "#open should create new active tab with specified url" do
|
141
|
+
t = @pnir.open("about:open1")
|
142
|
+
begin
|
143
|
+
t.should be_an_instance_of(SleipnirAPI::Tab)
|
144
|
+
t.location.href.should eql("about:open1")
|
145
|
+
t.should be_active
|
146
|
+
ensure
|
147
|
+
t.close
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
it "#open should take active flag" do
|
153
|
+
t = @pnir.open("about:open2", false)
|
154
|
+
sleep(0.1) while t.busy?
|
155
|
+
begin
|
156
|
+
t.should_not be_active
|
157
|
+
ensure
|
158
|
+
t.close
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it "#count should return # of documents" do
|
163
|
+
now = @pnir.count
|
164
|
+
new = @pnir.new_tab("about:count", true)
|
165
|
+
begin
|
166
|
+
@pnir.count.should == (now + 1)
|
167
|
+
ensure
|
168
|
+
new.close
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
it "#tab should return SleipnirAPI::Tab" do
|
174
|
+
t = @pnir.tab(@test.index)
|
175
|
+
t.should be_an_instance_of(SleipnirAPI::Tab)
|
176
|
+
t.should == @test
|
177
|
+
end
|
178
|
+
|
179
|
+
it "#tab should return nil if index is out of range" do
|
180
|
+
@pnir.tab(-1).should be_nil
|
181
|
+
@pnir.tab(@test.index + 1).should be_nil
|
182
|
+
end
|
183
|
+
|
184
|
+
it "#tabs should return all tab" do
|
185
|
+
@pnir.tabs.size.should == @pnir.count
|
186
|
+
@pnir.tabs.last.should == @test
|
187
|
+
end
|
188
|
+
|
189
|
+
it "#each should enumerate all tab" do
|
190
|
+
tabs = []
|
191
|
+
@pnir.each do |tab|
|
192
|
+
tab.should be_an_instance_of(SleipnirAPI::Tab)
|
193
|
+
tabs << tab
|
194
|
+
end
|
195
|
+
@pnir.tabs.should == tabs
|
196
|
+
end
|
197
|
+
|
198
|
+
it "#active_index return properly" do
|
199
|
+
@pnir.active_index.should == @test.index
|
200
|
+
end
|
201
|
+
|
202
|
+
it "#active_tab return properly" do
|
203
|
+
@pnir.active_tab.should == @test
|
204
|
+
end
|
205
|
+
|
206
|
+
it "#active_document return properly" do
|
207
|
+
doc = @pnir.active_document
|
208
|
+
doc.should be_an_instance_of(WIN32OLE)
|
209
|
+
doc.location.href.should eql("about:test")
|
210
|
+
end
|
211
|
+
|
212
|
+
it "#document should return WIN32OLE" do
|
213
|
+
doc = @pnir.document(@test.index)
|
214
|
+
doc.should be_an_instance_of(WIN32OLE)
|
215
|
+
doc.ole_obj_help.name.should == "DispHTMLDocument"
|
216
|
+
doc.location.href.should == "about:test"
|
217
|
+
end
|
218
|
+
|
219
|
+
it "#document should return nil if index is out of range" do
|
220
|
+
@pnir.document(-1).should be_nil
|
221
|
+
@pnir.document(@test.index + 1).should be_nil
|
222
|
+
end
|
223
|
+
|
224
|
+
it "#documents should return all documents" do
|
225
|
+
docs = @pnir.documents
|
226
|
+
docs.size.should == @pnir.count
|
227
|
+
docs.last.location.href.should eql("about:test")
|
228
|
+
end
|
229
|
+
|
230
|
+
it "#each_document should enumerate all documents" do
|
231
|
+
docs = []
|
232
|
+
@pnir.each_document do |doc|
|
233
|
+
doc.should be_an_instance_of(WIN32OLE)
|
234
|
+
doc.ole_obj_help.name.should == "DispHTMLDocument"
|
235
|
+
docs << doc
|
236
|
+
end
|
237
|
+
docs.size.should == @pnir.count
|
238
|
+
end
|
239
|
+
|
240
|
+
it "#get_url_tab should return SleipnirAPI::Tab" do
|
241
|
+
t = @pnir.get_url_tab("about:test")
|
242
|
+
t.should == @test
|
243
|
+
|
244
|
+
t = @pnir.get_url_tab("about:no_such_tab_aqwsedrftgyhjuikol")
|
245
|
+
t.should be_nil
|
246
|
+
end
|
247
|
+
|
248
|
+
it "#switch_to_tab(url) should switch active tab" do
|
249
|
+
t = @pnir.open("about:switch_to_tab", false)
|
250
|
+
begin
|
251
|
+
@test.should be_active
|
252
|
+
t2 = @pnir.switch_to_tab("about:switch_to_tab")
|
253
|
+
t2.should == t2
|
254
|
+
t2.should be_active
|
255
|
+
@test.should_not be_active
|
256
|
+
ensure
|
257
|
+
t.close
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
it "#switch_to_tab(url) should activate 1st tab" do
|
262
|
+
t = @pnir.open("about:switch_to_tab2", true)
|
263
|
+
sleep(0.1) while t.busy?
|
264
|
+
begin
|
265
|
+
t.should be_active
|
266
|
+
@test.should_not be_active
|
267
|
+
|
268
|
+
# test2 = @pnir.switch_to_tab("about:test")
|
269
|
+
# test2.should == @test
|
270
|
+
|
271
|
+
# t.should_not be_active
|
272
|
+
# @test.should be_active
|
273
|
+
ensure
|
274
|
+
t.close
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
it "#switch_to_tab(SleipnirAPI::Tab) should switch active tab" do
|
279
|
+
t = @pnir.open("about:switch_to_tab3", true)
|
280
|
+
sleep(0.1) while t.busy?
|
281
|
+
begin
|
282
|
+
t.should be_active
|
283
|
+
@test.should_not be_active
|
284
|
+
|
285
|
+
# test2 = @pnir.switch_to_tab(@test)
|
286
|
+
# test2.should == @test
|
287
|
+
#
|
288
|
+
# t.should_not be_active
|
289
|
+
# @test.should be_active
|
290
|
+
ensure
|
291
|
+
t.close
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|