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

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

Issue 150163003: drive: Switch Drive mount path to per-profile one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix. Created 6 years, 10 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"
13 #include "chrome/test/base/testing_browser_process.h"
12 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "chrome/test/base/testing_profile_manager.h"
16 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "content/public/test/test_file_system_options.h" 17 #include "content/public/test/test_file_system_options.h"
14 #include "google_apis/drive/test_util.h" 18 #include "google_apis/drive/test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/browser/fileapi/external_mount_points.h" 20 #include "webkit/browser/fileapi/external_mount_points.h"
17 #include "webkit/browser/fileapi/file_system_backend.h" 21 #include "webkit/browser/fileapi/file_system_backend.h"
18 #include "webkit/browser/fileapi/file_system_context.h" 22 #include "webkit/browser/fileapi/file_system_context.h"
19 #include "webkit/browser/fileapi/file_system_url.h" 23 #include "webkit/browser/fileapi/file_system_url.h"
20 #include "webkit/browser/fileapi/isolated_context.h" 24 #include "webkit/browser/fileapi/isolated_context.h"
21 25
22 namespace drive { 26 namespace drive {
23 namespace util { 27 namespace util {
24 28
29 namespace {
30
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
33 // touched from UI and hence has CHECK/DCHECKs for it.
34 class ProfileRelatedFileSystemUtilTest : public testing::Test {
35 protected:
36 ProfileRelatedFileSystemUtilTest()
37 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {
38 }
39
40 virtual void SetUp() OVERRIDE {
41 ASSERT_TRUE(testing_profile_manager_.SetUp());
42 }
43
44 Profile* CreateProfileWithName(const std::string& name) {
45 return testing_profile_manager_.CreateTestingProfile(
46 chrome::kProfileDirPrefix + name);
47 }
48
49 private:
50 content::TestBrowserThreadBundle thread_bundle_;
51 TestingProfileManager testing_profile_manager_;
52 };
53
54 } // namespace
55
25 TEST(FileSystemUtilTest, FilePathToDriveURL) { 56 TEST(FileSystemUtilTest, FilePathToDriveURL) {
26 base::FilePath path; 57 base::FilePath path;
27 58
28 // Path with alphabets and numbers. 59 // Path with alphabets and numbers.
29 path = GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); 60 path = GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt");
30 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); 61 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path)));
31 62
32 // Path with symbols. 63 // Path with symbols.
33 path = GetDriveMyDriveRootPath().AppendASCII( 64 path = GetDriveMyDriveRootPath().AppendASCII(
34 " !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~"); 65 " !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~");
35 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); 66 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path)));
36 67
37 // Path with '%'. 68 // Path with '%'.
38 path = GetDriveMyDriveRootPath().AppendASCII("%19%20%21.txt"); 69 path = GetDriveMyDriveRootPath().AppendASCII("%19%20%21.txt");
39 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); 70 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path)));
40 71
41 // Path with multi byte characters. 72 // Path with multi byte characters.
42 base::string16 utf16_string; 73 base::string16 utf16_string;
43 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO 74 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO
44 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE 75 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE
45 path = GetDriveMyDriveRootPath().Append( 76 path = GetDriveMyDriveRootPath().Append(
46 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt")); 77 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt"));
47 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); 78 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path)));
48 } 79 }
49 80
81 TEST_F(ProfileRelatedFileSystemUtilTest, GetDriveMountPointPath) {
82 Profile* profile = CreateProfileWithName("hash1");
83 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive-hash1"),
84 GetDriveMountPointPath(profile));
85 }
86
87 TEST_F(ProfileRelatedFileSystemUtilTest, ExtractProfileFromPath) {
88 Profile* profile1 = CreateProfileWithName("hash1");
89 Profile* profile2 = CreateProfileWithName("hash2");
90 EXPECT_EQ(profile1, ExtractProfileFromPath(
91 base::FilePath::FromUTF8Unsafe("/special/drive-hash1")));
92 EXPECT_EQ(profile2, ExtractProfileFromPath(
93 base::FilePath::FromUTF8Unsafe("/special/drive-hash2/root/xxx")));
94 EXPECT_EQ(NULL, ExtractProfileFromPath(
95 base::FilePath::FromUTF8Unsafe("/special/non-drive-path")));
96 }
97
50 TEST(FileSystemUtilTest, IsUnderDriveMountPoint) { 98 TEST(FileSystemUtilTest, IsUnderDriveMountPoint) {
51 EXPECT_FALSE(IsUnderDriveMountPoint( 99 EXPECT_FALSE(IsUnderDriveMountPoint(
52 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); 100 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt")));
53 EXPECT_FALSE(IsUnderDriveMountPoint( 101 EXPECT_FALSE(IsUnderDriveMountPoint(
54 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); 102 base::FilePath::FromUTF8Unsafe("/special/foo.txt")));
55 EXPECT_FALSE(IsUnderDriveMountPoint( 103 EXPECT_FALSE(IsUnderDriveMountPoint(
56 base::FilePath::FromUTF8Unsafe("special/drive/foo.txt"))); 104 base::FilePath::FromUTF8Unsafe("special/drive/foo.txt")));
57 105
58 EXPECT_TRUE(IsUnderDriveMountPoint( 106 EXPECT_TRUE(IsUnderDriveMountPoint(
59 base::FilePath::FromUTF8Unsafe("/special/drive"))); 107 base::FilePath::FromUTF8Unsafe("/special/drive")));
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 file = temp_dir.path().AppendASCII("test.txt"); 293 file = temp_dir.path().AppendASCII("test.txt");
246 std::string data = "Hello world!"; 294 std::string data = "Hello world!";
247 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data)); 295 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data));
248 EXPECT_FALSE(HasGDocFileExtension(file)); 296 EXPECT_FALSE(HasGDocFileExtension(file));
249 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty()); 297 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty());
250 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty()); 298 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty());
251 } 299 }
252 300
253 } // namespace util 301 } // namespace util
254 } // namespace drive 302 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_util.cc ('k') | chrome/browser/chromeos/file_manager/path_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698