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

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: All URLs -> all hosts; also rebased Created 7 years, 7 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)
45 return NULL;
46 const DictionaryValue* dict;
47 CHECK(result->GetAsDictionary(&dict));
48
49 scoped_refptr<Extension> extension = Extension::Create(
50 path.DirName(), location, *dict, extra_flags, id, error);
51 return extension;
52 }
53
54 scoped_refptr<Extension> LoadManifestUnchecked(const std::string& dir,
55 const std::string& test_file,
56 Manifest::Location location,
57 int extra_flags,
58 std::string* error) {
59 return LoadManifestUnchecked(
60 dir, test_file, location, extra_flags, std::string(), error);
61 }
62
63 scoped_refptr<Extension> LoadManifest(const std::string& dir,
64 const std::string& test_file,
65 Manifest::Location location,
66 int extra_flags) {
67 std::string error;
68 scoped_refptr<Extension> extension =
69 LoadManifestUnchecked(dir, test_file, location, extra_flags, &error);
70
71 EXPECT_TRUE(extension) << test_file << ":" << error;
72 return extension;
73 }
74
75 scoped_refptr<Extension> LoadManifest(const std::string& dir,
76 const std::string& test_file,
77 int extra_flags) {
78 return LoadManifest(dir, test_file, Manifest::INVALID_LOCATION, extra_flags);
79 }
80
81 scoped_refptr<Extension> LoadManifestStrict(const std::string& dir,
82 const std::string& test_file) {
83 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
84 }
85
86 scoped_refptr<Extension> LoadManifest(const std::string& dir,
87 const std::string& test_file) {
88 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
89 }
90
24 } // namespace extension_test_util 91 } // namespace extension_test_util
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_test_util.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698