| 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/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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 "| index: " + base::IntToString(i)); | 130 "| index: " + base::IntToString(i)); |
| 131 | 131 |
| 132 extensions::Command command; | 132 extensions::Command command; |
| 133 base::string16 error; | 133 base::string16 error; |
| 134 bool result = | 134 bool result = |
| 135 command.Parse(input.get(), kTests[i].command_name, i, &error); | 135 command.Parse(input.get(), kTests[i].command_name, i, &error); |
| 136 | 136 |
| 137 EXPECT_EQ(kTests[i].expected_result, result); | 137 EXPECT_EQ(kTests[i].expected_result, result); |
| 138 if (result) { | 138 if (result) { |
| 139 EXPECT_STREQ(kTests[i].description, | 139 EXPECT_STREQ(kTests[i].description, |
| 140 UTF16ToASCII(command.description()).c_str()); | 140 base::UTF16ToASCII(command.description()).c_str()); |
| 141 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); | 141 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); |
| 142 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); | 142 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Now parse the command as a dictionary of multiple values. | 145 // Now parse the command as a dictionary of multiple values. |
| 146 if (kTests[i].key[0] != '\0') { | 146 if (kTests[i].key[0] != '\0') { |
| 147 input.reset(new base::DictionaryValue); | 147 input.reset(new base::DictionaryValue); |
| 148 base::DictionaryValue* key_dict = new base::DictionaryValue(); | 148 base::DictionaryValue* key_dict = new base::DictionaryValue(); |
| 149 key_dict->SetString("default", kTests[i].key); | 149 key_dict->SetString("default", kTests[i].key); |
| 150 key_dict->SetString("windows", kTests[i].key); | 150 key_dict->SetString("windows", kTests[i].key); |
| 151 key_dict->SetString("mac", kTests[i].key); | 151 key_dict->SetString("mac", kTests[i].key); |
| 152 input->Set("suggested_key", key_dict); | 152 input->Set("suggested_key", key_dict); |
| 153 input->SetString("description", kTests[i].description); | 153 input->SetString("description", kTests[i].description); |
| 154 | 154 |
| 155 result = command.Parse(input.get(), kTests[i].command_name, i, &error); | 155 result = command.Parse(input.get(), kTests[i].command_name, i, &error); |
| 156 | 156 |
| 157 EXPECT_EQ(kTests[i].expected_result, result); | 157 EXPECT_EQ(kTests[i].expected_result, result); |
| 158 if (result) { | 158 if (result) { |
| 159 EXPECT_STREQ(kTests[i].description, | 159 EXPECT_STREQ(kTests[i].description, |
| 160 UTF16ToASCII(command.description()).c_str()); | 160 base::UTF16ToASCII(command.description()).c_str()); |
| 161 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); | 161 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); |
| 162 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); | 162 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 TEST(CommandTest, ExtensionCommandParsingFallback) { | 168 TEST(CommandTest, ExtensionCommandParsingFallback) { |
| 169 std::string description = "desc"; | 169 std::string description = "desc"; |
| 170 std::string command_name = "foo"; | 170 std::string command_name = "foo"; |
| 171 | 171 |
| 172 // Test that platform specific keys are honored on each platform, despite | 172 // Test that platform specific keys are honored on each platform, despite |
| 173 // fallback being given. | 173 // fallback being given. |
| 174 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue); | 174 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue); |
| 175 base::DictionaryValue* key_dict = new base::DictionaryValue(); | 175 base::DictionaryValue* key_dict = new base::DictionaryValue(); |
| 176 key_dict->SetString("default", "Ctrl+Shift+D"); | 176 key_dict->SetString("default", "Ctrl+Shift+D"); |
| 177 key_dict->SetString("windows", "Ctrl+Shift+W"); | 177 key_dict->SetString("windows", "Ctrl+Shift+W"); |
| 178 key_dict->SetString("mac", "Ctrl+Shift+M"); | 178 key_dict->SetString("mac", "Ctrl+Shift+M"); |
| 179 key_dict->SetString("linux", "Ctrl+Shift+L"); | 179 key_dict->SetString("linux", "Ctrl+Shift+L"); |
| 180 key_dict->SetString("chromeos", "Ctrl+Shift+C"); | 180 key_dict->SetString("chromeos", "Ctrl+Shift+C"); |
| 181 input->Set("suggested_key", key_dict); | 181 input->Set("suggested_key", key_dict); |
| 182 input->SetString("description", description); | 182 input->SetString("description", description); |
| 183 | 183 |
| 184 extensions::Command command; | 184 extensions::Command command; |
| 185 base::string16 error; | 185 base::string16 error; |
| 186 EXPECT_TRUE(command.Parse(input.get(), command_name, 0, &error)); | 186 EXPECT_TRUE(command.Parse(input.get(), command_name, 0, &error)); |
| 187 EXPECT_STREQ(description.c_str(), | 187 EXPECT_STREQ(description.c_str(), |
| 188 UTF16ToASCII(command.description()).c_str()); | 188 base::UTF16ToASCII(command.description()).c_str()); |
| 189 EXPECT_STREQ(command_name.c_str(), command.command_name().c_str()); | 189 EXPECT_STREQ(command_name.c_str(), command.command_name().c_str()); |
| 190 | 190 |
| 191 #if defined(OS_WIN) | 191 #if defined(OS_WIN) |
| 192 ui::Accelerator accelerator(ui::VKEY_W, | 192 ui::Accelerator accelerator(ui::VKEY_W, |
| 193 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); | 193 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
| 194 #elif defined(OS_MACOSX) | 194 #elif defined(OS_MACOSX) |
| 195 ui::Accelerator accelerator(ui::VKEY_M, | 195 ui::Accelerator accelerator(ui::VKEY_M, |
| 196 ui::EF_SHIFT_DOWN | ui::EF_COMMAND_DOWN); | 196 ui::EF_SHIFT_DOWN | ui::EF_COMMAND_DOWN); |
| 197 #elif defined(OS_CHROMEOS) | 197 #elif defined(OS_CHROMEOS) |
| 198 ui::Accelerator accelerator(ui::VKEY_C, | 198 ui::Accelerator accelerator(ui::VKEY_C, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 key_dict->SetString("windows", "Ctrl+Shift+W"); | 241 key_dict->SetString("windows", "Ctrl+Shift+W"); |
| 242 #endif | 242 #endif |
| 243 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); | 243 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); |
| 244 | 244 |
| 245 // Make sure Mac specific keys are not processed on other platforms. | 245 // Make sure Mac specific keys are not processed on other platforms. |
| 246 #if !defined(OS_MACOSX) | 246 #if !defined(OS_MACOSX) |
| 247 key_dict->SetString("windows", "Command+Shift+M"); | 247 key_dict->SetString("windows", "Command+Shift+M"); |
| 248 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); | 248 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); |
| 249 #endif | 249 #endif |
| 250 } | 250 } |
| OLD | NEW |