OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data_remover.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "chrome/browser/history/history.h" | 9 #include "chrome/browser/history/history.h" |
10 #include "chrome/test/testing_profile.h" | 10 #include "chrome/test/testing_profile.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webkit/fileapi/file_system_context.h" | 12 #include "webkit/fileapi/file_system_context.h" |
13 #include "webkit/fileapi/file_system_operation_context.h" | 13 #include "webkit/fileapi/file_system_operation_context.h" |
14 #include "webkit/fileapi/file_system_file_util.h" | 14 #include "webkit/fileapi/file_system_file_util.h" |
15 #include "webkit/fileapi/file_system_path_manager.h" | 15 #include "webkit/fileapi/file_system_path_manager.h" |
| 16 #include "webkit/fileapi/file_system_test_helper.h" |
16 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 17 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const char kTestkOrigin1[] = "http://host1:1/"; | 21 const char kTestkOrigin1[] = "http://host1:1/"; |
21 const char kTestkOrigin2[] = "http://host2:1/"; | 22 const char kTestkOrigin2[] = "http://host2:1/"; |
22 const char kTestkOrigin3[] = "http://host3:1/"; | 23 const char kTestkOrigin3[] = "http://host3:1/"; |
23 | 24 |
24 const GURL kOrigin1(kTestkOrigin1); | 25 const GURL kOrigin1(kTestkOrigin1); |
25 const GURL kOrigin2(kTestkOrigin2); | 26 const GURL kOrigin2(kTestkOrigin2); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 sandbox_->ValidateFileSystemRootAndGetURL( | 110 sandbox_->ValidateFileSystemRootAndGetURL( |
110 origin, type, false, NewCallback(this, | 111 origin, type, false, NewCallback(this, |
111 &RemoveFileSystemTester::FindFileSystemPathCallback)); | 112 &RemoveFileSystemTester::FindFileSystemPathCallback)); |
112 BlockUntilNotified(); | 113 BlockUntilNotified(); |
113 return found_file_system_; | 114 return found_file_system_; |
114 } | 115 } |
115 | 116 |
116 virtual void PopulateTestFileSystemData(TestingProfile* profile) { | 117 virtual void PopulateTestFileSystemData(TestingProfile* profile) { |
117 // Set up kOrigin1 with a temporary file system, kOrigin2 with a persistent | 118 // Set up kOrigin1 with a temporary file system, kOrigin2 with a persistent |
118 // file system, and kOrigin3 with both. | 119 // file system, and kOrigin3 with both. |
119 sandbox_ = profile->GetFileSystemContext()->path_manager()-> | 120 profile_ = profile; |
| 121 sandbox_ = profile_->GetFileSystemContext()->path_manager()-> |
120 sandbox_provider(); | 122 sandbox_provider(); |
121 | 123 |
122 CreateDirectoryForOriginAndType(kOrigin1, | 124 CreateDirectoryForOriginAndType(kOrigin1, |
123 fileapi::kFileSystemTypeTemporary); | 125 fileapi::kFileSystemTypeTemporary); |
124 CreateDirectoryForOriginAndType(kOrigin2, | 126 CreateDirectoryForOriginAndType(kOrigin2, |
125 fileapi::kFileSystemTypePersistent); | 127 fileapi::kFileSystemTypePersistent); |
126 CreateDirectoryForOriginAndType(kOrigin3, | 128 CreateDirectoryForOriginAndType(kOrigin3, |
127 fileapi::kFileSystemTypeTemporary); | 129 fileapi::kFileSystemTypeTemporary); |
128 CreateDirectoryForOriginAndType(kOrigin3, | 130 CreateDirectoryForOriginAndType(kOrigin3, |
129 fileapi::kFileSystemTypePersistent); | 131 fileapi::kFileSystemTypePersistent); |
130 | 132 |
| 133 FilePath temp("tempfile.tmp"); |
| 134 TouchTestFileForOriginAndType(kOrigin1, fileapi::kFileSystemTypeTemporary, |
| 135 temp, base::Time::Now()); |
| 136 TouchTestFileForOriginAndType(kOrigin2, fileapi::kFileSystemTypePersistent, |
| 137 temp, base::Time::Now()); |
| 138 TouchTestFileForOriginAndType(kOrigin3, fileapi::kFileSystemTypePersistent, |
| 139 temp, base::Time::Now()); |
| 140 TouchTestFileForOriginAndType(kOrigin3, fileapi::kFileSystemTypeTemporary, |
| 141 temp, base::Time::Now()); |
| 142 |
131 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, | 143 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, |
132 fileapi::kFileSystemTypePersistent)); | 144 fileapi::kFileSystemTypePersistent)); |
133 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, | 145 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, |
134 fileapi::kFileSystemTypeTemporary)); | 146 fileapi::kFileSystemTypeTemporary)); |
135 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, | 147 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, |
136 fileapi::kFileSystemTypePersistent)); | 148 fileapi::kFileSystemTypePersistent)); |
137 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, | 149 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, |
138 fileapi::kFileSystemTypeTemporary)); | 150 fileapi::kFileSystemTypeTemporary)); |
139 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, | 151 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, |
140 fileapi::kFileSystemTypePersistent)); | 152 fileapi::kFileSystemTypePersistent)); |
141 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, | 153 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, |
142 fileapi::kFileSystemTypeTemporary)); | 154 fileapi::kFileSystemTypeTemporary)); |
143 } | 155 } |
144 | 156 |
145 void CreateDirectoryForOriginAndType(const GURL& origin, | 157 void CreateDirectoryForOriginAndType(const GURL& origin, |
146 fileapi::FileSystemType type) { | 158 fileapi::FileSystemType type) { |
| 159 fileapi::FileSystemTestOriginHelper helper(origin, type); |
| 160 helper.SetUp(profile_->GetFileSystemContext(), |
| 161 sandbox_->GetFileSystemFileUtil()); |
147 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread( | 162 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread( |
148 origin, type, FilePath(), true); | 163 origin, type, FilePath(), true); |
149 EXPECT_TRUE(file_util::DirectoryExists(target)); | 164 EXPECT_TRUE(file_util::DirectoryExists(target)); |
150 } | 165 } |
151 | 166 |
| 167 void TouchTestFileForOriginAndType(const GURL& origin, |
| 168 fileapi::FileSystemType type, |
| 169 const FilePath& path, |
| 170 const base::Time& modified) { |
| 171 // We can use a raw pointer here for the same reason that `sandbox_` can be |
| 172 // a raw pointer: everything is destroyed when the profile destroys the |
| 173 // FileSystemContext in which they each live. |
| 174 fileapi::FileSystemFileUtil* file_util = sandbox_->GetFileSystemFileUtil(); |
| 175 |
| 176 // The operation context, though, we'll have to destroy ourselves. |
| 177 scoped_ptr<fileapi::FileSystemOperationContext> |
| 178 op_context(new fileapi::FileSystemOperationContext( |
| 179 profile_->GetFileSystemContext(), file_util)); |
| 180 op_context->set_src_origin_url(origin); |
| 181 op_context->set_src_type(type); |
| 182 |
| 183 bool created; |
| 184 base::PlatformFileError status = file_util->EnsureFileExists( |
| 185 op_context.get(), path, &created); |
| 186 EXPECT_EQ(base::PLATFORM_FILE_OK, status); |
| 187 EXPECT_TRUE(created); |
| 188 } |
| 189 |
152 private: | 190 private: |
| 191 // We own neither of these pointers; we shouldn't destroy them. |
153 fileapi::SandboxMountPointProvider* sandbox_; | 192 fileapi::SandboxMountPointProvider* sandbox_; |
| 193 TestingProfile* profile_; |
154 bool found_file_system_; | 194 bool found_file_system_; |
155 | 195 |
156 DISALLOW_COPY_AND_ASSIGN(RemoveFileSystemTester); | 196 DISALLOW_COPY_AND_ASSIGN(RemoveFileSystemTester); |
157 }; | 197 }; |
158 | 198 |
159 class BrowsingDataRemoverTest : public testing::Test { | 199 class BrowsingDataRemoverTest : public testing::Test { |
160 public: | 200 public: |
161 BrowsingDataRemoverTest() | 201 BrowsingDataRemoverTest() |
162 : ui_thread_(BrowserThread::UI, &message_loop_), | 202 : ui_thread_(BrowserThread::UI, &message_loop_), |
163 db_thread_(BrowserThread::DB, &message_loop_), | 203 db_thread_(BrowserThread::DB, &message_loop_), |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, | 297 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, |
258 fileapi::kFileSystemTypePersistent)); | 298 fileapi::kFileSystemTypePersistent)); |
259 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, | 299 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, |
260 fileapi::kFileSystemTypeTemporary)); | 300 fileapi::kFileSystemTypeTemporary)); |
261 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, | 301 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, |
262 fileapi::kFileSystemTypePersistent)); | 302 fileapi::kFileSystemTypePersistent)); |
263 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, | 303 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, |
264 fileapi::kFileSystemTypeTemporary)); | 304 fileapi::kFileSystemTypeTemporary)); |
265 } | 305 } |
266 | 306 |
| 307 TEST_F(BrowsingDataRemoverTest, RemoveFileSystemsForLastHour) { |
| 308 scoped_ptr<RemoveFileSystemTester> tester(new RemoveFileSystemTester()); |
| 309 |
| 310 tester->PopulateTestFileSystemData(GetProfile()); |
| 311 |
| 312 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 313 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
| 314 |
| 315 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1, |
| 316 fileapi::kFileSystemTypePersistent)); |
| 317 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1, |
| 318 fileapi::kFileSystemTypeTemporary)); |
| 319 EXPECT_TRUE(tester->FileSystemContainsOriginAndType(kOrigin2, |
| 320 fileapi::kFileSystemTypePersistent)); |
| 321 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, |
| 322 fileapi::kFileSystemTypeTemporary)); |
| 323 EXPECT_TRUE(tester->FileSystemContainsOriginAndType(kOrigin3, |
| 324 fileapi::kFileSystemTypePersistent)); |
| 325 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, |
| 326 fileapi::kFileSystemTypeTemporary)); |
| 327 } |
| 328 |
267 } // namespace | 329 } // namespace |
OLD | NEW |