| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 17 #include "base/values.h" |
| 16 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 class CommandTest : public testing::Test { | 21 class CommandTest : public testing::Test { |
| 20 }; | 22 }; |
| 21 | 23 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 if (platform_specific_only && | 67 if (platform_specific_only && |
| 66 std::find(platforms.begin(), platforms.end(), current_platform) == | 68 std::find(platforms.begin(), platforms.end(), current_platform) == |
| 67 platforms.end()) { | 69 platforms.end()) { |
| 68 // Given a |current_platform| without a |suggested_key|, |default| is | 70 // Given a |current_platform| without a |suggested_key|, |default| is |
| 69 // used. However, some keys, such as Search on Chrome OS, are only valid | 71 // used. However, some keys, such as Search on Chrome OS, are only valid |
| 70 // for platform specific entries. Skip the test in this case. | 72 // for platform specific entries. Skip the test in this case. |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 73 | 75 |
| 74 input.reset(new base::DictionaryValue); | 76 input.reset(new base::DictionaryValue); |
| 75 base::DictionaryValue* key_dict = new base::DictionaryValue(); | 77 auto key_dict = base::MakeUnique<base::DictionaryValue>(); |
| 76 | 78 |
| 77 for (size_t j = 0; j < platforms.size(); ++j) | 79 for (size_t j = 0; j < platforms.size(); ++j) |
| 78 key_dict->SetString(platforms[j], data.key); | 80 key_dict->SetString(platforms[j], data.key); |
| 79 | 81 |
| 80 input->Set("suggested_key", key_dict); | 82 input->Set("suggested_key", std::move(key_dict)); |
| 81 input->SetString("description", data.description); | 83 input->SetString("description", data.description); |
| 82 | 84 |
| 83 bool result = command.Parse(input.get(), data.command_name, i, &error); | 85 bool result = command.Parse(input.get(), data.command_name, i, &error); |
| 84 EXPECT_EQ(data.expected_result, result); | 86 EXPECT_EQ(data.expected_result, result); |
| 85 | 87 |
| 86 if (result) { | 88 if (result) { |
| 87 EXPECT_STREQ(data.description, | 89 EXPECT_STREQ(data.description, |
| 88 base::UTF16ToASCII(command.description()).c_str()); | 90 base::UTF16ToASCII(command.description()).c_str()); |
| 89 EXPECT_STREQ(data.command_name, command.command_name().c_str()); | 91 EXPECT_STREQ(data.command_name, command.command_name().c_str()); |
| 90 EXPECT_EQ(data.accelerator, command.accelerator()); | 92 EXPECT_EQ(data.accelerator, command.accelerator()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 CheckParse(kTests[i], i, false, all_platforms); | 202 CheckParse(kTests[i], i, false, all_platforms); |
| 201 } | 203 } |
| 202 | 204 |
| 203 TEST(CommandTest, ExtensionCommandParsingFallback) { | 205 TEST(CommandTest, ExtensionCommandParsingFallback) { |
| 204 std::string description = "desc"; | 206 std::string description = "desc"; |
| 205 std::string command_name = "foo"; | 207 std::string command_name = "foo"; |
| 206 | 208 |
| 207 // Test that platform specific keys are honored on each platform, despite | 209 // Test that platform specific keys are honored on each platform, despite |
| 208 // fallback being given. | 210 // fallback being given. |
| 209 std::unique_ptr<base::DictionaryValue> input(new base::DictionaryValue); | 211 std::unique_ptr<base::DictionaryValue> input(new base::DictionaryValue); |
| 210 base::DictionaryValue* key_dict = new base::DictionaryValue(); | 212 input->SetString("description", description); |
| 211 key_dict->SetString("default", "Ctrl+Shift+D"); | 213 base::DictionaryValue* key_dict = input->SetDictionary( |
| 212 key_dict->SetString("windows", "Ctrl+Shift+W"); | 214 "suggested_key", base::MakeUnique<base::DictionaryValue>()); |
| 213 key_dict->SetString("mac", "Ctrl+Shift+M"); | 215 key_dict->SetString("default", "Ctrl+Shift+D"); |
| 214 key_dict->SetString("linux", "Ctrl+Shift+L"); | 216 key_dict->SetString("windows", "Ctrl+Shift+W"); |
| 217 key_dict->SetString("mac", "Ctrl+Shift+M"); |
| 218 key_dict->SetString("linux", "Ctrl+Shift+L"); |
| 215 key_dict->SetString("chromeos", "Ctrl+Shift+C"); | 219 key_dict->SetString("chromeos", "Ctrl+Shift+C"); |
| 216 input->Set("suggested_key", key_dict); | |
| 217 input->SetString("description", description); | |
| 218 | 220 |
| 219 extensions::Command command; | 221 extensions::Command command; |
| 220 base::string16 error; | 222 base::string16 error; |
| 221 EXPECT_TRUE(command.Parse(input.get(), command_name, 0, &error)); | 223 EXPECT_TRUE(command.Parse(input.get(), command_name, 0, &error)); |
| 222 EXPECT_STREQ(description.c_str(), | 224 EXPECT_STREQ(description.c_str(), |
| 223 base::UTF16ToASCII(command.description()).c_str()); | 225 base::UTF16ToASCII(command.description()).c_str()); |
| 224 EXPECT_STREQ(command_name.c_str(), command.command_name().c_str()); | 226 EXPECT_STREQ(command_name.c_str(), command.command_name().c_str()); |
| 225 | 227 |
| 226 #if defined(OS_WIN) | 228 #if defined(OS_WIN) |
| 227 ui::Accelerator accelerator(ui::VKEY_W, | 229 ui::Accelerator accelerator(ui::VKEY_W, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 }; | 308 }; |
| 307 std::vector<std::string> non_chromeos; | 309 std::vector<std::string> non_chromeos; |
| 308 non_chromeos.push_back("default"); | 310 non_chromeos.push_back("default"); |
| 309 non_chromeos.push_back("windows"); | 311 non_chromeos.push_back("windows"); |
| 310 non_chromeos.push_back("mac"); | 312 non_chromeos.push_back("mac"); |
| 311 non_chromeos.push_back("linux"); | 313 non_chromeos.push_back("linux"); |
| 312 | 314 |
| 313 for (size_t i = 0; i < arraysize(kNonChromeOsSearchTests); ++i) | 315 for (size_t i = 0; i < arraysize(kNonChromeOsSearchTests); ++i) |
| 314 CheckParse(kNonChromeOsSearchTests[i], i, true, non_chromeos); | 316 CheckParse(kNonChromeOsSearchTests[i], i, true, non_chromeos); |
| 315 } | 317 } |
| OLD | NEW |