Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/common/extensions/command_unittest.cc

Issue 12965009: Remove the limit of number of commands per extension, but keep the limit of 4 shortcuts per extensi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/command.h" 5 #include "chrome/common/extensions/command.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 23 matching lines...) Expand all
34 34
35 const struct { 35 const struct {
36 bool expected_result; 36 bool expected_result;
37 ui::Accelerator accelerator; 37 ui::Accelerator accelerator;
38 const char* command_name; 38 const char* command_name;
39 const char* key; 39 const char* key;
40 const char* description; 40 const char* description;
41 } kTests[] = { 41 } kTests[] = {
42 // Negative test (one or more missing required fields). We don't need to 42 // Negative test (one or more missing required fields). We don't need to
43 // test |command_name| being blank as it is used as a key in the manifest, 43 // test |command_name| being blank as it is used as a key in the manifest,
44 // so it can't be blank (and we CHECK() when it is). 44 // so it can't be blank (and we CHECK() when it is). A blank shortcut is
45 // permitted.
45 { false, none, "command", "", "" }, 46 { false, none, "command", "", "" },
46 { false, none, "command", "Ctrl+f", "" }, 47 { false, none, "command", "Ctrl+f", "" },
47 { false, none, "command", "", "description" },
48 // Ctrl+Alt is not permitted, see MSDN link in comments in Parse function. 48 // Ctrl+Alt is not permitted, see MSDN link in comments in Parse function.
49 { false, none, "command", "Ctrl+Alt+F", "description" }, 49 { false, none, "command", "Ctrl+Alt+F", "description" },
50 // Unsupported shortcuts/too many, or missing modifier. 50 // Unsupported shortcuts/too many, or missing modifier.
51 { false, none, "command", "A", "description" }, 51 { false, none, "command", "A", "description" },
52 { false, none, "command", "F10", "description" }, 52 { false, none, "command", "F10", "description" },
53 { false, none, "command", "Ctrl+F+G", "description" }, 53 { false, none, "command", "Ctrl+F+G", "description" },
54 { false, none, "command", "Ctrl+Alt+Shift+G", "description" }, 54 { false, none, "command", "Ctrl+Alt+Shift+G", "description" },
55 // Shift on its own is not supported. 55 // Shift on its own is not supported.
56 { false, shift_f, "command", "Shift+F", "description" }, 56 { false, shift_f, "command", "Shift+F", "description" },
57 { false, shift_f, "command", "F+Shift", "description" }, 57 { false, shift_f, "command", "F+Shift", "description" },
58 // Basic tests. 58 // Basic tests.
59 { true, none, "command", "", "description" },
59 { true, ctrl_f, "command", "Ctrl+F", "description" }, 60 { true, ctrl_f, "command", "Ctrl+F", "description" },
60 { true, alt_f, "command", "Alt+F", "description" }, 61 { true, alt_f, "command", "Alt+F", "description" },
61 { true, ctrl_shift_f, "command", "Ctrl+Shift+F", "description" }, 62 { true, ctrl_shift_f, "command", "Ctrl+Shift+F", "description" },
62 { true, alt_shift_f, "command", "Alt+Shift+F", "description" }, 63 { true, alt_shift_f, "command", "Alt+Shift+F", "description" },
63 { true, ctrl_1, "command", "Ctrl+1", "description" }, 64 { true, ctrl_1, "command", "Ctrl+1", "description" },
64 // Shortcut token order tests. 65 // Shortcut token order tests.
65 { true, ctrl_f, "command", "F+Ctrl", "description" }, 66 { true, ctrl_f, "command", "F+Ctrl", "description" },
66 { true, alt_f, "command", "F+Alt", "description" }, 67 { true, alt_f, "command", "F+Alt", "description" },
67 { true, ctrl_shift_f, "command", "F+Ctrl+Shift", "description" }, 68 { true, ctrl_shift_f, "command", "F+Ctrl+Shift", "description" },
68 { true, ctrl_shift_f, "command", "F+Shift+Ctrl", "description" }, 69 { true, ctrl_shift_f, "command", "F+Shift+Ctrl", "description" },
(...skipping 25 matching lines...) Expand all
94 95
95 EXPECT_EQ(kTests[i].expected_result, result); 96 EXPECT_EQ(kTests[i].expected_result, result);
96 if (result) { 97 if (result) {
97 EXPECT_STREQ(kTests[i].description, 98 EXPECT_STREQ(kTests[i].description,
98 UTF16ToASCII(command.description()).c_str()); 99 UTF16ToASCII(command.description()).c_str());
99 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); 100 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str());
100 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); 101 EXPECT_EQ(kTests[i].accelerator, command.accelerator());
101 } 102 }
102 103
103 // Now parse the command as a dictionary of multiple values. 104 // Now parse the command as a dictionary of multiple values.
104 input.reset(new DictionaryValue); 105 if (kTests[i].key[0] != '\0') {
105 DictionaryValue* key_dict = new DictionaryValue(); 106 input.reset(new DictionaryValue);
106 key_dict->SetString("default", kTests[i].key); 107 DictionaryValue* key_dict = new DictionaryValue();
107 key_dict->SetString("windows", kTests[i].key); 108 key_dict->SetString("default", kTests[i].key);
108 key_dict->SetString("mac", kTests[i].key); 109 key_dict->SetString("windows", kTests[i].key);
109 input->Set("suggested_key", key_dict); 110 key_dict->SetString("mac", kTests[i].key);
110 input->SetString("description", kTests[i].description); 111 input->Set("suggested_key", key_dict);
112 input->SetString("description", kTests[i].description);
111 113
112 result = command.Parse(input.get(), kTests[i].command_name, i, &error); 114 result = command.Parse(input.get(), kTests[i].command_name, i, &error);
113 115
114 EXPECT_EQ(kTests[i].expected_result, result); 116 EXPECT_EQ(kTests[i].expected_result, result);
115 if (result) { 117 if (result) {
116 EXPECT_STREQ(kTests[i].description, 118 EXPECT_STREQ(kTests[i].description,
117 UTF16ToASCII(command.description()).c_str()); 119 UTF16ToASCII(command.description()).c_str());
118 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); 120 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str());
119 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); 121 EXPECT_EQ(kTests[i].accelerator, command.accelerator());
122 }
120 } 123 }
121 } 124 }
122 } 125 }
123 126
124 TEST(CommandTest, ExtensionCommandParsingFallback) { 127 TEST(CommandTest, ExtensionCommandParsingFallback) {
125 std::string description = "desc"; 128 std::string description = "desc";
126 std::string command_name = "foo"; 129 std::string command_name = "foo";
127 130
128 // Test that platform specific keys are honored on each platform, despite 131 // Test that platform specific keys are honored on each platform, despite
129 // fallback being given. 132 // fallback being given.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 key_dict->SetString("windows", "Ctrl+Shift+W"); 200 key_dict->SetString("windows", "Ctrl+Shift+W");
198 #endif 201 #endif
199 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); 202 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error));
200 203
201 // Make sure Mac specific keys are not processed on other platforms. 204 // Make sure Mac specific keys are not processed on other platforms.
202 #if !defined(OS_MACOSX) 205 #if !defined(OS_MACOSX)
203 key_dict->SetString("windows", "Command+Shift+M"); 206 key_dict->SetString("windows", "Command+Shift+M");
204 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); 207 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error));
205 #endif 208 #endif
206 } 209 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/command.cc ('k') | chrome/common/extensions/docs/templates/intros/commands.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698