1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/extensions/extension_install_prompt_test_utils.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/path_service.h"
#include "chrome/common/chrome_paths.h"
#include "extensions/common/extension.h"
using extensions::Extension;
namespace chrome {
void MockExtensionInstallPromptDelegate::InstallUIProceed() {
++proceed_count_;
}
void MockExtensionInstallPromptDelegate::InstallUIAbort(bool user_initiated) {
++abort_count_;
}
scoped_refptr<extensions::Extension> LoadInstallPromptExtension(
const char* extension_dir_name,
const char* manifest_file) {
scoped_refptr<Extension> extension;
base::FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
path = path.AppendASCII("extensions")
.AppendASCII(extension_dir_name)
.AppendASCII(manifest_file);
std::string error;
JSONFileValueSerializer serializer(path);
scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>(
serializer.Deserialize(NULL, &error)));
if (!value.get()) {
LOG(ERROR) << error;
return extension;
}
extension = Extension::Create(
path.DirName(), extensions::Manifest::INVALID_LOCATION, *value,
Extension::NO_FLAGS, &error);
if (!extension.get())
LOG(ERROR) << error;
return extension;
}
scoped_refptr<Extension> LoadInstallPromptExtension() {
return LoadInstallPromptExtension("install_prompt", "extension.json");
}
gfx::Image LoadInstallPromptIcon() {
base::FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
path = path.AppendASCII("extensions")
.AppendASCII("install_prompt")
.AppendASCII("icon.png");
std::string file_contents;
base::ReadFileToString(path, &file_contents);
return gfx::Image::CreateFrom1xPNGBytes(
reinterpret_cast<const unsigned char*>(file_contents.c_str()),
file_contents.length());
}
scoped_refptr<ExtensionInstallPrompt::Prompt> BuildExtensionInstallPrompt(
Extension* extension) {
scoped_refptr<ExtensionInstallPrompt::Prompt> prompt =
new ExtensionInstallPrompt::Prompt(
ExtensionInstallPrompt::INSTALL_PROMPT);
prompt->set_extension(extension);
prompt->set_icon(LoadInstallPromptIcon());
return prompt;
}
scoped_refptr<ExtensionInstallPrompt::Prompt>
BuildExtensionPostInstallPermissionsPrompt(Extension* extension) {
scoped_refptr<ExtensionInstallPrompt::Prompt> prompt =
new ExtensionInstallPrompt::Prompt(
ExtensionInstallPrompt::POST_INSTALL_PERMISSIONS_PROMPT);
prompt->set_extension(extension);
prompt->set_icon(LoadInstallPromptIcon());
return prompt;
}
} // namespace chrome
|