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
66
gaia/tests/jsmarionette/plugins/marionette-apps/examples/launch.js
Executable file
66
gaia/tests/jsmarionette/plugins/marionette-apps/examples/launch.js
Executable file
|
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @fileoverview An example that shows how to use the MarionetteApps plugin
|
||||
* to get a list of the installed apps and launch one.
|
||||
*/
|
||||
var Host = require('marionette-host-environment'),
|
||||
Marionette = require('marionette-client'),
|
||||
path = require('path');
|
||||
|
||||
|
||||
/**
|
||||
* Options to setup our b2g instance with.
|
||||
* @type {Object}
|
||||
*/
|
||||
var OPTIONS = {
|
||||
settings: {
|
||||
'ftu.manifestURL': null,
|
||||
'lockscreen.enabled': false
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* File path to B2G.
|
||||
* @const {string}
|
||||
*/
|
||||
var B2G_PATH = path.resolve(__dirname, '../b2g');
|
||||
|
||||
|
||||
/**
|
||||
* Origin URL for the calendar app.
|
||||
* @const {string}
|
||||
*/
|
||||
var CALENDAR_URL = 'app://calendar.gaiamobile.org';
|
||||
|
||||
|
||||
/**
|
||||
* Gets called once we have a child process booted with Firefox OS.
|
||||
* @param {Marionette.Client} client Marionette client to use.
|
||||
* @param {ChildProcess} childProcess Child process running b2g.
|
||||
*/
|
||||
function demo(client, childProcess) {
|
||||
client.apps.launch(CALENDAR_URL, function() {
|
||||
setTimeout(childProcess.kill.bind(childProcess), 5000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Bring up a b2g desktop instance.
|
||||
Host.spawn(B2G_PATH, OPTIONS, function(err, port, childProcess) {
|
||||
if (process.env.DEBUG) {
|
||||
childProcess.stdout.pipe(process.stdout);
|
||||
}
|
||||
|
||||
// Connect to the marionette server.
|
||||
var driver = new Marionette.Drivers.TcpSync({ port: port });
|
||||
driver.connect(function() {
|
||||
// Wrap the marionette connection with a client that we can pass
|
||||
// to our plugin.
|
||||
var client = new Marionette.Client(driver);
|
||||
client.plugin('apps', require('../index'));
|
||||
client.startSession(demo.bind(null, client, childProcess));
|
||||
});
|
||||
});
|
||||
43
gaia/tests/jsmarionette/plugins/marionette-apps/index.js
Executable file
43
gaia/tests/jsmarionette/plugins/marionette-apps/index.js
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
var Apps = require('./lib/apps');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Apps} apps private marionette apps api.
|
||||
*/
|
||||
function MarionetteApps(apps) {
|
||||
for (var key in MarionetteApps.ModuleToFunction) {
|
||||
var methodName = MarionetteApps.ModuleToFunction[key];
|
||||
var module = require('./lib/' + key);
|
||||
// bind the public interface to the object
|
||||
this[methodName] = module[methodName].bind(null, apps);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of public modules to expose to the main interface.
|
||||
* Key is module, value is function on the module.
|
||||
*/
|
||||
MarionetteApps.ModuleToFunction = {
|
||||
close: 'close',
|
||||
launch: 'launch',
|
||||
list: 'list',
|
||||
switchtoapp: 'switchToApp',
|
||||
switchtoactivity: 'switchToActivity',
|
||||
getapp: 'getApp',
|
||||
getself: 'getSelf'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a new marionette apps plugin.
|
||||
* @param {Marionette.Client} client marionette client to use.
|
||||
* @param {Objects} options optional configuration.
|
||||
* @return {MarionetteApps} new marionette apps.
|
||||
*/
|
||||
function setup(client, options) {
|
||||
var apps = Apps.setup(client, options);
|
||||
return new MarionetteApps(apps);
|
||||
}
|
||||
|
||||
exports.setup = setup;
|
||||
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;
|
||||
5
gaia/tests/jsmarionette/plugins/marionette-apps/package.json
Executable file
5
gaia/tests/jsmarionette/plugins/marionette-apps/package.json
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "marionette-apps",
|
||||
"version": "0.3.13",
|
||||
"author": "Gareth Aye <gaye@mozilla.com>"
|
||||
}
|
||||
64
gaia/tests/jsmarionette/plugins/marionette-apps/test/app_test.js
Executable file
64
gaia/tests/jsmarionette/plugins/marionette-apps/test/app_test.js
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('App', function() {
|
||||
var subject;
|
||||
var client = marionette.client();
|
||||
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
|
||||
suite('#launch', function() {
|
||||
var context;
|
||||
|
||||
var CALENDAR_URL = 'app://calendar.gaiamobile.org';
|
||||
setup(function(done) {
|
||||
client.mozApps.mgmt.getAll(function(err, result) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
var app = result[i];
|
||||
if (app.origin === CALENDAR_URL) {
|
||||
subject = app;
|
||||
context = client.context;
|
||||
subject.launch();
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('should launch the appropriate app', function(done) {
|
||||
/**
|
||||
* @param {string} app src for app.
|
||||
*/
|
||||
function checkForApp(app) {
|
||||
var selector = 'iframe[src="' + app + '"]';
|
||||
|
||||
if (client.isSync) {
|
||||
client.setSearchTimeout(10000);
|
||||
var result = client.findElement(selector);
|
||||
assert.notEqual(result.id, undefined);
|
||||
done();
|
||||
} else {
|
||||
client
|
||||
.setSearchTimeout(10000)
|
||||
.findElement(selector, function(err, result) {
|
||||
assert.notEqual(result.id, undefined);
|
||||
done();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (client.context !== 'content') {
|
||||
client.setContext('content');
|
||||
}
|
||||
checkForApp(CALENDAR_URL + '/index.html');
|
||||
});
|
||||
|
||||
test('should not change client context', function() {
|
||||
assert.strictEqual(client.context, context);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Activity Callee App</title>
|
||||
<script defer src="/js/index.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>I am Test Activity Callee App</div>
|
||||
<button id="close-activity" type="button">Close Activity</button>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
window.navigator.mozSetMessageHandler('activity', function(activity) {
|
||||
var closeActivityButton = document.getElementById('close-activity');
|
||||
|
||||
closeActivityButton.addEventListener('click', function() {
|
||||
activity.postResult({
|
||||
type: 'x-type/blob',
|
||||
blob: new Blob()
|
||||
});
|
||||
});
|
||||
});
|
||||
})(window);
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "Test Activity Callee App",
|
||||
"description": "Test Activity Callee App",
|
||||
"type": "certified",
|
||||
"launch_path": "/index.html",
|
||||
"activities": {
|
||||
"pick": {
|
||||
"filters": {
|
||||
"type": ["x-type/*"]
|
||||
},
|
||||
"disposition": "inline",
|
||||
"returnValue": true,
|
||||
"href": "/index.html#x-activity"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Activity Caller App</title>
|
||||
<script defer src="/js/index.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>Test Activity Caller App</div>
|
||||
<button id="open-activity">Open Activity</button>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/* global MozActivity */
|
||||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
var openActivityButton = document.getElementById('open-activity');
|
||||
|
||||
openActivityButton.addEventListener('click', function() {
|
||||
var activity = new MozActivity({
|
||||
name: 'pick',
|
||||
data: {
|
||||
type: 'x-type/*'
|
||||
}
|
||||
});
|
||||
|
||||
activity.onerror = function() {
|
||||
console.warn('Pick activity error %s', activity.error.name);
|
||||
};
|
||||
});
|
||||
});
|
||||
})(window);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "Test Activity Caller App",
|
||||
"description": "Test Activity Caller App",
|
||||
"type": "certified",
|
||||
"launch_path": "/index.html"
|
||||
}
|
||||
32
gaia/tests/jsmarionette/plugins/marionette-apps/test/apps_test.js
Executable file
32
gaia/tests/jsmarionette/plugins/marionette-apps/test/apps_test.js
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
/* global marionette */
|
||||
|
||||
var Apps = require('../lib/apps');
|
||||
var App = require('../lib/app');
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('Apps', function() {
|
||||
var client = marionette.client();
|
||||
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
|
||||
suite('#setup', function() {
|
||||
test('should return an App with a _client', function() {
|
||||
assert.ok(client.mozApps instanceof Apps);
|
||||
assert.strictEqual(client.mozApps._client, client);
|
||||
});
|
||||
});
|
||||
|
||||
suite('#getSelf', function() {
|
||||
test('should return a current app', function(done) {
|
||||
client.mozApps.getSelf(function(err, app) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.ok(app instanceof App, 'app instanceof App');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
68
gaia/tests/jsmarionette/plugins/marionette-apps/test/close_test.js
Executable file
68
gaia/tests/jsmarionette/plugins/marionette-apps/test/close_test.js
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('close', function() {
|
||||
// requires
|
||||
var Apps = require('../lib/apps'),
|
||||
close = require('../lib/close').close,
|
||||
launch = require('../lib/launch').launch,
|
||||
client = marionette.client();
|
||||
|
||||
marionette.plugin('mozApps', Apps);
|
||||
|
||||
suite('close app', function() {
|
||||
var origin = 'app://calendar.gaiamobile.org';
|
||||
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, origin, done);
|
||||
});
|
||||
|
||||
setup(function(done) {
|
||||
close(client.mozApps, origin, done);
|
||||
});
|
||||
|
||||
test('iframe is gone', function(done) {
|
||||
client.setSearchTimeout(100);
|
||||
client.findElement('iframe[src*="' + origin + '"]', function(err, el) {
|
||||
assert.ok(err, 'has error');
|
||||
assert.equal(err.type, 'NoSuchElement', 'element is missing');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('close entrypoint app', function() {
|
||||
var origin = 'app://communications.gaiamobile.org';
|
||||
|
||||
// launch some other entrypoint
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, origin, 'dialer', done);
|
||||
});
|
||||
|
||||
// launch contacts (which we will close later)
|
||||
var contacts;
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, origin, 'contacts', function(err, app) {
|
||||
contacts = app;
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
setup(function(done) {
|
||||
close(client.mozApps, origin, 'contacts', done);
|
||||
});
|
||||
|
||||
test('closes right app', function(done) {
|
||||
var source = origin + '/' + contacts.entrypoint.details.launch_path;
|
||||
|
||||
client.setSearchTimeout(100);
|
||||
client.findElement('iframe[src*="' + source + '"]', function(err, el) {
|
||||
assert.ok(err, 'has error');
|
||||
assert.equal(err.type, 'NoSuchElement', 'element is missing');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
97
gaia/tests/jsmarionette/plugins/marionette-apps/test/getapp_test.js
Executable file
97
gaia/tests/jsmarionette/plugins/marionette-apps/test/getapp_test.js
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('getapp', function() {
|
||||
var getApp = require('../lib/getapp').getApp;
|
||||
var sourceForEntrypoint = require('../lib/getapp').sourceForEntrypoint;
|
||||
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
var client = marionette.client();
|
||||
|
||||
var calendarOrigin = 'app://calendar.gaiamobile.org';
|
||||
|
||||
test('success origin', function(done) {
|
||||
getApp(client.mozApps, calendarOrigin, function(err, app) {
|
||||
assert.equal(app.origin, calendarOrigin, 'origin');
|
||||
assert.equal(app.source, calendarOrigin, 'source');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('missing origin', function(done) {
|
||||
var origin = 'xfoobarbaz';
|
||||
getApp(client.mozApps, origin, function(err) {
|
||||
assert.ok(err, 'has error');
|
||||
assert.ok(err.message.match(origin, 'has correct type of error'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('sourceForEntrypoint does not escape hash', function(done) {
|
||||
var source = sourceForEntrypoint({
|
||||
origin: 'http://mozilla.org',
|
||||
entrypoint: {
|
||||
details: {
|
||||
launch_path: 'omfg#bbq'
|
||||
}
|
||||
}
|
||||
});
|
||||
assert.equal(source, 'http://mozilla.org/omfg#bbq');
|
||||
|
||||
var origin = 'app://communications.gaiamobile.org';
|
||||
var entryPoint = 'dialer';
|
||||
|
||||
getApp(client.mozApps, origin, entryPoint, function(err, app) {
|
||||
assert.notEqual(app.source.indexOf('#'), -1, 'source');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('entrypoint apps', function() {
|
||||
var origin = 'app://communications.gaiamobile.org';
|
||||
var app;
|
||||
|
||||
// get the app without the entrypoint
|
||||
setup(function(done) {
|
||||
app = getApp(client.mozApps, origin, function(err, _app) {
|
||||
app = _app;
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('success', function(done) {
|
||||
getApp(client.mozApps, origin, 'contacts', function(err, contacts) {
|
||||
assert.deepEqual(
|
||||
contacts.entrypoint,
|
||||
{
|
||||
name: 'contacts',
|
||||
details: app.manifest.entry_points.contacts
|
||||
},
|
||||
'entrypoint'
|
||||
);
|
||||
|
||||
var launchPath = contacts.entrypoint.details.launch_path;
|
||||
|
||||
assert.ok(contacts.source.indexOf(origin) !== -1, 'has origin');
|
||||
assert.ok(
|
||||
contacts.source.indexOf(launchPath) !== -1,
|
||||
'has launchPath'
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('failure', function(done) {
|
||||
var entrypoint = 'epicfail';
|
||||
getApp(client.mozApps, origin, entrypoint, function(err) {
|
||||
assert.ok(err, 'has error');
|
||||
assert.ok(
|
||||
err.message.match(entrypoint),
|
||||
'error message contains: ' + entrypoint
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
44
gaia/tests/jsmarionette/plugins/marionette-apps/test/getself_test.js
Executable file
44
gaia/tests/jsmarionette/plugins/marionette-apps/test/getself_test.js
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
/* global marionette, setup */
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('getself', function() {
|
||||
var getSelf = require('../lib/getself').getSelf;
|
||||
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
var client = marionette.client();
|
||||
|
||||
var origins = {
|
||||
system: 'app://system.gaiamobile.org',
|
||||
calendar: 'app://calendar.gaiamobile.org'
|
||||
};
|
||||
|
||||
function testCurrentApp(origin) {
|
||||
test('current app self', function(done) {
|
||||
getSelf(client.mozApps, function(err, app) {
|
||||
assert.equal(app.origin, origins[origin], origin + ' origin');
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testCurrentApp('system');
|
||||
|
||||
suite('switch app', function() {
|
||||
setup(function(done) {
|
||||
if (client.isSync) {
|
||||
client.apps.launch(origins.calendar);
|
||||
client.apps.switchToApp(origins.calendar);
|
||||
done();
|
||||
} else {
|
||||
client.apps.launch(origins.calendar, function() {
|
||||
client.apps.switchToApp(origins.calendar, done);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
testCurrentApp('calendar');
|
||||
});
|
||||
});
|
||||
165
gaia/tests/jsmarionette/plugins/marionette-apps/test/index_test.js
Executable file
165
gaia/tests/jsmarionette/plugins/marionette-apps/test/index_test.js
Executable file
|
|
@ -0,0 +1,165 @@
|
|||
'use strict';
|
||||
|
||||
/* global marionette, setup */
|
||||
|
||||
var App = require('../lib/app');
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('public interface', function() {
|
||||
var client = marionette.client();
|
||||
marionette.plugin('apps', require('../index'));
|
||||
|
||||
suite('#launch', function() {
|
||||
var appOrigin = 'app://calendar.gaiamobile.org';
|
||||
var selector = 'iframe[src*="calendar"]';
|
||||
|
||||
setup(function(done) {
|
||||
if (client.isSync) {
|
||||
client.apps.launch(appOrigin);
|
||||
done();
|
||||
} else {
|
||||
client.apps.launch(appOrigin, done);
|
||||
}
|
||||
});
|
||||
|
||||
test('should create the appropriate app iframe', function(done) {
|
||||
function checkElement(err, el) {
|
||||
assert.ok(!err);
|
||||
assert.ok(!!el);
|
||||
done();
|
||||
}
|
||||
|
||||
client.scope({ searchTimeout: 1000 });
|
||||
if (client.isSync) {
|
||||
var el = client.findElement(selector);
|
||||
checkElement(null, el);
|
||||
} else {
|
||||
client.findElement(selector, checkElement);
|
||||
}
|
||||
});
|
||||
|
||||
suite('#switchToApp', function() {
|
||||
setup(function(done) {
|
||||
if (client.isSync) {
|
||||
client.apps.switchToApp(appOrigin);
|
||||
done();
|
||||
} else {
|
||||
client.apps.switchToApp(appOrigin, done);
|
||||
}
|
||||
});
|
||||
|
||||
test('should put us in the app', function(done) {
|
||||
function checkLocation(err, href) {
|
||||
assert.ok(href.indexOf(appOrigin) !== -1);
|
||||
done();
|
||||
}
|
||||
|
||||
function loc() {
|
||||
return window.location.href;
|
||||
}
|
||||
|
||||
if (client.isSync) {
|
||||
var href = client.executeScript(loc);
|
||||
checkLocation(null, href);
|
||||
} else {
|
||||
client.executeScript(loc, checkLocation);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
suite('#close', function() {
|
||||
setup(function(done) {
|
||||
if (client.isSync) {
|
||||
client.apps.close(appOrigin);
|
||||
done();
|
||||
} else {
|
||||
client.apps.close(appOrigin, done);
|
||||
}
|
||||
});
|
||||
|
||||
test('should get rid of app iframe', function(done) {
|
||||
client.setSearchTimeout(10);
|
||||
if (client.isSync) {
|
||||
try {
|
||||
client.findElement(selector);
|
||||
} catch (err) {
|
||||
assert.strictEqual(err.type, 'NoSuchElement');
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
client.findElement(selector, function(err) {
|
||||
assert.strictEqual(err.type, 'NoSuchElement');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('#list', function() {
|
||||
var apps;
|
||||
|
||||
setup(function(done) {
|
||||
if (client.isSync) {
|
||||
apps = client.apps.list();
|
||||
done();
|
||||
} else {
|
||||
client.apps.list(function(err, _apps) {
|
||||
apps = _apps;
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('should return many things', function() {
|
||||
assert.notStrictEqual(apps.length, 0);
|
||||
});
|
||||
|
||||
test('should return things and only things that are apps', function() {
|
||||
apps.forEach(function(app) {
|
||||
assert.ok(app instanceof App, app.origin);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('#getApp', function() {
|
||||
var app;
|
||||
var origin = 'app://calendar.gaiamobile.org';
|
||||
|
||||
setup(function(done) {
|
||||
if (client.isSync) {
|
||||
app = client.apps.getApp(origin);
|
||||
done();
|
||||
} else {
|
||||
client.apps.getApp(origin, function(err, _app) {
|
||||
app = _app;
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('should return app object', function() {
|
||||
assert.equal(app.origin, origin);
|
||||
});
|
||||
});
|
||||
|
||||
suite('#getSelf', function() {
|
||||
var app;
|
||||
|
||||
setup(function(done) {
|
||||
if (client.isSync) {
|
||||
app = client.apps.getSelf();
|
||||
done();
|
||||
} else {
|
||||
client.apps.getSelf(function(err, _app) {
|
||||
app = _app;
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('should return a current app object', function() {
|
||||
assert.ok(app instanceof App, app.origin);
|
||||
});
|
||||
});
|
||||
});
|
||||
132
gaia/tests/jsmarionette/plugins/marionette-apps/test/launch_test.js
Executable file
132
gaia/tests/jsmarionette/plugins/marionette-apps/test/launch_test.js
Executable file
|
|
@ -0,0 +1,132 @@
|
|||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('launch', function() {
|
||||
// requires
|
||||
var launch = require('../lib/launch').launch,
|
||||
getApp = require('../lib/getapp').getApp;
|
||||
|
||||
var client = marionette.client();
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
|
||||
suite('launch installed app', function() {
|
||||
|
||||
function waitForVisibility(iframe, callback) {
|
||||
iframe.displayed(function(err, isDisplayed) {
|
||||
if (err) return callback(err);
|
||||
if (isDisplayed)
|
||||
return callback();
|
||||
|
||||
setTimeout(waitForVisibility, 250, iframe, callback);
|
||||
});
|
||||
}
|
||||
|
||||
function getAppFrame(origin, callback) {
|
||||
client.findElement('iframe[src*="' + origin + '"]', callback);
|
||||
}
|
||||
|
||||
var origin = 'app://calendar.gaiamobile.org';
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, origin, done);
|
||||
});
|
||||
|
||||
// find iframe
|
||||
var iframe;
|
||||
setup(function(done) {
|
||||
getAppFrame(origin, function(err, el) {
|
||||
iframe = el;
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('iframe exists', function() {
|
||||
assert.ok(iframe, 'iframe exists');
|
||||
});
|
||||
|
||||
test('iframe is visible', function(done) {
|
||||
this.timeout('10s');
|
||||
/**
|
||||
* Wait until iframe is visible.
|
||||
*/
|
||||
|
||||
waitForVisibility(iframe, done);
|
||||
});
|
||||
|
||||
test('double launch does not timeout', function(done) {
|
||||
client.switchToFrame();
|
||||
launch(client.mozApps, origin, function() {
|
||||
getAppFrame(origin, function(err, el) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
waitForVisibility(el, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('entrypoints', function() {
|
||||
var origin = 'app://communications.gaiamobile.org';
|
||||
var app;
|
||||
|
||||
setup(function(done) {
|
||||
getApp(client.mozApps, origin, function(err, _app) {
|
||||
app = _app;
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('has entry_points', function() {
|
||||
assert.ok(app.manifest.entry_points, 'entrypoints are availalbe');
|
||||
});
|
||||
|
||||
function launchApp(entrypoint) {
|
||||
var state = {};
|
||||
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, origin, entrypoint, function(err, app, el) {
|
||||
state.error = err;
|
||||
state.app = app;
|
||||
state.frame = el;
|
||||
done();
|
||||
});
|
||||
});
|
||||
return state;
|
||||
}
|
||||
|
||||
suite('success', function() {
|
||||
// launch another app with this domain first to verify we can actually
|
||||
// pick the right one.
|
||||
var dialer = launchApp('dialer');
|
||||
var contacts = launchApp('contacts');
|
||||
|
||||
test('is launched to entrypoint', function(done) {
|
||||
assert.ok(!dialer.error, 'other app launched');
|
||||
var entrypoint = app.manifest.entry_points.contacts;
|
||||
|
||||
// switch to new iframe
|
||||
client.switchToFrame(contacts.frame);
|
||||
|
||||
// verify we are at the right entrypoint
|
||||
client.getUrl(function(err, url) {
|
||||
assert.ok(
|
||||
url.indexOf(entrypoint.launch_path) !== -1,
|
||||
url + ' contains ' + entrypoint
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('failure', function() {
|
||||
var fakeapp = launchApp('nowayappisnamedthis');
|
||||
|
||||
test('fails with an error', function() {
|
||||
assert.ok(fakeapp.error, 'has an error' + fakeapp.error);
|
||||
assert.ok(fakeapp.error.message.match(/entrypoint/));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
80
gaia/tests/jsmarionette/plugins/marionette-apps/test/mgmt_test.js
Executable file
80
gaia/tests/jsmarionette/plugins/marionette-apps/test/mgmt_test.js
Executable file
|
|
@ -0,0 +1,80 @@
|
|||
'use strict';
|
||||
|
||||
/* global marionette, setup */
|
||||
|
||||
var App = require(__dirname + '/../lib/app');
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('mgmt', function() {
|
||||
var subject;
|
||||
|
||||
var client = marionette.client();
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
|
||||
setup(function() {
|
||||
subject = client.mozApps.mgmt;
|
||||
});
|
||||
|
||||
function checkApp(app) {
|
||||
assert.ok(app instanceof App, 'app instanceof App');
|
||||
assert.equal(typeof(app.installOrigin), 'string');
|
||||
assert.ok(app.installOrigin.length > 0);
|
||||
assert.equal(typeof(app.installTime), 'number');
|
||||
assert.ok(app.installTime > 0);
|
||||
assert.equal(typeof(app.manifestURL), 'string');
|
||||
assert.ok(app.manifestURL.length > 0);
|
||||
assert.equal(typeof(app.origin), 'string');
|
||||
assert.ok(app.origin.length > 0);
|
||||
assert.equal(typeof app.manifest, 'object');
|
||||
}
|
||||
|
||||
suite('#getAll', function() {
|
||||
var context;
|
||||
|
||||
test('should return an array of app objects', function(done) {
|
||||
function checkApps(apps) {
|
||||
assert.ok(apps.length > 0);
|
||||
apps.forEach(checkApp);
|
||||
}
|
||||
|
||||
|
||||
subject.getAll(function(err, list) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
checkApps(list);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should not change client context', function(done) {
|
||||
context = client.context;
|
||||
subject.getAll(function() {
|
||||
assert.strictEqual(client.context, context);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('#getSelf', function() {
|
||||
var context;
|
||||
|
||||
test('should return a current app', function(done) {
|
||||
subject.getSelf(function(err, app) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
checkApp(app);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should not change client context', function(done) {
|
||||
context = client.context;
|
||||
subject.getSelf(function() {
|
||||
assert.strictEqual(client.context, context);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
97
gaia/tests/jsmarionette/plugins/marionette-apps/test/objectcache_test.js
Executable file
97
gaia/tests/jsmarionette/plugins/marionette-apps/test/objectcache_test.js
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
'use strict';
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
|
||||
marionette('ObjectCache', function() {
|
||||
var ObjectCache, script, window;
|
||||
|
||||
setup(function() {
|
||||
var filename = __dirname + '/../lib/scripts/objectcache.js';
|
||||
script = fs.readFileSync(filename, 'utf8');
|
||||
window = {
|
||||
wrappedJSObject: {}
|
||||
};
|
||||
|
||||
eval(script);
|
||||
|
||||
ObjectCache = window.wrappedJSObject.ObjectCache;
|
||||
});
|
||||
|
||||
suite('load', function() {
|
||||
test('should define ObjectCache', function() {
|
||||
assert.notEqual(ObjectCache, undefined);
|
||||
});
|
||||
|
||||
test('should make an ObjectCache', function() {
|
||||
assert.deepEqual(ObjectCache._inst._cache, {});
|
||||
assert.strictEqual(ObjectCache._inst._nextId, 0);
|
||||
});
|
||||
});
|
||||
|
||||
suite('#get', function() {
|
||||
var one, two, three;
|
||||
|
||||
setup(function() {
|
||||
one = { fish: 'blue' };
|
||||
two = { fish: 'red' };
|
||||
three = {
|
||||
dog: 'linus',
|
||||
human: 'alison',
|
||||
parrot: 'harvey',
|
||||
number: 3
|
||||
};
|
||||
|
||||
ObjectCache._inst._cache = {
|
||||
'1': one,
|
||||
'2': two,
|
||||
'3': three
|
||||
};
|
||||
});
|
||||
|
||||
test('should read things from the internal _cache', function() {
|
||||
assert.deepEqual(ObjectCache._inst.get('1'), one);
|
||||
assert.deepEqual(ObjectCache._inst.get('2'), two);
|
||||
assert.deepEqual(ObjectCache._inst.get('3'), three);
|
||||
});
|
||||
});
|
||||
|
||||
suite('#set', function() {
|
||||
var bweop, resultWithKey, resultWithoutKey;
|
||||
|
||||
setup(function() {
|
||||
bweop = { fish: 'blue' };
|
||||
resultWithKey = ObjectCache._inst.set(bweop, 'bweop');
|
||||
resultWithoutKey = ObjectCache._inst.set(bweop);
|
||||
});
|
||||
|
||||
test('should write things to the internal _cache', function() {
|
||||
assert.deepEqual(ObjectCache._inst._cache.bweop, bweop);
|
||||
assert.deepEqual(ObjectCache._inst._cache['1'], bweop);
|
||||
});
|
||||
|
||||
test('should take key if provided', function() {
|
||||
assert.deepEqual(resultWithKey, 'bweop');
|
||||
});
|
||||
|
||||
test('should generate a new key when no key is provided', function() {
|
||||
assert.strictEqual(resultWithoutKey, '1');
|
||||
});
|
||||
});
|
||||
|
||||
suite('#getNextId', function() {
|
||||
var result;
|
||||
|
||||
setup(function() {
|
||||
ObjectCache._inst._nextId = 5;
|
||||
result = ObjectCache._inst.getNextId();
|
||||
});
|
||||
|
||||
test('should return a string equal to previous nextId + 1', function() {
|
||||
assert.strictEqual(result, '6');
|
||||
});
|
||||
|
||||
test('should update internal count', function() {
|
||||
assert.strictEqual(ObjectCache._inst._nextId, 6);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('switchToActivity', function() {
|
||||
var launch = require('../lib/launch').launch;
|
||||
var switchToApp = require('../lib/switchtoapp').switchToApp;
|
||||
var switchToActivity = require('../lib/switchtoactivity').switchToActivity;
|
||||
|
||||
var ACTIVITY_CALLER_DOMAIN = 'activity.caller.gaiamobile.org';
|
||||
var ACTIVITY_CALLEE_DOMAIN = 'activity.callee.gaiamobile.org';
|
||||
|
||||
var apps = {};
|
||||
apps[ACTIVITY_CALLER_DOMAIN] = __dirname + '/apps/activitycaller';
|
||||
apps[ACTIVITY_CALLEE_DOMAIN] = __dirname + '/apps/activitycallee';
|
||||
|
||||
var profile = {
|
||||
settings: {
|
||||
'ftu.manifestURL': null,
|
||||
'lockscreen.enabled': false,
|
||||
'screen.timeout': 0
|
||||
},
|
||||
// Need this so that swithToApp can also focus on the app frame.
|
||||
prefs: {
|
||||
'focusmanager.testmode': true
|
||||
},
|
||||
apps: apps
|
||||
};
|
||||
|
||||
var client = marionette.client({ profile: profile });
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
|
||||
suite('switch to app that is run as inline activity', function() {
|
||||
var activityCallerOrigin = 'app://' + ACTIVITY_CALLER_DOMAIN;
|
||||
var activityCalleeOrigin = 'app://' + ACTIVITY_CALLEE_DOMAIN;
|
||||
var href = '/index.html#x-activity';
|
||||
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, activityCallerOrigin, done);
|
||||
});
|
||||
|
||||
setup(function(done) {
|
||||
switchToApp(client.mozApps, activityCallerOrigin, function(err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// Run activity callee as inline activity
|
||||
client.findElement('#open-activity').tap();
|
||||
|
||||
client.switchToFrame();
|
||||
switchToActivity(client.mozApps, activityCalleeOrigin, href, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('should be visible', function() {
|
||||
client.switchToFrame();
|
||||
var iframe = client.findElement(
|
||||
'iframe[src*="' + activityCalleeOrigin + '"]'
|
||||
);
|
||||
|
||||
assert.ok(iframe);
|
||||
assert.ok(iframe.displayed());
|
||||
});
|
||||
|
||||
test('app should be the target of scripts', function() {
|
||||
var location = client.executeScript(function() {
|
||||
return window.wrappedJSObject.location.href;
|
||||
});
|
||||
assert.ok(location.indexOf(activityCalleeOrigin) === 0);
|
||||
});
|
||||
|
||||
test('app should have the focus', function() {
|
||||
assert.ok(client.executeScript(function() {
|
||||
return window.wrappedJSObject.document.hasFocus();
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
112
gaia/tests/jsmarionette/plugins/marionette-apps/test/switchtoapp_test.js
Executable file
112
gaia/tests/jsmarionette/plugins/marionette-apps/test/switchtoapp_test.js
Executable file
|
|
@ -0,0 +1,112 @@
|
|||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('launch', function() {
|
||||
var launch = require('../lib/launch').launch;
|
||||
var switchToApp = require('../lib/switchtoapp').switchToApp;
|
||||
|
||||
var profile = {
|
||||
settings: {
|
||||
'ftu.manifestURL': null,
|
||||
'lockscreen.enabled': false
|
||||
},
|
||||
// Need this so that swithToApp can also focus on the app frame.
|
||||
prefs: {
|
||||
'focusmanager.testmode': true
|
||||
}
|
||||
};
|
||||
|
||||
var client = marionette.client({ profile: profile });
|
||||
var system;
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
|
||||
setup(function() {
|
||||
system = client.loader.getAppClass('system');
|
||||
system.waitForFullyLoaded();
|
||||
});
|
||||
|
||||
suite('switch to running app', function() {
|
||||
var domain = 'homescreen.gaiamobile.org';
|
||||
var origin = 'app://' + domain;
|
||||
setup(function(done) {
|
||||
switchToApp(client.mozApps, origin, done);
|
||||
});
|
||||
|
||||
test('should be visible', function(done) {
|
||||
// switch to root (system app)
|
||||
client.switchToFrame();
|
||||
client.findElement('iframe[src*="' + domain + '"]', function(err, el) {
|
||||
if (err) return done(err);
|
||||
el.displayed(function(err, isDisplayed) {
|
||||
assert.ok(isDisplayed);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('app should be the target of scripts', function(done) {
|
||||
function remote() {
|
||||
return window.wrappedJSObject.location.href;
|
||||
}
|
||||
|
||||
client.executeScript(remote, function(err, result) {
|
||||
assert.ok(result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('app should have the focus', function(done) {
|
||||
function remote() {
|
||||
return window.wrappedJSObject.document.hasFocus();
|
||||
}
|
||||
|
||||
client.executeScript(remote, function(err, result) {
|
||||
assert.ok(result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should be able to switchToApp from app to app', function(done) {
|
||||
// already called switchToApp once by now, call it again.
|
||||
switchToApp(client.mozApps, origin);
|
||||
|
||||
function remote() {
|
||||
return window.wrappedJSObject.document.hasFocus();
|
||||
}
|
||||
|
||||
client.executeScript(remote, function(err, result) {
|
||||
assert.ok(result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('entrypoint', function() {
|
||||
var origin = 'app://communications.gaiamobile.org';
|
||||
var entrypoint = 'contacts';
|
||||
var app;
|
||||
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, origin, entrypoint, function(err, _app) {
|
||||
app = _app;
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
setup(function(done) {
|
||||
switchToApp(client.mozApps, origin, entrypoint, done);
|
||||
});
|
||||
|
||||
test('context of marionette after switch', function(done) {
|
||||
client.getUrl(function(err, url) {
|
||||
assert.ok(
|
||||
url.indexOf(app.source) !== -1,
|
||||
'url contains: ' + app.source
|
||||
);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
154
gaia/tests/jsmarionette/plugins/marionette-apps/test/waitforapp_test.js
Executable file
154
gaia/tests/jsmarionette/plugins/marionette-apps/test/waitforapp_test.js
Executable file
|
|
@ -0,0 +1,154 @@
|
|||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
marionette('waitforapp', function() {
|
||||
// requires
|
||||
var launch = require('../lib/launch').launch;
|
||||
var switchToApp = require('../lib/switchtoapp').switchToApp;
|
||||
var waitForApp = require('../lib/waitforapp').waitForApp;
|
||||
var waitForActivity = require('../lib/waitforapp').waitForActivity;
|
||||
|
||||
var ACTIVITY_CALLER_DOMAIN = 'activity.caller.gaiamobile.org';
|
||||
var ACTIVITY_CALLEE_DOMAIN = 'activity.callee.gaiamobile.org';
|
||||
|
||||
var apps = {};
|
||||
apps[ACTIVITY_CALLER_DOMAIN] = __dirname + '/apps/activitycaller';
|
||||
apps[ACTIVITY_CALLEE_DOMAIN] = __dirname + '/apps/activitycallee';
|
||||
|
||||
var client = marionette.client({
|
||||
profile: {
|
||||
settings: {
|
||||
'ftu.manifestURL': null,
|
||||
'lockscreen.enabled': false,
|
||||
'screen.timeout': 0
|
||||
},
|
||||
|
||||
apps: apps
|
||||
}
|
||||
});
|
||||
marionette.plugin('mozApps', require('../lib/apps'));
|
||||
|
||||
function getParentClass(iframeElement) {
|
||||
return iframeElement.scriptWith(function(el) {
|
||||
return el.parentNode.getAttribute('class');
|
||||
});
|
||||
}
|
||||
|
||||
function getTransitionState(iframeElement) {
|
||||
return iframeElement.scriptWith(function(el) {
|
||||
return el.parentNode.parentNode.getAttribute('transition-state');
|
||||
});
|
||||
}
|
||||
|
||||
test(function() {
|
||||
assert.equal(true, false);
|
||||
});
|
||||
|
||||
suite('waiting for running app', function() {
|
||||
var domain = 'homescreen.gaiamobile.org';
|
||||
var element;
|
||||
|
||||
setup(function(done) {
|
||||
this.timeout('20s');
|
||||
waitForApp(client.mozApps, domain, function(err, el) {
|
||||
if (err) return done(err);
|
||||
element = el;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('it should return element', function() {
|
||||
assert.ok(element);
|
||||
assert.ok(element.getAttribute('src').indexOf(domain) !== -1);
|
||||
});
|
||||
|
||||
test('iframe is with the render class', function() {
|
||||
var iframe = client.findElement('iframe[src*="' + domain + '"]');
|
||||
|
||||
assert.ok(iframe);
|
||||
assert.ok(getParentClass(iframe).indexOf('render') >= 0);
|
||||
});
|
||||
|
||||
test('the transition-state of the iframe is opened', function() {
|
||||
var iframe = client.findElement('iframe[src*="' + domain + '"]');
|
||||
|
||||
assert.ok(iframe);
|
||||
assert.equal(getTransitionState(iframe), 'opened');
|
||||
});
|
||||
|
||||
test('iframe is visible', function() {
|
||||
var iframe = client.findElement('iframe[src*="' + domain + '"]');
|
||||
assert.ok(iframe);
|
||||
assert.ok(iframe.displayed());
|
||||
});
|
||||
});
|
||||
|
||||
suite('correctly works with inline activity apps', function() {
|
||||
var activityCallerOrigin = 'app://' + ACTIVITY_CALLER_DOMAIN;
|
||||
var activityCalleeOrigin = 'app://' + ACTIVITY_CALLEE_DOMAIN;
|
||||
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, activityCalleeOrigin, done);
|
||||
});
|
||||
|
||||
setup(function(done) {
|
||||
launch(client.mozApps, activityCallerOrigin, done);
|
||||
});
|
||||
|
||||
setup(function(done) {
|
||||
switchToApp(client.mozApps, activityCallerOrigin, function(err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// Run activity callee as inline activity
|
||||
client.findElement('#open-activity').tap();
|
||||
client.switchToFrame();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('waitForActivity should return activity iframe', function(done) {
|
||||
waitForActivity(client.mozApps, ACTIVITY_CALLEE_DOMAIN,
|
||||
function(err, el) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
assert.ok(el);
|
||||
assert.ok(el.displayed());
|
||||
assert.ok(el.getAttribute('src').indexOf(activityCalleeOrigin) === 0);
|
||||
assert.ok(
|
||||
el.getAttribute('parentapp').indexOf(activityCallerOrigin) === 0
|
||||
);
|
||||
assert.ok(getParentClass(el).indexOf('render') >= 0);
|
||||
assert.equal(getTransitionState(el), 'opened');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('waitForApp should return non-activity iframe', function(done) {
|
||||
// Focus on main instance
|
||||
launch(client.mozApps, activityCalleeOrigin, function(err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
waitForApp(client.mozApps, ACTIVITY_CALLEE_DOMAIN, function(err, el) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.ok(el);
|
||||
assert.ok(el.displayed());
|
||||
assert.ok(el.getAttribute('src').indexOf(activityCalleeOrigin) === 0);
|
||||
assert.equal(el.getAttribute('parentapp'), null);
|
||||
assert.ok(getParentClass(el).indexOf('render') >= 0);
|
||||
assert.equal(getTransitionState(el), 'opened');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue