OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/common/test_util.h" | 5 #include "extensions/common/test_util.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "extensions/common/extension.h" | 9 #include "extensions/common/extension.h" |
10 #include "extensions/common/extension_builder.h" | 10 #include "extensions/common/extension_builder.h" |
11 #include "extensions/common/value_builder.h" | 11 #include "extensions/common/value_builder.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 namespace test_util { | 15 namespace test_util { |
16 | 16 |
17 ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) { | 17 ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) { |
18 return builder | 18 return builder |
19 .SetManifest(DictionaryBuilder() | 19 .SetManifest(DictionaryBuilder() |
20 .Set("name", "Test extension") | 20 .Set("name", "Test extension") |
21 .Set("version", "1.0") | 21 .Set("version", "1.0") |
22 .Set("manifest_version", 2)); | 22 .Set("manifest_version", 2)); |
23 } | 23 } |
24 | 24 |
| 25 scoped_refptr<Extension> CreateEmptyExtension() { |
| 26 scoped_refptr<Extension> empty_extension( |
| 27 ExtensionBuilder() |
| 28 .SetManifest( |
| 29 DictionaryBuilder().Set("name", "Test").Set("version", "1.0")) |
| 30 .Build()); |
| 31 return empty_extension; |
| 32 } |
| 33 |
25 scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) { | 34 scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) { |
26 return ExtensionBuilder() | 35 return ExtensionBuilder() |
27 .SetManifest( | 36 .SetManifest( |
28 DictionaryBuilder().Set("name", "test").Set("version", "0.1")) | 37 DictionaryBuilder().Set("name", "test").Set("version", "0.1")) |
29 .SetID(id) | 38 .SetID(id) |
30 .Build(); | 39 .Build(); |
31 } | 40 } |
32 | 41 |
33 scoped_ptr<base::DictionaryValue> ParseJsonDictionaryWithSingleQuotes( | 42 scoped_ptr<base::DictionaryValue> ParseJsonDictionaryWithSingleQuotes( |
34 std::string json) { | 43 std::string json) { |
35 std::replace(json.begin(), json.end(), '\'', '"'); | 44 std::replace(json.begin(), json.end(), '\'', '"'); |
36 std::string error_msg; | 45 std::string error_msg; |
37 scoped_ptr<base::Value> result(base::JSONReader::ReadAndReturnError( | 46 scoped_ptr<base::Value> result(base::JSONReader::ReadAndReturnError( |
38 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg)); | 47 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg)); |
39 scoped_ptr<base::DictionaryValue> result_dict; | 48 scoped_ptr<base::DictionaryValue> result_dict; |
40 if (result && result->IsType(base::Value::TYPE_DICTIONARY)) { | 49 if (result && result->IsType(base::Value::TYPE_DICTIONARY)) { |
41 result_dict.reset(static_cast<base::DictionaryValue*>(result.release())); | 50 result_dict.reset(static_cast<base::DictionaryValue*>(result.release())); |
42 } else { | 51 } else { |
43 ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg; | 52 ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg; |
44 result_dict.reset(new base::DictionaryValue()); | 53 result_dict.reset(new base::DictionaryValue()); |
45 } | 54 } |
46 return result_dict.Pass(); | 55 return result_dict.Pass(); |
47 } | 56 } |
48 | 57 |
49 } // namespace test_util | 58 } // namespace test_util |
50 } // namespace extensions | 59 } // namespace extensions |
OLD | NEW |