# ********** Copyright Viacom, Inc. Apache 2.0 **********
require_relative "../test_helper.rb"
module RokuBuilder
class InspectorTest < Minitest::Test
def setup
Logger.set_testing
RokuBuilder.setup_plugins
register_plugins(Inspector)
@requests = []
end
def teardown
@requests.each {|req| remove_request_stub(req)}
end
def test_inspector_parse_options_long
parser = OptionParser.new
options = {}
Inspector.parse_options(parser: parser, options: options)
argv = ["roku", "--inspect", "--screencapture", "--password", "password"]
parser.parse! argv
assert options[:inspect]
assert options[:screencapture]
assert_equal "password", options[:password]
end
def test_scripter_parse_options_short
parser = OptionParser.new
options = {}
Inspector.parse_options(parser: parser, options: options)
argv = ["roku", "-S"]
parser.parse! argv
assert options[:screencapture]
end
def test_inspector_inspect
logger = Minitest::Mock.new()
logger.expect(:formatter=, nil, [Proc])
logger.expect(:unknown, nil){|text| /=*/ =~ text}
logger.expect(:unknown, nil){|text| /app_name/ =~ text}
logger.expect(:unknown, nil){|text| /dev_id/ =~ text}
logger.expect(:unknown, nil, [String])
logger.expect(:unknown, nil){|text| /dev_zip/ =~ text}
logger.expect(:unknown, nil){|text| /=*/ =~ text}
body = "r1.insertCell(0).innerHTML = 'App Name: ';"+
" r1.insertCell(1).innerHTML = '
app_name
';"+
""+
" var r2 = table.insertRow(1);"+
" r2.insertCell(0).innerHTML = 'Dev ID: ';"+
" r2.insertCell(1).innerHTML = 'dev_id
';"+
" "+
" var dd = new Date(628232400);"+
" var ddStr = \"\";"+
" ddStr += (dd.getMonth()+1);"+
" ddStr += \"/\";"+
" ddStr += dd.getDate();"+
" ddStr += \"/\";"+
" ddStr += dd.getFullYear();"+
" ddStr += \" \";"+
" ddStr += dd.getHours();"+
" ddStr += \":\";"+
" ddStr += dd.getMinutes();"+
" ddStr += \":\";"+
" ddStr += dd.getSeconds(); "+
" "+
" var r3 = table.insertRow(2);"+
" r3.insertCell(0).innerHTML = 'Creation Date: ';"+
" r3.insertCell(1).innerHTML = ''+ddStr+'
';"+
" "+
" var r4 = table.insertRow(3);"+
" r4.insertCell(0).innerHTML = 'dev.zip: ';"+
" r4.insertCell(1).innerHTML = 'dev_zip
';"
@requests.push(stub_request(:post, "http://192.168.0.100/plugin_inspect").
to_return(status: 200, body: body, headers: {}))
options = {inspect: true, in: File.join(test_files_path(InspectorTest), "test.pkg"), password: "password"}
config, options = build_config_options_objects(InspectorTest, options, false)
inspector = Inspector.new(config: config)
::Logger.stub(:new, logger) do
inspector.inspect(options: options)
end
end
def test_inspector_inspect_old_interface
logger = Minitest::Mock.new()
logger.expect(:formatter=, nil, [Proc])
logger.expect(:unknown, nil){|text| /=*/ =~ text}
logger.expect(:unknown, nil){|text| /app_name/ =~ text}
logger.expect(:unknown, nil){|text| /dev_id/ =~ text}
logger.expect(:unknown, nil, [String])
logger.expect(:unknown, nil){|text| /dev_zip/ =~ text}
logger.expect(:unknown, nil){|text| /=*/ =~ text}
body = " "+
" App Name: | app_name |
"+
" Dev ID: | dev_id |
"+
" Creation Date: | "+
" 1/17/1970 16:42:28"+
" |
"+
" dev.zip: | dev_zip |
"+
"
"
@requests.push(stub_request(:post, "http://192.168.0.100/plugin_inspect").
to_return(status: 200, body: body, headers: {}))
options = {inspect: true, in: File.join(test_files_path(InspectorTest), "test.pkg"), password: "password"}
config, options = build_config_options_objects(InspectorTest, options, false)
inspector = Inspector.new(config: config)
::Logger.stub(:new, logger) do
inspector.inspect(options: options)
end
end
def test_screencapture
body = "
"
@requests.push(stub_request(:post, "http://192.168.0.100/plugin_inspect").
to_return(status: 200, body: body, headers: {}))
body2 = ""
@requests.push(stub_request(:get, "http://192.168.0.100/pkgs/dev.jpg?time=1455629573").
to_return(status: 200, body: body2, headers: {}))
io = Minitest::Mock.new()
io.expect("write", nil, [body2])
options = {screencapture: true }
config, options = build_config_options_objects(InspectorTest, options, false)
inspector = Inspector.new(config: config)
File.stub(:open, nil, io) do
inspector.screencapture(options: options)
end
end
def test_screencapture_png
body = "
"
@requests.push(stub_request(:post, "http://192.168.0.100/plugin_inspect").
to_return(status: 200, body: body, headers: {}))
body2 = ""
@requests.push(stub_request(:get, "http://192.168.0.100/pkgs/dev.png?time=1455629573").
to_return(status: 200, body: body2, headers: {}))
io = Minitest::Mock.new()
io.expect("write", nil, [body2])
options = {screencapture: true }
config, options = build_config_options_objects(InspectorTest, options, false)
inspector = Inspector.new(config: config)
File.stub(:open, nil, io) do
inspector.screencapture(options: options)
end
end
end
end