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.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
97
gaia/tests/jsmarionette/plugins/marionette-apps/lib/app.js
Executable file
97
gaia/tests/jsmarionette/plugins/marionette-apps/lib/app.js
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
'use strict';
|
||||
var GeckoObject = require(__dirname + '/geckoobject');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Marionette.Client} client Marionette client to use.
|
||||
*/
|
||||
function App(client) {
|
||||
GeckoObject.apply(this, arguments);
|
||||
this._client = client;
|
||||
}
|
||||
module.exports = App;
|
||||
|
||||
|
||||
App.prototype = {
|
||||
__proto__: GeckoObject.prototype,
|
||||
|
||||
|
||||
/**
|
||||
* @type {Marionette.Client}
|
||||
* @private
|
||||
*/
|
||||
_client: undefined,
|
||||
|
||||
|
||||
/**
|
||||
* The origin of the site that triggered the installation of the app.
|
||||
* @type {string}
|
||||
*/
|
||||
installOrigin: undefined,
|
||||
|
||||
|
||||
/**
|
||||
* The time that the app was installed.
|
||||
* This is generated using Date().getTime(),
|
||||
* represented as the number of milliseconds
|
||||
* since midnight of January 1st, 1970.
|
||||
* @type {number}
|
||||
*/
|
||||
installTime: undefined,
|
||||
|
||||
|
||||
/**
|
||||
* The currently stored instance of the manifest of the app.
|
||||
* @type {Object}
|
||||
*/
|
||||
manifest: undefined,
|
||||
|
||||
|
||||
/**
|
||||
* Where the manifest was found.
|
||||
* @type {string}
|
||||
*/
|
||||
manifestURL: undefined,
|
||||
|
||||
|
||||
/**
|
||||
* The origin of the app (protocol, host, and optional port number).
|
||||
* For example: http://example.com.
|
||||
* @type {string}
|
||||
*/
|
||||
origin: undefined,
|
||||
|
||||
|
||||
/**
|
||||
* An object containing an array of one or more receipts.
|
||||
* Each receipt is a string. If there are no receipts, this is null.
|
||||
* @type {Object}
|
||||
*/
|
||||
receipts: undefined,
|
||||
|
||||
|
||||
checkForUpdate: function() {
|
||||
throw 'Not yet implemented';
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Launches the application. Does not return any value.
|
||||
*
|
||||
* @param {String} entrypoint for app.
|
||||
*/
|
||||
launch: function(entrypoint) {
|
||||
var client = this._client.scope({ context: 'content' });
|
||||
client.executeAsyncScript(function(id, entrypoint) {
|
||||
var ObjectCache = window.wrappedJSObject.ObjectCache;
|
||||
var app = ObjectCache._inst.get(id);
|
||||
app.launch(entrypoint || null);
|
||||
marionetteScriptFinished();
|
||||
}, [this._id, entrypoint], function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
97
gaia/tests/jsmarionette/plugins/marionette-apps/lib/apps.js
Executable file
97
gaia/tests/jsmarionette/plugins/marionette-apps/lib/apps.js
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
'use strict';
|
||||
var BootWatcher = require('./bootwatcher');
|
||||
var Mgmt = require('./mgmt');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Marionette.Client} client Marionette client to use.
|
||||
*/
|
||||
function Apps(client) {
|
||||
this.mgmt = new Mgmt(client);
|
||||
this._client = client;
|
||||
}
|
||||
module.exports = Apps;
|
||||
|
||||
|
||||
/**
|
||||
* Make a new apps and register a client hook to startSession that triggers
|
||||
* the BootWatcher.
|
||||
* @param {Marionette.Client} client Marionette client to use.
|
||||
* @param {Object} options Optional map of attributes for Apps.
|
||||
* @return {Apps} instance.
|
||||
*/
|
||||
Apps.setup = function(client, options) {
|
||||
var apps = new Apps(client);
|
||||
|
||||
client.addHook('startSession', function(done) {
|
||||
BootWatcher.setup(client, function(err) {
|
||||
if (err) return done && done(err);
|
||||
apps.mgmt.prepareClient(done);
|
||||
});
|
||||
});
|
||||
|
||||
return apps;
|
||||
};
|
||||
|
||||
|
||||
Apps.prototype = {
|
||||
/**
|
||||
* A mgmt object that exposes functions that let dashboards
|
||||
* manage and launch apps on a user's behalf.
|
||||
* @type {Mgmt}
|
||||
*/
|
||||
mgmt: undefined,
|
||||
|
||||
|
||||
/**
|
||||
* @type {Marionette.Client}
|
||||
* @private
|
||||
*/
|
||||
_client: undefined,
|
||||
|
||||
|
||||
/**
|
||||
* Returns information about the current app, which means
|
||||
* an installed app whose domain matches the domain of the calling app.
|
||||
* Note: Multiple apps per origin are not supported.
|
||||
* To host several apps from one domain, set up a subdomain for each app;
|
||||
* for example: myapp.mydomain.com, otherapp.mydomain.com, and so forth.
|
||||
* @return {DOMRequest} Request that supports onsuccess, onerror callbacks.
|
||||
*/
|
||||
getSelf: function(callback) {
|
||||
return this.mgmt.getSelf(callback);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all installed apps from this origin.
|
||||
* For example, if you call this on the Firefox Marketplace,
|
||||
* you will get the list of apps installed by the Firefox Marketplace.
|
||||
* @return {DOMRequest} Request that supports onsuccess, onerror callbacks.
|
||||
*/
|
||||
getInstalled: function() {
|
||||
throw 'Not yet implemented';
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Triggers the installation of an app. During the installation process,
|
||||
* the app is validated and the user is prompted to approve the installation.
|
||||
* If the app has previously been installed from the same domain,
|
||||
* calling install() again may silently overwrite the existing install data.
|
||||
* This can be used to modify the purchase receipt, for example,
|
||||
* when a user upgrades from a free app to a premium app.
|
||||
* @param {string} url A string URL containing the location of the manifest
|
||||
* to be installed. In the case of self distribution
|
||||
* (where the installing origin is the same as the app origin),
|
||||
* the installing site may omit the origin part of the URL
|
||||
* and provide an absolute path (beginning with /).
|
||||
* @param {Object} receipts (Optional) A JSON object containing an array
|
||||
* of one or more receipts.
|
||||
* @return {DOMRequest} Request that supports onsuccess, onerror callbacks.
|
||||
*/
|
||||
install: function(url, receipts) {
|
||||
throw 'Not yet implemented';
|
||||
}
|
||||
};
|
||||
79
gaia/tests/jsmarionette/plugins/marionette-apps/lib/bootwatcher.js
Executable file
79
gaia/tests/jsmarionette/plugins/marionette-apps/lib/bootwatcher.js
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
'use strict';
|
||||
/**
|
||||
* @fileoverview Simple tool to notify listeners when a Firefox OS instance
|
||||
* finishes booting.
|
||||
*/
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Marionette.Client} client Marionette client to use.
|
||||
*/
|
||||
function BootWatcher(client) {
|
||||
EventEmitter.call(this, arguments);
|
||||
this._client = client;
|
||||
}
|
||||
module.exports = BootWatcher;
|
||||
|
||||
/**
|
||||
* Initialize the BootWatcher plugin!
|
||||
* @param {Marionette.Client} client Marionette client to use.
|
||||
* @param {Object} options Optional map of attributes for MarionetteApps.
|
||||
* @param {Function} cb Optional callback function to call after setup.
|
||||
* @return {BootWatcher} instance of bootwatcher.
|
||||
*/
|
||||
BootWatcher.setup = function(client, options, cb) {
|
||||
var bootwatcher = new BootWatcher(client);
|
||||
if (arguments.length === 2 && typeof(options) === 'function') {
|
||||
cb = options;
|
||||
options = undefined;
|
||||
}
|
||||
|
||||
process.nextTick(function() {
|
||||
// wait until client is booted up
|
||||
try {
|
||||
bootwatcher.start();
|
||||
} catch (error) {
|
||||
console.error('Never saw webapps-registry-ready yes');
|
||||
} finally {
|
||||
bootwatcher.emit('boot');
|
||||
if (cb) {
|
||||
cb(null, bootwatcher);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return bootwatcher;
|
||||
};
|
||||
|
||||
BootWatcher.prototype = {
|
||||
__proto__: EventEmitter.prototype,
|
||||
|
||||
/**
|
||||
* @type {Marionette.Client}
|
||||
* @private
|
||||
*/
|
||||
_client: undefined,
|
||||
|
||||
/**
|
||||
* Start watching for when we're booted.
|
||||
* Initially we were watching the window for the 'applicationready'
|
||||
* event. However, some javascript exceptions in the system app may
|
||||
* keep 'applicationready' from being fired, so poll instead. Also,
|
||||
* an error may be thrown while we're executing. In that case, retry.
|
||||
*/
|
||||
start: function() {
|
||||
var client = this._client;
|
||||
client.waitFor(function() {
|
||||
return client.executeScript(function() {
|
||||
try {
|
||||
var sessionStorage = window.wrappedJSObject.sessionStorage;
|
||||
var item = sessionStorage.getItem('webapps-registry-ready');
|
||||
return item === 'yes';
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}, { timeout: 30000 });
|
||||
}
|
||||
};
|
||||
78
gaia/tests/jsmarionette/plugins/marionette-apps/lib/close.js
Executable file
78
gaia/tests/jsmarionette/plugins/marionette-apps/lib/close.js
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
'use strict';
|
||||
var switchToApp = require('./switchtoapp').switchToApp;
|
||||
|
||||
/**
|
||||
* Small search timeout for faster polling.
|
||||
* @const {number}
|
||||
*/
|
||||
var SEARCH_TIMEOUT = 100;
|
||||
|
||||
/**
|
||||
* Close a currently running application.
|
||||
*
|
||||
* @param {Apps} apps state.
|
||||
* @param {String} origin of the application.
|
||||
* @param {String} [entrypoint] of the application.
|
||||
* @param {Function} callback [Error err].
|
||||
*/
|
||||
function close(apps, origin, entrypoint, callback) {
|
||||
if (typeof entrypoint === 'function') {
|
||||
callback = entrypoint;
|
||||
entrypoint = null;
|
||||
}
|
||||
|
||||
// populated during the app switch contains the "App" instance.
|
||||
var appInstance;
|
||||
|
||||
var client = apps._client.scope({
|
||||
searchTimeout: SEARCH_TIMEOUT
|
||||
});
|
||||
|
||||
/**
|
||||
* Go back to root frame now that app is closed.
|
||||
*/
|
||||
function switchToRoot(app, err) {
|
||||
if (err) return callback(err);
|
||||
client.switchToFrame(waitUntilClosed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the iframe with the origin is no longer in the dom tree.
|
||||
*/
|
||||
function waitUntilClosed(err) {
|
||||
if (err) return callback(err);
|
||||
|
||||
var query = 'iframe[src*="' + appInstance.source + '"]';
|
||||
// wait until the element has been removed.
|
||||
client.waitFor(function(done) {
|
||||
// poll until it's gone
|
||||
client.findElement(query, function(err) {
|
||||
// no element is found is the success condition.
|
||||
if (err && err.type === 'NoSuchElement') {
|
||||
return done(null, true);
|
||||
}
|
||||
|
||||
// error or element still exists...
|
||||
done(err, false);
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
|
||||
|
||||
// switch to root context
|
||||
client.switchToFrame();
|
||||
|
||||
// find the app we are looking for
|
||||
return switchToApp(apps, origin, entrypoint, function(err, el, app) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// used in the following callbacks to ensure the right frame is closed.
|
||||
appInstance = app;
|
||||
|
||||
return client.executeScript(function() { window.close(); }, switchToRoot);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.close = close;
|
||||
22
gaia/tests/jsmarionette/plugins/marionette-apps/lib/geckoobject.js
Executable file
22
gaia/tests/jsmarionette/plugins/marionette-apps/lib/geckoobject.js
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
'use strict';
|
||||
/**
|
||||
* @fileoverview A base class for WebApi objects like App that get shared
|
||||
* between gecko and node.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function GeckoObject() {
|
||||
}
|
||||
module.exports = GeckoObject;
|
||||
|
||||
|
||||
GeckoObject.prototype = {
|
||||
/**
|
||||
* Id for objects that allows them to be identified across gecko and node.
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
_id: ''
|
||||
};
|
||||
139
gaia/tests/jsmarionette/plugins/marionette-apps/lib/getapp.js
Executable file
139
gaia/tests/jsmarionette/plugins/marionette-apps/lib/getapp.js
Executable file
|
|
@ -0,0 +1,139 @@
|
|||
'use strict';
|
||||
var fsPath = require('path'),
|
||||
list = require('./list').list,
|
||||
url = require('url');
|
||||
|
||||
/**
|
||||
* Creates the expected source of a app iframe.
|
||||
*
|
||||
* @param {App} app object to get source from.
|
||||
* @private
|
||||
*/
|
||||
function sourceForEntrypoint(app) {
|
||||
var origin = app.origin;
|
||||
var launchPath = app.entrypoint.details.launch_path;
|
||||
|
||||
var urlParts = url.parse(origin);
|
||||
|
||||
// Handle hashes in the launchPath
|
||||
if (launchPath.indexOf('#') !== -1) {
|
||||
var hashParts = launchPath.split('#');
|
||||
launchPath = hashParts[0];
|
||||
urlParts.hash = hashParts[1];
|
||||
}
|
||||
|
||||
urlParts.pathname = fsPath.join(urlParts.pathname || '/', launchPath);
|
||||
return url.format(urlParts);
|
||||
}
|
||||
|
||||
function sourceForActivity(app, activityHref) {
|
||||
var origin = app.origin;
|
||||
var activities = app.manifest.activities;
|
||||
var isHrefValid = false;
|
||||
|
||||
for (var key in activities) {
|
||||
if (activities[key].href === activityHref) {
|
||||
isHrefValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isHrefValid) {
|
||||
throw new Error(origin + ' does not contain the href ' + activityHref);
|
||||
}
|
||||
|
||||
return origin + activityHref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a given app by its origin and optionally an entrypoint.
|
||||
*
|
||||
* @param {Object} state current app state.
|
||||
* @param {String} origin of the app.
|
||||
* @param {String} [entrypoint] of the app.
|
||||
* @param {Function} callback [Error, App].
|
||||
*/
|
||||
function getApp(state, origin, entrypoint, callback) {
|
||||
if (typeof entrypoint === 'function') {
|
||||
callback = entrypoint;
|
||||
entrypoint = null;
|
||||
}
|
||||
|
||||
callback = callback || state._client.defaultCallback;
|
||||
|
||||
return getAppWithCheckOnOriginOnly(state, origin, function(err, originApp) {
|
||||
if (err) {
|
||||
return callback && callback(err);
|
||||
}
|
||||
|
||||
originApp.source = origin;
|
||||
|
||||
if (entrypoint) {
|
||||
// verify this is a valid entrypoint
|
||||
var details = originApp.manifest.entry_points[entrypoint];
|
||||
if (!details) {
|
||||
return callback(new Error('invalid entrypoint "' + entrypoint + '"'));
|
||||
}
|
||||
|
||||
// add sugar for the apps entrypoint instance.
|
||||
originApp = Object.create(originApp);
|
||||
|
||||
originApp.entrypoint = {
|
||||
name: entrypoint,
|
||||
details: details
|
||||
};
|
||||
|
||||
// must come after the entrypoint assignment
|
||||
originApp.source = sourceForEntrypoint(originApp);
|
||||
}
|
||||
|
||||
return callback(null, originApp);
|
||||
});
|
||||
}
|
||||
|
||||
function getActivity(state, origin, activityHref, callback) {
|
||||
if (typeof activityHref === 'function') {
|
||||
callback = activityHref;
|
||||
activityHref = null;
|
||||
}
|
||||
|
||||
return getAppWithCheckOnOriginOnly(state, origin, function(err, originApp) {
|
||||
if (err) {
|
||||
return callback && callback(err);
|
||||
}
|
||||
|
||||
originApp.source = sourceForActivity(originApp, activityHref);
|
||||
return callback(null, originApp);
|
||||
});
|
||||
}
|
||||
|
||||
function getAppWithCheckOnOriginOnly(state, origin, callback) {
|
||||
callback = callback || state._client.defaultCallback;
|
||||
|
||||
var originApp;
|
||||
return list(state, function(err, apps) {
|
||||
|
||||
if (err) {
|
||||
return callback && callback(err);
|
||||
}
|
||||
|
||||
for (var i = 0, len = apps.length; i < len; i++) {
|
||||
if (apps[i].origin === origin) {
|
||||
originApp = apps[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!originApp) {
|
||||
return callback(
|
||||
new Error('could not find an app with the origin: "' + origin + '"')
|
||||
);
|
||||
}
|
||||
|
||||
originApp.source = origin;
|
||||
return callback(null, originApp);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.getApp = getApp;
|
||||
module.exports.getActivity = getActivity;
|
||||
module.exports.sourceForEntrypoint = sourceForEntrypoint;
|
||||
16
gaia/tests/jsmarionette/plugins/marionette-apps/lib/getself.js
Executable file
16
gaia/tests/jsmarionette/plugins/marionette-apps/lib/getself.js
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
/**
|
||||
* Returns information about the current app.
|
||||
*
|
||||
* apps.getSelf(apps, function(err, app) {
|
||||
* app.origin; // origin of a given app
|
||||
* });
|
||||
*
|
||||
* @param {Apps} apps state.
|
||||
* @param {Function} callback [Err err, <App> app].
|
||||
*/
|
||||
function getSelf(apps, callback) {
|
||||
return apps.getSelf(callback);
|
||||
}
|
||||
|
||||
module.exports.getSelf = getSelf;
|
||||
49
gaia/tests/jsmarionette/plugins/marionette-apps/lib/launch.js
Executable file
49
gaia/tests/jsmarionette/plugins/marionette-apps/lib/launch.js
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
'use strict';
|
||||
var getApp = require('./getapp').getApp;
|
||||
var waitForApp = require('./waitforapp').waitForApp;
|
||||
|
||||
/**
|
||||
* Launch an application based on its origin and optionally entrypoint.
|
||||
* Will wait until app's iframe is visible before firing callback.
|
||||
*
|
||||
* launch(apps, 'app://calendar.gaiamobile.org', function(err, app) {
|
||||
* // yey
|
||||
* });
|
||||
*
|
||||
* @param {Apps} apps instance.
|
||||
* @param {String} origin of the app.
|
||||
* @param {String} [entrypoint] for the app.
|
||||
* @param {Function} callback [Error err, App app].
|
||||
*/
|
||||
function launch(apps, origin, entrypoint, callback) {
|
||||
if (typeof entrypoint === 'function') {
|
||||
callback = entrypoint;
|
||||
entrypoint = null;
|
||||
}
|
||||
|
||||
callback = callback || apps._client.defaultCallback;
|
||||
|
||||
// Wait for the system to be fully loaded.
|
||||
var client = apps._client;
|
||||
var body = client.findElement('body');
|
||||
client.waitFor(function() {
|
||||
return body.getAttribute('ready-state') == 'fullyLoaded';
|
||||
}, { timeout: 60000 });
|
||||
|
||||
// launch the given app
|
||||
return getApp(apps, origin, entrypoint, function(err, app) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// if a null entrypoint is given it is safely ignored.
|
||||
app.launch(entrypoint);
|
||||
|
||||
// wait for this app to be visible
|
||||
return waitForApp(apps, app.source, function(err, element) {
|
||||
return callback(err, app, element);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.launch = launch;
|
||||
18
gaia/tests/jsmarionette/plugins/marionette-apps/lib/list.js
Executable file
18
gaia/tests/jsmarionette/plugins/marionette-apps/lib/list.js
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
/**
|
||||
* Find all apps.
|
||||
*
|
||||
* apps.list(apps, function(err, list) {
|
||||
* // list is an array of "Apps"
|
||||
* list[0].origin; // origin of a given app
|
||||
* });
|
||||
*
|
||||
* @param {Apps} apps state.
|
||||
* @param {Function} callback [Err err, Array<App> apps].
|
||||
* @return {Array}
|
||||
*/
|
||||
function list(apps, callback) {
|
||||
return apps.mgmt.getAll(callback);
|
||||
}
|
||||
|
||||
module.exports.list = list;
|
||||
107
gaia/tests/jsmarionette/plugins/marionette-apps/lib/mgmt.js
Executable file
107
gaia/tests/jsmarionette/plugins/marionette-apps/lib/mgmt.js
Executable file
|
|
@ -0,0 +1,107 @@
|
|||
'use strict';
|
||||
var App = require(__dirname + '/app'),
|
||||
fs = require('fs');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Marionette.Client} client Marionette client to use.
|
||||
*/
|
||||
function Mgmt(client) {
|
||||
this._client = client;
|
||||
}
|
||||
module.exports = Mgmt;
|
||||
|
||||
|
||||
Mgmt.prototype = {
|
||||
/**
|
||||
* @type {Marionette.Client}
|
||||
* @private
|
||||
*/
|
||||
_client: undefined,
|
||||
|
||||
_formatApp: function(client, data) {
|
||||
var app = new App(client);
|
||||
for (var key in data) {
|
||||
app[key] = data[key];
|
||||
}
|
||||
return app;
|
||||
},
|
||||
|
||||
/**
|
||||
* List all installed apps in the user's repository.
|
||||
*
|
||||
* @param {Function} callback [Error, Array<App>].
|
||||
*/
|
||||
getAll: function(callback) {
|
||||
callback = callback || this._client.defaultCallback;
|
||||
|
||||
var script = fs.readFileSync(
|
||||
__dirname + '/scripts/getallapps.js',
|
||||
'utf8'
|
||||
);
|
||||
|
||||
var client = this._client.scope({ context: 'content' });
|
||||
var format = this._formatApp.bind(this, client);
|
||||
|
||||
return client.executeAsyncScript(script, function(err, operation) {
|
||||
// handle scripting error
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// handle error from operation
|
||||
if (operation.error) {
|
||||
return callback(new Error(operation.error));
|
||||
}
|
||||
|
||||
// success format the apps
|
||||
var apps = operation.result.map(format);
|
||||
return callback(null, apps);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns information about the calling app, if any.
|
||||
* @param {Function} callback [Error, Array<App>].
|
||||
*/
|
||||
getSelf: function(callback) {
|
||||
callback = callback || this._client.defaultCallback;
|
||||
|
||||
var script = fs.readFileSync(
|
||||
__dirname + '/scripts/getself.js',
|
||||
'utf8'
|
||||
);
|
||||
|
||||
var client = this._client.scope({ context: 'content' });
|
||||
var format = this._formatApp.bind(this, client);
|
||||
|
||||
return client.executeAsyncScript(script, function(err, operation) {
|
||||
// handle scripting error
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// handle error from operation
|
||||
if (operation.error) {
|
||||
return callback(new Error(operation.error));
|
||||
}
|
||||
|
||||
// success format the app
|
||||
return callback(null, operation.result ? format(operation.result) : null);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Inject utility functions into gecko through the marionette client.
|
||||
* @param {Function} cb Optional callback function.
|
||||
*/
|
||||
prepareClient: function(cb) {
|
||||
var script = fs.readFileSync(
|
||||
__dirname + '/scripts/objectcache.js',
|
||||
'utf8'
|
||||
);
|
||||
|
||||
this._client.importScript(script, cb);
|
||||
}
|
||||
};
|
||||
48
gaia/tests/jsmarionette/plugins/marionette-apps/lib/scripts/getallapps.js
Executable file
48
gaia/tests/jsmarionette/plugins/marionette-apps/lib/scripts/getallapps.js
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Take an app from a DOMRequest and serialize it to send back
|
||||
* to the client.
|
||||
* @return {Object} App representation.
|
||||
*/
|
||||
function serialize(app) {
|
||||
return {
|
||||
installOrigin: app.installOrigin,
|
||||
installTime: app.installTime,
|
||||
// sync transfer of the entire manifest is slow so for now opt in to the
|
||||
// fields we actually need internally.
|
||||
manifest: {
|
||||
entry_points: app.manifest.entry_points,
|
||||
activities: app.manifest.activities
|
||||
},
|
||||
manifestURL: app.manifestURL,
|
||||
origin: app.origin,
|
||||
receipts: app.receipts
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var ObjectCache = window.wrappedJSObject.ObjectCache;
|
||||
|
||||
var req = navigator.mozApps.mgmt.getAll();
|
||||
req.onsuccess = function(evt) {
|
||||
var result = evt.target.result;
|
||||
var apps = result.map(function(app) {
|
||||
var id = ObjectCache._inst.set(app);
|
||||
var obj = serialize(app);
|
||||
obj._id = id;
|
||||
return obj;
|
||||
});
|
||||
|
||||
marionetteScriptFinished({
|
||||
result: apps
|
||||
});
|
||||
};
|
||||
|
||||
req.onerror = function(evt) {
|
||||
marionetteScriptFinished({
|
||||
error: req.error.name
|
||||
});
|
||||
};
|
||||
})();
|
||||
42
gaia/tests/jsmarionette/plugins/marionette-apps/lib/scripts/getself.js
Executable file
42
gaia/tests/jsmarionette/plugins/marionette-apps/lib/scripts/getself.js
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
(function() {
|
||||
|
||||
/* global marionetteScriptFinished */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Take an app from a DOMRequest and serialize it to send back
|
||||
* to the client.
|
||||
* @return {Object} App representation.
|
||||
*/
|
||||
function serialize(app) {
|
||||
return {
|
||||
installOrigin: app.installOrigin,
|
||||
installTime: app.installTime,
|
||||
// sync transfer of the entire manifest is slow so for now opt in to the
|
||||
// fields we actually need internally.
|
||||
manifest: {
|
||||
entry_points: app.manifest.entry_points
|
||||
},
|
||||
manifestURL: app.manifestURL,
|
||||
origin: app.origin,
|
||||
receipts: app.receipts
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var ObjectCache = window.wrappedJSObject.ObjectCache;
|
||||
|
||||
var req = navigator.mozApps.getSelf();
|
||||
req.onsuccess = function(evt) {
|
||||
var app = evt.target.result;
|
||||
var id = ObjectCache._inst.set(app);
|
||||
var obj = serialize(app);
|
||||
obj._id = id;
|
||||
marionetteScriptFinished({ result: obj });
|
||||
};
|
||||
|
||||
req.onerror = function(evt) {
|
||||
marionetteScriptFinished({ error: req.error.name });
|
||||
};
|
||||
})();
|
||||
64
gaia/tests/jsmarionette/plugins/marionette-apps/lib/scripts/objectcache.js
Executable file
64
gaia/tests/jsmarionette/plugins/marionette-apps/lib/scripts/objectcache.js
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
if (window.wrappedJSObject.ObjectCache !== undefined) {
|
||||
// Don't redefine ObjectCache!
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function ObjectCache() {
|
||||
}
|
||||
|
||||
|
||||
ObjectCache.prototype = {
|
||||
/**
|
||||
* Find the gecko object that corresponds to some node object.
|
||||
* @param {string} key Some id.
|
||||
*/
|
||||
get: function(key) {
|
||||
return this._cache[key];
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Add some gecko object to the client's object cache.
|
||||
* @param {Object} obj Gecko object.
|
||||
* @param {string} opt_key Optional key to store obj on.
|
||||
* @return {string} The key that we end up storing obj on.
|
||||
*/
|
||||
set: function(obj, opt_key) {
|
||||
var key = opt_key || this.getNextId();
|
||||
this._cache[key] = obj;
|
||||
return key;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Generate a new, unique id.
|
||||
* @return {string}
|
||||
*/
|
||||
getNextId: function() {
|
||||
this._nextId += 1;
|
||||
return this._nextId.toString();
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Map from id to gecko objects.
|
||||
* @type {Object<string, Object>}
|
||||
*/
|
||||
_cache: {},
|
||||
|
||||
|
||||
/**
|
||||
* @type {number} Count of number of ids we've generated.
|
||||
*/
|
||||
_nextId: 0
|
||||
};
|
||||
|
||||
ObjectCache._inst = new ObjectCache();
|
||||
window.wrappedJSObject.ObjectCache = ObjectCache;
|
||||
})();
|
||||
39
gaia/tests/jsmarionette/plugins/marionette-apps/lib/switchtoactivity.js
Executable file
39
gaia/tests/jsmarionette/plugins/marionette-apps/lib/switchtoactivity.js
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
'use strict';
|
||||
var getActivity = require('./getapp').getActivity;
|
||||
var waitForActivity = require('./waitforapp').waitForActivity;
|
||||
|
||||
/**
|
||||
* Switch focus to an app that is run as inline activity based on the origin.
|
||||
* @param {Apps} apps to manage state.
|
||||
* @param {String} origin of the application.
|
||||
* @param {String} [activityHref] of the activity.
|
||||
* @param {Function} callback [Error err].
|
||||
*/
|
||||
function switchToActivity(apps, origin, activityHref, callback) {
|
||||
if (typeof activityHref === 'function') {
|
||||
callback = activityHref;
|
||||
activityHref = null;
|
||||
}
|
||||
|
||||
var client = apps._client;
|
||||
callback = callback || client.defaultCallback;
|
||||
|
||||
return getActivity(apps, origin, activityHref, function(err, app) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
return waitForActivity(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.switchToActivity = switchToActivity;
|
||||
42
gaia/tests/jsmarionette/plugins/marionette-apps/lib/switchtoapp.js
Executable file
42
gaia/tests/jsmarionette/plugins/marionette-apps/lib/switchtoapp.js
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
'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;
|
||||
85
gaia/tests/jsmarionette/plugins/marionette-apps/lib/waitforapp.js
Executable file
85
gaia/tests/jsmarionette/plugins/marionette-apps/lib/waitforapp.js
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
'use strict';
|
||||
/**
|
||||
* @const {number}
|
||||
*/
|
||||
var SEARCH_TIMEOUT = 10000;
|
||||
|
||||
function assertDriverIsSync(client) {
|
||||
if (!client.isSync) {
|
||||
throw new Error('No longer support async driver. Please use sync driver.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the app is visible.
|
||||
* @param {Apps} apps state.
|
||||
* @param {String} source to wait for.
|
||||
* @param {Function} callback [Err error, Marionette.Element el].
|
||||
*/
|
||||
function waitForApp(apps, source, callback) {
|
||||
var client = apps._client.scope({ searchTimeout: SEARCH_TIMEOUT });
|
||||
callback = callback || client.defaultCallback;
|
||||
|
||||
assertDriverIsSync(client);
|
||||
waitForAppSync(
|
||||
client, '#windows iframe[src*="' + source + '"]', callback
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until the app that is run as inline activity becomes visible.
|
||||
* @param {Apps} apps state.
|
||||
* @param {String} source to wait for.
|
||||
* @param {Function} callback [Err error, Marionette.Element el].
|
||||
*/
|
||||
function waitForActivity(apps, source, callback) {
|
||||
var client = apps._client.scope({ searchTimeout: SEARCH_TIMEOUT });
|
||||
callback = callback || client.defaultCallback;
|
||||
|
||||
assertDriverIsSync(client);
|
||||
waitForAppSync(
|
||||
client, '#windows iframe[src*="' + source + '"][parentapp]', callback
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wait until the app is visible using a sync driver.
|
||||
* @param {Marionette.Client} client with sync driver.
|
||||
* @param {String} source to wait for.
|
||||
* @param {Function} callback [Err error, Marionette.Element el].
|
||||
*/
|
||||
function waitForAppSync(client, sourceSelector, callback) {
|
||||
var el = client.findElement(sourceSelector);
|
||||
|
||||
// Wait for the iframe is rendered.
|
||||
client.waitFor(function() {
|
||||
var frameClass = el.scriptWith(function(el) {
|
||||
return el.parentNode.parentNode.getAttribute('class');
|
||||
});
|
||||
|
||||
if (frameClass !== null) {
|
||||
return frameClass.indexOf('render') !== -1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for the iframe is displayed on screen.
|
||||
client.waitFor(function() {
|
||||
var transitionState = el.scriptWith(function(el) {
|
||||
return el.parentNode.parentNode.getAttribute('transition-state');
|
||||
});
|
||||
|
||||
if (transitionState !== null) {
|
||||
return transitionState === 'opened';
|
||||
} else {
|
||||
return el.displayed();
|
||||
}
|
||||
});
|
||||
|
||||
callback && callback(null, el);
|
||||
}
|
||||
|
||||
module.exports.waitForApp = waitForApp;
|
||||
module.exports.waitForActivity = waitForActivity;
|
||||
Loading…
Reference in a new issue