Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / common / extensions / extension_test_util.cc
blobec223f6054631e16dc695c179ffcf6d5ad6e92b7
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
3 // found in the LICENSE file.
5 #include "chrome/common/extensions/extension_test_util.h"
7 #include "base/files/file_path.h"
8 #include "base/json/json_file_value_serializer.h"
9 #include "base/path_service.h"
10 #include "base/values.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_constants.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using extensions::Extension;
17 using extensions::Manifest;
19 namespace extension_test_util {
21 scoped_refptr<Extension> LoadManifestUnchecked(const std::string& dir,
22 const std::string& test_file,
23 Manifest::Location location,
24 int extra_flags,
25 const std::string& id,
26 std::string* error) {
27 base::FilePath path;
28 PathService::Get(chrome::DIR_TEST_DATA, &path);
29 path = path.AppendASCII("extensions")
30 .AppendASCII(dir)
31 .AppendASCII(test_file);
33 JSONFileValueDeserializer deserializer(path);
34 scoped_ptr<base::Value> result(deserializer.Deserialize(NULL, error));
35 if (!result)
36 return NULL;
37 const base::DictionaryValue* dict;
38 CHECK(result->GetAsDictionary(&dict));
40 scoped_refptr<Extension> extension = Extension::Create(
41 path.DirName(), location, *dict, extra_flags, id, error);
42 return extension;
45 scoped_refptr<Extension> LoadManifestUnchecked(const std::string& dir,
46 const std::string& test_file,
47 Manifest::Location location,
48 int extra_flags,
49 std::string* error) {
50 return LoadManifestUnchecked(
51 dir, test_file, location, extra_flags, std::string(), error);
54 scoped_refptr<Extension> LoadManifest(const std::string& dir,
55 const std::string& test_file,
56 Manifest::Location location,
57 int extra_flags) {
58 std::string error;
59 scoped_refptr<Extension> extension =
60 LoadManifestUnchecked(dir, test_file, location, extra_flags, &error);
62 EXPECT_TRUE(extension.get()) << test_file << ":" << error;
63 return extension;
66 scoped_refptr<Extension> LoadManifest(const std::string& dir,
67 const std::string& test_file,
68 int extra_flags) {
69 return LoadManifest(dir, test_file, Manifest::INVALID_LOCATION, extra_flags);
72 scoped_refptr<Extension> LoadManifestStrict(const std::string& dir,
73 const std::string& test_file) {
74 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
77 scoped_refptr<Extension> LoadManifest(const std::string& dir,
78 const std::string& test_file) {
79 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
82 } // namespace extension_test_util