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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/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/browser/storage_partition.h" |
16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "webkit/browser/fileapi/file_system_context.h" | 18 #include "storage/browser/fileapi/file_system_context.h" |
19 #include "webkit/browser/fileapi/file_system_url.h" | 19 #include "storage/browser/fileapi/file_system_url.h" |
20 #include "webkit/common/fileapi/file_system_types.h" | 20 #include "storage/common/fileapi/file_system_types.h" |
21 | 21 |
22 using content::BrowserContext; | 22 using content::BrowserContext; |
23 using content::BrowserThread; | 23 using content::BrowserThread; |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Shorter names for fileapi::* constants. | 27 // Shorter names for storage::* constants. |
28 const fileapi::FileSystemType kTemporary = fileapi::kFileSystemTypeTemporary; | 28 const storage::FileSystemType kTemporary = storage::kFileSystemTypeTemporary; |
29 const fileapi::FileSystemType kPersistent = fileapi::kFileSystemTypePersistent; | 29 const storage::FileSystemType kPersistent = storage::kFileSystemTypePersistent; |
30 | 30 |
31 // We'll use these three distinct origins for testing, both as strings and as | 31 // We'll use these three distinct origins for testing, both as strings and as |
32 // GURLs in appropriate contexts. | 32 // GURLs in appropriate contexts. |
33 const char kTestOrigin1[] = "http://host1:1/"; | 33 const char kTestOrigin1[] = "http://host1:1/"; |
34 const char kTestOrigin2[] = "http://host2:2/"; | 34 const char kTestOrigin2[] = "http://host2:2/"; |
35 const char kTestOrigin3[] = "http://host3:3/"; | 35 const char kTestOrigin3[] = "http://host3:3/"; |
36 | 36 |
37 // Extensions and Devtools should be ignored. | 37 // Extensions and Devtools should be ignored. |
38 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; | 38 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; |
39 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; | 39 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 base::MessageLoop::current()->Run(); | 85 base::MessageLoop::current()->Run(); |
86 } | 86 } |
87 | 87 |
88 // Unblocks the current MessageLoop. Should be called in response to some sort | 88 // Unblocks the current MessageLoop. Should be called in response to some sort |
89 // of async activity in a callback method. | 89 // of async activity in a callback method. |
90 void Notify() { | 90 void Notify() { |
91 base::MessageLoop::current()->Quit(); | 91 base::MessageLoop::current()->Quit(); |
92 } | 92 } |
93 | 93 |
94 // Callback that should be executed in response to | 94 // Callback that should be executed in response to |
95 // fileapi::FileSystemContext::OpenFileSystem. | 95 // storage::FileSystemContext::OpenFileSystem. |
96 void OpenFileSystemCallback(const GURL& root, | 96 void OpenFileSystemCallback(const GURL& root, |
97 const std::string& name, | 97 const std::string& name, |
98 base::File::Error error) { | 98 base::File::Error error) { |
99 open_file_system_result_ = error; | 99 open_file_system_result_ = error; |
100 Notify(); | 100 Notify(); |
101 } | 101 } |
102 | 102 |
103 bool OpenFileSystem(const GURL& origin, | 103 bool OpenFileSystem(const GURL& origin, |
104 fileapi::FileSystemType type, | 104 storage::FileSystemType type, |
105 fileapi::OpenFileSystemMode open_mode) { | 105 storage::OpenFileSystemMode open_mode) { |
106 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 106 BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
107 GetFileSystemContext()->OpenFileSystem( | 107 GetFileSystemContext()->OpenFileSystem( |
108 origin, type, open_mode, | 108 origin, type, open_mode, |
109 base::Bind( | 109 base::Bind( |
110 &BrowsingDataFileSystemHelperTest::OpenFileSystemCallback, | 110 &BrowsingDataFileSystemHelperTest::OpenFileSystemCallback, |
111 base::Unretained(this))); | 111 base::Unretained(this))); |
112 BlockUntilNotified(); | 112 BlockUntilNotified(); |
113 return open_file_system_result_ == base::File::FILE_OK; | 113 return open_file_system_result_ == base::File::FILE_OK; |
114 } | 114 } |
115 | 115 |
116 // Calls fileapi::FileSystemContext::OpenFileSystem with | 116 // Calls storage::FileSystemContext::OpenFileSystem with |
117 // OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT flag | 117 // OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT flag |
118 // to verify the existence of a file system for a specified type and origin, | 118 // to verify the existence of a file system for a specified type and origin, |
119 // blocks until a response is available, then returns the result | 119 // blocks until a response is available, then returns the result |
120 // synchronously to it's caller. | 120 // synchronously to it's caller. |
121 bool FileSystemContainsOriginAndType(const GURL& origin, | 121 bool FileSystemContainsOriginAndType(const GURL& origin, |
122 fileapi::FileSystemType type) { | 122 storage::FileSystemType type) { |
123 return OpenFileSystem(origin, type, | 123 return OpenFileSystem( |
124 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT); | 124 origin, type, storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT); |
125 } | 125 } |
126 | 126 |
127 // Callback that should be executed in response to StartFetching(), and stores | 127 // Callback that should be executed in response to StartFetching(), and stores |
128 // found file systems locally so that they are available via GetFileSystems(). | 128 // found file systems locally so that they are available via GetFileSystems(). |
129 void CallbackStartFetching( | 129 void CallbackStartFetching( |
130 const std::list<BrowsingDataFileSystemHelper::FileSystemInfo>& | 130 const std::list<BrowsingDataFileSystemHelper::FileSystemInfo>& |
131 file_system_info_list) { | 131 file_system_info_list) { |
132 file_system_info_list_.reset( | 132 file_system_info_list_.reset( |
133 new std::list<BrowsingDataFileSystemHelper::FileSystemInfo>( | 133 new std::list<BrowsingDataFileSystemHelper::FileSystemInfo>( |
134 file_system_info_list)); | 134 file_system_info_list)); |
(...skipping 30 matching lines...) Expand all Loading... |
165 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, kTemporary)); | 165 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, kTemporary)); |
166 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent)); | 166 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent)); |
167 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary)); | 167 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary)); |
168 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kPersistent)); | 168 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kPersistent)); |
169 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kTemporary)); | 169 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, kTemporary)); |
170 } | 170 } |
171 | 171 |
172 // Calls OpenFileSystem with OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT | 172 // Calls OpenFileSystem with OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT |
173 // to create a filesystem of a given type for a specified origin. | 173 // to create a filesystem of a given type for a specified origin. |
174 void CreateDirectoryForOriginAndType(const GURL& origin, | 174 void CreateDirectoryForOriginAndType(const GURL& origin, |
175 fileapi::FileSystemType type) { | 175 storage::FileSystemType type) { |
176 OpenFileSystem(origin, type, | 176 OpenFileSystem( |
177 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT); | 177 origin, type, storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT); |
178 EXPECT_EQ(base::File::FILE_OK, open_file_system_result_); | 178 EXPECT_EQ(base::File::FILE_OK, open_file_system_result_); |
179 } | 179 } |
180 | 180 |
181 // Returns a list of the FileSystemInfo objects gathered in the most recent | 181 // Returns a list of the FileSystemInfo objects gathered in the most recent |
182 // call to StartFetching(). | 182 // call to StartFetching(). |
183 FileSystemInfoList* GetFileSystems() { | 183 FileSystemInfoList* GetFileSystems() { |
184 return file_system_info_list_.get(); | 184 return file_system_info_list_.get(); |
185 } | 185 } |
186 | 186 |
187 protected: | 187 protected: |
(...skipping 24 matching lines...) Expand all Loading... |
212 bool test_hosts_found[3] = {false, false, false}; | 212 bool test_hosts_found[3] = {false, false, false}; |
213 for (std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator info = | 213 for (std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator info = |
214 file_system_info_list_->begin(); info != file_system_info_list_->end(); | 214 file_system_info_list_->begin(); info != file_system_info_list_->end(); |
215 ++info) { | 215 ++info) { |
216 if (info->origin == kOrigin1) { | 216 if (info->origin == kOrigin1) { |
217 EXPECT_FALSE(test_hosts_found[0]); | 217 EXPECT_FALSE(test_hosts_found[0]); |
218 test_hosts_found[0] = true; | 218 test_hosts_found[0] = true; |
219 EXPECT_FALSE(ContainsKey(info->usage_map, kPersistent)); | 219 EXPECT_FALSE(ContainsKey(info->usage_map, kPersistent)); |
220 EXPECT_TRUE(ContainsKey(info->usage_map, kTemporary)); | 220 EXPECT_TRUE(ContainsKey(info->usage_map, kTemporary)); |
221 EXPECT_EQ(kEmptyFileSystemSize, | 221 EXPECT_EQ(kEmptyFileSystemSize, |
222 info->usage_map[fileapi::kFileSystemTypeTemporary]); | 222 info->usage_map[storage::kFileSystemTypeTemporary]); |
223 } else if (info->origin == kOrigin2) { | 223 } else if (info->origin == kOrigin2) { |
224 EXPECT_FALSE(test_hosts_found[1]); | 224 EXPECT_FALSE(test_hosts_found[1]); |
225 test_hosts_found[1] = true; | 225 test_hosts_found[1] = true; |
226 EXPECT_TRUE(ContainsKey(info->usage_map, kPersistent)); | 226 EXPECT_TRUE(ContainsKey(info->usage_map, kPersistent)); |
227 EXPECT_FALSE(ContainsKey(info->usage_map, kTemporary)); | 227 EXPECT_FALSE(ContainsKey(info->usage_map, kTemporary)); |
228 EXPECT_EQ(kEmptyFileSystemSize, info->usage_map[kPersistent]); | 228 EXPECT_EQ(kEmptyFileSystemSize, info->usage_map[kPersistent]); |
229 } else if (info->origin == kOrigin3) { | 229 } else if (info->origin == kOrigin3) { |
230 EXPECT_FALSE(test_hosts_found[2]); | 230 EXPECT_FALSE(test_hosts_found[2]); |
231 test_hosts_found[2] = true; | 231 test_hosts_found[2] = true; |
232 EXPECT_TRUE(ContainsKey(info->usage_map, kPersistent)); | 232 EXPECT_TRUE(ContainsKey(info->usage_map, kPersistent)); |
(...skipping 66 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 |