Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19482 from davehunt/bug_921939
Browse files Browse the repository at this point in the history
Bug 921939 - Support launching localised apps by name
  • Loading branch information
Zac committed Jun 27, 2014
2 parents 104a835 + 8420111 commit ef5c623
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 28 deletions.
73 changes: 46 additions & 27 deletions tests/atoms/gaia_apps.js
Expand Up @@ -30,7 +30,7 @@ var GaiaApps = {
anApp[key] = runningApps[app][key];
}
}
apps[app.origin] = anApp;
apps[runningApps[app]['origin']] = anApp;
}
return apps;
},
Expand All @@ -53,11 +53,11 @@ var GaiaApps = {
return undefined;
},

getAppByName: function(name) {
getAppByURL: function(url) {
// return the app window with the specified URL
let apps = GaiaApps.getApps();

for (let id in apps) {
if (apps[id].name == name) {
if (apps[id].url == url) {
return apps[id];
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ var GaiaApps = {
});
},

sendLocateResponse: function(aCallback, app, appName, entryPoint) {
sendLocateResponse: function(aCallback, app, appName, launchPath, entryPoint) {
var callback = aCallback || marionetteScriptFinished;
if (callback === marionetteScriptFinished) {
var result = false;
Expand All @@ -100,7 +100,7 @@ var GaiaApps = {
}
callback(result);
} else {
callback(app, appName, entryPoint);
callback(app, appName, launchPath, entryPoint);
}
},

Expand All @@ -118,16 +118,38 @@ var GaiaApps = {
for (let ep in entryPoints) {
let currentEntryPoint = entryPoints[ep];
let appName = currentEntryPoint.name;

if (normalizedSearchName === GaiaApps.normalizeName(appName)) {
return GaiaApps.sendLocateResponse(callback, app, appName, ep);
let launchPath = currentEntryPoint.launch_path;

let locales = currentEntryPoint.locales;
if (locales) {
for (let id in locales) {
let localisedAppName = locales[id].name;
if (localisedAppName && normalizedSearchName === GaiaApps.normalizeName(localisedAppName)) {
return GaiaApps.sendLocateResponse(callback, app, appName, launchPath, ep);
}
}
} else {
if (normalizedSearchName === GaiaApps.normalizeName(appName)) {
return GaiaApps.sendLocateResponse(callback, app, appName, launchPath, ep);
}
}
}
} else {
let appName = app.manifest.name;

if (normalizedSearchName === GaiaApps.normalizeName(appName)) {
return GaiaApps.sendLocateResponse(callback, app, appName);
let launchPath = app.manifest.launch_path;

let locales = app.manifest.locales;
if (locales) {
for (let id in locales) {
let localisedAppName = locales[id].name;
if (localisedAppName && normalizedSearchName === GaiaApps.normalizeName(localisedAppName)) {
return GaiaApps.sendLocateResponse(callback, app, appName, launchPath);
}
}
} else {
if (normalizedSearchName === GaiaApps.normalizeName(appName)) {
return GaiaApps.sendLocateResponse(callback, app, appName, launchPath);
}
}
}
}
Expand All @@ -142,15 +164,17 @@ var GaiaApps = {

if (entryPoint) {
if (app.manifest.entry_points[entryPoint]) {
appName = app.manifest.entry_points[entryPoint].name;
let appName = app.manifest.entry_points[entryPoint].name;
let launchPath = app.manifest.entry_points[entryPoint].launchPath;
} else {
app = null;
}
} else {
appName = app.manifest.name;
let appName = app.manifest.name;
let launchPath = app.manifest.launchPath;
}

GaiaApps.sendLocateResponse(callback, app, appName, entryPoint);
GaiaApps.sendLocateResponse(callback, app, appName, launchPath, entryPoint);
},

// Returns the number of running apps.
Expand Down Expand Up @@ -229,12 +253,12 @@ var GaiaApps = {
);
},

launch: function(app, appName, entryPoint) {
launch: function(app, appName, launchPath, entryPoint) {
if (app) {
let origin = app.origin;

let sendResponse = function() {
let appWindow = GaiaApps.getAppByName(appName);
let appWindow = GaiaApps.getAppByURL(app.origin + launchPath);
let origin = appWindow.origin;
let result = {
frame: (appWindow.browser) ? appWindow.browser.element : appWindow.frame.firstChild,
Expand All @@ -244,7 +268,7 @@ var GaiaApps = {
marionetteScriptFinished(result);
};

if (GaiaApps.getActiveApp().origin == origin) {
if (GaiaApps.getDisplayedApp().origin == origin) {
console.log("app with origin '" + origin + "' is already running");
sendResponse();
} else {
Expand All @@ -256,7 +280,8 @@ var GaiaApps = {
sendResponse();
},
function() {
return GaiaApps.getActiveApp().name == appName;
// wait for the displayed app to have the expected source URL
return GaiaApps.getDisplayedApp().src == (origin + launchPath);
}
);
});
Expand Down Expand Up @@ -305,16 +330,10 @@ var GaiaApps = {
GaiaApps.locateWithManifestURL(manifestURL, entryPoint, this.close);
},

getActiveApp: function() {
let manager = window.wrappedJSObject.AppWindowManager || window.wrappedJSObject.WindowManager;
let app = ('getActiveApp' in manager) ? manager.getActiveApp() : manager.getCurrentDisplayedApp();
return app;
},

/**
* Returns the currently displayed app.
*/
displayedApp: function() {
getDisplayedApp: function() {
let manager = window.wrappedJSObject.AppWindowManager || window.wrappedJSObject.WindowManager;
let app = ('getActiveApp' in manager) ? manager.getActiveApp() : manager.getCurrentDisplayedApp();

Expand All @@ -332,7 +351,7 @@ var GaiaApps = {
name: app.name,
origin: origin
};
marionetteScriptFinished(result);
return result;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/python/gaia-ui-tests/gaiatest/gaia_test.py
Expand Up @@ -63,7 +63,7 @@ def launch(self, name, switch_to_frame=True, launch_timeout=None):
@property
def displayed_app(self):
self.marionette.switch_to_frame()
result = self.marionette.execute_async_script('return GaiaApps.displayedApp();')
result = self.marionette.execute_script('return GaiaApps.getDisplayedApp();')
return GaiaApp(frame=result.get('frame'),
src=result.get('src'),
name=result.get('name'),
Expand Down
Expand Up @@ -11,6 +11,7 @@ skip-if = os == "mac"
[unit/test_file_manager.py]
[unit/test_kill.py]
[unit/test_killall.py]
[unit/test_launch_l10n.py]
[unit/test_launch_twice.py]
[unit/test_lock_screen.py]
[unit/test_permissions.py]
Expand Down
Expand Up @@ -35,6 +35,7 @@ online = true
[test_kill.py]
[test_killall.py]
[test_cold_launch.py]
[test_launch_l10n.py]
[test_launch_twice.py]
[test_warm_launch.py]
[test_lock_screen.py]
Expand Down
47 changes: 47 additions & 0 deletions tests/python/gaia-ui-tests/gaiatest/tests/unit/test_launch_l10n.py
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from gaiatest import GaiaTestCase


class TestLaunchL10n(GaiaTestCase):

default_locale = 'en-US'
alternate_locale = 'fr'
test_apps = {'Clock': 'Horloge',
'Phone': u'Téléphone'}

def _test_launch_by_english_name_in_alternate_locale(self):
'''
Launch apps by English name in a different locale
'''

# set language to non-English
self.data_layer.set_setting('language.current', self.alternate_locale)

for app in self.test_apps.keys():
self.apps.launch(app)

for app in self.test_apps.values():
self.assertIn(app.lower(), [a.name.lower() for a in self.apps.running_apps])

def test_launch_by_localised_name(self):
'''
Launch apps by (non-English) localised name
'''

# set language to non-English
self.data_layer.set_setting('language.current', self.alternate_locale)

for app in self.test_apps.values():
self.apps.launch(app)

for app in self.test_apps.values():
self.assertIn(app.lower(), [a.name.lower() for a in self.apps.running_apps])

def tearDown(self):
# switch back to the default locale
self.data_layer.set_setting('language.current', self.default_locale)

0 comments on commit ef5c623

Please sign in to comment.