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

Commit

Permalink
Bug 1029336 - Only disable contextmenu for certified apps. r=alive
Browse files Browse the repository at this point in the history
  • Loading branch information
daleharvey committed Jun 30, 2014
1 parent e298a65 commit d377fc6
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 5 deletions.
9 changes: 9 additions & 0 deletions apps/system/js/app_window.js
Expand Up @@ -599,6 +599,15 @@
return !this.manifestURL;
};

/**
* Check an appWindow contains a certified application
*
* @return {Boolean} is the current instance a certified application.
*/
AppWindow.prototype.isCertified = function aw_iscertified() {
return this.config.manifest && 'certified' === this.config.manifest.type;
};

/**
* Try to navigate the current frame to a given url if current instance
* is a browsing window.
Expand Down
13 changes: 10 additions & 3 deletions apps/system/js/browser_context_menu.js
Expand Up @@ -91,9 +91,15 @@
var hasSystemTargets = detail.systemTargets &&
detail.systemTargets.length > 0;

// systemTargets are currently disabled for non browsing contexts
// https://bugzilla.mozilla.org/show_bug.cgi?id=1010160
if (!(hasContextMenu || (hasSystemTargets && this.app.isBrowser()))) {
// Nothing to show
if (!hasSystemTargets && !hasContextMenu) {
return;
}

// context menus in certified apps that only have system targets are
// currently disabled. https://bugzilla.mozilla.org/show_bug.cgi?id=1010160
// is tracking reenabling
if (!hasContextMenu && hasSystemTargets && this.app.isCertified()) {
return;
}

Expand All @@ -117,6 +123,7 @@
this.elements.list.innerHTML = '';
items.forEach(function traveseItems(item) {
var action = document.createElement('button');
action.dataset.id = item.id;
action.dataset.value = item.value;
action.textContent = item.label;

Expand Down
42 changes: 42 additions & 0 deletions apps/system/test/marionette/context_menu_test.js
@@ -0,0 +1,42 @@
/* global __dirname */

'use strict';

var Actions = require('marionette-client').Actions;

var APP_NAME = 'contextmenuapp';
var APP_HOST = APP_NAME + '.gaiamobile.org';
var APP_URL = 'app://' + APP_HOST;

marionette('Test Context Menu Events', function() {

var opts = {
settings: {
'ftu.manifestURL': null,
'lockscreen.enabled': false
},
apps: {}
};

opts.apps[APP_HOST] = __dirname + '/' + APP_NAME;

var client = marionette.client(opts);
var actions = new Actions(client);

test('Test basic context menu functionality', function() {

// Launch test app
client.apps.launch(APP_URL);
client.apps.switchToApp(APP_URL);

// Long press on a link
var link = client.helper.waitForElement('#link');
actions.longPress(link, 1.5).perform();

// Ensure the share and open tab menu items are present
client.switchToFrame();
client.helper.waitForElement('[data-id=open-in-new-tab]');
client.helper.waitForElement('[data-id=share-link]');
});

});
13 changes: 13 additions & 0 deletions apps/system/test/marionette/contextmenuapp/index.html
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Fake Activity Caller</title>
</head>

<body>
<a href="http://example.com" id="link">A Link!</a>
</body>

</html>
11 changes: 11 additions & 0 deletions apps/system/test/marionette/contextmenuapp/manifest.webapp
@@ -0,0 +1,11 @@
{
"name": "Context Menu App",
"description": "App used to test context menus",
"type": "privileged",
"launch_path": "/index.html",
"fullscreen": true,
"developer": {
"name": "The Gaia Team",
"url": "https://github.com/mozilla-b2g/gaia"
}
}
15 changes: 15 additions & 0 deletions apps/system/test/unit/app_window_test.js
Expand Up @@ -134,6 +134,14 @@ suite('system/AppWindow', function() {
}
};

var fakeAppConfigCertified = {
url: 'app://www.fakecertified/index.html',
manifest: {
type: 'certified'
},
origin: 'app://www.fake4'
};

test('App created with instanceID', function() {
var app1 = new AppWindow(fakeAppConfig1);
var app2 = new AppWindow(fakeAppConfig2);
Expand Down Expand Up @@ -1653,6 +1661,13 @@ suite('system/AppWindow', function() {
assert.isTrue(app2.isBrowser());
});

test('isCertified', function() {
var app1 = new AppWindow(fakeAppConfig1);
var app2 = new AppWindow(fakeAppConfigCertified);
assert.isFalse(app1.isCertified());
assert.isTrue(app2.isCertified());
});

test('navigate', function() {
var app1 = new AppWindow(fakeAppConfig1);
var app2 = new AppWindow(fakeAppConfig4);
Expand Down
4 changes: 2 additions & 2 deletions apps/system/test/unit/browser_context_menu_test.js
Expand Up @@ -181,8 +181,8 @@ suite('system/BrowserContextMenu', function() {
var app1 = new AppWindow(fakeAppConfig1);
var md1 = new BrowserContextMenu(app1);

app1.isBrowser = function() {
return false;
app1.isCertified = function() {
return true;
};

for (var i = 0; i < fakeSystemContextMenuEvents.length; i++) {
Expand Down
1 change: 1 addition & 0 deletions apps/system/test/unit/mock_app_window.js
Expand Up @@ -68,6 +68,7 @@
back: function() {},
reload: function() {},
isBrowser: function() {},
isCertified: function() {},
navigate: function() {},
isFullScreen: function() {},
_changeState: function() {},
Expand Down

0 comments on commit d377fc6

Please sign in to comment.