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/file_util.h"
8 #include "base/files/file_path.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 JSONFileValueSerializer serializer(path);
39 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>(
40 serializer.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 ExtensionInstallPrompt::Prompt BuildExtensionInstallPrompt(
75 Extension* extension) {
76 ExtensionInstallPrompt::Prompt prompt(ExtensionInstallPrompt::INSTALL_PROMPT);
77 prompt.set_extension(extension);
78 prompt.set_icon(LoadInstallPromptIcon());
82 ExtensionInstallPrompt::Prompt BuildExtensionPostInstallPermissionsPrompt(
83 Extension* extension) {
84 ExtensionInstallPrompt::Prompt prompt(
85 ExtensionInstallPrompt::POST_INSTALL_PERMISSIONS_PROMPT);
86 prompt.set_extension(extension);
87 prompt.set_icon(LoadInstallPromptIcon());