| Index: chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc
|
| diff --git a/chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc b/chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7ab8e3a8d7e23f269bedd9093d240addc5fefdeb
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc
|
| @@ -0,0 +1,81 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.h"
|
| +
|
| +#include "base/utf_string_conversions.h"
|
| +
|
| +using extensions::api::experimental_system_info_storage::ParseStorageUnitType;
|
| +using extensions::api::experimental_system_info_storage::StorageUnitInfo;
|
| +using extensions::StorageInfoProvider;
|
| +using extensions::systeminfo::kStorageTypeFixed;
|
| +using extensions::systeminfo::kStorageTypeRemovable;
|
| +using extensions::systeminfo::kStorageTypeUnknown;
|
| +
|
| +// Watching interval for testing.
|
| +const size_t kTestingIntervalMS = 10;
|
| +
|
| +TestStorageInfoProvider::TestStorageInfoProvider(
|
| + const struct TestUnitInfo testing_data[], size_t n)
|
| + : testing_data_(testing_data, testing_data + n) {
|
| + SetWatchingIntervalForTesting(kTestingIntervalMS);
|
| +}
|
| +
|
| +TestStorageInfoProvider::~TestStorageInfoProvider() {
|
| +}
|
| +
|
| +// static
|
| +chrome::StorageInfo TestStorageInfoProvider::BuildStorageInfo(
|
| + const TestUnitInfo& unit) {
|
| + chrome::StorageInfo info(
|
| + unit.device_id,
|
| + string16(), /* no device name */
|
| +#if defined(OS_POSIX)
|
| + unit.location,
|
| +#elif defined(OS_WIN)
|
| + UTF8ToWide(unit.location),
|
| +#endif
|
| + string16(), /* no storage label */
|
| + string16(), /* no storage vendor */
|
| + string16(), /* no storage model */
|
| + unit.capacity);
|
| + return info;
|
| +}
|
| +
|
| +bool TestStorageInfoProvider::QueryInfo(extensions::StorageInfo* info) {
|
| + extensions::StorageInfo results;
|
| + for (size_t i = 0; i < testing_data_.size(); i++) {
|
| + linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
|
| + unit->id = testing_data_[i].device_id;
|
| + unit->location = testing_data_[i].location;
|
| + unit->type = ParseStorageUnitType(testing_data_[i].type);
|
| + unit->capacity = testing_data_[i].capacity;
|
| + unit->available_capacity = testing_data_[i].available_capacity;
|
| + results.push_back(unit);
|
| + }
|
| + info->swap(results);
|
| + return true;
|
| +}
|
| +
|
| +std::vector<chrome::StorageInfo>
|
| +TestStorageInfoProvider::GetAllStorages() const {
|
| + std::vector<chrome::StorageInfo> results;
|
| + for (size_t i = 0; i < testing_data_.size(); ++i)
|
| + results.push_back(BuildStorageInfo(testing_data_[i]));
|
| +
|
| + return results;
|
| +}
|
| +
|
| +int64 TestStorageInfoProvider::GetStorageFreeSpace(
|
| + const base::FilePath& mount_path) {
|
| + for (size_t i = 0; i < testing_data_.size(); i++) {
|
| + if (testing_data_[i].location == mount_path.AsUTF8Unsafe()) {
|
| + // We simulate free space change by increasing the |available_capacity|
|
| + // with a fixed change step.
|
| + testing_data_[i].available_capacity += testing_data_[i].change_step;
|
| + return testing_data_[i].available_capacity;
|
| + }
|
| + }
|
| + return -1;
|
| +}
|
|
|