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

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

Issue 7063020: Adding `browsing_data_filesystem_helper*` as the first step towards content settings UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dropping explicit use of UI thread. Created 9 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/basictypes.h"
8 #include "base/callback.h"
9 #include "base/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/message_loop.h"
12 #include "chrome/browser/browsing_data_file_system_helper.h"
13 #include "chrome/browser/browsing_data_helper_browsertest.h"
14 #include "chrome/test/in_process_browser_test.h"
15 #include "chrome/test/testing_profile.h"
16 #include "chrome/test/ui_test_utils.h"
17 #include "content/browser/browser_thread.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webkit/fileapi/file_system_context.h"
20 #include "webkit/fileapi/file_system_path_manager.h"
21 #include "webkit/fileapi/file_system_types.h"
22 #include "webkit/fileapi/file_system_usage_cache.h"
23 #include "webkit/fileapi/sandbox_mount_point_provider.h"
24
25 namespace {
26
27 typedef BrowsingDataHelperCallback<BrowsingDataFileSystemHelper::FileSystemInfo>
28 TestCompletionCallback;
29
30 const char kTestOrigin1[] = "http://host1:1/";
31 const char kTestOrigin2[] = "http://host2:1/";
32 const char kTestOrigin3[] = "http://host3:1/";
33
34 const char kTestOriginExtension[] =
35 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj:1/";
36
37 const int kEmptyFileSystemSize = fileapi::FileSystemUsageCache::kUsageFileSize;
38
39 class BrowsingDataFileSystemHelperTest : public InProcessBrowserTest {
40 public:
41 virtual void PopulateTestData() {
42 const GURL origin1(kTestOrigin1);
43 const GURL origin2(kTestOrigin2);
44 const GURL origin3(kTestOrigin3);
45
46 sandbox_ = testing_profile_.GetFileSystemContext()->
47 path_manager()->sandbox_provider();
48
49 CreateDirectoryForOriginAndType(origin1, fileapi::kFileSystemTypeTemporary);
50 CreateDirectoryForOriginAndType(origin2,
51 fileapi::kFileSystemTypePersistent);
52 CreateDirectoryForOriginAndType(origin3, fileapi::kFileSystemTypeTemporary);
53 CreateDirectoryForOriginAndType(origin3,
54 fileapi::kFileSystemTypePersistent);
55 }
56
57 protected:
58 void CreateDirectoryForOriginAndType(const GURL& origin,
59 fileapi::FileSystemType type) {
60 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread(
61 origin, type, FilePath(), true);
62 ASSERT_TRUE(file_util::CreateDirectory(target));
63 }
64
65 TestingProfile testing_profile_;
66 fileapi::SandboxMountPointProvider* sandbox_;
67 };
68
69 // Called back by BrowsingDataFileSystemHelper on the UI thread once the
70 // database information has been retrieved.
71 class StopTestOnCallback {
72 public:
73 explicit StopTestOnCallback(
74 BrowsingDataFileSystemHelper* file_system_helper)
75 : file_system_helper_(file_system_helper) {
76 DCHECK(file_system_helper_);
77 }
78
79 void CallbackFetchData(
80 const std::vector<BrowsingDataFileSystemHelper::FileSystemInfo>&
81 file_system_info_list) {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 EXPECT_EQ(3UL, file_system_info_list.size());
84
85 // Order is arbitrary, verify all three origins.
86 bool test_hosts_found[3] = {false, false, false};
87 for (size_t i = 0; i < file_system_info_list.size(); i++) {
88 BrowsingDataFileSystemHelper::FileSystemInfo info =
89 file_system_info_list.at(i);
90 if (info.origin == GURL(kTestOrigin1)) {
91 test_hosts_found[0] = true;
92 EXPECT_FALSE(info.has_persistent);
93 EXPECT_TRUE(info.has_temporary);
94 EXPECT_EQ(0, info.usage_persistent);
95 EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary);
96 } else if (info.origin == GURL(kTestOrigin2)) {
97 test_hosts_found[1] = true;
98 EXPECT_TRUE(info.has_persistent);
99 EXPECT_FALSE(info.has_temporary);
100 EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent);
101 EXPECT_EQ(0, info.usage_temporary);
102 } else if (info.origin == GURL(kTestOrigin3)) {
103 test_hosts_found[2] = true;
104 EXPECT_TRUE(info.has_persistent);
105 EXPECT_TRUE(info.has_temporary);
106 EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent);
107 EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary);
108 } else {
109 ADD_FAILURE() << info.origin.spec() << " isn't an origin we added.";
110 }
111 }
112 for (size_t i = 0; i < arraysize(test_hosts_found); i++) {
113 EXPECT_TRUE(test_hosts_found[i]);
114 }
115 MessageLoop::current()->Quit();
116 }
117
118 void CallbackDeleteData(
119 const std::vector<BrowsingDataFileSystemHelper::FileSystemInfo>&
120 file_system_info_list) {
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
122 EXPECT_EQ(1UL, file_system_info_list.size());
123 BrowsingDataFileSystemHelper::FileSystemInfo info =
124 file_system_info_list.at(0);
125 EXPECT_EQ(info.origin, GURL(kTestOrigin3));
126 EXPECT_TRUE(info.has_persistent);
127 EXPECT_TRUE(info.has_temporary);
128 EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent);
129 EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary);
130 MessageLoop::current()->Quit();
131 }
132
133 private:
134 BrowsingDataFileSystemHelper* file_system_helper_;
135 };
136
137
138 IN_PROC_BROWSER_TEST_F(BrowsingDataFileSystemHelperTest, FetchData) {
139 PopulateTestData();
140 scoped_refptr<BrowsingDataFileSystemHelper> file_system_helper(
141 BrowsingDataFileSystemHelper::Create(&testing_profile_));
142 StopTestOnCallback stop_test_on_callback(file_system_helper);
143 file_system_helper->StartFetching(
144 NewCallback(&stop_test_on_callback,
145 &StopTestOnCallback::CallbackFetchData));
146 // Blocks until StopTestOnCallback::CallbackFetchData is notified.
147 ui_test_utils::RunMessageLoop();
148 }
149
150 IN_PROC_BROWSER_TEST_F(BrowsingDataFileSystemHelperTest, DeleteData) {
151 PopulateTestData();
152 scoped_refptr<BrowsingDataFileSystemHelper> file_system_helper(
153 BrowsingDataFileSystemHelper::Create(&testing_profile_));
154 StopTestOnCallback stop_test_on_callback(file_system_helper);
155 file_system_helper->DeleteFileSystemOrigin(GURL(kTestOrigin1));
156 file_system_helper->DeleteFileSystemOrigin(GURL(kTestOrigin2));
157 file_system_helper->StartFetching(
158 NewCallback(&stop_test_on_callback,
159 &StopTestOnCallback::CallbackDeleteData));
160 // Blocks until StopTestOnCallback::CallbackDeleteData is notified.
161 ui_test_utils::RunMessageLoop();
162 }
163
164 IN_PROC_BROWSER_TEST_F(BrowsingDataFileSystemHelperTest, CannedAddFileSystem) {
165 const GURL origin1(kTestOrigin1);
166 const GURL origin2(kTestOrigin2);
167
168 scoped_refptr<CannedBrowsingDataFileSystemHelper> helper(
169 new CannedBrowsingDataFileSystemHelper(&testing_profile_));
170 helper->AddFileSystem(origin1, fileapi::kFileSystemTypePersistent, 200);
171 helper->AddFileSystem(origin2, fileapi::kFileSystemTypeTemporary, 100);
172
173 TestCompletionCallback callback;
174 helper->StartFetching(
175 NewCallback(&callback, &TestCompletionCallback::callback));
176
177 std::vector<BrowsingDataFileSystemHelper::FileSystemInfo> result =
178 callback.result();
179
180 EXPECT_EQ(2U, result.size());
181 EXPECT_EQ(origin1, result[0].origin);
182 EXPECT_TRUE(result[0].has_persistent);
183 EXPECT_FALSE(result[0].has_temporary);
184 EXPECT_EQ(200, result[0].usage_persistent);
185 EXPECT_EQ(0, result[0].usage_temporary);
186 EXPECT_EQ(origin2, result[1].origin);
187 EXPECT_FALSE(result[1].has_persistent);
188 EXPECT_TRUE(result[1].has_temporary);
189 EXPECT_EQ(0, result[1].usage_persistent);
190 EXPECT_EQ(100, result[1].usage_temporary);
191 }
192
193 IN_PROC_BROWSER_TEST_F(BrowsingDataFileSystemHelperTest, CannedUnique) {
194 const GURL origin3(kTestOrigin3);
195
196 scoped_refptr<CannedBrowsingDataFileSystemHelper> helper(
197 new CannedBrowsingDataFileSystemHelper(&testing_profile_));
198 helper->AddFileSystem(origin3, fileapi::kFileSystemTypePersistent, 200);
199 helper->AddFileSystem(origin3, fileapi::kFileSystemTypeTemporary, 100);
200
201 TestCompletionCallback callback;
202 helper->StartFetching(
203 NewCallback(&callback, &TestCompletionCallback::callback));
204
205 std::vector<BrowsingDataFileSystemHelper::FileSystemInfo> result =
206 callback.result();
207
208 EXPECT_EQ(1U, result.size());
209 EXPECT_EQ(origin3, result[0].origin);
210 EXPECT_TRUE(result[0].has_persistent);
211 EXPECT_TRUE(result[0].has_temporary);
212 EXPECT_EQ(200, result[0].usage_persistent);
213 EXPECT_EQ(100, result[0].usage_temporary);
214 }
215
216 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_file_system_helper.cc ('k') | chrome/browser/browsing_data_file_system_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698