Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / component_updater / test / test_installer.cc
blob400edca82c98214a093ba2a4d10a7ba89ca45354
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 "chrome/browser/component_updater/test/test_installer.h"
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/values.h"
11 namespace component_updater {
13 TestInstaller::TestInstaller()
14 : error_(0), install_count_(0) {
17 void TestInstaller::OnUpdateError(int error) {
18 error_ = error;
21 bool TestInstaller::Install(const base::DictionaryValue& manifest,
22 const base::FilePath& unpack_path) {
23 ++install_count_;
24 return base::DeleteFile(unpack_path, true);
27 bool TestInstaller::GetInstalledFile(const std::string& file,
28 base::FilePath* installed_file) {
29 return false;
32 int TestInstaller::error() const { return error_; }
34 int TestInstaller::install_count() const { return install_count_; }
37 ReadOnlyTestInstaller::ReadOnlyTestInstaller(const base::FilePath& install_dir)
38 : install_directory_(install_dir) {
41 ReadOnlyTestInstaller::~ReadOnlyTestInstaller() {
44 bool ReadOnlyTestInstaller::GetInstalledFile(const std::string& file,
45 base::FilePath* installed_file) {
46 *installed_file = install_directory_.AppendASCII(file);
47 return true;
51 VersionedTestInstaller::VersionedTestInstaller() {
52 base::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &install_directory_);
55 VersionedTestInstaller::~VersionedTestInstaller() {
56 base::DeleteFile(install_directory_, true);
60 bool VersionedTestInstaller::Install(const base::DictionaryValue& manifest,
61 const base::FilePath& unpack_path) {
62 std::string version_string;
63 manifest.GetStringASCII("version", &version_string);
64 Version version(version_string.c_str());
66 base::FilePath path;
67 path = install_directory_.AppendASCII(version.GetString());
68 base::CreateDirectory(path.DirName());
69 if (!base::Move(unpack_path, path))
70 return false;
71 current_version_ = version;
72 ++install_count_;
73 return true;
76 bool VersionedTestInstaller::GetInstalledFile(const std::string& file,
77 base::FilePath* installed_file) {
78 base::FilePath path;
79 path = install_directory_.AppendASCII(current_version_.GetString());
80 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file));
81 return true;
84 } // namespace component_updater