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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/mount_path_util_unittest.cc

Issue 237583015: [fsp] Add FileSystemURLParser to the file system provider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplified. Created 6 years, 8 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 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"
9 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system .h"
8 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
12 #include "chrome/browser/chromeos/file_system_provider/service.h"
13 #include "chrome/browser/chromeos/file_system_provider/service_factory.h"
9 #include "chrome/browser/chromeos/login/fake_user_manager.h" 14 #include "chrome/browser/chromeos/login/fake_user_manager.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/test/base/testing_browser_process.h"
10 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/base/testing_profile_manager.h"
19 #include "components/keyed_service/core/keyed_service.h"
20 #include "content/public/browser/browser_context.h"
11 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "webkit/browser/fileapi/external_mount_points.h"
13 24
14 namespace chromeos { 25 namespace chromeos {
15 namespace file_system_provider { 26 namespace file_system_provider {
16 namespace util { 27 namespace util {
17 28
29 namespace {
30
31 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
32 const char kFileSystemName[] = "Camera Pictures";
33
34 // Creates a FileSystemURL for tests.
35 fileapi::FileSystemURL CreateFileSystemURL(Profile* profile,
36 const std::string& extension_id,
37 int file_system_id,
38 const base::FilePath& file_path) {
39 const std::string origin = std::string("chrome-extension://") + kExtensionId;
40 const base::FilePath mount_path =
41 util::GetMountPath(profile, extension_id, file_system_id);
42 const fileapi::ExternalMountPoints* const mount_points =
43 fileapi::ExternalMountPoints::GetSystemInstance();
44 DCHECK(mount_points);
45 return mount_points->CreateCrackedFileSystemURL(
46 GURL(origin),
47 fileapi::kFileSystemTypeExternal,
48 base::FilePath(mount_path.BaseName().Append(file_path)));
49 }
50
51 // Creates a Service instance. Used to be able to destroy the service in
52 // TearDown().
53 KeyedService* CreateService(content::BrowserContext* context) {
54 return new Service(Profile::FromBrowserContext(context));
55 }
56
57 } // namespace
58
18 class FileSystemProviderMountPathUtilTest : public testing::Test { 59 class FileSystemProviderMountPathUtilTest : public testing::Test {
19 protected: 60 protected:
20 FileSystemProviderMountPathUtilTest() {} 61 FileSystemProviderMountPathUtilTest() {}
21 virtual ~FileSystemProviderMountPathUtilTest() {} 62 virtual ~FileSystemProviderMountPathUtilTest() {}
22 63
23 virtual void SetUp() OVERRIDE { 64 virtual void SetUp() OVERRIDE {
65 profile_manager_.reset(
66 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
67 ASSERT_TRUE(profile_manager_->SetUp());
68 profile_ = profile_manager_->CreateTestingProfile("testing-profile");
24 user_manager_ = new FakeUserManager(); 69 user_manager_ = new FakeUserManager();
25 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_)); 70 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_));
26 profile_.reset(new TestingProfile);
27 user_manager_->AddUser(profile_->GetProfileName()); 71 user_manager_->AddUser(profile_->GetProfileName());
72 ServiceFactory::GetInstance()->SetTestingFactory(profile_, &CreateService);
73 file_system_provider_service_ = Service::Get(profile_);
74 file_system_provider_service_->SetFileSystemFactoryForTests(
75 base::Bind(&FakeProvidedFileSystem::Create));
76 }
77
78 virtual void TearDown() OVERRIDE {
79 // Setting the testing factory to NULL will destroy the created service
80 // associated with the testing profile.
81 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL);
28 } 82 }
29 83
30 content::TestBrowserThreadBundle thread_bundle_; 84 content::TestBrowserThreadBundle thread_bundle_;
31 scoped_ptr<TestingProfile> profile_; 85 scoped_ptr<TestingProfileManager> profile_manager_;
86 TestingProfile* profile_; // Owned by TestingProfileManager.
32 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; 87 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
33 FakeUserManager* user_manager_; 88 FakeUserManager* user_manager_;
89 Service* file_system_provider_service_; // Owned by its factory.
34 }; 90 };
35 91
36 TEST_F(FileSystemProviderMountPathUtilTest, GetMountPointPath) { 92 TEST_F(FileSystemProviderMountPathUtilTest, GetMountPath) {
37 const std::string kExtensionId = "mbflcebpggnecokmikipoihdbecnjfoj"; 93 const std::string kExtensionId = "mbflcebpggnecokmikipoihdbecnjfoj";
38 const int kFileSystemId = 1; 94 const int kFileSystemId = 1;
39 95
40 base::FilePath result = 96 base::FilePath result = GetMountPath(profile_, kExtensionId, kFileSystemId);
41 GetMountPointPath(profile_.get(), kExtensionId, kFileSystemId); 97 EXPECT_EQ("/provided/mbflcebpggnecokmikipoihdbecnjfoj-1-testing-profile-hash",
42 EXPECT_EQ("/provided/mbflcebpggnecokmikipoihdbecnjfoj-1-testing_profile-hash",
43 result.AsUTF8Unsafe()); 98 result.AsUTF8Unsafe());
44 } 99 }
45 100
101 TEST_F(FileSystemProviderMountPathUtilTest, Parser) {
102 const int file_system_id = file_system_provider_service_->MountFileSystem(
103 kExtensionId, kFileSystemName);
104 EXPECT_LT(0, file_system_id);
105
106 const base::FilePath kFilePath = base::FilePath("hello/world.txt");
107 const fileapi::FileSystemURL url =
108 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath);
109 EXPECT_TRUE(url.is_valid());
110
111 FileSystemURLParser parser(url);
112 EXPECT_TRUE(parser.Parse());
113
114 ProvidedFileSystemInterface* file_system = parser.file_system();
115 ASSERT_TRUE(file_system);
116 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id());
117 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe());
118 }
119
120 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) {
121 const int file_system_id = file_system_provider_service_->MountFileSystem(
122 kExtensionId, kFileSystemName);
123 EXPECT_LT(0, file_system_id);
124
125 const base::FilePath kFilePath = base::FilePath();
126 const fileapi::FileSystemURL url =
127 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath);
128 EXPECT_TRUE(url.is_valid());
129
130 FileSystemURLParser parser(url);
131 EXPECT_TRUE(parser.Parse());
132
133 ProvidedFileSystemInterface* file_system = parser.file_system();
134 ASSERT_TRUE(file_system);
135 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id());
136 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe());
137 }
138
139 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) {
140 const int file_system_id = file_system_provider_service_->MountFileSystem(
141 kExtensionId, kFileSystemName);
142 EXPECT_LT(0, file_system_id);
143
144 const base::FilePath kFilePath = base::FilePath("hello");
145 const fileapi::FileSystemURL url = CreateFileSystemURL(
146 profile_, kExtensionId, file_system_id + 1, kFilePath);
147 // It is impossible to create a cracked URL for a mount point which doesn't
148 // exist, therefore is will always be invalid, and empty.
149 EXPECT_FALSE(url.is_valid());
150
151 FileSystemURLParser parser(url);
152 EXPECT_FALSE(parser.Parse());
153 }
154
46 } // namespace util 155 } // namespace util
47 } // namespace file_system_provider 156 } // namespace file_system_provider
48 } // namespace chromeos 157 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698