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 #import "chrome/browser/ui/cocoa/extensions/extension_install_prompt_test_utils.h"
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/json/json_file_value_serializer.h"
10 #include "base/path_service.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "extensions/common/extension.h"
14 using extensions::Extension;
18 void MockExtensionInstallPromptDelegate::InstallUIProceed() {
22 void MockExtensionInstallPromptDelegate::InstallUIAbort(bool user_initiated) {
26 scoped_refptr<extensions::Extension> LoadInstallPromptExtension(
27 const char* extension_dir_name,
28 const char* manifest_file) {
29 scoped_refptr<Extension> extension;
32 PathService::Get(chrome::DIR_TEST_DATA, &path);
33 path = path.AppendASCII("extensions")
34 .AppendASCII(extension_dir_name)
35 .AppendASCII(manifest_file);
38 JSONFileValueDeserializer deserializer(path);
39 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>(
40 deserializer.Deserialize(NULL, &error)));
46 extension = Extension::Create(
47 path.DirName(), extensions::Manifest::INVALID_LOCATION, *value,
48 Extension::NO_FLAGS, &error);
55 scoped_refptr<Extension> LoadInstallPromptExtension() {
56 return LoadInstallPromptExtension("install_prompt", "extension.json");
59 gfx::Image LoadInstallPromptIcon() {
61 PathService::Get(chrome::DIR_TEST_DATA, &path);
62 path = path.AppendASCII("extensions")
63 .AppendASCII("install_prompt")
64 .AppendASCII("icon.png");
66 std::string file_contents;
67 base::ReadFileToString(path, &file_contents);
69 return gfx::Image::CreateFrom1xPNGBytes(
70 reinterpret_cast<const unsigned char*>(file_contents.c_str()),
71 file_contents.length());
74 scoped_refptr<ExtensionInstallPrompt::Prompt> BuildExtensionInstallPrompt(
75 Extension* extension) {
76 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt =
77 new ExtensionInstallPrompt::Prompt(
78 ExtensionInstallPrompt::INSTALL_PROMPT);
79 prompt->set_extension(extension);
80 prompt->set_icon(LoadInstallPromptIcon());
84 scoped_refptr<ExtensionInstallPrompt::Prompt>
85 BuildExtensionPostInstallPermissionsPrompt(Extension* extension) {
86 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt =
87 new ExtensionInstallPrompt::Prompt(
88 ExtensionInstallPrompt::POST_INSTALL_PERMISSIONS_PROMPT);
89 prompt->set_extension(extension);
90 prompt->set_icon(LoadInstallPromptIcon());