Commit a53aa155 authored by finnur@chromium.org's avatar finnur@chromium.org

Enabling Commands API for Apps (on dev)

BUG=302437

Review URL: https://codereview.chromium.org/44553002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233310 0039d316-1c4b-4281-b951-d872f2087c98
parent f7374eda
...@@ -4919,7 +4919,7 @@ Make sure you do not expose any sensitive information. ...@@ -4919,7 +4919,7 @@ Make sure you do not expose any sensitive information.
Keyboard shortcuts Keyboard shortcuts
</message> </message>
<message name="IDS_EXTENSION_COMMANDS_DIALOG_TITLE" desc="Title of extension commands dialog"> <message name="IDS_EXTENSION_COMMANDS_DIALOG_TITLE" desc="Title of extension commands dialog">
Keyboard Shortcuts for Extensions Keyboard Shortcuts for Extensions and Apps
</message> </message>
<message name="IDS_EXTENSION_COMMANDS_EMPTY" desc="The heading of the extension commands dialog when there are no commands to show."> <message name="IDS_EXTENSION_COMMANDS_EMPTY" desc="The heading of the extension commands dialog when there are no commands to show.">
No extensions have keyboard shortcuts assigned. No extensions have keyboard shortcuts assigned.
......
...@@ -79,16 +79,24 @@ ...@@ -79,16 +79,24 @@
"channel": "stable", "channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"] "extension_types": ["extension", "legacy_packaged_app"]
}, },
"commands": { "commands": [
"channel": "stable", {
"extension_types": ["extension"], "channel": "dev",
"min_manifest_version": 2 "extension_types": ["platform_app"],
}, "min_manifest_version": 2
"commands.global": { }, {
"channel": "dev", "channel": "stable",
"extension_types": ["extension"], "extension_types": ["extension"],
"min_manifest_version": 2 "min_manifest_version": 2
}, }
],
"commands.global": [
{
"channel": "dev",
"extension_types": ["extension", "platform_app"],
"min_manifest_version": 2
}
],
"content_pack": { "content_pack": {
"channel": "dev", "channel": "dev",
"extension_types": ["extension"] "extension_types": ["extension"]
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/commands/commands_handler.h" #include "chrome/common/extensions/api/commands/commands_handler.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -93,4 +94,42 @@ TEST_F(CommandsManifestTest, BrowserActionSynthesizesCommand) { ...@@ -93,4 +94,42 @@ TEST_F(CommandsManifestTest, BrowserActionSynthesizesCommand) {
ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code()); ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code());
} }
// This test makes sure that the "commands" feature and the "commands.global"
// property behave as expected on dev and stable (enabled and working on dev,
// not working on stable).
TEST_F(CommandsManifestTest, ChannelTests) {
// This tests the following combinations.
// Ext+Command Stable : OK.
// Ext+Command+Global Stable : Property is silently ignored (expect success).
// App+Command Stable : NOT OK.
// App+Command+Global Stable : NOT OK.
{
std::string warning = "'commands' requires Google Chrome dev channel or "
"newer, but this is the stable channel.";
ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
scoped_refptr<Extension> extension1 =
LoadAndExpectSuccess("command_ext.json");
scoped_refptr<Extension> extension2 =
LoadAndExpectSuccess("command_ext_global.json");
LoadAndExpectWarning("command_app.json", warning);
LoadAndExpectWarning("command_app_global.json", warning);
}
// Ext+Command Dev : OK.
// App+Command Dev : OK.
// Ext+Command+Global Dev : OK.
// App+Command+Global Dev : OK.
{
ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
scoped_refptr<Extension> extension1 =
LoadAndExpectSuccess("command_ext.json");
scoped_refptr<Extension> extension2 =
LoadAndExpectSuccess("command_app.json");
scoped_refptr<Extension> extension3 =
LoadAndExpectSuccess("command_ext_global.json");
scoped_refptr<Extension> extension4 =
LoadAndExpectSuccess("command_app_global.json");
}
}
} // namespace extensions } // namespace extensions
...@@ -438,7 +438,9 @@ bool Command::Parse(const base::DictionaryValue* command, ...@@ -438,7 +438,9 @@ bool Command::Parse(const base::DictionaryValue* command,
// Check if this is a global or a regular shortcut. // Check if this is a global or a regular shortcut.
bool global = false; bool global = false;
command->GetBoolean(keys::kGlobal, &global); if (FeatureSwitch::global_commands()->IsEnabled() &&
chrome::VersionInfo::GetChannel() <= chrome::VersionInfo::CHANNEL_DEV)
command->GetBoolean(keys::kGlobal, &global);
// Normalize the suggestions. // Normalize the suggestions.
for (SuggestionMap::iterator iter = suggestions.begin(); for (SuggestionMap::iterator iter = suggestions.begin();
......
{
"name": "Command test - App with Command",
"manifest_version": 2,
"version": "1",
"app": {
"background": { "scripts": ["background.js"] }
},
"commands": {
"feature1": {
"suggested_key": "Ctrl+Shift+0",
"description": "desc"
}
}
}
{
"name": "Command test - App with Command that is global",
"manifest_version": 2,
"version": "1",
"app": {
"background": { "scripts": ["background.js"] }
},
"commands": {
"feature1": {
"suggested_key": "Ctrl+Shift+0",
"description": "desc",
"global": true
}
}
}
{
"name": "Command test - Extension with Command",
"manifest_version": 2,
"version": "1",
"commands": {
"feature1": {
"suggested_key": "Ctrl+Shift+0",
"description": "desc"
}
}
}
{
"name": "Command test - Extension with Command that is global",
"manifest_version": 2,
"version": "1",
"commands": {
"feature1": {
"suggested_key": "Ctrl+Shift+0",
"description": "desc",
"global": true
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment