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

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

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

Powered by Google App Engine
This is Rietveld 408576698