Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_file_system_helper_unittest.cc

Issue 10909182: Make FileSystemContext respect StoragePartitions. filesystem:// urls will be properly isolated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch unittest fix from michael Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browsing_data_file_system_helper.h" 13 #include "chrome/browser/browsing_data/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/public/browser/storage_partition.h"
15 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
16 #include "webkit/fileapi/file_system_context.h" 17 #include "webkit/fileapi/file_system_context.h"
18 #include "webkit/fileapi/file_system_task_runners.h"
17 #include "webkit/fileapi/file_system_types.h" 19 #include "webkit/fileapi/file_system_types.h"
18 #include "webkit/fileapi/file_system_usage_cache.h" 20 #include "webkit/fileapi/file_system_usage_cache.h"
21 #include "webkit/fileapi/mock_file_system_options.h"
19 #include "webkit/fileapi/sandbox_mount_point_provider.h" 22 #include "webkit/fileapi/sandbox_mount_point_provider.h"
23 #include "webkit/quota/mock_special_storage_policy.h"
20 24
21 using content::BrowserContext; 25 using content::BrowserContext;
22 using content::BrowserThread; 26 using content::BrowserThread;
23 27
24 namespace { 28 namespace {
25 29
26 // Shorter names for fileapi::* constants. 30 // Shorter names for fileapi::* constants.
27 const fileapi::FileSystemType kTemporary = fileapi::kFileSystemTypeTemporary; 31 const fileapi::FileSystemType kTemporary = fileapi::kFileSystemTypeTemporary;
28 const fileapi::FileSystemType kPersistent = fileapi::kFileSystemTypePersistent; 32 const fileapi::FileSystemType kPersistent = fileapi::kFileSystemTypePersistent;
29 33
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 public: 66 public:
63 BrowsingDataFileSystemHelperTest() 67 BrowsingDataFileSystemHelperTest()
64 : ui_thread_(BrowserThread::UI, &message_loop_), 68 : ui_thread_(BrowserThread::UI, &message_loop_),
65 db_thread_(BrowserThread::DB, &message_loop_), 69 db_thread_(BrowserThread::DB, &message_loop_),
66 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), 70 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_),
67 file_thread_(BrowserThread::FILE, &message_loop_), 71 file_thread_(BrowserThread::FILE, &message_loop_),
68 file_user_blocking_thread_( 72 file_user_blocking_thread_(
69 BrowserThread::FILE_USER_BLOCKING, &message_loop_), 73 BrowserThread::FILE_USER_BLOCKING, &message_loop_),
70 io_thread_(BrowserThread::IO, &message_loop_) { 74 io_thread_(BrowserThread::IO, &message_loop_) {
71 profile_.reset(new TestingProfile()); 75 profile_.reset(new TestingProfile());
72 helper_ = BrowsingDataFileSystemHelper::Create(profile_.get()); 76
77 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
78 new quota::MockSpecialStoragePolicy();
79 file_system_context_ = new fileapi::FileSystemContext(
80 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(),
81 special_storage_policy.get(),
82 NULL,
83 profile_->GetPath(),
84 fileapi::CreateAllowFileAccessOptions());
85
86 helper_ = BrowsingDataFileSystemHelper::Create(file_system_context_);
73 message_loop_.RunAllPending(); 87 message_loop_.RunAllPending();
74 canned_helper_ = new CannedBrowsingDataFileSystemHelper(profile_.get()); 88 canned_helper_ = new CannedBrowsingDataFileSystemHelper(profile_.get());
75 } 89 }
76 virtual ~BrowsingDataFileSystemHelperTest() { 90 virtual ~BrowsingDataFileSystemHelperTest() {
77 // Avoid memory leaks. 91 // Avoid memory leaks.
78 profile_.reset(); 92 profile_.reset();
79 message_loop_.RunAllPending(); 93 message_loop_.RunAllPending();
80 } 94 }
81 95
82 TestingProfile* GetProfile() { 96 TestingProfile* GetProfile() {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 void FetchCannedFileSystems() { 155 void FetchCannedFileSystems() {
142 canned_helper_->StartFetching( 156 canned_helper_->StartFetching(
143 base::Bind(&BrowsingDataFileSystemHelperTest::CallbackStartFetching, 157 base::Bind(&BrowsingDataFileSystemHelperTest::CallbackStartFetching,
144 base::Unretained(this))); 158 base::Unretained(this)));
145 BlockUntilNotified(); 159 BlockUntilNotified();
146 } 160 }
147 161
148 // Sets up kOrigin1 with a temporary file system, kOrigin2 with a persistent 162 // Sets up kOrigin1 with a temporary file system, kOrigin2 with a persistent
149 // file system, and kOrigin3 with both. 163 // file system, and kOrigin3 with both.
150 virtual void PopulateTestFileSystemData() { 164 virtual void PopulateTestFileSystemData() {
151 sandbox_ = BrowserContext::GetFileSystemContext(profile_.get())-> 165 sandbox_ = BrowserContext::GetDefaultStoragePartition(profile_.get())->
152 sandbox_provider(); 166 GetFileSystemContext()->sandbox_provider();
153 167
154 CreateDirectoryForOriginAndType(kOrigin1, kTemporary); 168 CreateDirectoryForOriginAndType(kOrigin1, kTemporary);
155 CreateDirectoryForOriginAndType(kOrigin2, kPersistent); 169 CreateDirectoryForOriginAndType(kOrigin2, kPersistent);
156 CreateDirectoryForOriginAndType(kOrigin3, kTemporary); 170 CreateDirectoryForOriginAndType(kOrigin3, kTemporary);
157 CreateDirectoryForOriginAndType(kOrigin3, kPersistent); 171 CreateDirectoryForOriginAndType(kOrigin3, kPersistent);
158 172
159 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, kPersistent)); 173 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, kPersistent));
160 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, kTemporary)); 174 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, kTemporary));
161 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent)); 175 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent));
162 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary)); 176 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary));
(...skipping 29 matching lines...) Expand all
192 // defined before profile_ to prevent explosions. The threads also must be 206 // defined before profile_ to prevent explosions. The threads also must be
193 // defined in the order they're listed here. Oh how I love C++. 207 // defined in the order they're listed here. Oh how I love C++.
194 MessageLoopForUI message_loop_; 208 MessageLoopForUI message_loop_;
195 content::TestBrowserThread ui_thread_; 209 content::TestBrowserThread ui_thread_;
196 content::TestBrowserThread db_thread_; 210 content::TestBrowserThread db_thread_;
197 content::TestBrowserThread webkit_thread_; 211 content::TestBrowserThread webkit_thread_;
198 content::TestBrowserThread file_thread_; 212 content::TestBrowserThread file_thread_;
199 content::TestBrowserThread file_user_blocking_thread_; 213 content::TestBrowserThread file_user_blocking_thread_;
200 content::TestBrowserThread io_thread_; 214 content::TestBrowserThread io_thread_;
201 scoped_ptr<TestingProfile> profile_; 215 scoped_ptr<TestingProfile> profile_;
216 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
202 217
203 // We don't own this pointer: don't delete it. 218 // We don't own this pointer: don't delete it.
204 fileapi::SandboxMountPointProvider* sandbox_; 219 fileapi::SandboxMountPointProvider* sandbox_;
205 220
206 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperTest); 221 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperTest);
207 }; 222 };
208 223
209 // Verifies that the BrowsingDataFileSystemHelper correctly finds the test file 224 // Verifies that the BrowsingDataFileSystemHelper correctly finds the test file
210 // system data, and that each file system returned contains the expected data. 225 // system data, and that each file system returned contains the expected data.
211 TEST_F(BrowsingDataFileSystemHelperTest, FetchData) { 226 TEST_F(BrowsingDataFileSystemHelperTest, FetchData) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // extension and devtools schemes. 324 // extension and devtools schemes.
310 TEST_F(BrowsingDataFileSystemHelperTest, IgnoreExtensionsAndDevTools) { 325 TEST_F(BrowsingDataFileSystemHelperTest, IgnoreExtensionsAndDevTools) {
311 ASSERT_TRUE(canned_helper_->empty()); 326 ASSERT_TRUE(canned_helper_->empty());
312 canned_helper_->AddFileSystem(kOriginExt, kTemporary, 0); 327 canned_helper_->AddFileSystem(kOriginExt, kTemporary, 0);
313 ASSERT_TRUE(canned_helper_->empty()); 328 ASSERT_TRUE(canned_helper_->empty());
314 canned_helper_->AddFileSystem(kOriginDevTools, kTemporary, 0); 329 canned_helper_->AddFileSystem(kOriginDevTools, kTemporary, 0);
315 ASSERT_TRUE(canned_helper_->empty()); 330 ASSERT_TRUE(canned_helper_->empty());
316 } 331 }
317 332
318 } // namespace 333 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698