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

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

Issue 9016020: Cleanup FileSystemOperation for preparing for adding FSO-factory method (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 8 years, 11 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/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browsing_data_file_system_helper.h" 13 #include "chrome/browser/browsing_data_file_system_helper.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
14 #include "content/test/test_browser_thread.h" 15 #include "content/test/test_browser_thread.h"
15 #include "webkit/fileapi/file_system_context.h" 16 #include "webkit/fileapi/file_system_context.h"
16 #include "webkit/fileapi/file_system_types.h" 17 #include "webkit/fileapi/file_system_types.h"
17 #include "webkit/fileapi/file_system_usage_cache.h" 18 #include "webkit/fileapi/file_system_usage_cache.h"
18 #include "webkit/fileapi/sandbox_mount_point_provider.h" 19 #include "webkit/fileapi/sandbox_mount_point_provider.h"
19 20
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 MessageLoop::current()->Run(); 71 MessageLoop::current()->Run();
71 } 72 }
72 73
73 // Unblocks the current MessageLoop. Should be called in response to some sort 74 // Unblocks the current MessageLoop. Should be called in response to some sort
74 // of async activity in a callback method. 75 // of async activity in a callback method.
75 void Notify() { 76 void Notify() {
76 MessageLoop::current()->Quit(); 77 MessageLoop::current()->Quit();
77 } 78 }
78 79
79 // Callback that should be executed in response to 80 // Callback that should be executed in response to
80 // fileapi::SandboxMountPointProvider::ValidateFileSystemRootAndGetURL 81 // fileapi::SandboxMountPointProvider::ValidateFileSystemRoot
81 void CallbackFindFileSystemPath(bool success, 82 void ValidateFileSystemCallback(base::PlatformFileError error) {
82 const FilePath& path, 83 validate_file_system_result_ = error;
83 const std::string& name) {
84 found_file_system_ = success;
85 Notify(); 84 Notify();
86 } 85 }
87 86
88 // Calls fileapi::SandboxMountPointProvider::ValidateFileSystemRootAndGetURL 87 // Calls fileapi::SandboxMountPointProvider::ValidateFileSystemRootAndGetURL
89 // to verify the existence of a file system for a specified type and origin, 88 // to verify the existence of a file system for a specified type and origin,
90 // blocks until a response is available, then returns the result 89 // blocks until a response is available, then returns the result
91 // synchronously to it's caller. 90 // synchronously to it's caller.
92 bool FileSystemContainsOriginAndType(const GURL& origin, 91 bool FileSystemContainsOriginAndType(const GURL& origin,
93 fileapi::FileSystemType type) { 92 fileapi::FileSystemType type) {
94 sandbox_->ValidateFileSystemRootAndGetURL( 93 sandbox_->ValidateFileSystemRoot(
95 origin, type, false, 94 origin, type, false,
96 base::Bind( 95 base::Bind(
97 &BrowsingDataFileSystemHelperTest::CallbackFindFileSystemPath, 96 &BrowsingDataFileSystemHelperTest::ValidateFileSystemCallback,
98 base::Unretained(this))); 97 base::Unretained(this)));
99 BlockUntilNotified(); 98 BlockUntilNotified();
100 return found_file_system_; 99 return validate_file_system_result_ == base::PLATFORM_FILE_OK;
101 } 100 }
102 101
103 // Callback that should be executed in response to StartFetching(), and stores 102 // Callback that should be executed in response to StartFetching(), and stores
104 // found file systems locally so that they are available via GetFileSystems(). 103 // found file systems locally so that they are available via GetFileSystems().
105 void CallbackStartFetching( 104 void CallbackStartFetching(
106 const std::list<BrowsingDataFileSystemHelper::FileSystemInfo>& 105 const std::list<BrowsingDataFileSystemHelper::FileSystemInfo>&
107 file_system_info_list) { 106 file_system_info_list) {
108 file_system_info_list_.reset( 107 file_system_info_list_.reset(
109 new std::list<BrowsingDataFileSystemHelper::FileSystemInfo>( 108 new std::list<BrowsingDataFileSystemHelper::FileSystemInfo>(
110 file_system_info_list)); 109 file_system_info_list));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent)); 143 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent));
145 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary)); 144 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary));
146 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kPersistent)); 145 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kPersistent));
147 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kTemporary)); 146 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kTemporary));
148 } 147 }
149 148
150 // Uses the fileapi methods to create a filesystem of a given type for a 149 // Uses the fileapi methods to create a filesystem of a given type for a
151 // specified origin. 150 // specified origin.
152 void CreateDirectoryForOriginAndType(const GURL& origin, 151 void CreateDirectoryForOriginAndType(const GURL& origin,
153 fileapi::FileSystemType type) { 152 fileapi::FileSystemType type) {
154 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread( 153 FilePath target = sandbox_->GetFileSystemRootPathOnFileThread(
155 origin, type, FilePath(), true); 154 origin, type, FilePath(), true);
156 EXPECT_TRUE(file_util::DirectoryExists(target)); 155 EXPECT_TRUE(file_util::DirectoryExists(target));
157 } 156 }
158 157
159 // Returns a list of the FileSystemInfo objects gathered in the most recent 158 // Returns a list of the FileSystemInfo objects gathered in the most recent
160 // call to StartFetching(). 159 // call to StartFetching().
161 FileSystemInfoList* GetFileSystems() { 160 FileSystemInfoList* GetFileSystems() {
162 return file_system_info_list_.get(); 161 return file_system_info_list_.get();
163 } 162 }
164 163
165 164
166 // Temporary storage to pass information back from callbacks. 165 // Temporary storage to pass information back from callbacks.
167 bool found_file_system_; 166 base::PlatformFileError validate_file_system_result_;
168 ScopedFileSystemInfoList file_system_info_list_; 167 ScopedFileSystemInfoList file_system_info_list_;
169 168
170 scoped_refptr<BrowsingDataFileSystemHelper> helper_; 169 scoped_refptr<BrowsingDataFileSystemHelper> helper_;
171 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_; 170 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_;
172 171
173 private: 172 private:
174 // message_loop_, as well as all the threads associated with it must be 173 // message_loop_, as well as all the threads associated with it must be
175 // defined before profile_ to prevent explosions. The threads also must be 174 // defined before profile_ to prevent explosions. The threads also must be
176 // defined in the order they're listed here. Oh how I love C++. 175 // defined in the order they're listed here. Oh how I love C++.
177 MessageLoopForUI message_loop_; 176 MessageLoopForUI message_loop_;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 278
280 info++; 279 info++;
281 EXPECT_EQ(kOrigin2, info->origin); 280 EXPECT_EQ(kOrigin2, info->origin);
282 EXPECT_FALSE(info->has_persistent); 281 EXPECT_FALSE(info->has_persistent);
283 EXPECT_TRUE(info->has_temporary); 282 EXPECT_TRUE(info->has_temporary);
284 EXPECT_EQ(0, info->usage_persistent); 283 EXPECT_EQ(0, info->usage_persistent);
285 EXPECT_EQ(100, info->usage_temporary); 284 EXPECT_EQ(100, info->usage_temporary);
286 } 285 }
287 286
288 } // namespace 287 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698