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_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 shift_f = ui::Accelerator(ui::VKEY_F, | 19 const ui::Accelerator shift_f = ui::Accelerator(ui::VKEY_F, |
18 ui::EF_SHIFT_DOWN); | 20 ui::EF_SHIFT_DOWN); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 "| description: |" + kTests[i].description + | 82 "| description: |" + kTests[i].description + |
81 "| index: " + base::IntToString(i)); | 83 "| index: " + base::IntToString(i)); |
82 | 84 |
83 extensions::Command command; | 85 extensions::Command command; |
84 string16 error; | 86 string16 error; |
85 bool result = | 87 bool result = |
86 command.Parse(input.get(), kTests[i].command_name, i, &error); | 88 command.Parse(input.get(), kTests[i].command_name, i, &error); |
87 | 89 |
88 EXPECT_EQ(kTests[i].expected_result, result); | 90 EXPECT_EQ(kTests[i].expected_result, result); |
89 if (result) { | 91 if (result) { |
90 EXPECT_STREQ(kTests[i].description, command.description().c_str()); | 92 EXPECT_STREQ(kTests[i].description, |
| 93 UTF16ToASCII(command.description()).c_str()); |
91 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); | 94 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); |
92 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); | 95 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); |
93 } | 96 } |
94 | 97 |
95 // Now parse the command as a dictionary of multiple values. | 98 // Now parse the command as a dictionary of multiple values. |
96 input.reset(new DictionaryValue); | 99 input.reset(new DictionaryValue); |
97 DictionaryValue* key_dict = new DictionaryValue(); | 100 DictionaryValue* key_dict = new DictionaryValue(); |
98 key_dict->SetString("default", kTests[i].key); | 101 key_dict->SetString("default", kTests[i].key); |
99 key_dict->SetString("windows", kTests[i].key); | 102 key_dict->SetString("windows", kTests[i].key); |
100 key_dict->SetString("mac", kTests[i].key); | 103 key_dict->SetString("mac", kTests[i].key); |
101 input->Set("suggested_key", key_dict); | 104 input->Set("suggested_key", key_dict); |
102 input->SetString("description", kTests[i].description); | 105 input->SetString("description", kTests[i].description); |
103 | 106 |
104 result = command.Parse(input.get(), kTests[i].command_name, i, &error); | 107 result = command.Parse(input.get(), kTests[i].command_name, i, &error); |
105 | 108 |
106 EXPECT_EQ(kTests[i].expected_result, result); | 109 EXPECT_EQ(kTests[i].expected_result, result); |
107 if (result) { | 110 if (result) { |
108 EXPECT_STREQ(kTests[i].description, command.description().c_str()); | 111 EXPECT_STREQ(kTests[i].description, |
| 112 UTF16ToASCII(command.description()).c_str()); |
109 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); | 113 EXPECT_STREQ(kTests[i].command_name, command.command_name().c_str()); |
110 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); | 114 EXPECT_EQ(kTests[i].accelerator, command.accelerator()); |
111 } | 115 } |
112 } | 116 } |
113 } | 117 } |
114 | 118 |
115 TEST(ExtensionCommandsTest, ExtensionCommandParsingFallback) { | 119 TEST(ExtensionCommandsTest, ExtensionCommandParsingFallback) { |
116 std::string description = "desc"; | 120 std::string description = "desc"; |
117 std::string command_name = "foo"; | 121 std::string command_name = "foo"; |
118 | 122 |
119 // Test that platform specific keys are honored on each platform, despite | 123 // Test that platform specific keys are honored on each platform, despite |
120 // fallback being given. | 124 // fallback being given. |
121 scoped_ptr<DictionaryValue> input(new DictionaryValue); | 125 scoped_ptr<DictionaryValue> input(new DictionaryValue); |
122 DictionaryValue* key_dict = new DictionaryValue(); | 126 DictionaryValue* key_dict = new DictionaryValue(); |
123 key_dict->SetString("default", "Ctrl+Shift+D"); | 127 key_dict->SetString("default", "Ctrl+Shift+D"); |
124 key_dict->SetString("windows", "Ctrl+Shift+W"); | 128 key_dict->SetString("windows", "Ctrl+Shift+W"); |
125 key_dict->SetString("mac", "Ctrl+Shift+M"); | 129 key_dict->SetString("mac", "Ctrl+Shift+M"); |
126 key_dict->SetString("linux", "Ctrl+Shift+L"); | 130 key_dict->SetString("linux", "Ctrl+Shift+L"); |
127 key_dict->SetString("chromeos", "Ctrl+Shift+C"); | 131 key_dict->SetString("chromeos", "Ctrl+Shift+C"); |
128 input->Set("suggested_key", key_dict); | 132 input->Set("suggested_key", key_dict); |
129 input->SetString("description", description); | 133 input->SetString("description", description); |
130 | 134 |
131 extensions::Command command; | 135 extensions::Command command; |
132 string16 error; | 136 string16 error; |
133 EXPECT_TRUE(command.Parse(input.get(), command_name, 0, &error)); | 137 EXPECT_TRUE(command.Parse(input.get(), command_name, 0, &error)); |
134 EXPECT_STREQ(description.c_str(), command.description().c_str()); | 138 EXPECT_STREQ(description.c_str(), |
| 139 UTF16ToASCII(command.description()).c_str()); |
135 EXPECT_STREQ(command_name.c_str(), command.command_name().c_str()); | 140 EXPECT_STREQ(command_name.c_str(), command.command_name().c_str()); |
136 | 141 |
137 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
138 ui::Accelerator accelerator(ui::VKEY_W, | 143 ui::Accelerator accelerator(ui::VKEY_W, |
139 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); | 144 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
140 #elif defined(OS_MACOSX) | 145 #elif defined(OS_MACOSX) |
141 ui::Accelerator accelerator(ui::VKEY_M, | 146 ui::Accelerator accelerator(ui::VKEY_M, |
142 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); | 147 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
143 #elif defined(OS_CHROMEOS) | 148 #elif defined(OS_CHROMEOS) |
144 ui::Accelerator accelerator(ui::VKEY_C, | 149 ui::Accelerator accelerator(ui::VKEY_C, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); | 186 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); |
182 | 187 |
183 // Make sure Mac specific keys are not processed on other platforms. | 188 // Make sure Mac specific keys are not processed on other platforms. |
184 #if !defined(OS_MACOSX) | 189 #if !defined(OS_MACOSX) |
185 key_dict->SetString("windows", "Command+Shift+M"); | 190 key_dict->SetString("windows", "Command+Shift+M"); |
186 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); | 191 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); |
187 key_dict->SetString("windows", "Options+Shift+M"); | 192 key_dict->SetString("windows", "Options+Shift+M"); |
188 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); | 193 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); |
189 #endif | 194 #endif |
190 } | 195 } |
OLD | NEW |