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