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/test_installer.h"
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
) {
22 bool TestInstaller::Install(const base::DictionaryValue
& manifest
,
23 const base::FilePath
& unpack_path
) {
25 return base::DeleteFile(unpack_path
, true);
28 bool TestInstaller::GetInstalledFile(const std::string
& file
,
29 base::FilePath
* installed_file
) {
33 TestInstaller::~TestInstaller() {
36 bool TestInstaller::Uninstall() {
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
);
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());
68 path
= install_directory_
.AppendASCII(version
.GetString());
69 base::CreateDirectory(path
.DirName());
70 if (!base::Move(unpack_path
, path
))
72 current_version_
= version
;
77 bool VersionedTestInstaller::GetInstalledFile(const std::string
& file
,
78 base::FilePath
* installed_file
) {
80 path
= install_directory_
.AppendASCII(current_version_
.GetString());
81 *installed_file
= path
.Append(base::FilePath::FromUTF8Unsafe(file
));
85 } // namespace update_client