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

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

Issue 10383240: This adds a webui overlay on the extensions page for showing what Extension keybindings are active.… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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/extension_commands.h" 5 #include "chrome/common/extensions/extension_commands.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h"
9 #include "base/values.h" 11 #include "base/values.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 class ExtensionCommandsTest : public testing::Test { 14 class ExtensionCommandsTest : public testing::Test {
13 }; 15 };
14 16
15 TEST(ExtensionCommandsTest, ExtensionCommandParsing) { 17 TEST(ExtensionCommandsTest, ExtensionCommandParsing) {
16 const ui::Accelerator None = ui::Accelerator(); 18 const ui::Accelerator None = ui::Accelerator();
17 const ui::Accelerator ShiftF = 19 const ui::Accelerator ShiftF =
18 ui::Accelerator(ui::VKEY_F, true, false, false); 20 ui::Accelerator(ui::VKEY_F, true, false, false);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 "| description: |" + kTests[i].description + 83 "| description: |" + kTests[i].description +
82 "| index: " + base::IntToString(i)); 84 "| index: " + base::IntToString(i));
83 85
84 extensions::Command command; 86 extensions::Command command;
85 string16 error; 87 string16 error;
86 bool result = 88 bool result =
87 command.Parse(input.get(), kTests[i].command_name, i, &error); 89 command.Parse(input.get(), kTests[i].command_name, i, &error);
88 90
89 EXPECT_EQ(kTests[i].expected_result, result); 91 EXPECT_EQ(kTests[i].expected_result, result);
90 if (result) { 92 if (result) {
91 EXPECT_STREQ(kTests[i].description, command.description().c_str()); 93 EXPECT_STREQ(kTests[i].description,
94 UTF16ToASCII(command.description()).c_str());
92 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); 95 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str());
93 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); 96 EXPECT_EQ(kTests[i].accelerator, command.accelerator());
94 } 97 }
95 98
96 // Now parse the command as a dictionary of multiple values. 99 // Now parse the command as a dictionary of multiple values.
97 input.reset(new DictionaryValue); 100 input.reset(new DictionaryValue);
98 DictionaryValue* key_dict = new DictionaryValue(); 101 DictionaryValue* key_dict = new DictionaryValue();
99 key_dict->SetString("default", kTests[i].key); 102 key_dict->SetString("default", kTests[i].key);
100 key_dict->SetString("windows", kTests[i].key); 103 key_dict->SetString("windows", kTests[i].key);
101 key_dict->SetString("mac", kTests[i].key); 104 key_dict->SetString("mac", kTests[i].key);
102 input->Set("suggested_key", key_dict); 105 input->Set("suggested_key", key_dict);
103 input->SetString("description", kTests[i].description); 106 input->SetString("description", kTests[i].description);
104 107
105 result = command.Parse(input.get(), kTests[i].command_name, i, &error); 108 result = command.Parse(input.get(), kTests[i].command_name, i, &error);
106 109
107 EXPECT_EQ(kTests[i].expected_result, result); 110 EXPECT_EQ(kTests[i].expected_result, result);
108 if (result) { 111 if (result) {
109 EXPECT_STREQ(kTests[i].description, command.description().c_str()); 112 EXPECT_STREQ(kTests[i].description,
113 UTF16ToASCII(command.description()).c_str());
110 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); 114 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str());
111 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); 115 EXPECT_EQ(kTests[i].accelerator, command.accelerator());
112 } 116 }
113 } 117 }
114 } 118 }
115 119
116 TEST(ExtensionCommandsTest, ExtensionCommandParsingFallback) { 120 TEST(ExtensionCommandsTest, ExtensionCommandParsingFallback) {
117 std::string description = "desc"; 121 std::string description = "desc";
118 std::string command_name = "foo"; 122 std::string command_name = "foo";
119 123
120 // Test that platform specific keys are honored on each platform, despite 124 // Test that platform specific keys are honored on each platform, despite
121 // fallback being given. 125 // fallback being given.
122 scoped_ptr<DictionaryValue> input(new DictionaryValue); 126 scoped_ptr<DictionaryValue> input(new DictionaryValue);
123 DictionaryValue* key_dict = new DictionaryValue(); 127 DictionaryValue* key_dict = new DictionaryValue();
124 key_dict->SetString("default", "Ctrl+Shift+D"); 128 key_dict->SetString("default", "Ctrl+Shift+D");
125 key_dict->SetString("windows", "Ctrl+Shift+W"); 129 key_dict->SetString("windows", "Ctrl+Shift+W");
126 key_dict->SetString("mac", "Ctrl+Shift+M"); 130 key_dict->SetString("mac", "Ctrl+Shift+M");
127 key_dict->SetString("linux", "Ctrl+Shift+L"); 131 key_dict->SetString("linux", "Ctrl+Shift+L");
128 key_dict->SetString("chromeos", "Ctrl+Shift+C"); 132 key_dict->SetString("chromeos", "Ctrl+Shift+C");
129 input->Set("suggested_key", key_dict); 133 input->Set("suggested_key", key_dict);
130 input->SetString("description", description); 134 input->SetString("description", description);
131 135
132 extensions::Command command; 136 extensions::Command command;
133 string16 error; 137 string16 error;
134 EXPECT_TRUE(command.Parse(input.get(), command_name, 0, &error)); 138 EXPECT_TRUE(command.Parse(input.get(), command_name, 0, &error));
135 EXPECT_STREQ(description.c_str(), command.description().c_str()); 139 EXPECT_STREQ(description.c_str(),
140 UTF16ToASCII(command.description()).c_str());
136 EXPECT_STREQ(command_name.c_str(), command.command_name().c_str()); 141 EXPECT_STREQ(command_name.c_str(), command.command_name().c_str());
137 142
138 #if defined(OS_WIN) 143 #if defined(OS_WIN)
139 ui::Accelerator accelerator(ui::VKEY_W, true, true, false); 144 ui::Accelerator accelerator(ui::VKEY_W, true, true, false);
140 #elif defined(OS_MACOSX) 145 #elif defined(OS_MACOSX)
141 ui::Accelerator accelerator(ui::VKEY_M, true, true, false); 146 ui::Accelerator accelerator(ui::VKEY_M, true, true, false);
142 #elif defined(OS_CHROMEOS) 147 #elif defined(OS_CHROMEOS)
143 ui::Accelerator accelerator(ui::VKEY_C, true, true, false); 148 ui::Accelerator accelerator(ui::VKEY_C, true, true, false);
144 #elif defined(OS_LINUX) 149 #elif defined(OS_LINUX)
145 ui::Accelerator accelerator(ui::VKEY_L, true, true, false); 150 ui::Accelerator accelerator(ui::VKEY_L, true, true, false);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); 182 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error));
178 183
179 // Make sure Mac specific keys are not processed on other platforms. 184 // Make sure Mac specific keys are not processed on other platforms.
180 #if !defined(OS_MACOSX) 185 #if !defined(OS_MACOSX)
181 key_dict->SetString("windows", "Command+Shift+M"); 186 key_dict->SetString("windows", "Command+Shift+M");
182 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); 187 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error));
183 key_dict->SetString("windows", "Options+Shift+M"); 188 key_dict->SetString("windows", "Options+Shift+M");
184 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); 189 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error));
185 #endif 190 #endif
186 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698