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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_util_unittest.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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
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 "chrome/browser/chromeos/drive/file_system_util.h" 5 #include "chrome/browser/chromeos/drive/file_system_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/common/chrome_constants.h" 12 #include "chrome/common/chrome_constants.h"
13 #include "chrome/test/base/testing_browser_process.h" 13 #include "chrome/test/base/testing_browser_process.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "chrome/test/base/testing_profile_manager.h" 15 #include "chrome/test/base/testing_profile_manager.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "content/public/test/test_file_system_options.h" 17 #include "content/public/test/test_file_system_options.h"
18 #include "google_apis/drive/test_util.h" 18 #include "google_apis/drive/test_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "webkit/browser/fileapi/external_mount_points.h" 20 #include "storage/browser/fileapi/external_mount_points.h"
21 #include "webkit/browser/fileapi/file_system_backend.h" 21 #include "storage/browser/fileapi/file_system_backend.h"
22 #include "webkit/browser/fileapi/file_system_context.h" 22 #include "storage/browser/fileapi/file_system_context.h"
23 #include "webkit/browser/fileapi/file_system_url.h" 23 #include "storage/browser/fileapi/file_system_url.h"
24 #include "webkit/browser/fileapi/isolated_context.h" 24 #include "storage/browser/fileapi/isolated_context.h"
25 25
26 namespace drive { 26 namespace drive {
27 namespace util { 27 namespace util {
28 28
29 namespace { 29 namespace {
30 30
31 // Sets up ProfileManager for testing and marks the current thread as UI by 31 // Sets up ProfileManager for testing and marks the current thread as UI by
32 // TestBrowserThreadBundle. We need the thread since Profile objects must be 32 // TestBrowserThreadBundle. We need the thread since Profile objects must be
33 // touched from UI and hence has CHECK/DCHECKs for it. 33 // touched from UI and hence has CHECK/DCHECKs for it.
34 class ProfileRelatedFileSystemUtilTest : public testing::Test { 34 class ProfileRelatedFileSystemUtilTest : public testing::Test {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 137
138 TEST(FileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) { 138 TEST(FileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) {
139 TestingProfile profile; 139 TestingProfile profile;
140 140
141 // Set up file system context for testing. 141 // Set up file system context for testing.
142 base::ScopedTempDir temp_dir_; 142 base::ScopedTempDir temp_dir_;
143 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 143 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
144 144
145 base::MessageLoop message_loop; 145 base::MessageLoop message_loop;
146 scoped_refptr<fileapi::ExternalMountPoints> mount_points = 146 scoped_refptr<storage::ExternalMountPoints> mount_points =
147 fileapi::ExternalMountPoints::CreateRefCounted(); 147 storage::ExternalMountPoints::CreateRefCounted();
148 scoped_refptr<fileapi::FileSystemContext> context( 148 scoped_refptr<storage::FileSystemContext> context(
149 new fileapi::FileSystemContext( 149 new storage::FileSystemContext(
150 base::MessageLoopProxy::current().get(), 150 base::MessageLoopProxy::current().get(),
151 base::MessageLoopProxy::current().get(), 151 base::MessageLoopProxy::current().get(),
152 mount_points.get(), 152 mount_points.get(),
153 NULL, // special_storage_policy 153 NULL, // special_storage_policy
154 NULL, // quota_manager_proxy, 154 NULL, // quota_manager_proxy,
155 ScopedVector<fileapi::FileSystemBackend>(), 155 ScopedVector<storage::FileSystemBackend>(),
156 std::vector<fileapi::URLRequestAutoMountHandler>(), 156 std::vector<storage::URLRequestAutoMountHandler>(),
157 temp_dir_.path(), // partition_path 157 temp_dir_.path(), // partition_path
158 content::CreateAllowFileAccessOptions())); 158 content::CreateAllowFileAccessOptions()));
159 159
160 // Type:"external" + virtual_path:"drive/foo/bar" resolves to "drive/foo/bar". 160 // Type:"external" + virtual_path:"drive/foo/bar" resolves to "drive/foo/bar".
161 const std::string& drive_mount_name = 161 const std::string& drive_mount_name =
162 GetDriveMountPointPath(&profile).BaseName().AsUTF8Unsafe(); 162 GetDriveMountPointPath(&profile).BaseName().AsUTF8Unsafe();
163 mount_points->RegisterFileSystem( 163 mount_points->RegisterFileSystem(drive_mount_name,
164 drive_mount_name, 164 storage::kFileSystemTypeDrive,
165 fileapi::kFileSystemTypeDrive, 165 storage::FileSystemMountOption(),
166 fileapi::FileSystemMountOption(), 166 GetDriveMountPointPath(&profile));
167 GetDriveMountPointPath(&profile));
168 EXPECT_EQ( 167 EXPECT_EQ(
169 base::FilePath::FromUTF8Unsafe("drive/foo/bar"), 168 base::FilePath::FromUTF8Unsafe("drive/foo/bar"),
170 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( 169 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL(
171 "filesystem:chrome-extension://dummy-id/external/" + 170 "filesystem:chrome-extension://dummy-id/external/" +
172 drive_mount_name + "/foo/bar")))); 171 drive_mount_name + "/foo/bar"))));
173 172
174 // Virtual mount name should not affect the extracted path. 173 // Virtual mount name should not affect the extracted path.
175 mount_points->RevokeFileSystem(drive_mount_name); 174 mount_points->RevokeFileSystem(drive_mount_name);
176 mount_points->RegisterFileSystem( 175 mount_points->RegisterFileSystem("drive2",
177 "drive2", 176 storage::kFileSystemTypeDrive,
178 fileapi::kFileSystemTypeDrive, 177 storage::FileSystemMountOption(),
179 fileapi::FileSystemMountOption(), 178 GetDriveMountPointPath(&profile));
180 GetDriveMountPointPath(&profile));
181 EXPECT_EQ( 179 EXPECT_EQ(
182 base::FilePath::FromUTF8Unsafe("drive/foo/bar"), 180 base::FilePath::FromUTF8Unsafe("drive/foo/bar"),
183 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( 181 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL(
184 "filesystem:chrome-extension://dummy-id/external/drive2/foo/bar")))); 182 "filesystem:chrome-extension://dummy-id/external/drive2/foo/bar"))));
185 183
186 // Type:"external" + virtual_path:"Downloads/foo" is not a Drive path. 184 // Type:"external" + virtual_path:"Downloads/foo" is not a Drive path.
187 mount_points->RegisterFileSystem( 185 mount_points->RegisterFileSystem("Downloads",
188 "Downloads", 186 storage::kFileSystemTypeNativeLocal,
189 fileapi::kFileSystemTypeNativeLocal, 187 storage::FileSystemMountOption(),
190 fileapi::FileSystemMountOption(), 188 temp_dir_.path());
191 temp_dir_.path());
192 EXPECT_EQ( 189 EXPECT_EQ(
193 base::FilePath(), 190 base::FilePath(),
194 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( 191 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL(
195 "filesystem:chrome-extension://dummy-id/external/Downloads/foo")))); 192 "filesystem:chrome-extension://dummy-id/external/Downloads/foo"))));
196 193
197 // Type:"isolated" + virtual_path:"isolated_id/name" mapped on a Drive path. 194 // Type:"isolated" + virtual_path:"isolated_id/name" mapped on a Drive path.
198 std::string isolated_name; 195 std::string isolated_name;
199 std::string isolated_id = 196 std::string isolated_id =
200 fileapi::IsolatedContext::GetInstance()->RegisterFileSystemForPath( 197 storage::IsolatedContext::GetInstance()->RegisterFileSystemForPath(
201 fileapi::kFileSystemTypeNativeForPlatformApp, 198 storage::kFileSystemTypeNativeForPlatformApp,
202 std::string(), 199 std::string(),
203 GetDriveMountPointPath(&profile).AppendASCII("bar/buz"), 200 GetDriveMountPointPath(&profile).AppendASCII("bar/buz"),
204 &isolated_name); 201 &isolated_name);
205 EXPECT_EQ( 202 EXPECT_EQ(
206 base::FilePath::FromUTF8Unsafe("drive/bar/buz"), 203 base::FilePath::FromUTF8Unsafe("drive/bar/buz"),
207 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( 204 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL(
208 "filesystem:chrome-extension://dummy-id/isolated/" + 205 "filesystem:chrome-extension://dummy-id/isolated/" +
209 isolated_id + "/" + isolated_name)))); 206 isolated_id + "/" + isolated_name))));
210 } 207 }
211 208
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // Non GDoc file. 279 // Non GDoc file.
283 file = temp_dir.path().AppendASCII("test.txt"); 280 file = temp_dir.path().AppendASCII("test.txt");
284 std::string data = "Hello world!"; 281 std::string data = "Hello world!";
285 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data)); 282 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data));
286 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty()); 283 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty());
287 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty()); 284 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty());
288 } 285 }
289 286
290 } // namespace util 287 } // namespace util
291 } // namespace drive 288 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_util.cc ('k') | chrome/browser/chromeos/drive/file_task_executor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698