brazenhead 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/driver/brazenhead-release-unsigned.apk +0 -0
- data/features/step_definitions/string_ids_steps.rb +8 -0
- data/features/strings_ids.feature +5 -0
- data/lib/brazenhead/builder.rb +33 -33
- data/lib/brazenhead/package.rb +9 -0
- data/lib/brazenhead/version.rb +1 -1
- data/spec/lib/brazenhead/builder_spec.rb +52 -14
- metadata +10 -6
Binary file
|
@@ -0,0 +1,8 @@
|
|
1
|
+
When /^I call "(.*?)" with "(.*?)" on the target "(.*?)"$/ do |method, arg, target|
|
2
|
+
@driver.send method, arg, :target => target
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should receive an id value back from the Brazenhead module$/ do
|
6
|
+
@driver.last_response.body.to_i.should be > 0
|
7
|
+
end
|
8
|
+
|
data/lib/brazenhead/builder.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
require 'brazenhead/manifest_info'
|
3
3
|
require 'brazenhead/package'
|
4
|
+
require 'brazenhead/process'
|
4
5
|
require 'ADB'
|
5
6
|
|
6
7
|
module Brazenhead
|
@@ -9,20 +10,27 @@ module Brazenhead
|
|
9
10
|
include ADB
|
10
11
|
|
11
12
|
def build_for(apk, keystore)
|
12
|
-
@source_apk = apk
|
13
|
-
@keystore = keystore
|
13
|
+
@source_apk = File.expand_path apk
|
14
14
|
invalid_package_err(apk) unless File.exists? @source_apk
|
15
|
-
|
15
|
+
|
16
|
+
@keystore = keystore
|
17
|
+
@keystore[:path] = File.expand_path @keystore[:path]
|
18
|
+
|
19
|
+
Dir.mktmpdir do |temp_dir|
|
20
|
+
install_server temp_dir
|
21
|
+
end
|
22
|
+
|
16
23
|
manifest_info
|
17
24
|
end
|
18
25
|
|
19
26
|
private
|
20
|
-
def install_server
|
21
|
-
Dir.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
def install_server(dir)
|
28
|
+
Dir.chdir(dir) do |here|
|
29
|
+
copy_base_files
|
30
|
+
update_test_manifest
|
31
|
+
store_resources
|
32
|
+
sign test_apk, @keystore
|
33
|
+
reinstall test_apk
|
26
34
|
reinstall @source_apk
|
27
35
|
end
|
28
36
|
end
|
@@ -31,41 +39,29 @@ module Brazenhead
|
|
31
39
|
install apk, "-r", {}, timeout
|
32
40
|
end
|
33
41
|
|
34
|
-
def
|
35
|
-
[test_apk,
|
36
|
-
FileUtils.
|
42
|
+
def copy_base_files
|
43
|
+
[test_apk, android_manifest].each do |file|
|
44
|
+
FileUtils.cp driver_path_for(file), Dir.pwd
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
40
48
|
def driver_path_for(file)
|
41
|
-
join
|
49
|
+
File.join File.expand_path("../../../", __FILE__), 'driver', file
|
42
50
|
end
|
43
51
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def update_manifest_in(dir)
|
49
|
-
manifest_path = join(dir, manifest)
|
50
|
-
|
51
|
-
replace(manifest_path, target_match, target_replace)
|
52
|
-
update_manifest(test_apk_in(dir), manifest_path, manifest_info.target_sdk)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_apk_in(dir)
|
56
|
-
join(dir, test_apk)
|
52
|
+
def update_test_manifest
|
53
|
+
replace android_manifest, /\btargetPackage="[^"]+"/, "targetPackage=\"#{the_target}\""
|
54
|
+
update_manifest test_apk, android_manifest, manifest_info.target_sdk
|
57
55
|
end
|
58
56
|
|
59
57
|
def replace(file, match, replacement)
|
60
58
|
File.write(file, File.read(file).gsub(match, replacement))
|
61
59
|
end
|
62
60
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def target_replace
|
68
|
-
"targetPackage=\"#{the_target}\""
|
61
|
+
def store_resources
|
62
|
+
Dir.mkdir "assets"
|
63
|
+
dump_resources @source_apk, "assets/resources.txt"
|
64
|
+
add_file test_apk, "assets/resources.txt"
|
69
65
|
end
|
70
66
|
|
71
67
|
def the_target
|
@@ -80,7 +76,7 @@ module Brazenhead
|
|
80
76
|
'brazenhead-release-unsigned.apk'
|
81
77
|
end
|
82
78
|
|
83
|
-
def
|
79
|
+
def android_manifest
|
84
80
|
'AndroidManifest.xml'
|
85
81
|
end
|
86
82
|
|
@@ -88,5 +84,9 @@ module Brazenhead
|
|
88
84
|
raise Exception.new("Invalid package path: #{apk}")
|
89
85
|
end
|
90
86
|
|
87
|
+
def process
|
88
|
+
@process ||= Brazenhead::Process.new
|
89
|
+
end
|
90
|
+
|
91
91
|
end
|
92
92
|
end
|
data/lib/brazenhead/package.rb
CHANGED
@@ -10,6 +10,15 @@ module Brazenhead
|
|
10
10
|
process.run(*update, *package(apk), *with(manifest), *using(path_to(min_sdk)))
|
11
11
|
end
|
12
12
|
|
13
|
+
def dump_resources(apk, resource_file)
|
14
|
+
process.run(*"aapt dump resources".split, apk)
|
15
|
+
File.write resource_file, process.last_stdout
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_file(apk, file)
|
19
|
+
process.run(*"aapt add".split, apk, file)
|
20
|
+
end
|
21
|
+
|
13
22
|
private
|
14
23
|
def process
|
15
24
|
@process ||= Brazenhead::Process.new
|
data/lib/brazenhead/version.rb
CHANGED
@@ -2,23 +2,37 @@ require 'brazenhead/builder'
|
|
2
2
|
|
3
3
|
describe Brazenhead::Builder do
|
4
4
|
let(:apk) { 'some_apk.apk' }
|
5
|
+
let(:expanded_apk) { File.expand_path(apk) }
|
5
6
|
let(:activity) { 'SomeActivityToStart' }
|
6
7
|
let(:server) { Brazenhead::Builder.new }
|
7
8
|
let(:manifest_info) { double('manifest-info').as_null_object }
|
8
9
|
let(:tmpdir) { '/some/tmp/dir' }
|
9
10
|
let(:driver_apk) { 'brazenhead-release-unsigned.apk' }
|
10
11
|
let(:keystore) { {:path => 'default.keystore'} }
|
12
|
+
let(:process) { double('brazenhead-process').as_null_object }
|
11
13
|
|
12
14
|
before(:each) do
|
15
|
+
File.stub(:expand_path) do |arg|
|
16
|
+
"expanded/#{arg}"
|
17
|
+
end
|
13
18
|
File.stub(:exists?).and_return(true)
|
14
19
|
Dir.stub(:mktmpdir).and_yield(tmpdir)
|
15
|
-
|
20
|
+
Dir.stub(:chdir).and_yield(tmpdir)
|
21
|
+
Dir.stub(:mkdir)
|
22
|
+
Dir.stub(:pwd).and_return(tmpdir)
|
23
|
+
FileUtils.stub(:cp)
|
16
24
|
File.stub(:read).and_return('')
|
17
25
|
File.stub(:write)
|
18
|
-
server
|
19
|
-
|
20
|
-
|
21
|
-
Brazenhead::
|
26
|
+
stub_all server, :update_manifest, :sign, :install
|
27
|
+
|
28
|
+
Brazenhead::ManifestInfo.stub(:new).with(expanded_apk).and_return(manifest_info)
|
29
|
+
Brazenhead::Process.stub(:new).and_return(process)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_all(type, *methods)
|
33
|
+
methods.each do |method|
|
34
|
+
type.stub(method)
|
35
|
+
end
|
22
36
|
end
|
23
37
|
|
24
38
|
context "building the test server" do
|
@@ -46,19 +60,43 @@ describe Brazenhead::Builder do
|
|
46
60
|
end
|
47
61
|
|
48
62
|
it "should copy the unsigned release package into the directory" do
|
49
|
-
FileUtils.should_receive(:
|
63
|
+
FileUtils.should_receive(:cp).with(base_test_apk, "#{tmpdir}")
|
50
64
|
server.build_for(apk, keystore)
|
51
65
|
end
|
52
66
|
|
53
67
|
it "should copy the manifest into the directory" do
|
54
|
-
FileUtils.should_receive(:
|
68
|
+
FileUtils.should_receive(:cp).with(base_manifest, "#{tmpdir}")
|
55
69
|
server.build_for(apk, keystore)
|
56
70
|
end
|
57
71
|
end
|
58
72
|
|
73
|
+
context "grabbing resource information" do
|
74
|
+
it "should retrieve resource information from the target package" do
|
75
|
+
process.should_receive(:run).with(*"aapt dump resources #{expanded_apk}".split)
|
76
|
+
server.build_for apk, keystore
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should create an assets directory for the resource information" do
|
80
|
+
Dir.should_receive(:mkdir).with("assets")
|
81
|
+
server.build_for apk, keystore
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should write the resource information to the assets directory" do
|
85
|
+
process.should_receive(:last_stdout).and_return("resource info")
|
86
|
+
resources = "assets/resources.txt"
|
87
|
+
File.should_receive(:write).with(resources, "resource info")
|
88
|
+
server.build_for apk, keystore
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should store the resources in the test server" do
|
92
|
+
process.should_receive(:run).with(*"aapt add #{driver_apk} assets/resources.txt".split)
|
93
|
+
server.build_for apk, keystore
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
59
97
|
context "updating the manifest" do
|
60
98
|
it "should load the contents of the existing manifest" do
|
61
|
-
File.should_receive(:read).with("
|
99
|
+
File.should_receive(:read).with("AndroidManifest.xml")
|
62
100
|
server.build_for(apk, keystore)
|
63
101
|
end
|
64
102
|
|
@@ -66,14 +104,14 @@ describe Brazenhead::Builder do
|
|
66
104
|
the_target_package = "the.target.package"
|
67
105
|
File.should_receive(:read).and_return("android:targetPackage=\"it.does.not.matter\"")
|
68
106
|
manifest_info.should_receive(:package).and_return(the_target_package)
|
69
|
-
File.should_receive(:write).with("
|
107
|
+
File.should_receive(:write).with("AndroidManifest.xml", "android:targetPackage=\"#{the_target_package}\"")
|
70
108
|
|
71
109
|
server.build_for(apk, keystore)
|
72
110
|
end
|
73
111
|
|
74
112
|
it "should package the modified manifest back into the test package" do
|
75
113
|
manifest_info.should_receive(:target_sdk).and_return(10)
|
76
|
-
server.should_receive(:update_manifest).with("#{
|
114
|
+
server.should_receive(:update_manifest).with("#{driver_apk}", "AndroidManifest.xml", 10)
|
77
115
|
server.build_for(apk, keystore)
|
78
116
|
end
|
79
117
|
|
@@ -81,26 +119,26 @@ describe Brazenhead::Builder do
|
|
81
119
|
|
82
120
|
context "signing the test server" do
|
83
121
|
it "should use the provided keystore to sign the package" do
|
84
|
-
server.should_receive(:sign).with("#{
|
122
|
+
server.should_receive(:sign).with("#{driver_apk}", {:path => 'expanded/another keystore'})
|
85
123
|
server.build_for(apk, :path => 'another keystore')
|
86
124
|
end
|
87
125
|
end
|
88
126
|
|
89
127
|
context "installing the test server" do
|
90
128
|
it "should reinstall the test server to the device" do
|
91
|
-
server.should_receive(:install).with("#{
|
129
|
+
server.should_receive(:install).with("#{driver_apk}", "-r", {}, 90)
|
92
130
|
server.build_for(apk, keystore)
|
93
131
|
end
|
94
132
|
|
95
133
|
it "should reinstall the target package to the device" do
|
96
|
-
server.should_receive(:install).with(
|
134
|
+
server.should_receive(:install).with(expanded_apk, "-r", {}, 90)
|
97
135
|
server.build_for(apk, keystore)
|
98
136
|
end
|
99
137
|
|
100
138
|
end
|
101
139
|
end
|
102
140
|
|
103
|
-
context "sending back
|
141
|
+
context "sending back information about the server" do
|
104
142
|
it "should send back information about the target package" do
|
105
143
|
server.build_for(apk, keystore).should_be manifest_info
|
106
144
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brazenhead
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Levi Wilson
|
9
8
|
- Jeffrey S. Morgan
|
9
|
+
- Levi Wilson
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: childprocess
|
@@ -79,8 +79,8 @@ dependencies:
|
|
79
79
|
description: Driver that accepts remote json requests and invokes methods inside Android
|
80
80
|
emulator / device.
|
81
81
|
email:
|
82
|
-
- levi@leandog.com
|
83
82
|
- jeff.morgan@leandog.com
|
83
|
+
- levi@leandog.com
|
84
84
|
executables: []
|
85
85
|
extensions: []
|
86
86
|
extra_rdoc_files: []
|
@@ -92,6 +92,8 @@ files:
|
|
92
92
|
- features/step_definitions/brazenhead_steps.rb
|
93
93
|
- features/step_definitions/exception_steps.rb
|
94
94
|
- features/step_definitions/robotium_steps.rb
|
95
|
+
- features/step_definitions/string_ids_steps.rb
|
96
|
+
- features/strings_ids.feature
|
95
97
|
- features/support/ApiDemos.apk
|
96
98
|
- features/support/debug.keystore
|
97
99
|
- features/support/env.rb
|
@@ -135,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
137
|
version: '0'
|
136
138
|
segments:
|
137
139
|
- 0
|
138
|
-
hash:
|
140
|
+
hash: -501269856312341157
|
139
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
142
|
none: false
|
141
143
|
requirements:
|
@@ -144,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
146
|
version: '0'
|
145
147
|
segments:
|
146
148
|
- 0
|
147
|
-
hash:
|
149
|
+
hash: -501269856312341157
|
148
150
|
requirements: []
|
149
151
|
rubyforge_project:
|
150
152
|
rubygems_version: 1.8.24
|
@@ -159,6 +161,8 @@ test_files:
|
|
159
161
|
- features/step_definitions/brazenhead_steps.rb
|
160
162
|
- features/step_definitions/exception_steps.rb
|
161
163
|
- features/step_definitions/robotium_steps.rb
|
164
|
+
- features/step_definitions/string_ids_steps.rb
|
165
|
+
- features/strings_ids.feature
|
162
166
|
- features/support/ApiDemos.apk
|
163
167
|
- features/support/debug.keystore
|
164
168
|
- features/support/env.rb
|