VulpesOS/gaia/tests/jsmarionette/plugins/marionette-apps/lib/switchtoapp.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

42 lines
1.1 KiB
JavaScript
Executable file

'use strict';
var getApp = require('./getapp').getApp;
var waitForApp = require('./waitforapp').waitForApp;
/**
* Switch focus to a given app based on the origin.
* @param {Apps} apps to manage state.
* @param {String} origin of the application.
* @param {String} [entrypoint] of the application.
* @param {Function} callback [Error err].
*/
function switchToApp(apps, origin, entrypoint, callback) {
if (typeof entrypoint === 'function') {
callback = entrypoint;
entrypoint = null;
}
var client = apps._client;
callback = callback || client.defaultCallback;
// Always go back to root (system) application.
client.switchToFrame();
return getApp(apps, origin, entrypoint, function(err, app) {
if (err) {
return callback(err);
}
return waitForApp(apps, app.source, function(err, iframe) {
if (err) {
return callback(err);
}
// By default, should set focus to the frame.
return client.switchToFrame(iframe, {focus: true}, function(err) {
return callback(err, iframe, app);
});
});
});
}
module.exports.switchToApp = switchToApp;