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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // Unblocks the current MessageLoop. Should be called in response to some sort | 89 // Unblocks the current MessageLoop. Should be called in response to some sort |
90 // of async activity in a callback method. | 90 // of async activity in a callback method. |
91 void Notify() { | 91 void Notify() { |
92 base::MessageLoop::current()->Quit(); | 92 base::MessageLoop::current()->Quit(); |
93 } | 93 } |
94 | 94 |
95 // Callback that should be executed in response to | 95 // Callback that should be executed in response to |
96 // fileapi::FileSystemContext::OpenFileSystem. | 96 // fileapi::FileSystemContext::OpenFileSystem. |
97 void OpenFileSystemCallback(const GURL& root, | 97 void OpenFileSystemCallback(const GURL& root, |
98 const std::string& name, | 98 const std::string& name, |
99 base::PlatformFileError error) { | 99 base::File::Error error) { |
100 open_file_system_result_ = error; | 100 open_file_system_result_ = error; |
101 Notify(); | 101 Notify(); |
102 } | 102 } |
103 | 103 |
104 bool OpenFileSystem(const GURL& origin, | 104 bool OpenFileSystem(const GURL& origin, |
105 fileapi::FileSystemType type, | 105 fileapi::FileSystemType type, |
106 fileapi::OpenFileSystemMode open_mode) { | 106 fileapi::OpenFileSystemMode open_mode) { |
107 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 107 BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
108 GetFileSystemContext()->OpenFileSystem( | 108 GetFileSystemContext()->OpenFileSystem( |
109 origin, type, open_mode, | 109 origin, type, open_mode, |
110 base::Bind( | 110 base::Bind( |
111 &BrowsingDataFileSystemHelperTest::OpenFileSystemCallback, | 111 &BrowsingDataFileSystemHelperTest::OpenFileSystemCallback, |
112 base::Unretained(this))); | 112 base::Unretained(this))); |
113 BlockUntilNotified(); | 113 BlockUntilNotified(); |
114 return open_file_system_result_ == base::PLATFORM_FILE_OK; | 114 return open_file_system_result_ == base::File::FILE_OK; |
115 } | 115 } |
116 | 116 |
117 // Calls fileapi::FileSystemContext::OpenFileSystem with | 117 // Calls fileapi::FileSystemContext::OpenFileSystem with |
118 // OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT flag | 118 // OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT flag |
119 // to verify the existence of a file system for a specified type and origin, | 119 // to verify the existence of a file system for a specified type and origin, |
120 // blocks until a response is available, then returns the result | 120 // blocks until a response is available, then returns the result |
121 // synchronously to it's caller. | 121 // synchronously to it's caller. |
122 bool FileSystemContainsOriginAndType(const GURL& origin, | 122 bool FileSystemContainsOriginAndType(const GURL& origin, |
123 fileapi::FileSystemType type) { | 123 fileapi::FileSystemType type) { |
124 return OpenFileSystem(origin, type, | 124 return OpenFileSystem(origin, type, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kPersistent)); | 169 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kPersistent)); |
170 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kTemporary)); | 170 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kTemporary)); |
171 } | 171 } |
172 | 172 |
173 // Calls OpenFileSystem with OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT | 173 // Calls OpenFileSystem with OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT |
174 // to create a filesystem of a given type for a specified origin. | 174 // to create a filesystem of a given type for a specified origin. |
175 void CreateDirectoryForOriginAndType(const GURL& origin, | 175 void CreateDirectoryForOriginAndType(const GURL& origin, |
176 fileapi::FileSystemType type) { | 176 fileapi::FileSystemType type) { |
177 OpenFileSystem(origin, type, | 177 OpenFileSystem(origin, type, |
178 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT); | 178 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT); |
179 EXPECT_EQ(base::PLATFORM_FILE_OK, open_file_system_result_); | 179 EXPECT_EQ(base::File::FILE_OK, open_file_system_result_); |
180 } | 180 } |
181 | 181 |
182 // Returns a list of the FileSystemInfo objects gathered in the most recent | 182 // Returns a list of the FileSystemInfo objects gathered in the most recent |
183 // call to StartFetching(). | 183 // call to StartFetching(). |
184 FileSystemInfoList* GetFileSystems() { | 184 FileSystemInfoList* GetFileSystems() { |
185 return file_system_info_list_.get(); | 185 return file_system_info_list_.get(); |
186 } | 186 } |
187 | 187 |
188 protected: | 188 protected: |
189 content::TestBrowserThreadBundle thread_bundle_; | 189 content::TestBrowserThreadBundle thread_bundle_; |
190 scoped_ptr<TestingProfile> profile_; | 190 scoped_ptr<TestingProfile> profile_; |
191 | 191 |
192 // Temporary storage to pass information back from callbacks. | 192 // Temporary storage to pass information back from callbacks. |
193 base::PlatformFileError open_file_system_result_; | 193 base::File::Error open_file_system_result_; |
194 ScopedFileSystemInfoList file_system_info_list_; | 194 ScopedFileSystemInfoList file_system_info_list_; |
195 | 195 |
196 scoped_refptr<BrowsingDataFileSystemHelper> helper_; | 196 scoped_refptr<BrowsingDataFileSystemHelper> helper_; |
197 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_; | 197 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_; |
198 | 198 |
199 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperTest); | 199 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperTest); |
200 }; | 200 }; |
201 | 201 |
202 // Verifies that the BrowsingDataFileSystemHelper correctly finds the test file | 202 // Verifies that the BrowsingDataFileSystemHelper correctly finds the test file |
203 // system data, and that each file system returned contains the expected data. | 203 // system data, and that each file system returned contains the expected data. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 // extension and devtools schemes. | 299 // extension and devtools schemes. |
300 TEST_F(BrowsingDataFileSystemHelperTest, IgnoreExtensionsAndDevTools) { | 300 TEST_F(BrowsingDataFileSystemHelperTest, IgnoreExtensionsAndDevTools) { |
301 ASSERT_TRUE(canned_helper_->empty()); | 301 ASSERT_TRUE(canned_helper_->empty()); |
302 canned_helper_->AddFileSystem(kOriginExt, kTemporary, 0); | 302 canned_helper_->AddFileSystem(kOriginExt, kTemporary, 0); |
303 ASSERT_TRUE(canned_helper_->empty()); | 303 ASSERT_TRUE(canned_helper_->empty()); |
304 canned_helper_->AddFileSystem(kOriginDevTools, kTemporary, 0); | 304 canned_helper_->AddFileSystem(kOriginDevTools, kTemporary, 0); |
305 ASSERT_TRUE(canned_helper_->empty()); | 305 ASSERT_TRUE(canned_helper_->empty()); |
306 } | 306 } |
307 | 307 |
308 } // namespace | 308 } // namespace |
OLD | NEW |