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 3// found in the LICENSE file. 4 5#include "chrome/browser/browsing_data/mock_browsing_data_file_system_helper.h" 6 7#include "base/callback.h" 8#include "base/logging.h" 9#include "testing/gtest/include/gtest/gtest.h" 10 11MockBrowsingDataFileSystemHelper::MockBrowsingDataFileSystemHelper( 12 Profile* profile) { 13} 14 15MockBrowsingDataFileSystemHelper::~MockBrowsingDataFileSystemHelper() { 16} 17 18void MockBrowsingDataFileSystemHelper::StartFetching( 19 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { 20 ASSERT_FALSE(callback.is_null()); 21 ASSERT_TRUE(callback_.is_null()); 22 callback_ = callback; 23} 24 25void MockBrowsingDataFileSystemHelper::DeleteFileSystemOrigin( 26 const GURL& origin) { 27 ASSERT_FALSE(callback_.is_null()); 28 std::string key = origin.spec(); 29 ASSERT_TRUE(file_systems_.find(key) != file_systems_.end()); 30 last_deleted_origin_ = origin; 31 file_systems_[key] = false; 32} 33 34void MockBrowsingDataFileSystemHelper::AddFileSystem( 35 const GURL& origin, bool has_persistent, bool has_temporary, 36 bool has_syncable) { 37 BrowsingDataFileSystemHelper::FileSystemInfo info(origin); 38 if (has_persistent) 39 info.usage_map[storage::kFileSystemTypePersistent] = 0; 40 if (has_temporary) 41 info.usage_map[storage::kFileSystemTypeTemporary] = 0; 42 if (has_syncable) 43 info.usage_map[storage::kFileSystemTypeSyncable] = 0; 44 response_.push_back(info); 45 file_systems_[origin.spec()] = true; 46} 47 48void MockBrowsingDataFileSystemHelper::AddFileSystemSamples() { 49 AddFileSystem(GURL("http://fshost1:1/"), false, true, false); 50 AddFileSystem(GURL("http://fshost2:2/"), true, false, true); 51 AddFileSystem(GURL("http://fshost3:3/"), true, true, true); 52} 53 54void MockBrowsingDataFileSystemHelper::Notify() { 55 callback_.Run(response_); 56} 57 58void MockBrowsingDataFileSystemHelper::Reset() { 59 for (std::map<const std::string, bool>::iterator i = file_systems_.begin(); 60 i != file_systems_.end(); ++i) 61 i->second = true; 62} 63 64bool MockBrowsingDataFileSystemHelper::AllDeleted() { 65 for (std::map<const std::string, bool>::const_iterator i = 66 file_systems_.begin(); 67 i != file_systems_.end(); ++i) { 68 if (i->second) 69 return false; 70 } 71 return true; 72} 73