mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
URLs can now be opened.
This commit is contained in:
parent
71bf2fd131
commit
33d2862704
6 changed files with 77 additions and 44 deletions
|
@ -556,6 +556,16 @@ module.exports = function(options) {
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
.on('browser.open', function(channel, responseChannel, data) {
|
||||||
|
joinChannel(responseChannel)
|
||||||
|
push.send([
|
||||||
|
channel
|
||||||
|
, wireutil.transaction(
|
||||||
|
responseChannel
|
||||||
|
, new wire.BrowserOpenMessage(data)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.finally(function() {
|
.finally(function() {
|
||||||
// Clean up all listeners and subscriptions
|
// Clean up all listeners and subscriptions
|
||||||
|
@ -582,8 +592,6 @@ module.exports = function(options) {
|
||||||
socket.on('forward', function(data) {})
|
socket.on('forward', function(data) {})
|
||||||
socket.on('refresh', function(data) {})
|
socket.on('refresh', function(data) {})
|
||||||
socket.on('internal.relaunch', function(data) {})
|
socket.on('internal.relaunch', function(data) {})
|
||||||
socket.on('browser.open', function(data) {})
|
|
||||||
socket.on('chrome.open', function(data) {})
|
|
||||||
socket.on('browser.clear', function(data) {})
|
socket.on('browser.clear', function(data) {})
|
||||||
socket.on('chrome.clear', function(data) {})
|
socket.on('chrome.clear', function(data) {})
|
||||||
socket.on('internal.clear', function(data) {})
|
socket.on('internal.clear', function(data) {})
|
||||||
|
|
|
@ -1,51 +1,63 @@
|
||||||
var util = require('util')
|
|
||||||
|
|
||||||
var syrup = require('syrup')
|
var syrup = require('syrup')
|
||||||
|
|
||||||
var logger = require('../../../util/logger')
|
var logger = require('../../../util/logger')
|
||||||
|
var wire = require('../../../wire')
|
||||||
|
var wireutil = require('../../../wire/util')
|
||||||
|
|
||||||
module.exports = syrup.serial()
|
module.exports = syrup.serial()
|
||||||
.dependency(require('../support/http'))
|
.dependency(require('../support/router'))
|
||||||
|
.dependency(require('../support/push'))
|
||||||
|
.dependency(require('../support/adb'))
|
||||||
.dependency(require('./input'))
|
.dependency(require('./input'))
|
||||||
.define(function(options, http, input) {
|
.define(function(options, router, push, adb, input) {
|
||||||
var log = logger.createLogger('device:plugins:browsers')
|
var log = logger.createLogger('device:plugins:browsers')
|
||||||
|
|
||||||
log.info('Fetching browser list')
|
log.info('Fetching browser list')
|
||||||
return input.getBrowsers()
|
return input.getBrowsers()
|
||||||
.timeout(15000)
|
.timeout(15000)
|
||||||
.then(function(browsers) {
|
.then(function(browsers) {
|
||||||
var icons = Object.create(null)
|
|
||||||
|
|
||||||
browsers.apps.forEach(function(app) {
|
browsers.apps.forEach(function(app) {
|
||||||
icons[app.component] = app.icon.toBuffer()
|
var pkg = app.component.split('/', 1)[0]
|
||||||
app.icon = util.format(
|
|
||||||
'%s/api/v1/browsers/%s/icon'
|
switch (pkg) {
|
||||||
, http.get('public url')
|
case 'com.android.chrome':
|
||||||
, app.component
|
app.type = 'chrome'
|
||||||
)
|
break
|
||||||
|
case 'com.sec.android.app.sbrowser':
|
||||||
|
app.type = 'samsung-chrome'
|
||||||
|
break
|
||||||
|
case 'com.android.browser':
|
||||||
|
app.type = 'default'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
app.id = app.component
|
||||||
|
|
||||||
|
delete app.icon
|
||||||
|
delete app.component
|
||||||
})
|
})
|
||||||
|
|
||||||
http.get(
|
router.on(wire.BrowserOpenMessage, function(channel, message) {
|
||||||
'/api/v1/browsers/:package/:activity/icon'
|
var reply = wireutil.reply(options.serial)
|
||||||
, function(req, res) {
|
adb.startActivity(options.serial, {
|
||||||
var component = util.format(
|
action: 'android.intent.action.VIEW'
|
||||||
'%s/%s'
|
, component: message.browser
|
||||||
, req.params.package
|
, data: message.url
|
||||||
, req.params.activity
|
})
|
||||||
)
|
.then(function() {
|
||||||
|
push.send([
|
||||||
var icon = icons[component]
|
channel
|
||||||
|
, reply.okay()
|
||||||
if (icon) {
|
])
|
||||||
res.set('Content-Type', 'image/png')
|
})
|
||||||
res.set('Content-Length', icon.length)
|
.catch(function(err) {
|
||||||
res.send(200, icon)
|
log.error('Browser could not be opened', err.stack)
|
||||||
}
|
push.send([
|
||||||
else {
|
channel
|
||||||
res.send(404)
|
, reply.fail()
|
||||||
}
|
])
|
||||||
}
|
})
|
||||||
)
|
})
|
||||||
|
|
||||||
return browsers
|
return browsers
|
||||||
})
|
})
|
||||||
|
|
|
@ -46,10 +46,10 @@ module.exports = syrup.serial()
|
||||||
identity.browsers.selected
|
identity.browsers.selected
|
||||||
, identity.browsers.apps.map(function(app) {
|
, identity.browsers.apps.map(function(app) {
|
||||||
return new wire.DeviceBrowserAppMessage(
|
return new wire.DeviceBrowserAppMessage(
|
||||||
app.name
|
app.id
|
||||||
, app.component
|
, app.type
|
||||||
|
, app.name
|
||||||
, app.selected
|
, app.selected
|
||||||
, app.icon
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
@ -45,7 +45,7 @@ var wireutil = {
|
||||||
source
|
source
|
||||||
, seq++
|
, seq++
|
||||||
, true
|
, true
|
||||||
, data
|
, data || 'success'
|
||||||
, body ? JSON.stringify(body) : null
|
, body ? JSON.stringify(body) : null
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ var wireutil = {
|
||||||
source
|
source
|
||||||
, seq++
|
, seq++
|
||||||
, false
|
, false
|
||||||
, data
|
, data || 'fail'
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
, progress: function(data, progress) {
|
, progress: function(data, progress) {
|
||||||
|
|
|
@ -41,6 +41,7 @@ enum MessageType {
|
||||||
ForwardRemoveMessage = 38;
|
ForwardRemoveMessage = 38;
|
||||||
LogcatStartMessage = 39;
|
LogcatStartMessage = 39;
|
||||||
LogcatStopMessage = 40;
|
LogcatStopMessage = 40;
|
||||||
|
BrowserOpenMessage = 41;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Envelope {
|
message Envelope {
|
||||||
|
@ -136,10 +137,10 @@ message DeviceDisplayMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeviceBrowserAppMessage {
|
message DeviceBrowserAppMessage {
|
||||||
required string name = 1;
|
required string id = 1;
|
||||||
required string component = 2;
|
required string type = 2;
|
||||||
required bool selected = 3;
|
required string name = 3;
|
||||||
required string icon = 4;
|
required bool selected = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeviceBrowsersMessage {
|
message DeviceBrowsersMessage {
|
||||||
|
@ -376,3 +377,8 @@ message ForwardCreateMessage {
|
||||||
message ForwardRemoveMessage {
|
message ForwardRemoveMessage {
|
||||||
required uint32 devicePort = 1;
|
required uint32 devicePort = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message BrowserOpenMessage {
|
||||||
|
required string url = 1;
|
||||||
|
optional string browser = 2;
|
||||||
|
}
|
||||||
|
|
|
@ -197,6 +197,13 @@ module.exports = function ControlServiceFactory(
|
||||||
this.stopLogcat = function() {
|
this.stopLogcat = function() {
|
||||||
return sendTwoWay('logcat.stop')
|
return sendTwoWay('logcat.stop')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.openBrowser = function(browser, url) {
|
||||||
|
return sendTwoWay('browser.open', {
|
||||||
|
url: url
|
||||||
|
, browser: browser.id
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
controlService.create = function(target, channel) {
|
controlService.create = function(target, channel) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue