Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: extensions/common/test_util.cc

Issue 178253007: Parse manifest file with app.service_worker.script. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved test utils out of base Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « extensions/common/test_util.h ('k') | extensions/extensions.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "base/values.h"
7 #include "extensions/common/extension.h" 9 #include "extensions/common/extension.h"
8 #include "extensions/common/extension_builder.h" 10 #include "extensions/common/extension_builder.h"
9 #include "extensions/common/value_builder.h" 11 #include "extensions/common/value_builder.h"
12 #include "testing/gtest/include/gtest/gtest.h"
10 13
11 namespace extensions { 14 namespace extensions {
12 namespace test_util { 15 namespace test_util {
13 16
14 ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) { 17 ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) {
15 return builder 18 return builder
16 .SetManifest(DictionaryBuilder() 19 .SetManifest(DictionaryBuilder()
17 .Set("name", "Test extension") 20 .Set("name", "Test extension")
18 .Set("version", "1.0") 21 .Set("version", "1.0")
19 .Set("manifest_version", 2)); 22 .Set("manifest_version", 2));
20 } 23 }
21 24
22 scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) { 25 scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) {
23 return ExtensionBuilder() 26 return ExtensionBuilder()
24 .SetManifest( 27 .SetManifest(
25 DictionaryBuilder().Set("name", "test").Set("version", "0.1")) 28 DictionaryBuilder().Set("name", "test").Set("version", "0.1"))
26 .SetID(id) 29 .SetID(id)
27 .Build(); 30 .Build();
28 } 31 }
29 32
33 scoped_ptr<base::DictionaryValue> ParseJsonDictionaryWithSingleQuotes(
34 std::string json) {
35 std::replace(json.begin(), json.end(), '\'', '"');
36 std::string error_msg;
37 scoped_ptr<base::Value> result(base::JSONReader::ReadAndReturnError(
38 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg));
39 scoped_ptr<base::DictionaryValue> result_dict;
40 if (result && result->IsType(base::Value::TYPE_DICTIONARY)) {
41 result_dict.reset(static_cast<base::DictionaryValue*>(result.release()));
42 } else {
43 ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg;
44 result_dict.reset(new base::DictionaryValue());
45 }
46 return result_dict.Pass();
47 }
48
30 } // namespace test_util 49 } // namespace test_util
31 } // namespace extensions 50 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/test_util.h ('k') | extensions/extensions.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698