| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browsing_data_file_system_helper.h" | 13 #include "chrome/browser/browsing_data_file_system_helper.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "content/test/test_browser_thread.h" | 15 #include "content/test/test_browser_thread.h" |
| 16 #include "webkit/fileapi/file_system_context.h" | 16 #include "webkit/fileapi/file_system_context.h" |
| 17 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
| 18 #include "webkit/fileapi/file_system_usage_cache.h" | 18 #include "webkit/fileapi/file_system_usage_cache.h" |
| 19 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 19 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 20 | 20 |
| 21 using content::BrowserContext; |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Shorter names for fileapi::* constants. | 26 // Shorter names for fileapi::* constants. |
| 26 const fileapi::FileSystemType kTemporary = fileapi::kFileSystemTypeTemporary; | 27 const fileapi::FileSystemType kTemporary = fileapi::kFileSystemTypeTemporary; |
| 27 const fileapi::FileSystemType kPersistent = fileapi::kFileSystemTypePersistent; | 28 const fileapi::FileSystemType kPersistent = fileapi::kFileSystemTypePersistent; |
| 28 | 29 |
| 29 // We'll use these three distinct origins for testing, both as strings and as | 30 // We'll use these three distinct origins for testing, both as strings and as |
| 30 // GURLs in appropriate contexts. | 31 // GURLs in appropriate contexts. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 // to BlockUntilNotified(), which will (shockingly!) block until Notify() is | 51 // to BlockUntilNotified(), which will (shockingly!) block until Notify() is |
| 51 // called. For this to work, you'll need to ensure that each async call is | 52 // called. For this to work, you'll need to ensure that each async call is |
| 52 // implemented as a class method that that calls Notify() at an appropriate | 53 // implemented as a class method that that calls Notify() at an appropriate |
| 53 // point. | 54 // point. |
| 54 class BrowsingDataFileSystemHelperTest : public testing::Test { | 55 class BrowsingDataFileSystemHelperTest : public testing::Test { |
| 55 public: | 56 public: |
| 56 BrowsingDataFileSystemHelperTest() | 57 BrowsingDataFileSystemHelperTest() |
| 57 : helper_(BrowsingDataFileSystemHelper::Create(&profile_)), | 58 : helper_(BrowsingDataFileSystemHelper::Create(&profile_)), |
| 58 canned_helper_(new CannedBrowsingDataFileSystemHelper(&profile_)), | 59 canned_helper_(new CannedBrowsingDataFileSystemHelper(&profile_)), |
| 59 ui_thread_(BrowserThread::UI, &message_loop_), | 60 ui_thread_(BrowserThread::UI, &message_loop_), |
| 61 db_thread_(BrowserThread::DB, &message_loop_), |
| 62 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), |
| 60 file_thread_(BrowserThread::FILE, &message_loop_), | 63 file_thread_(BrowserThread::FILE, &message_loop_), |
| 64 file_user_blocking_thread_( |
| 65 BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 61 io_thread_(BrowserThread::IO, &message_loop_) { | 66 io_thread_(BrowserThread::IO, &message_loop_) { |
| 62 } | 67 } |
| 63 virtual ~BrowsingDataFileSystemHelperTest() {} | 68 virtual ~BrowsingDataFileSystemHelperTest() { |
| 69 } |
| 64 | 70 |
| 65 TestingProfile* GetProfile() { | 71 TestingProfile* GetProfile() { |
| 66 return &profile_; | 72 return &profile_; |
| 67 } | 73 } |
| 68 | 74 |
| 69 // Blocks on the current MessageLoop until Notify() is called. | 75 // Blocks on the current MessageLoop until Notify() is called. |
| 70 void BlockUntilNotified() { | 76 void BlockUntilNotified() { |
| 71 MessageLoop::current()->Run(); | 77 MessageLoop::current()->Run(); |
| 72 } | 78 } |
| 73 | 79 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void FetchCannedFileSystems() { | 130 void FetchCannedFileSystems() { |
| 125 canned_helper_->StartFetching( | 131 canned_helper_->StartFetching( |
| 126 base::Bind(&BrowsingDataFileSystemHelperTest::CallbackStartFetching, | 132 base::Bind(&BrowsingDataFileSystemHelperTest::CallbackStartFetching, |
| 127 base::Unretained(this))); | 133 base::Unretained(this))); |
| 128 BlockUntilNotified(); | 134 BlockUntilNotified(); |
| 129 } | 135 } |
| 130 | 136 |
| 131 // Sets up kOrigin1 with a temporary file system, kOrigin2 with a persistent | 137 // Sets up kOrigin1 with a temporary file system, kOrigin2 with a persistent |
| 132 // file system, and kOrigin3 with both. | 138 // file system, and kOrigin3 with both. |
| 133 virtual void PopulateTestFileSystemData() { | 139 virtual void PopulateTestFileSystemData() { |
| 134 sandbox_ = profile_.GetFileSystemContext()->sandbox_provider(); | 140 sandbox_ = BrowserContext::GetFileSystemContext(&profile_)-> |
| 141 sandbox_provider(); |
| 135 | 142 |
| 136 CreateDirectoryForOriginAndType(kOrigin1, kTemporary); | 143 CreateDirectoryForOriginAndType(kOrigin1, kTemporary); |
| 137 CreateDirectoryForOriginAndType(kOrigin2, kPersistent); | 144 CreateDirectoryForOriginAndType(kOrigin2, kPersistent); |
| 138 CreateDirectoryForOriginAndType(kOrigin3, kTemporary); | 145 CreateDirectoryForOriginAndType(kOrigin3, kTemporary); |
| 139 CreateDirectoryForOriginAndType(kOrigin3, kPersistent); | 146 CreateDirectoryForOriginAndType(kOrigin3, kPersistent); |
| 140 | 147 |
| 141 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, kPersistent)); | 148 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, kPersistent)); |
| 142 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, kTemporary)); | 149 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, kTemporary)); |
| 143 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent)); | 150 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent)); |
| 144 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary)); | 151 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 168 | 175 |
| 169 scoped_refptr<BrowsingDataFileSystemHelper> helper_; | 176 scoped_refptr<BrowsingDataFileSystemHelper> helper_; |
| 170 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_; | 177 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_; |
| 171 | 178 |
| 172 private: | 179 private: |
| 173 // message_loop_, as well as all the threads associated with it must be | 180 // message_loop_, as well as all the threads associated with it must be |
| 174 // defined before profile_ to prevent explosions. The threads also must be | 181 // defined before profile_ to prevent explosions. The threads also must be |
| 175 // defined in the order they're listed here. Oh how I love C++. | 182 // defined in the order they're listed here. Oh how I love C++. |
| 176 MessageLoopForUI message_loop_; | 183 MessageLoopForUI message_loop_; |
| 177 content::TestBrowserThread ui_thread_; | 184 content::TestBrowserThread ui_thread_; |
| 185 content::TestBrowserThread db_thread_; |
| 186 content::TestBrowserThread webkit_thread_; |
| 178 content::TestBrowserThread file_thread_; | 187 content::TestBrowserThread file_thread_; |
| 188 content::TestBrowserThread file_user_blocking_thread_; |
| 179 content::TestBrowserThread io_thread_; | 189 content::TestBrowserThread io_thread_; |
| 180 TestingProfile profile_; | 190 TestingProfile profile_; |
| 181 | 191 |
| 182 // We don't own this pointer: don't delete it. | 192 // We don't own this pointer: don't delete it. |
| 183 fileapi::SandboxMountPointProvider* sandbox_; | 193 fileapi::SandboxMountPointProvider* sandbox_; |
| 184 | 194 |
| 185 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperTest); | 195 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperTest); |
| 186 }; | 196 }; |
| 187 | 197 |
| 188 // Verifies that the BrowsingDataFileSystemHelper correctly finds the test file | 198 // Verifies that the BrowsingDataFileSystemHelper correctly finds the test file |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 288 |
| 279 info++; | 289 info++; |
| 280 EXPECT_EQ(kOrigin2, info->origin); | 290 EXPECT_EQ(kOrigin2, info->origin); |
| 281 EXPECT_FALSE(info->has_persistent); | 291 EXPECT_FALSE(info->has_persistent); |
| 282 EXPECT_TRUE(info->has_temporary); | 292 EXPECT_TRUE(info->has_temporary); |
| 283 EXPECT_EQ(0, info->usage_persistent); | 293 EXPECT_EQ(0, info->usage_persistent); |
| 284 EXPECT_EQ(100, info->usage_temporary); | 294 EXPECT_EQ(100, info->usage_temporary); |
| 285 } | 295 } |
| 286 | 296 |
| 287 } // namespace | 297 } // namespace |
| OLD | NEW |