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

Side by Side Diff: chrome/browser/chromeos/fileapi/external_file_url_util_unittest.cc

Issue 589473002: Files.app: Enable externalfile: protocol for MTP volumes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « chrome/browser/chromeos/fileapi/external_file_url_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/chromeos/fileapi/external_file_url_util.h" 5 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chromeos/drive/file_system_util.h" 8 #include "chrome/browser/chromeos/drive/file_system_util.h"
9 #include "chrome/test/base/testing_browser_process.h" 9 #include "chrome/test/base/testing_browser_process.h"
10 #include "chrome/test/base/testing_profile_manager.h" 10 #include "chrome/test/base/testing_profile_manager.h"
(...skipping 14 matching lines...) Expand all
25 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {} 25 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {}
26 26
27 virtual void SetUp() OVERRIDE { 27 virtual void SetUp() OVERRIDE {
28 ASSERT_TRUE(testing_profile_manager_.SetUp()); 28 ASSERT_TRUE(testing_profile_manager_.SetUp());
29 } 29 }
30 30
31 TestingProfileManager& testing_profile_manager() { 31 TestingProfileManager& testing_profile_manager() {
32 return testing_profile_manager_; 32 return testing_profile_manager_;
33 } 33 }
34 34
35 storage::FileSystemURL CreateTestURL(const base::FilePath& path) {
36 return storage::FileSystemURL::CreateForTest(
37 GURL("chrome-extension://xxx"),
38 storage::kFileSystemTypeDrive,
39 base::FilePath("drive-test-user-hash").Append(path));
40 }
41
35 private: 42 private:
36 content::TestBrowserThreadBundle thread_bundle_; 43 content::TestBrowserThreadBundle thread_bundle_;
37 TestingProfileManager testing_profile_manager_; 44 TestingProfileManager testing_profile_manager_;
38 }; 45 };
39 46
40 } // namespace 47 } // namespace
41 48
42 TEST(ExternalFileURLUtilTest, FilePathToExternalFileURL) { 49 TEST_F(ExternalFileURLUtilTest, FilePathToExternalFileURL) {
43 base::FilePath path; 50 storage::FileSystemURL url;
44 51 Profile* profile =
52 testing_profile_manager().CreateTestingProfile("test-user");
45 // Path with alphabets and numbers. 53 // Path with alphabets and numbers.
46 path = drive::util::GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); 54 url = CreateTestURL(base::FilePath("foo/bar012.txt"));
47 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); 55 EXPECT_EQ(url.virtual_path(),
56 ExternalFileURLToVirtualPath(profile,
57 FileSystemURLToExternalFileURL(url)));
48 58
49 // Path with symbols. 59 // Path with symbols.
50 path = drive::util::GetDriveMyDriveRootPath().AppendASCII( 60 url = CreateTestURL(base::FilePath(" !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~"));
51 " !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~"); 61 EXPECT_EQ(url.virtual_path(),
52 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); 62 ExternalFileURLToVirtualPath(profile,
63 FileSystemURLToExternalFileURL(url)));
53 64
54 // Path with '%'. 65 // Path with '%'.
55 path = drive::util::GetDriveMyDriveRootPath().AppendASCII("%19%20%21.txt"); 66 url = CreateTestURL(base::FilePath("%19%20%21.txt"));
56 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); 67 EXPECT_EQ(url.virtual_path(),
68 ExternalFileURLToVirtualPath(profile,
69 FileSystemURLToExternalFileURL(url)));
57 70
58 // Path with multi byte characters. 71 // Path with multi byte characters.
59 base::string16 utf16_string; 72 base::string16 utf16_string;
60 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO 73 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO
61 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE 74 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE
62 path = drive::util::GetDriveMyDriveRootPath().Append( 75 url = CreateTestURL(
63 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt")); 76 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt"));
64 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); 77 EXPECT_EQ(url.virtual_path().AsUTF8Unsafe(),
78 ExternalFileURLToVirtualPath(
79 profile, FileSystemURLToExternalFileURL(url)).AsUTF8Unsafe());
65 } 80 }
66 81
67 TEST(ExternalFileURLUtilTest, ParseFileURLWithExternalFileOrigin) { 82 TEST_F(ExternalFileURLUtilTest, ParseFileURLWithExternalFileOrigin) {
68 // filesystem:externalfile:/*** is used only internally. It should not parsed 83 // filesystem:externalfile:/xxx is used only internally. It should not parsed
69 // directly. 84 // directly.
70 ASSERT_FALSE(storage::FileSystemURL::CreateForTest( 85 ASSERT_FALSE(storage::FileSystemURL::CreateForTest(
71 GURL("filesystem:externalfile:/")).is_valid()); 86 GURL("filesystem:externalfile:/")).is_valid());
72 ASSERT_FALSE( 87 ASSERT_FALSE(
73 storage::FileSystemURL::CreateForTest( 88 storage::FileSystemURL::CreateForTest(
74 GURL("filesystem:externalfile:/external/drive/file.txt")).is_valid()); 89 GURL("filesystem:externalfile:/external/drive/file.txt")).is_valid());
75 } 90 }
76 91
77 } // namespace chromeos 92 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/fileapi/external_file_url_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698