Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / common / test_util.cc
blob03b35b84801522cd6f945ee3b99549e9a9efb362
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
3 // found in the LICENSE file.
5 #include "extensions/common/test_util.h"
7 #include "base/json/json_reader.h"
8 #include "base/values.h"
9 #include "extensions/common/extension.h"
10 #include "extensions/common/extension_builder.h"
11 #include "extensions/common/value_builder.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace extensions {
15 namespace test_util {
17 ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) {
18 return builder
19 .SetManifest(DictionaryBuilder()
20 .Set("name", "Test extension")
21 .Set("version", "1.0")
22 .Set("manifest_version", 2));
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;
34 scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) {
35 return ExtensionBuilder()
36 .SetManifest(
37 DictionaryBuilder().Set("name", "test").Set("version", "0.1"))
38 .SetID(id)
39 .Build();
42 scoped_ptr<base::DictionaryValue> ParseJsonDictionaryWithSingleQuotes(
43 std::string json) {
44 std::replace(json.begin(), json.end(), '\'', '"');
45 std::string error_msg;
46 scoped_ptr<base::Value> result(base::JSONReader::ReadAndReturnError(
47 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg));
48 scoped_ptr<base::DictionaryValue> result_dict;
49 if (result && result->IsType(base::Value::TYPE_DICTIONARY)) {
50 result_dict.reset(static_cast<base::DictionaryValue*>(result.release()));
51 } else {
52 ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg;
53 result_dict.reset(new base::DictionaryValue());
55 return result_dict.Pass();
58 } // namespace test_util
59 } // namespace extensions