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 = base::FilePath("/hello/world.txt"); |
kinaba
2014/04/30 07:55:03
FromUTF8Unsafe or FILE_PATH_LITERAL (ditto for oth
mtomasz
2014/04/30 09:18:24
Done.
| |
109 const fileapi::FileSystemURL url = | 111 const fileapi::FileSystemURL url = |
110 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); | 112 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); |
111 EXPECT_TRUE(url.is_valid()); | 113 EXPECT_TRUE(url.is_valid()); |
112 | 114 |
113 FileSystemURLParser parser(url); | 115 FileSystemURLParser parser(url); |
114 EXPECT_TRUE(parser.Parse()); | 116 EXPECT_TRUE(parser.Parse()); |
115 | 117 |
116 ProvidedFileSystemInterface* file_system = parser.file_system(); | 118 ProvidedFileSystemInterface* file_system = parser.file_system(); |
117 ASSERT_TRUE(file_system); | 119 ASSERT_TRUE(file_system); |
118 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); | 120 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); |
119 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 121 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
120 } | 122 } |
121 | 123 |
122 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { | 124 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { |
123 const int file_system_id = file_system_provider_service_->MountFileSystem( | 125 const int file_system_id = file_system_provider_service_->MountFileSystem( |
124 kExtensionId, kFileSystemName); | 126 kExtensionId, kFileSystemName); |
125 EXPECT_LT(0, file_system_id); | 127 EXPECT_LT(0, file_system_id); |
126 | 128 |
127 const base::FilePath kFilePath = base::FilePath(); | 129 const base::FilePath kFilePath = base::FilePath("/"); |
128 const fileapi::FileSystemURL url = | 130 const fileapi::FileSystemURL url = |
129 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); | 131 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); |
130 EXPECT_TRUE(url.is_valid()); | 132 EXPECT_TRUE(url.is_valid()); |
131 | 133 |
132 FileSystemURLParser parser(url); | 134 FileSystemURLParser parser(url); |
133 EXPECT_TRUE(parser.Parse()); | 135 EXPECT_TRUE(parser.Parse()); |
134 | 136 |
135 ProvidedFileSystemInterface* file_system = parser.file_system(); | 137 ProvidedFileSystemInterface* file_system = parser.file_system(); |
136 ASSERT_TRUE(file_system); | 138 ASSERT_TRUE(file_system); |
137 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); | 139 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); |
138 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 140 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
139 } | 141 } |
140 | 142 |
141 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { | 143 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { |
142 const int file_system_id = file_system_provider_service_->MountFileSystem( | 144 const int file_system_id = file_system_provider_service_->MountFileSystem( |
143 kExtensionId, kFileSystemName); | 145 kExtensionId, kFileSystemName); |
144 EXPECT_LT(0, file_system_id); | 146 EXPECT_LT(0, file_system_id); |
145 | 147 |
146 const base::FilePath kFilePath = base::FilePath("hello"); | 148 const base::FilePath kFilePath = base::FilePath("/hello"); |
147 const fileapi::FileSystemURL url = CreateFileSystemURL( | 149 const fileapi::FileSystemURL url = CreateFileSystemURL( |
148 profile_, kExtensionId, file_system_id + 1, kFilePath); | 150 profile_, kExtensionId, file_system_id + 1, kFilePath); |
149 // It is impossible to create a cracked URL for a mount point which doesn't | 151 // 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. | 152 // exist, therefore is will always be invalid, and empty. |
151 EXPECT_FALSE(url.is_valid()); | 153 EXPECT_FALSE(url.is_valid()); |
152 | 154 |
153 FileSystemURLParser parser(url); | 155 FileSystemURLParser parser(url); |
154 EXPECT_FALSE(parser.Parse()); | 156 EXPECT_FALSE(parser.Parse()); |
155 } | 157 } |
156 | 158 |
157 } // namespace util | 159 } // namespace util |
158 } // namespace file_system_provider | 160 } // namespace file_system_provider |
159 } // namespace chromeos | 161 } // namespace chromeos |
OLD | NEW |