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> |
| 10 |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 class CommandTest : public testing::Test { | 19 class CommandTest : public testing::Test { |
19 }; | 20 }; |
20 | 21 |
(...skipping 12 matching lines...) Expand all Loading... |
33 // dictionary. | 34 // dictionary. |
34 void CheckParse(ConstCommandsTestData data, | 35 void CheckParse(ConstCommandsTestData data, |
35 int i, | 36 int i, |
36 bool platform_specific_only, | 37 bool platform_specific_only, |
37 std::vector<std::string>& platforms) { | 38 std::vector<std::string>& platforms) { |
38 SCOPED_TRACE(std::string("Command name: |") + data.command_name + "| key: |" + | 39 SCOPED_TRACE(std::string("Command name: |") + data.command_name + "| key: |" + |
39 data.key + "| description: |" + data.description + "| index: " + | 40 data.key + "| description: |" + data.description + "| index: " + |
40 base::IntToString(i)); | 41 base::IntToString(i)); |
41 | 42 |
42 extensions::Command command; | 43 extensions::Command command; |
43 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue); | 44 std::unique_ptr<base::DictionaryValue> input(new base::DictionaryValue); |
44 base::string16 error; | 45 base::string16 error; |
45 | 46 |
46 // First, test the parse of a string suggested_key value. | 47 // First, test the parse of a string suggested_key value. |
47 input->SetString("suggested_key", data.key); | 48 input->SetString("suggested_key", data.key); |
48 input->SetString("description", data.description); | 49 input->SetString("description", data.description); |
49 | 50 |
50 if (!platform_specific_only) { | 51 if (!platform_specific_only) { |
51 bool result = command.Parse(input.get(), data.command_name, i, &error); | 52 bool result = command.Parse(input.get(), data.command_name, i, &error); |
52 EXPECT_EQ(data.expected_result, result); | 53 EXPECT_EQ(data.expected_result, result); |
53 if (result) { | 54 if (result) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 for (size_t i = 0; i < arraysize(kTests); ++i) | 199 for (size_t i = 0; i < arraysize(kTests); ++i) |
199 CheckParse(kTests[i], i, false, all_platforms); | 200 CheckParse(kTests[i], i, false, all_platforms); |
200 } | 201 } |
201 | 202 |
202 TEST(CommandTest, ExtensionCommandParsingFallback) { | 203 TEST(CommandTest, ExtensionCommandParsingFallback) { |
203 std::string description = "desc"; | 204 std::string description = "desc"; |
204 std::string command_name = "foo"; | 205 std::string command_name = "foo"; |
205 | 206 |
206 // Test that platform specific keys are honored on each platform, despite | 207 // Test that platform specific keys are honored on each platform, despite |
207 // fallback being given. | 208 // fallback being given. |
208 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue); | 209 std::unique_ptr<base::DictionaryValue> input(new base::DictionaryValue); |
209 base::DictionaryValue* key_dict = new base::DictionaryValue(); | 210 base::DictionaryValue* key_dict = new base::DictionaryValue(); |
210 key_dict->SetString("default", "Ctrl+Shift+D"); | 211 key_dict->SetString("default", "Ctrl+Shift+D"); |
211 key_dict->SetString("windows", "Ctrl+Shift+W"); | 212 key_dict->SetString("windows", "Ctrl+Shift+W"); |
212 key_dict->SetString("mac", "Ctrl+Shift+M"); | 213 key_dict->SetString("mac", "Ctrl+Shift+M"); |
213 key_dict->SetString("linux", "Ctrl+Shift+L"); | 214 key_dict->SetString("linux", "Ctrl+Shift+L"); |
214 key_dict->SetString("chromeos", "Ctrl+Shift+C"); | 215 key_dict->SetString("chromeos", "Ctrl+Shift+C"); |
215 input->Set("suggested_key", key_dict); | 216 input->Set("suggested_key", key_dict); |
216 input->SetString("description", description); | 217 input->SetString("description", description); |
217 | 218 |
218 extensions::Command command; | 219 extensions::Command command; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 }; | 306 }; |
306 std::vector<std::string> non_chromeos; | 307 std::vector<std::string> non_chromeos; |
307 non_chromeos.push_back("default"); | 308 non_chromeos.push_back("default"); |
308 non_chromeos.push_back("windows"); | 309 non_chromeos.push_back("windows"); |
309 non_chromeos.push_back("mac"); | 310 non_chromeos.push_back("mac"); |
310 non_chromeos.push_back("linux"); | 311 non_chromeos.push_back("linux"); |
311 | 312 |
312 for (size_t i = 0; i < arraysize(kNonChromeOsSearchTests); ++i) | 313 for (size_t i = 0; i < arraysize(kNonChromeOsSearchTests); ++i) |
313 CheckParse(kNonChromeOsSearchTests[i], i, true, non_chromeos); | 314 CheckParse(kNonChromeOsSearchTests[i], i, true, non_chromeos); |
314 } | 315 } |
OLD | NEW |