BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_install_prompt_test_utils.mm
blobbbfc886a3ec35d5d52cb9eab521ff170ccf3d4e5
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;
16 namespace chrome {
18 void MockExtensionInstallPromptDelegate::InstallUIProceed() {
19   ++proceed_count_;
22 void MockExtensionInstallPromptDelegate::InstallUIAbort(bool user_initiated) {
23   ++abort_count_;
26 scoped_refptr<extensions::Extension> LoadInstallPromptExtension(
27     const char* extension_dir_name,
28     const char* manifest_file) {
29   scoped_refptr<Extension> extension;
31   base::FilePath path;
32   PathService::Get(chrome::DIR_TEST_DATA, &path);
33   path = path.AppendASCII("extensions")
34              .AppendASCII(extension_dir_name)
35              .AppendASCII(manifest_file);
37   std::string error;
38   JSONFileValueDeserializer deserializer(path);
39   scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>(
40       deserializer.Deserialize(NULL, &error)));
41   if (!value.get()) {
42     LOG(ERROR) << error;
43     return extension;
44   }
46   extension = Extension::Create(
47       path.DirName(), extensions::Manifest::INVALID_LOCATION, *value,
48       Extension::NO_FLAGS, &error);
49   if (!extension.get())
50     LOG(ERROR) << error;
52   return extension;
55 scoped_refptr<Extension> LoadInstallPromptExtension() {
56   return LoadInstallPromptExtension("install_prompt", "extension.json");
59 gfx::Image LoadInstallPromptIcon() {
60   base::FilePath path;
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());
81   return prompt;
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());
91   return prompt;
94 }  // namespace chrome