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