Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_filesystem_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/sandbox_mount_point_provider.h" | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 typedef BrowsingDataHelperCallback<BrowsingDataFilesystemHelper::FilesystemInfo> | |
| 27 TestCompletionCallback; | |
| 28 | |
| 29 const char kTestOrigin1[] = "http://host1:1/"; | |
| 30 const char kTestOrigin2[] = "http://host2:1/"; | |
| 31 const char kTestOrigin3[] = "http://host3:1/"; | |
| 32 | |
| 33 const char kTestOriginExtension[] = | |
| 34 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj:1/"; | |
| 35 | |
| 36 class BrowsingDataFilesystemHelperTest : public InProcessBrowserTest { | |
| 37 public: | |
| 38 virtual void PopulateTestData() { | |
| 39 const GURL origin1(kTestOrigin1); | |
| 40 const GURL origin2(kTestOrigin2); | |
| 41 const GURL origin3(kTestOrigin3); | |
| 42 | |
| 43 sandbox_ = testing_profile_.GetFileSystemContext()-> | |
| 44 path_manager()->sandbox_provider(); | |
| 45 | |
| 46 CreateDirectoryForOriginAndType(origin1, fileapi::kFileSystemTypeTemporary); | |
| 47 CreateDirectoryForOriginAndType(origin2, | |
| 48 fileapi::kFileSystemTypePersistent); | |
| 49 CreateDirectoryForOriginAndType(origin3, fileapi::kFileSystemTypeTemporary); | |
| 50 CreateDirectoryForOriginAndType(origin3, | |
| 51 fileapi::kFileSystemTypePersistent); | |
| 52 } | |
| 53 | |
| 54 protected: | |
| 55 void CreateDirectoryForOriginAndType(const GURL& origin, | |
| 56 fileapi::FileSystemType type) { | |
| 57 FilePath target = sandbox_->GetBaseDirectoryForOriginAndType(origin, | |
| 58 type, true); | |
| 59 ASSERT_TRUE(file_util::CreateDirectory(target)); | |
| 60 } | |
|
Paweł Hajdan Jr.
2011/05/24 17:04:19
nit: Add an empty line below.
Mike West
2011/05/25 09:22:36
Done.
| |
| 61 TestingProfile testing_profile_; | |
| 62 fileapi::SandboxMountPointProvider* sandbox_; | |
| 63 }; | |
| 64 | |
| 65 // Called back by BrowsingDataFilesystemHelper on the UI thread once the | |
| 66 // database information has been retrieved. | |
| 67 class StopTestOnCallback { | |
| 68 public: | |
| 69 explicit StopTestOnCallback( | |
| 70 BrowsingDataFilesystemHelper* filesystem_helper) | |
| 71 : filesystem_helper_(filesystem_helper) { | |
| 72 DCHECK(filesystem_helper_); | |
| 73 } | |
| 74 | |
| 75 void CallbackFetchData( | |
| 76 const std::vector<BrowsingDataFilesystemHelper::FilesystemInfo>& | |
| 77 filesystem_info_list) { | |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 79 ASSERT_EQ(3UL, filesystem_info_list.size()); | |
| 80 | |
| 81 // Order is arbitrary, verify all three origins. | |
| 82 bool test_hosts_found[3] = {false, false, false}; | |
| 83 for (size_t i = 0; i < filesystem_info_list.size(); i++) { | |
| 84 BrowsingDataFilesystemHelper::FilesystemInfo info = | |
| 85 filesystem_info_list.at(i); | |
| 86 if (info.origin == GURL(kTestOrigin1)) { | |
| 87 test_hosts_found[0] = true; | |
| 88 ASSERT_TRUE(info.has_temporary); | |
| 89 ASSERT_FALSE(info.has_persistent); | |
| 90 } else if (info.origin == GURL(kTestOrigin2)) { | |
| 91 test_hosts_found[1] = true; | |
| 92 ASSERT_FALSE(info.has_temporary); | |
| 93 ASSERT_TRUE(info.has_persistent); | |
| 94 } else if (info.origin == GURL(kTestOrigin3)) { | |
| 95 test_hosts_found[2] = true; | |
| 96 ASSERT_TRUE(info.has_temporary); | |
| 97 ASSERT_TRUE(info.has_persistent); | |
| 98 } else { | |
| 99 ADD_FAILURE() << info.origin.spec() << " isn't an origin we added."; | |
| 100 } | |
| 101 } | |
| 102 for (size_t i = 0; i < arraysize(test_hosts_found); i++) { | |
| 103 ASSERT_TRUE(test_hosts_found[i]); | |
| 104 } | |
| 105 MessageLoop::current()->Quit(); | |
| 106 } | |
| 107 | |
| 108 void CallbackDeleteData( | |
| 109 const std::vector<BrowsingDataFilesystemHelper::FilesystemInfo>& | |
| 110 filesystem_info_list) { | |
| 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 112 ASSERT_EQ(1UL, filesystem_info_list.size()); | |
| 113 BrowsingDataFilesystemHelper::FilesystemInfo info = | |
| 114 filesystem_info_list.at(0); | |
| 115 ASSERT_EQ(info.origin, GURL(kTestOrigin3)); | |
| 116 ASSERT_TRUE(info.has_temporary); | |
| 117 ASSERT_TRUE(info.has_persistent); | |
| 118 MessageLoop::current()->Quit(); | |
| 119 } | |
| 120 | |
| 121 private: | |
| 122 BrowsingDataFilesystemHelper* filesystem_helper_; | |
| 123 }; | |
| 124 | |
| 125 | |
| 126 IN_PROC_BROWSER_TEST_F(BrowsingDataFilesystemHelperTest, FetchData) { | |
| 127 PopulateTestData(); | |
| 128 scoped_refptr<BrowsingDataFilesystemHelper> filesystem_helper( | |
| 129 BrowsingDataFilesystemHelper::Create(&testing_profile_)); | |
| 130 StopTestOnCallback stop_test_on_callback(filesystem_helper); | |
| 131 filesystem_helper->StartFetching( | |
| 132 NewCallback(&stop_test_on_callback, | |
| 133 &StopTestOnCallback::CallbackFetchData)); | |
| 134 // Blocks until StopTestOnCallback::CallbackFetchData is notified. | |
| 135 ui_test_utils::RunMessageLoop(); | |
| 136 } | |
| 137 | |
| 138 IN_PROC_BROWSER_TEST_F(BrowsingDataFilesystemHelperTest, DeleteData) { | |
| 139 PopulateTestData(); | |
| 140 scoped_refptr<BrowsingDataFilesystemHelper> filesystem_helper( | |
| 141 BrowsingDataFilesystemHelper::Create(&testing_profile_)); | |
| 142 StopTestOnCallback stop_test_on_callback(filesystem_helper); | |
| 143 filesystem_helper->DeleteFilesystemOrigin(GURL(kTestOrigin1)); | |
| 144 filesystem_helper->DeleteFilesystemOrigin(GURL(kTestOrigin2)); | |
| 145 filesystem_helper->StartFetching( | |
| 146 NewCallback(&stop_test_on_callback, | |
| 147 &StopTestOnCallback::CallbackDeleteData)); | |
| 148 // Blocks until StopTestOnCallback::CallbackDeleteData is notified. | |
| 149 ui_test_utils::RunMessageLoop(); | |
| 150 } | |
| 151 | |
| 152 IN_PROC_BROWSER_TEST_F(BrowsingDataFilesystemHelperTest, CannedAddFilesystem) { | |
| 153 const GURL origin1(kTestOrigin1); | |
| 154 const GURL origin2(kTestOrigin2); | |
| 155 | |
| 156 scoped_refptr<CannedBrowsingDataFilesystemHelper> helper( | |
| 157 new CannedBrowsingDataFilesystemHelper(&testing_profile_)); | |
| 158 helper->AddFilesystem(origin1, fileapi::kFileSystemTypeTemporary); | |
| 159 helper->AddFilesystem(origin2, fileapi::kFileSystemTypePersistent); | |
| 160 | |
| 161 TestCompletionCallback callback; | |
| 162 helper->StartFetching( | |
| 163 NewCallback(&callback, &TestCompletionCallback::callback)); | |
| 164 | |
| 165 std::vector<BrowsingDataFilesystemHelper::FilesystemInfo> result = | |
| 166 callback.result(); | |
| 167 | |
| 168 ASSERT_EQ(2U, result.size()); | |
| 169 ASSERT_EQ(origin1, result[0].origin); | |
| 170 ASSERT_TRUE(result[0].has_temporary); | |
| 171 ASSERT_FALSE(result[0].has_persistent); | |
| 172 ASSERT_EQ(origin2, result[1].origin); | |
| 173 ASSERT_FALSE(result[1].has_temporary); | |
| 174 ASSERT_TRUE(result[1].has_persistent); | |
| 175 } | |
| 176 | |
| 177 IN_PROC_BROWSER_TEST_F(BrowsingDataFilesystemHelperTest, CannedUnique) { | |
| 178 const GURL origin3(kTestOrigin3); | |
| 179 | |
| 180 scoped_refptr<CannedBrowsingDataFilesystemHelper> helper( | |
| 181 new CannedBrowsingDataFilesystemHelper(&testing_profile_)); | |
| 182 helper->AddFilesystem(origin3, fileapi::kFileSystemTypePersistent); | |
| 183 helper->AddFilesystem(origin3, fileapi::kFileSystemTypeTemporary); | |
| 184 | |
| 185 TestCompletionCallback callback; | |
| 186 helper->StartFetching( | |
| 187 NewCallback(&callback, &TestCompletionCallback::callback)); | |
| 188 | |
| 189 std::vector<BrowsingDataFilesystemHelper::FilesystemInfo> result = | |
| 190 callback.result(); | |
| 191 | |
| 192 ASSERT_EQ(1U, result.size()); | |
| 193 ASSERT_EQ(origin3, result[0].origin); | |
| 194 ASSERT_TRUE(result[0].has_temporary); | |
| 195 ASSERT_TRUE(result[0].has_persistent); | |
| 196 } | |
| 197 | |
| 198 } // namespace | |
| OLD | NEW |