Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / update_client / test_installer.cc
blobad6015b980083cba9386902bfad983e741bdbd14
1 // Copyright 2013 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 #include "components/update_client/test_installer.h"
7 #include <string>
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/values.h"
13 namespace update_client {
15 TestInstaller::TestInstaller() : error_(0), install_count_(0) {
18 void TestInstaller::OnUpdateError(int error) {
19 error_ = error;
22 bool TestInstaller::Install(const base::DictionaryValue& manifest,
23 const base::FilePath& unpack_path) {
24 ++install_count_;
25 return base::DeleteFile(unpack_path, true);
28 bool TestInstaller::GetInstalledFile(const std::string& file,
29 base::FilePath* installed_file) {
30 return false;
33 TestInstaller::~TestInstaller() {
36 bool TestInstaller::Uninstall() {
37 return false;
40 ReadOnlyTestInstaller::ReadOnlyTestInstaller(const base::FilePath& install_dir)
41 : install_directory_(install_dir) {
44 ReadOnlyTestInstaller::~ReadOnlyTestInstaller() {
47 bool ReadOnlyTestInstaller::GetInstalledFile(const std::string& file,
48 base::FilePath* installed_file) {
49 *installed_file = install_directory_.AppendASCII(file);
50 return true;
53 VersionedTestInstaller::VersionedTestInstaller() {
54 base::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &install_directory_);
57 VersionedTestInstaller::~VersionedTestInstaller() {
58 base::DeleteFile(install_directory_, true);
61 bool VersionedTestInstaller::Install(const base::DictionaryValue& manifest,
62 const base::FilePath& unpack_path) {
63 std::string version_string;
64 manifest.GetStringASCII("version", &version_string);
65 Version version(version_string.c_str());
67 base::FilePath path;
68 path = install_directory_.AppendASCII(version.GetString());
69 base::CreateDirectory(path.DirName());
70 if (!base::Move(unpack_path, path))
71 return false;
72 current_version_ = version;
73 ++install_count_;
74 return true;
77 bool VersionedTestInstaller::GetInstalledFile(const std::string& file,
78 base::FilePath* installed_file) {
79 base::FilePath path;
80 path = install_directory_.AppendASCII(current_version_.GetString());
81 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file));
82 return true;
85 } // namespace update_client