OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" | 9 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" |
10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 fileapi::FileSystemURL CreateFileSystemURL(Profile* profile, | 36 fileapi::FileSystemURL CreateFileSystemURL(Profile* profile, |
37 const std::string& extension_id, | 37 const std::string& extension_id, |
38 int file_system_id, | 38 int file_system_id, |
39 const base::FilePath& file_path) { | 39 const base::FilePath& file_path) { |
40 const std::string origin = std::string("chrome-extension://") + kExtensionId; | 40 const std::string origin = std::string("chrome-extension://") + kExtensionId; |
41 const base::FilePath mount_path = | 41 const base::FilePath mount_path = |
42 util::GetMountPath(profile, extension_id, file_system_id); | 42 util::GetMountPath(profile, extension_id, file_system_id); |
43 const fileapi::ExternalMountPoints* const mount_points = | 43 const fileapi::ExternalMountPoints* const mount_points = |
44 fileapi::ExternalMountPoints::GetSystemInstance(); | 44 fileapi::ExternalMountPoints::GetSystemInstance(); |
45 DCHECK(mount_points); | 45 DCHECK(mount_points); |
| 46 DCHECK(file_path.IsAbsolute()); |
| 47 base::FilePath relative_path(file_path.value().substr(1)); |
46 return mount_points->CreateCrackedFileSystemURL( | 48 return mount_points->CreateCrackedFileSystemURL( |
47 GURL(origin), | 49 GURL(origin), |
48 fileapi::kFileSystemTypeExternal, | 50 fileapi::kFileSystemTypeExternal, |
49 base::FilePath(mount_path.BaseName().Append(file_path))); | 51 base::FilePath(mount_path.BaseName().Append(relative_path))); |
50 } | 52 } |
51 | 53 |
52 // Creates a Service instance. Used to be able to destroy the service in | 54 // Creates a Service instance. Used to be able to destroy the service in |
53 // TearDown(). | 55 // TearDown(). |
54 KeyedService* CreateService(content::BrowserContext* context) { | 56 KeyedService* CreateService(content::BrowserContext* context) { |
55 return new Service(Profile::FromBrowserContext(context), | 57 return new Service(Profile::FromBrowserContext(context), |
56 extensions::ExtensionRegistry::Get(context)); | 58 extensions::ExtensionRegistry::Get(context)); |
57 } | 59 } |
58 | 60 |
59 } // namespace | 61 } // namespace |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 base::FilePath result = GetMountPath(profile_, kExtensionId, kFileSystemId); | 100 base::FilePath result = GetMountPath(profile_, kExtensionId, kFileSystemId); |
99 EXPECT_EQ("/provided/mbflcebpggnecokmikipoihdbecnjfoj-1-testing-profile-hash", | 101 EXPECT_EQ("/provided/mbflcebpggnecokmikipoihdbecnjfoj-1-testing-profile-hash", |
100 result.AsUTF8Unsafe()); | 102 result.AsUTF8Unsafe()); |
101 } | 103 } |
102 | 104 |
103 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { | 105 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { |
104 const int file_system_id = file_system_provider_service_->MountFileSystem( | 106 const int file_system_id = file_system_provider_service_->MountFileSystem( |
105 kExtensionId, kFileSystemName); | 107 kExtensionId, kFileSystemName); |
106 EXPECT_LT(0, file_system_id); | 108 EXPECT_LT(0, file_system_id); |
107 | 109 |
108 const base::FilePath kFilePath = base::FilePath("hello/world.txt"); | 110 const base::FilePath kFilePath = |
| 111 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
109 const fileapi::FileSystemURL url = | 112 const fileapi::FileSystemURL url = |
110 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); | 113 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); |
111 EXPECT_TRUE(url.is_valid()); | 114 EXPECT_TRUE(url.is_valid()); |
112 | 115 |
113 FileSystemURLParser parser(url); | 116 FileSystemURLParser parser(url); |
114 EXPECT_TRUE(parser.Parse()); | 117 EXPECT_TRUE(parser.Parse()); |
115 | 118 |
116 ProvidedFileSystemInterface* file_system = parser.file_system(); | 119 ProvidedFileSystemInterface* file_system = parser.file_system(); |
117 ASSERT_TRUE(file_system); | 120 ASSERT_TRUE(file_system); |
118 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); | 121 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); |
119 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 122 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
120 } | 123 } |
121 | 124 |
122 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { | 125 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { |
123 const int file_system_id = file_system_provider_service_->MountFileSystem( | 126 const int file_system_id = file_system_provider_service_->MountFileSystem( |
124 kExtensionId, kFileSystemName); | 127 kExtensionId, kFileSystemName); |
125 EXPECT_LT(0, file_system_id); | 128 EXPECT_LT(0, file_system_id); |
126 | 129 |
127 const base::FilePath kFilePath = base::FilePath(); | 130 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
128 const fileapi::FileSystemURL url = | 131 const fileapi::FileSystemURL url = |
129 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); | 132 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); |
130 EXPECT_TRUE(url.is_valid()); | 133 EXPECT_TRUE(url.is_valid()); |
131 | 134 |
132 FileSystemURLParser parser(url); | 135 FileSystemURLParser parser(url); |
133 EXPECT_TRUE(parser.Parse()); | 136 EXPECT_TRUE(parser.Parse()); |
134 | 137 |
135 ProvidedFileSystemInterface* file_system = parser.file_system(); | 138 ProvidedFileSystemInterface* file_system = parser.file_system(); |
136 ASSERT_TRUE(file_system); | 139 ASSERT_TRUE(file_system); |
137 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); | 140 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); |
138 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 141 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
139 } | 142 } |
140 | 143 |
141 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { | 144 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { |
142 const int file_system_id = file_system_provider_service_->MountFileSystem( | 145 const int file_system_id = file_system_provider_service_->MountFileSystem( |
143 kExtensionId, kFileSystemName); | 146 kExtensionId, kFileSystemName); |
144 EXPECT_LT(0, file_system_id); | 147 EXPECT_LT(0, file_system_id); |
145 | 148 |
146 const base::FilePath kFilePath = base::FilePath("hello"); | 149 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); |
147 const fileapi::FileSystemURL url = CreateFileSystemURL( | 150 const fileapi::FileSystemURL url = CreateFileSystemURL( |
148 profile_, kExtensionId, file_system_id + 1, kFilePath); | 151 profile_, kExtensionId, file_system_id + 1, kFilePath); |
149 // It is impossible to create a cracked URL for a mount point which doesn't | 152 // It is impossible to create a cracked URL for a mount point which doesn't |
150 // exist, therefore is will always be invalid, and empty. | 153 // exist, therefore is will always be invalid, and empty. |
151 EXPECT_FALSE(url.is_valid()); | 154 EXPECT_FALSE(url.is_valid()); |
152 | 155 |
153 FileSystemURLParser parser(url); | 156 FileSystemURLParser parser(url); |
154 EXPECT_FALSE(parser.Parse()); | 157 EXPECT_FALSE(parser.Parse()); |
155 } | 158 } |
156 | 159 |
157 } // namespace util | 160 } // namespace util |
158 } // namespace file_system_provider | 161 } // namespace file_system_provider |
159 } // namespace chromeos | 162 } // namespace chromeos |
OLD | NEW |