| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browsing_data_file_system_helper.h" | 8 #include "chrome/browser/browsing_data_file_system_helper.h" |
| 9 #include "chrome/test/base/testing_browser_process_test.h" | 9 #include "chrome/test/base/testing_browser_process_test.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 const char kTestOrigin3[] = "http://host3:3/"; | 28 const char kTestOrigin3[] = "http://host3:3/"; |
| 29 | 29 |
| 30 const GURL kOrigin1(kTestOrigin1); | 30 const GURL kOrigin1(kTestOrigin1); |
| 31 const GURL kOrigin2(kTestOrigin2); | 31 const GURL kOrigin2(kTestOrigin2); |
| 32 const GURL kOrigin3(kTestOrigin3); | 32 const GURL kOrigin3(kTestOrigin3); |
| 33 | 33 |
| 34 // TODO(mkwst): Update this size once the discussion in http://crbug.com/86114 | 34 // TODO(mkwst): Update this size once the discussion in http://crbug.com/86114 |
| 35 // is concluded. | 35 // is concluded. |
| 36 const int kEmptyFileSystemSize = 0; | 36 const int kEmptyFileSystemSize = 0; |
| 37 | 37 |
| 38 typedef std::vector<BrowsingDataFileSystemHelper::FileSystemInfo> | 38 typedef std::list<BrowsingDataFileSystemHelper::FileSystemInfo> |
| 39 FileSystemInfoVector; | 39 FileSystemInfoList; |
| 40 typedef scoped_ptr<FileSystemInfoVector> ScopedFileSystemInfoVector; | 40 typedef scoped_ptr<FileSystemInfoList> ScopedFileSystemInfoList; |
| 41 | 41 |
| 42 // The FileSystem APIs are all asynchronous; this testing class wraps up the | 42 // The FileSystem APIs are all asynchronous; this testing class wraps up the |
| 43 // boilerplate code necessary to deal with waiting for responses. In a nutshell, | 43 // boilerplate code necessary to deal with waiting for responses. In a nutshell, |
| 44 // any async call whose response we want to test ought to be followed by a call | 44 // any async call whose response we want to test ought to be followed by a call |
| 45 // to BlockUntilNotified(), which will (shockingly!) block until Notify() is | 45 // to BlockUntilNotified(), which will (shockingly!) block until Notify() is |
| 46 // called. For this to work, you'll need to ensure that each async call is | 46 // called. For this to work, you'll need to ensure that each async call is |
| 47 // implemented as a class method that that calls Notify() at an appropriate | 47 // implemented as a class method that that calls Notify() at an appropriate |
| 48 // point. | 48 // point. |
| 49 class BrowsingDataFileSystemHelperTest : public TestingBrowserProcessTest { | 49 class BrowsingDataFileSystemHelperTest : public TestingBrowserProcessTest { |
| 50 public: | 50 public: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 sandbox_->ValidateFileSystemRootAndGetURL( | 90 sandbox_->ValidateFileSystemRootAndGetURL( |
| 91 origin, type, false, NewCallback(this, | 91 origin, type, false, NewCallback(this, |
| 92 &BrowsingDataFileSystemHelperTest::CallbackFindFileSystemPath)); | 92 &BrowsingDataFileSystemHelperTest::CallbackFindFileSystemPath)); |
| 93 BlockUntilNotified(); | 93 BlockUntilNotified(); |
| 94 return found_file_system_; | 94 return found_file_system_; |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Callback that should be executed in response to StartFetching(), and stores | 97 // Callback that should be executed in response to StartFetching(), and stores |
| 98 // found file systems locally so that they are available via GetFileSystems(). | 98 // found file systems locally so that they are available via GetFileSystems(). |
| 99 void CallbackStartFetching( | 99 void CallbackStartFetching( |
| 100 const std::vector<BrowsingDataFileSystemHelper::FileSystemInfo>& | 100 const std::list<BrowsingDataFileSystemHelper::FileSystemInfo>& |
| 101 file_system_info_list) { | 101 file_system_info_list) { |
| 102 file_system_info_list_.reset( | 102 file_system_info_list_.reset( |
| 103 new std::vector<BrowsingDataFileSystemHelper::FileSystemInfo>( | 103 new std::list<BrowsingDataFileSystemHelper::FileSystemInfo>( |
| 104 file_system_info_list)); | 104 file_system_info_list)); |
| 105 Notify(); | 105 Notify(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Calls StartFetching() on the test's BrowsingDataFileSystemHelper | 108 // Calls StartFetching() on the test's BrowsingDataFileSystemHelper |
| 109 // object, then blocks until the callback is executed. | 109 // object, then blocks until the callback is executed. |
| 110 void FetchFileSystems() { | 110 void FetchFileSystems() { |
| 111 helper_->StartFetching(NewCallback(this, | 111 helper_->StartFetching(NewCallback(this, |
| 112 &BrowsingDataFileSystemHelperTest::CallbackStartFetching)); | 112 &BrowsingDataFileSystemHelperTest::CallbackStartFetching)); |
| 113 BlockUntilNotified(); | 113 BlockUntilNotified(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 144 // specified origin. | 144 // specified origin. |
| 145 void CreateDirectoryForOriginAndType(const GURL& origin, | 145 void CreateDirectoryForOriginAndType(const GURL& origin, |
| 146 fileapi::FileSystemType type) { | 146 fileapi::FileSystemType type) { |
| 147 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread( | 147 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread( |
| 148 origin, type, FilePath(), true); | 148 origin, type, FilePath(), true); |
| 149 EXPECT_TRUE(file_util::DirectoryExists(target)); | 149 EXPECT_TRUE(file_util::DirectoryExists(target)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Returns a list of the FileSystemInfo objects gathered in the most recent | 152 // Returns a list of the FileSystemInfo objects gathered in the most recent |
| 153 // call to StartFetching(). | 153 // call to StartFetching(). |
| 154 FileSystemInfoVector* GetFileSystems() { | 154 FileSystemInfoList* GetFileSystems() { |
| 155 return file_system_info_list_.get(); | 155 return file_system_info_list_.get(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 | 158 |
| 159 // Temporary storage to pass information back from callbacks. | 159 // Temporary storage to pass information back from callbacks. |
| 160 bool found_file_system_; | 160 bool found_file_system_; |
| 161 ScopedFileSystemInfoVector file_system_info_list_; | 161 ScopedFileSystemInfoList file_system_info_list_; |
| 162 | 162 |
| 163 scoped_refptr<BrowsingDataFileSystemHelper> helper_; | 163 scoped_refptr<BrowsingDataFileSystemHelper> helper_; |
| 164 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_; | 164 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_; |
| 165 | 165 |
| 166 private: | 166 private: |
| 167 // message_loop_, as well as all the threads associated with it must be | 167 // message_loop_, as well as all the threads associated with it must be |
| 168 // defined before profile_ to prevent explosions. The threads also must be | 168 // defined before profile_ to prevent explosions. The threads also must be |
| 169 // defined in the order they're listed here. Oh how I love C++. | 169 // defined in the order they're listed here. Oh how I love C++. |
| 170 MessageLoopForUI message_loop_; | 170 MessageLoopForUI message_loop_; |
| 171 BrowserThread ui_thread_; | 171 BrowserThread ui_thread_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 183 // system data, and that each file system returned contains the expected data. | 183 // system data, and that each file system returned contains the expected data. |
| 184 TEST_F(BrowsingDataFileSystemHelperTest, FetchData) { | 184 TEST_F(BrowsingDataFileSystemHelperTest, FetchData) { |
| 185 PopulateTestFileSystemData(); | 185 PopulateTestFileSystemData(); |
| 186 | 186 |
| 187 FetchFileSystems(); | 187 FetchFileSystems(); |
| 188 | 188 |
| 189 EXPECT_EQ(3UL, file_system_info_list_->size()); | 189 EXPECT_EQ(3UL, file_system_info_list_->size()); |
| 190 | 190 |
| 191 // Order is arbitrary, verify all three origins. | 191 // Order is arbitrary, verify all three origins. |
| 192 bool test_hosts_found[3] = {false, false, false}; | 192 bool test_hosts_found[3] = {false, false, false}; |
| 193 for (size_t i = 0; i < file_system_info_list_->size(); i++) { | 193 for (std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator info = |
| 194 BrowsingDataFileSystemHelper::FileSystemInfo info = | 194 file_system_info_list_->begin(); info != file_system_info_list_->end(); |
| 195 file_system_info_list_->at(i); | 195 ++info) { |
| 196 if (info.origin == kOrigin1) { | 196 if (info->origin == kOrigin1) { |
| 197 EXPECT_FALSE(test_hosts_found[0]); | 197 EXPECT_FALSE(test_hosts_found[0]); |
| 198 test_hosts_found[0] = true; | 198 test_hosts_found[0] = true; |
| 199 EXPECT_FALSE(info.has_persistent); | 199 EXPECT_FALSE(info->has_persistent); |
| 200 EXPECT_TRUE(info.has_temporary); | 200 EXPECT_TRUE(info->has_temporary); |
| 201 EXPECT_EQ(0, info.usage_persistent); | 201 EXPECT_EQ(0, info->usage_persistent); |
| 202 EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary); | 202 EXPECT_EQ(kEmptyFileSystemSize, info->usage_temporary); |
| 203 } else if (info.origin == kOrigin2) { | 203 } else if (info->origin == kOrigin2) { |
| 204 EXPECT_FALSE(test_hosts_found[1]); | 204 EXPECT_FALSE(test_hosts_found[1]); |
| 205 test_hosts_found[1] = true; | 205 test_hosts_found[1] = true; |
| 206 EXPECT_TRUE(info.has_persistent); | 206 EXPECT_TRUE(info->has_persistent); |
| 207 EXPECT_FALSE(info.has_temporary); | 207 EXPECT_FALSE(info->has_temporary); |
| 208 EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent); | 208 EXPECT_EQ(kEmptyFileSystemSize, info->usage_persistent); |
| 209 EXPECT_EQ(0, info.usage_temporary); | 209 EXPECT_EQ(0, info->usage_temporary); |
| 210 } else if (info.origin == kOrigin3) { | 210 } else if (info->origin == kOrigin3) { |
| 211 EXPECT_FALSE(test_hosts_found[2]); | 211 EXPECT_FALSE(test_hosts_found[2]); |
| 212 test_hosts_found[2] = true; | 212 test_hosts_found[2] = true; |
| 213 EXPECT_TRUE(info.has_persistent); | 213 EXPECT_TRUE(info->has_persistent); |
| 214 EXPECT_TRUE(info.has_temporary); | 214 EXPECT_TRUE(info->has_temporary); |
| 215 EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent); | 215 EXPECT_EQ(kEmptyFileSystemSize, info->usage_persistent); |
| 216 EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary); | 216 EXPECT_EQ(kEmptyFileSystemSize, info->usage_temporary); |
| 217 } else { | 217 } else { |
| 218 ADD_FAILURE() << info.origin.spec() << " isn't an origin we added."; | 218 ADD_FAILURE() << info->origin.spec() << " isn't an origin we added."; |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 for (size_t i = 0; i < arraysize(test_hosts_found); i++) { | 221 for (size_t i = 0; i < arraysize(test_hosts_found); i++) { |
| 222 EXPECT_TRUE(test_hosts_found[i]); | 222 EXPECT_TRUE(test_hosts_found[i]); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Verifies that the BrowsingDataFileSystemHelper correctly deletes file | 226 // Verifies that the BrowsingDataFileSystemHelper correctly deletes file |
| 227 // systems via DeleteFileSystemOrigin(). | 227 // systems via DeleteFileSystemOrigin(). |
| 228 TEST_F(BrowsingDataFileSystemHelperTest, DeleteData) { | 228 TEST_F(BrowsingDataFileSystemHelperTest, DeleteData) { |
| 229 PopulateTestFileSystemData(); | 229 PopulateTestFileSystemData(); |
| 230 | 230 |
| 231 helper_->DeleteFileSystemOrigin(kOrigin1); | 231 helper_->DeleteFileSystemOrigin(kOrigin1); |
| 232 helper_->DeleteFileSystemOrigin(kOrigin2); | 232 helper_->DeleteFileSystemOrigin(kOrigin2); |
| 233 | 233 |
| 234 FetchFileSystems(); | 234 FetchFileSystems(); |
| 235 | 235 |
| 236 EXPECT_EQ(1UL, file_system_info_list_->size()); | 236 EXPECT_EQ(1UL, file_system_info_list_->size()); |
| 237 BrowsingDataFileSystemHelper::FileSystemInfo info = | 237 BrowsingDataFileSystemHelper::FileSystemInfo info = |
| 238 file_system_info_list_->at(0); | 238 *(file_system_info_list_->begin()); |
| 239 EXPECT_EQ(kOrigin3, info.origin); | 239 EXPECT_EQ(kOrigin3, info.origin); |
| 240 EXPECT_TRUE(info.has_persistent); | 240 EXPECT_TRUE(info.has_persistent); |
| 241 EXPECT_TRUE(info.has_temporary); | 241 EXPECT_TRUE(info.has_temporary); |
| 242 EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent); | 242 EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent); |
| 243 EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary); | 243 EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Verifies that the CannedBrowsingDataFileSystemHelper correctly reports | 246 // Verifies that the CannedBrowsingDataFileSystemHelper correctly reports |
| 247 // whether or not it currently contains file systems. | 247 // whether or not it currently contains file systems. |
| 248 TEST_F(BrowsingDataFileSystemHelperTest, Empty) { | 248 TEST_F(BrowsingDataFileSystemHelperTest, Empty) { |
| 249 ASSERT_TRUE(canned_helper_->empty()); | 249 ASSERT_TRUE(canned_helper_->empty()); |
| 250 canned_helper_->AddFileSystem(kOrigin1, kTemporary, 0); | 250 canned_helper_->AddFileSystem(kOrigin1, kTemporary, 0); |
| 251 ASSERT_FALSE(canned_helper_->empty()); | 251 ASSERT_FALSE(canned_helper_->empty()); |
| 252 canned_helper_->Reset(); | 252 canned_helper_->Reset(); |
| 253 ASSERT_TRUE(canned_helper_->empty()); | 253 ASSERT_TRUE(canned_helper_->empty()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Verifies that AddFileSystem correctly adds file systems, and that both | 256 // Verifies that AddFileSystem correctly adds file systems, and that both |
| 257 // the type and usage metadata are reported as provided. | 257 // the type and usage metadata are reported as provided. |
| 258 TEST_F(BrowsingDataFileSystemHelperTest, CannedAddFileSystem) { | 258 TEST_F(BrowsingDataFileSystemHelperTest, CannedAddFileSystem) { |
| 259 canned_helper_->AddFileSystem(kOrigin1, kPersistent, 200); | 259 canned_helper_->AddFileSystem(kOrigin1, kPersistent, 200); |
| 260 canned_helper_->AddFileSystem(kOrigin2, kTemporary, 100); | 260 canned_helper_->AddFileSystem(kOrigin2, kTemporary, 100); |
| 261 | 261 |
| 262 FetchCannedFileSystems(); | 262 FetchCannedFileSystems(); |
| 263 | 263 |
| 264 EXPECT_EQ(2U, file_system_info_list_->size()); | 264 EXPECT_EQ(2U, file_system_info_list_->size()); |
| 265 EXPECT_EQ(kOrigin1, file_system_info_list_->at(0).origin); | 265 std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator info = |
| 266 EXPECT_TRUE(file_system_info_list_->at(0).has_persistent); | 266 file_system_info_list_->begin(); |
| 267 EXPECT_FALSE(file_system_info_list_->at(0).has_temporary); | 267 EXPECT_EQ(kOrigin1, info->origin); |
| 268 EXPECT_EQ(200, file_system_info_list_->at(0).usage_persistent); | 268 EXPECT_TRUE(info->has_persistent); |
| 269 EXPECT_EQ(0, file_system_info_list_->at(0).usage_temporary); | 269 EXPECT_FALSE(info->has_temporary); |
| 270 EXPECT_EQ(kOrigin2, file_system_info_list_->at(1).origin); | 270 EXPECT_EQ(200, info->usage_persistent); |
| 271 EXPECT_FALSE(file_system_info_list_->at(1).has_persistent); | 271 EXPECT_EQ(0, info->usage_temporary); |
| 272 EXPECT_TRUE(file_system_info_list_->at(1).has_temporary); | 272 |
| 273 EXPECT_EQ(0, file_system_info_list_->at(1).usage_persistent); | 273 info++; |
| 274 EXPECT_EQ(100, file_system_info_list_->at(1).usage_temporary); | 274 EXPECT_EQ(kOrigin2, info->origin); |
| 275 EXPECT_FALSE(info->has_persistent); |
| 276 EXPECT_TRUE(info->has_temporary); |
| 277 EXPECT_EQ(0, info->usage_persistent); |
| 278 EXPECT_EQ(100, info->usage_temporary); |
| 275 } | 279 } |
| 276 | 280 |
| 277 } // namespace | 281 } // namespace |
| 278 | 282 |
| OLD | NEW |