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