OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_value_serializer.h" | 10 #include "base/json/json_value_serializer.h" |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 914 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
915 Extension::INTERNAL, 0, FilePath())); | 915 Extension::INTERNAL, 0, FilePath())); |
916 EXPECT_FALSE(extension->ShouldDisplayInLauncher()); | 916 EXPECT_FALSE(extension->ShouldDisplayInLauncher()); |
917 | 917 |
918 scoped_refptr<Extension> app( | 918 scoped_refptr<Extension> app( |
919 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"), | 919 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"), |
920 Extension::INTERNAL, 0, FilePath())); | 920 Extension::INTERNAL, 0, FilePath())); |
921 EXPECT_TRUE(app->ShouldDisplayInLauncher()); | 921 EXPECT_TRUE(app->ShouldDisplayInLauncher()); |
922 } | 922 } |
923 | 923 |
| 924 TEST(ExtensionTest, ExtensionKeybindingParsing) { |
| 925 const ui::Accelerator None = ui::Accelerator(); |
| 926 const ui::Accelerator ShiftF = |
| 927 ui::Accelerator(ui::VKEY_F, true, false, false); |
| 928 const ui::Accelerator CtrlF = |
| 929 ui::Accelerator(ui::VKEY_F, false, true, false); |
| 930 const ui::Accelerator AltF = |
| 931 ui::Accelerator(ui::VKEY_F, false, false, true); |
| 932 const ui::Accelerator CtrlShiftF = |
| 933 ui::Accelerator(ui::VKEY_F, true, true, false); |
| 934 const ui::Accelerator AltShiftF = |
| 935 ui::Accelerator(ui::VKEY_F, true, false, true); |
| 936 |
| 937 const struct { |
| 938 bool expected_result; |
| 939 ui::Accelerator accelerator; |
| 940 const char* command_name; |
| 941 const char* key; |
| 942 const char* description; |
| 943 } kTests[] = { |
| 944 // Negative test (one or more missing required fields). We don't need to |
| 945 // test |command_name| being blank as it is used as a key in the manifest, |
| 946 // so it can't be blank (and we DCHECK when it is). |
| 947 { false, None, "command", "", "" }, |
| 948 { false, None, "command", "ctrl+f", "" }, |
| 949 { false, None, "command", "", "description" }, |
| 950 // Ctrl+Alt is not permitted, see MSDN link in comments in Parse function. |
| 951 { false, None, "command", "Ctrl+Alt+F", "description" }, |
| 952 // Unsupported shortcuts/too many. |
| 953 { false, None, "command", "F10", "description" }, |
| 954 { false, None, "command", "Ctrl+1", "description" }, |
| 955 { false, None, "command", "Ctrl+F+G", "description" }, |
| 956 // Basic tests. |
| 957 { true, CtrlF, "command", "Ctrl+F", "description" }, |
| 958 { true, ShiftF, "command", "Shift+F", "description" }, |
| 959 { true, AltF, "command", "Alt+F", "description" }, |
| 960 { true, CtrlShiftF, "command", "Ctrl+Shift+F", "description" }, |
| 961 { true, AltShiftF, "command", "Alt+Shift+F", "description" }, |
| 962 // Order tests. |
| 963 { true, CtrlF, "command", "F+Ctrl", "description" }, |
| 964 { true, ShiftF, "command", "F+Shift", "description" }, |
| 965 { true, AltF, "command", "F+Alt", "description" }, |
| 966 { true, CtrlShiftF, "command", "F+Ctrl+Shift", "description" }, |
| 967 { true, CtrlShiftF, "command", "F+Shift+Ctrl", "description" }, |
| 968 { true, AltShiftF, "command", "F+Alt+Shift", "description" }, |
| 969 { true, AltShiftF, "command", "F+Shift+Alt", "description" }, |
| 970 // Case insensitivity is OK. |
| 971 { true, CtrlF, "command", "Ctrl+F", "description" }, |
| 972 { true, CtrlF, "command", "cTrL+f", "description" }, |
| 973 // Extra spaces are fine. |
| 974 { true, CtrlShiftF, "command", " Ctrl + Shift +F", "description" }, |
| 975 // Minus is equivalent to plus. |
| 976 { true, CtrlShiftF, "command", "Ctrl+Shift-F", "description" }, |
| 977 // Skipping description is OK for browser- and pageActions. |
| 978 { true, CtrlF, "browserAction", "Ctrl+F", "" }, |
| 979 { true, CtrlF, "pageAction", "Ctrl+F", "" }, |
| 980 }; |
| 981 |
| 982 // TODO(finnur): test Command/Options on Mac when implemented. |
| 983 |
| 984 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
| 985 scoped_ptr<DictionaryValue> command(new DictionaryValue); |
| 986 command->SetString("key", kTests[i].key); |
| 987 command->SetString("description", kTests[i].description); |
| 988 |
| 989 Extension::ExtensionKeybinding keybinding; |
| 990 string16 error; |
| 991 bool result = |
| 992 keybinding.Parse(command.get(), kTests[i].command_name, i, &error); |
| 993 |
| 994 SCOPED_TRACE(std::string("Command name: |") + kTests[i].command_name + |
| 995 "| key: |" + kTests[i].key + |
| 996 "| description: |" + kTests[i].description + |
| 997 "| index: " + base::IntToString(i)); |
| 998 |
| 999 EXPECT_EQ(kTests[i].expected_result, result); |
| 1000 if (result) { |
| 1001 EXPECT_STREQ(kTests[i].description, keybinding.description().c_str()); |
| 1002 EXPECT_STREQ(kTests[i].command_name, keybinding.command_name().c_str()); |
| 1003 EXPECT_EQ(kTests[i].accelerator, keybinding.accelerator()); |
| 1004 } |
| 1005 } |
| 1006 } |
| 1007 |
924 // These last 2 tests don't make sense on Chrome OS, where extension plugins | 1008 // These last 2 tests don't make sense on Chrome OS, where extension plugins |
925 // are not allowed. | 1009 // are not allowed. |
926 #if !defined(OS_CHROMEOS) | 1010 #if !defined(OS_CHROMEOS) |
927 TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) { | 1011 TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) { |
928 scoped_refptr<Extension> extension( | 1012 scoped_refptr<Extension> extension( |
929 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1013 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
930 Extension::INTERNAL, 1, FilePath())); | 1014 Extension::INTERNAL, 1, FilePath())); |
931 if (extension) | 1015 if (extension) |
932 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1016 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
933 } | 1017 } |
934 | 1018 |
935 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | 1019 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { |
936 scoped_refptr<Extension> extension( | 1020 scoped_refptr<Extension> extension( |
937 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1021 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
938 Extension::INTERNAL, 2, FilePath())); | 1022 Extension::INTERNAL, 2, FilePath())); |
939 if (extension) | 1023 if (extension) |
940 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1024 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
941 } | 1025 } |
942 #endif // !defined(OS_CHROMEOS) | 1026 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |