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

Side by Side Diff: chrome/common/extensions/extension_test_util.cc

Issue 14358004: Almost all actions in Declarative Web Request require all_urls host permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Without error messages yet Created 7 years, 8 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
OLDNEW
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_test_util.h"
6
7 #include "base/files/file_path.h"
8 #include "base/json/json_file_value_serializer.h"
9 #include "base/path_service.h"
5 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/chrome_paths.h"
6 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
7 #include "chrome/common/extensions/extension_manifest_constants.h" 13 #include "chrome/common/extensions/extension_manifest_constants.h"
8 #include "chrome/common/extensions/extension_test_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
10 15
11 using extensions::Extension; 16 using extensions::Extension;
17 using extensions::Manifest;
12 18
13 namespace extension_test_util { 19 namespace extension_test_util {
14 20
15 scoped_refptr<Extension> CreateExtensionWithID(std::string id) { 21 scoped_refptr<Extension> CreateExtensionWithID(std::string id) {
16 DictionaryValue values; 22 DictionaryValue values;
17 values.SetString(extension_manifest_keys::kName, "test"); 23 values.SetString(extension_manifest_keys::kName, "test");
18 values.SetString(extension_manifest_keys::kVersion, "0.1"); 24 values.SetString(extension_manifest_keys::kVersion, "0.1");
19 std::string error; 25 std::string error;
20 return Extension::Create(base::FilePath(), extensions::Manifest::INTERNAL, 26 return Extension::Create(base::FilePath(), extensions::Manifest::INTERNAL,
21 values, Extension::NO_FLAGS, id, &error); 27 values, Extension::NO_FLAGS, id, &error);
22 } 28 }
23 29
30 scoped_refptr<Extension> LoadManifestUnchecked(const std::string& dir,
31 const std::string& test_file,
32 Manifest::Location location,
33 int extra_flags,
34 const std::string& id,
35 std::string* error) {
36 base::FilePath path;
37 PathService::Get(chrome::DIR_TEST_DATA, &path);
38 path = path.AppendASCII("extensions")
39 .AppendASCII(dir)
40 .AppendASCII(test_file);
41
42 JSONFileValueSerializer serializer(path);
43 scoped_ptr<Value> result(serializer.Deserialize(NULL, error));
44 if (!result.get())
45 return NULL;
46
47 scoped_refptr<Extension> extension = Extension::Create(
48 path.DirName(), location, *static_cast<DictionaryValue*>(result.get()),
49 extra_flags, id, error);
50 return extension;
51 }
52
53 scoped_refptr<Extension> LoadManifestUnchecked(const std::string& dir,
54 const std::string& test_file,
55 Manifest::Location location,
56 int extra_flags,
57 std::string* error) {
58 return LoadManifestUnchecked(
59 dir, test_file, location, extra_flags, std::string(), error);
60 }
61
62 scoped_refptr<Extension> LoadManifest(const std::string& dir,
63 const std::string& test_file,
64 Manifest::Location location,
65 int extra_flags) {
66 std::string error;
67 scoped_refptr<Extension> extension = LoadManifestUnchecked(dir, test_file,
68 location, extra_flags, &error);
69
70 EXPECT_TRUE(extension) << test_file << ":" << error;
71 return extension;
72 }
73
74 scoped_refptr<Extension> LoadManifest(const std::string& dir,
75 const std::string& test_file,
76 int extra_flags) {
77 return LoadManifest(dir, test_file, Manifest::INVALID_LOCATION, extra_flags);
78 }
79
80 scoped_refptr<Extension> LoadManifestStrict(const std::string& dir,
81 const std::string& test_file) {
82 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
83 }
84
85 scoped_refptr<Extension> LoadManifest(const std::string& dir,
86 const std::string& test_file) {
87 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
88 }
89
24 } // namespace extension_test_util 90 } // namespace extension_test_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698